use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.
the class EntityhubTest method testEntityUpdate.
private void testEntityUpdate() throws IOException, JSONException {
InputStream in = EntityhubTest.class.getClassLoader().getResourceAsStream("mod_doap_Stanbol.rdf");
Assert.assertNotNull("Unable to load test resource 'mod_doap_Stanbol.rdf'", in);
String stanbolProjectUri = "http://stanbol.apache.org";
//create a POST request with a test RDF file
RequestExecutor test = executor.execute(buildImportRdfData(in, RDF_XML, false, stanbolProjectUri));
//assert that the entity was created
test.assertStatus(200);
//check that the updated entity was returned
assertEntity(test.getContent(), stanbolProjectUri, "entityhub");
}
use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.
the class ScopeTest method testActive.
@Test
public void testActive() throws Exception {
RequestExecutor request;
String tempActiveScopeUri = BASE_SCOPES_URI + "/" + getClass().getCanonicalName() + "-testActive-" + System.currentTimeMillis() + "-active";
String tempInactiveScopeUri = BASE_SCOPES_URI + "/" + getClass().getCanonicalName() + "-testActive-" + System.currentTimeMillis() + "-inactive";
// Scopes should not be there
request = executor.execute(builder.buildGetRequest(tempActiveScopeUri).withHeader("Accept", KRFormat.TURTLE));
request.assertStatus(404);
log.info("Request: " + tempActiveScopeUri + " (should return 404) ... DONE");
request = executor.execute(builder.buildGetRequest(tempInactiveScopeUri).withHeader("Accept", KRFormat.TURTLE));
request.assertStatus(404);
log.info("Request: " + tempInactiveScopeUri + " (should return 404) ... DONE");
// Create scopes, only activate one
executor.execute(builder.buildOtherRequest(new HttpPut(builder.buildUrl(tempActiveScopeUri + "?activate=true"))));
log.info("PUT Request: " + tempActiveScopeUri + " ... DONE");
executor.execute(builder.buildOtherRequest(new HttpPut(builder.buildUrl(tempInactiveScopeUri))));
log.info("PUT Request: " + tempInactiveScopeUri + " ... DONE");
// By default, we should only see the active scope
executor.execute(builder.buildGetRequest(BASE_SCOPES_URI).withHeader("Accept", KRFormat.TURTLE)).assertStatus(200).assertContentRegexp(false, tempInactiveScopeUri + ">\\s+rdf:type\\s+<" + URI_SCOPE_CLASS + ">").assertContentRegexp(true, tempActiveScopeUri + ">\\s+rdf:type\\s+<" + URI_SCOPE_CLASS + ">");
log.info("Request: " + BASE_SCOPES_URI + " ... DONE");
// Using with-inactive we should see both scopes
executor.execute(builder.buildGetRequest(BASE_SCOPES_URI + "?with-inactive=true").withHeader("Accept", KRFormat.TURTLE)).assertStatus(200).assertContentRegexp(true, tempInactiveScopeUri + ">\\s+rdf:type\\s+<" + URI_SCOPE_CLASS + ">").assertContentRegexp(true, tempActiveScopeUri + ">\\s+rdf:type\\s+<" + URI_SCOPE_CLASS + ">");
log.info("Request: " + BASE_SCOPES_URI + " ... DONE");
// Delete scopes
executor.execute(builder.buildOtherRequest(new HttpDelete(builder.buildUrl(tempActiveScopeUri))));
log.info("DELETE Request: " + tempActiveScopeUri + " ... DONE");
executor.execute(builder.buildOtherRequest(new HttpDelete(builder.buildUrl(tempInactiveScopeUri))));
log.info("DELETE Request: " + tempInactiveScopeUri + " ... DONE");
// We won't test here if deletion succeeded.
}
use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.
the class EntityhubTest method testEntityLookup.
@Test
public void testEntityLookup() throws IOException, JSONException {
String uri = "http://dbpedia.org/resource/Paris";
//first check that lookup without create returns 404
RequestExecutor re = executor.execute(builder.buildGetRequest("/entityhub/lookup", "id", uri));
re.assertStatus(404);
//Now check that lookup with create does work
re = executor.execute(builder.buildGetRequest("/entityhub/lookup", "id", uri, "create", "true"));
re.assertStatus(200);
JSONObject entity = assertEntity(re.getContent(), null, "entityhub");
String ehUri = entity.optString("id", null);
//try to retrieve the entity with the generated id
re = executor.execute(builder.buildGetRequest("/entityhub/entity", "id", ehUri));
re.assertStatus(200);
assertEntity(re.getContent(), ehUri, "entityhub");
//no try again to lookup the entity without create
re = executor.execute(builder.buildGetRequest("/entityhub/lookup", "id", uri));
re.assertStatus(200);
assertEntity(re.getContent(), ehUri, "entityhub");
//finally delete the entity
re = executor.execute(builder.buildOtherRequest(new HttpDelete(builder.buildUrl("/entityhub/entity", "id", ehUri))));
re.assertStatus(200);
}
use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.
the class ReferencedSiteTest method testRetrievel.
/**
* Tests retrieval of Entities
* @throws IOException
* @throws JSONException
*/
@Test
public void testRetrievel() throws IOException, JSONException {
String id = "http://dbpedia.org/resource/Paris";
RequestExecutor re = executor.execute(builder.buildGetRequest(DBPEDIA_SITE_PATH + "/entity", "id", id).withHeader("Accept", "application/json"));
re.assertStatus(200);
JSONObject jEntity = assertEntity(re.getContent(), id, DBPEDIA_SITE_ID);
assertRepresentation(jEntity.getJSONObject("representation"), DBPEDIA_DEFAULTDATA_REQUIRED_FIELDS, DBPEDIA_DEFAULTDATA_OPTIONAL_FIELDS);
}
use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.
the class EntityhubTest method testEntityDeleted.
private void testEntityDeleted() throws IOException {
String id = "http://stanbol.apache.org";
RequestExecutor re = executor.execute(builder.buildGetRequest("/entityhub/entity", "id", id).withHeader("Accept", "application/json"));
re.assertStatus(404);
}
Aggregations