Skip to content

Commit

Permalink
Minor test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Jul 9, 2015
1 parent 5a2bfc6 commit 501b6ba
Showing 1 changed file with 25 additions and 33 deletions.
Expand Up @@ -38,8 +38,9 @@
import javax.jcr.Session;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import static java.util.Objects.requireNonNull;
import static java.util.UUID.randomUUID;
import static org.fcrepo.kernel.RdfLexicon.REPOSITORY_NAMESPACE;
import static org.junit.Assert.assertFalse;
Expand All @@ -51,6 +52,7 @@
*
* @author cbeer
* @author ajs6f
* @author awoods
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/spring-test/master.xml"})
Expand All @@ -66,60 +68,50 @@ public class SparqlQueryTransformIT extends AbstractResourceIT {
private SparqlQueryTransform testObj;

@Test
public void testQueryPrimaryType() throws RepositoryException {
Session session = null;
public void testQueryPrimaryType() throws RepositoryException, IOException {
final Session session = repo.login();
try {
session = repo.login();

final Container object = containerService.findOrCreate(session, "/testObject-" + randomUUID());

final String s = "SELECT ?x ?type\n" +
"WHERE { ?x <" + REPOSITORY_NAMESPACE + "primaryType> ?type }";
final InputStream stringReader = new ByteArrayInputStream(s.getBytes());
try (final InputStream stringReader = new ByteArrayInputStream(s.getBytes())) {

testObj = new SparqlQueryTransform(stringReader);
testObj = new SparqlQueryTransform(stringReader);

final RdfStream stream = object.getTriples(new DefaultIdentifierTranslator(session),
PropertiesRdfContext.class);
try (final QueryExecution qexec = testObj.apply(stream)) {
assert (qexec != null);
final ResultSet results = qexec.execSelect();
assert (results != null);
assertTrue(results.hasNext());
final RdfStream stream = object.getTriples(new DefaultIdentifierTranslator(session),
PropertiesRdfContext.class);
try (final QueryExecution qexec = testObj.apply(stream)) {
final ResultSet results = requireNonNull(qexec).execSelect();
assertTrue(requireNonNull(results).hasNext());
}
}
} finally {
if (null != session) {
session.logout();
}
session.logout();
}
}

@Test
public void testQueryNoUUID() throws RepositoryException {
Session session = null;
public void testQueryNoUUID() throws RepositoryException, IOException {
final Session session = repo.login();
try {
session = repo.login();

final Container object = containerService.findOrCreate(session, "/testObject-" + randomUUID());

final String s = "SELECT ?x ?uuid\n" +
"WHERE { ?x <" + REPOSITORY_NAMESPACE + "uuid> ?uuid }";
final InputStream stringReader = new ByteArrayInputStream(s.getBytes());
try (final InputStream stringReader = new ByteArrayInputStream(s.getBytes())) {

testObj = new SparqlQueryTransform(stringReader);
testObj = new SparqlQueryTransform(stringReader);

final RdfStream stream = object.getTriples(new DefaultIdentifierTranslator(session),
PropertiesRdfContext.class);
try (final QueryExecution qexec = testObj.apply(stream)) {
assert (qexec != null);
final ResultSet results = qexec.execSelect();
assert (results != null);
assertFalse(results.hasNext());
final RdfStream stream = object.getTriples(new DefaultIdentifierTranslator(session),
PropertiesRdfContext.class);
try (final QueryExecution qexec = testObj.apply(stream)) {
final ResultSet results = requireNonNull(qexec).execSelect();
assertFalse(requireNonNull(results).hasNext());
}
}
} finally {
if (null != session) {
session.logout();
}
session.logout();
}
}
}

0 comments on commit 501b6ba

Please sign in to comment.