Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix tests
  • Loading branch information
cbeer committed May 15, 2013
1 parent efaf799 commit 2d9582a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
Expand Up @@ -11,6 +11,9 @@
import java.util.Collection;
import java.util.Date;

import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.update.GraphStore;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
Expand Down Expand Up @@ -188,12 +191,13 @@ public void testMultipleDatastreams() throws Exception {

final HttpGet getDSesMethod =
new HttpGet(serverAddress +
"objects/FedoraDatastreamsTest7/fcr:children?mixin=" + FedoraJcrTypes.FEDORA_DATASTREAM);
"objects/FedoraDatastreamsTest7");
final HttpResponse response = client.execute(getDSesMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
Collection<String> result = TestHelpers.parseChildren(response.getEntity());
assertTrue("Didn't find the first datastream! ", result.contains("ds1"));
assertTrue("Didn't find the second datastream! ", result.contains("ds2"));
GraphStore result = TestHelpers.parseTriples(response.getEntity().getContent());
logger.warn(result.toString());
assertTrue("Didn't find the first datastream! ", result.contains(Node.ANY, Node.createURI("info:fedora/objects/FedoraDatastreamsTest7"), Node.ANY, Node.createURI("info:fedora/objects/FedoraDatastreamsTest7/ds1")));
assertTrue("Didn't find the second datastream! ", result.contains(Node.ANY, Node.createURI("info:fedora/objects/FedoraDatastreamsTest7"), Node.ANY, Node.createURI("info:fedora/objects/FedoraDatastreamsTest7/ds2")));
}

@Test
Expand Down Expand Up @@ -223,17 +227,15 @@ public void testModifyMultipleDatastreams() throws Exception {

final HttpGet getDSesMethod =
new HttpGet(serverAddress +
"objects/FedoraDatastreamsTest8/fcr:datastreams");
"objects/FedoraDatastreamsTest8");
final HttpResponse response = client.execute(getDSesMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
final String content = EntityUtils.toString(response.getEntity());
assertTrue("Didn't find the first datastream!", compile("dsid=\"ds1\"",
DOTALL).matcher(content).find());
assertTrue("Didn't find the second datastream!", compile(
"dsid=\"ds2\"", DOTALL).matcher(content).find());

assertFalse("Found the deleted datastream!", compile(
"dsid=\"ds_void\"", DOTALL).matcher(content).find());
GraphStore result = TestHelpers.parseTriples(response.getEntity().getContent());
assertTrue("Didn't find the first datastream! ", result.contains(Node.ANY, Node.createURI("info:fedora/objects/FedoraDatastreamsTest8"), Node.ANY, Node.createURI("info:fedora/objects/FedoraDatastreamsTest8/ds1")));
assertTrue("Didn't find the second datastream! ", result.contains(Node.ANY, Node.createURI("info:fedora/objects/FedoraDatastreamsTest8"), Node.ANY, Node.createURI("info:fedora/objects/FedoraDatastreamsTest8/ds2")));
assertFalse("Found the deleted datastream! ", result.contains(Node.ANY, Node.createURI("info:fedora/objects/FedoraDatastreamsTest8"), Node.ANY, Node.createURI("info:fedora/objects/FedoraDatastreamsTest8/ds_void")));


}

Expand Down
Expand Up @@ -5,12 +5,15 @@
import static java.util.regex.Pattern.compile;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.TEXT_XML;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Collection;
import java.util.regex.Matcher;

import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.update.GraphStore;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils;
Expand Down Expand Up @@ -122,18 +125,15 @@ public void testDescribeSize() throws Exception {
*/
@Test
public void testGetProjectedNode() throws Exception {
HttpGet method = new HttpGet(serverAddress + "files/FileSystem1/fcr:children?mixin=" + FedoraJcrTypes.FEDORA_OBJECT);
HttpGet method = new HttpGet(serverAddress + "files/FileSystem1");
HttpResponse response = execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
Collection<String> childNames = TestHelpers.parseChildren(response.getEntity());
assertEquals(1, childNames.size());
assertEquals("TestSubdir", childNames.iterator().next());
method = new HttpGet(serverAddress + "files/FileSystem1/fcr:children?mixin=" + FedoraJcrTypes.FEDORA_DATASTREAM);
response = execute(method);
childNames = TestHelpers.parseChildren(response.getEntity());
assertEquals(2, childNames.size());
assertTrue(childNames.contains("ds1"));
assertTrue(childNames.contains("ds2"));

GraphStore result = TestHelpers.parseTriples(response.getEntity().getContent());
assertTrue("Didn't find the first datastream! ", result.contains(Node.ANY, Node.createURI("info:fedora/files/FileSystem1"), Node.ANY, Node.createURI("info:fedora/files/FileSystem1/ds1")));
assertTrue("Didn't find the second datastream! ", result.contains(Node.ANY, Node.createURI("info:fedora/files/FileSystem1"), Node.ANY, Node.createURI("info:fedora/files/FileSystem1/ds2")));
assertTrue("Didn't find the first object! ", result.contains(Node.ANY, Node.createURI("info:fedora/files/FileSystem1"), Node.ANY, Node.createURI("info:fedora/files/FileSystem1/TestSubdir")));

}

}
Expand Up @@ -34,6 +34,10 @@
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.update.GraphStore;
import com.hp.hpl.jena.update.GraphStoreFactory;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils;
Expand Down Expand Up @@ -252,4 +256,14 @@ public static Datastream mockDatastream(final String pid,
}
return mockDs;
}

public static GraphStore parseTriples(final InputStream content) {
final Model model = ModelFactory.createDefaultModel();

model.read(content, "", "N3");


return GraphStoreFactory.create(model);

}
}

0 comments on commit 2d9582a

Please sign in to comment.