Search in sources :

Example 26 with RequestExecutor

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");
}
Also used : InputStream(java.io.InputStream) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor)

Example 27 with RequestExecutor

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.
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 28 with RequestExecutor

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);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) HttpDelete(org.apache.http.client.methods.HttpDelete) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) Test(org.junit.Test)

Example 29 with RequestExecutor

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);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) DbpediaQueryTest(org.apache.stanbol.entityhub.it.query.DbpediaQueryTest) Test(org.junit.Test)

Example 30 with RequestExecutor

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);
}
Also used : RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor)

Aggregations

RequestExecutor (org.apache.stanbol.commons.testing.http.RequestExecutor)31 Test (org.junit.Test)18 JSONObject (org.codehaus.jettison.json.JSONObject)12 HttpDelete (org.apache.http.client.methods.HttpDelete)7 ArrayList (java.util.ArrayList)4 Request (org.apache.stanbol.commons.testing.http.Request)4 JSONArray (org.codehaus.jettison.json.JSONArray)4 HttpPut (org.apache.http.client.methods.HttpPut)3 InputStream (java.io.InputStream)2 List (java.util.List)2 Set (java.util.Set)2 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)2 DbpediaQueryTest (org.apache.stanbol.entityhub.it.query.DbpediaQueryTest)2 Before (org.junit.Before)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 TreeSet (java.util.TreeSet)1 ZipEntry (java.util.zip.ZipEntry)1