use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.
the class ScopeTest method testCRUD.
@Test
public void testCRUD() throws Exception {
RequestExecutor request;
// The needed Web resources to GET from.
executor.execute(builder.buildGetRequest(BASE_SCOPES_URI).withHeader("Accept", KRFormat.TURTLE)).assertStatus(200);
log.info("Request: " + BASE_SCOPES_URI + " ... DONE");
String tempScopeUri = BASE_SCOPES_URI + "/" + getClass().getCanonicalName() + "-" + System.currentTimeMillis();
// Scope should not be there
request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
request.assertStatus(404);
log.info("Request: " + tempScopeUri + " (should return 404) ... DONE");
// Create scope
executor.execute(builder.buildOtherRequest(new HttpPut(builder.buildUrl(tempScopeUri))));
log.info("PUT Request: " + tempScopeUri + " ... DONE");
// Scope should be there now
request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
request.assertStatus(200).assertContentContains(tempScopeUri);
log.info("Request: " + tempScopeUri + " ... DONE");
// TODO the U of CRUD
// Delete scope
executor.execute(builder.buildOtherRequest(new HttpDelete(builder.buildUrl(tempScopeUri))));
log.info("DELETE Request: " + tempScopeUri + " ... DONE");
// Scope should not be there
request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
request.assertStatus(404);
log.info("Request: " + tempScopeUri + " (should return 404) ... DONE");
}
use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.
the class EntityhubTest method testEntityDelete.
private void testEntityDelete() throws IOException {
String stanbolProjectUri = "http://stanbol.apache.org";
Request request = builder.buildOtherRequest(new HttpDelete(builder.buildUrl("/entityhub/entity", "id", stanbolProjectUri)));
RequestExecutor re = executor.execute(request);
re.assertStatus(200);
}
use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.
the class EntityhubTest method testFindLimitAndOffsetQuery.
private void testFindLimitAndOffsetQuery() throws IOException, JSONException {
//With Solr4 we need a test that produces different scores for results,
//to ensure consistant odering
FindQueryTestCase test = new FindQueryTestCase("XML XSL*", Arrays.asList("http://velocity.apache.org/anakia/", "http://xalan.apache.org/xalan-c/", "http://xalan.apache.org/xalan-j/", "http://velocity.apache.org/dvsl/devel/", "http://xmlgraphics.apache.org/commons/", "http://xmlgraphics.apache.org/fop"), null);
test.setField("http://usefulinc.com/ns/doap#description");
test.setLimit(10);
test.setLanguage(null);
RequestExecutor re = executeQuery(test);
//get the list of results (will assert the response twice)
//to check the expected limit and offset results
List<String> resultList = assertQueryResults(re, test);
//3rd and 4th element
List<String> expected = resultList.subList(2, 4);
//all other
List<String> excluded = new ArrayList<String>();
excluded.addAll(resultList.subList(0, 2));
excluded.addAll(resultList.subList(4, resultList.size()));
//repeat the test with offset 2 and limit 2 to only retrieve the 3-4 result
test = new FindQueryTestCase("XML XSL*", expected, excluded);
test.setField("http://usefulinc.com/ns/doap#description");
test.setOffset(2);
test.setLimit(2);
test.setLanguage(null);
executeQuery(test);
}
use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.
the class EntityhubTest method testQueries.
@Test
public void testQueries() throws IOException, JSONException {
//first load the data for the rquery test
URL url = EntityhubTest.class.getClassLoader().getResource("apache-project-doap-files.zip");
Assert.assertNotNull(url);
File f;
try {
f = new File(url.toURI());
} catch (URISyntaxException e) {
f = new File(url.getPath());
}
Assert.assertNotNull(f.isFile());
ZipFile archive = new ZipFile(f);
try {
for (Enumeration<? extends ZipEntry> e = archive.entries(); e.hasMoreElements(); ) {
ZipEntry entry = e.nextElement();
log.debug(" - uploading {} to entityhub", entry);
RequestExecutor re = executor.execute(buildImportRdfData(archive.getInputStream(entry), RDF_XML, false, null));
//assert that the entity was created (or already existed)
//some projects seams to have more than a single doap file
int status = re.getResponse().getStatusLine().getStatusCode();
Assert.assertTrue("Unable to add '" + entry.getName() + "'! Status:" + re.getResponse().getStatusLine(), status == 200 || status == 304);
}
} finally {
archive.close();
}
testFindNameQuery();
testFindWildcards();
testFindLimitAndOffsetQuery();
testFieldQueryTextConstraints();
//finally delete all added entity
RequestExecutor re = executor.execute(builder.buildOtherRequest(new HttpDelete(builder.buildUrl("/entityhub/entity", "id", "*"))));
re.assertStatus(200);
}
use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.
the class EntityhubTest method testAllEntitiesDeleted.
private void testAllEntitiesDeleted() throws IOException {
String id = "http://xml.apache.org/xerces-c/";
RequestExecutor re = executor.execute(builder.buildGetRequest("/entityhub/entity", "id", id).withHeader("Accept", "application/json"));
re.assertStatus(404);
}
Aggregations