Search in sources :

Example 21 with RequestExecutor

use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.

the class HttpQueryHeaderGetTest method testGetAccept.

/**
     * Validates that parsing rdf+xml normally as Accept header and that
     * JSON is the default if no header is parsed. 
     * NOTE: This does not actually test the http query header, but checks 
     * the assumptions behind all the following tests.
     * @throws IOException
     * @throws JSONException 
     */
@Test
public void testGetAccept() throws IOException, JSONException {
    //first a normal request with application/rdf+xml
    String id = "http://dbpedia.org/resource/Paris";
    RequestExecutor re = executor.execute(builder.buildGetRequest(DBPEDIA_SITE_PATH + "/entity", "id", id).withHeader("Accept", "application/rdf+xml"));
    re.assertStatus(200);
    re.assertContentType("application/rdf+xml");
    re.assertContentContains("<rdf:Description rdf:about=\"http://dbpedia.org/resource/Paris\">", "<rdf:type rdf:resource=\"http://dbpedia.org/ontology/Place\"/>");
    //now test the default Accept
    re = executor.execute(builder.buildGetRequest(DBPEDIA_SITE_PATH + "/entity", "id", id));
    re.assertContentType("application/json");
    re.assertStatus(200);
    assertEntity(re.getContent(), id, DBPEDIA_SITE_ID);
}
Also used : RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) Test(org.junit.Test)

Example 22 with RequestExecutor

use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.

the class EntityhubTest method testEntityCreated.

private void testEntityCreated() throws IOException, JSONException {
    String id = "http://stanbol.apache.org";
    RequestExecutor re = executor.execute(builder.buildGetRequest("/entityhub/entity", "id", id).withHeader("Accept", "application/json"));
    re.assertStatus(200);
    JSONObject jEntity = assertEntity(re.getContent(), id, "entityhub");
    Map<String, Set<List<String>>> data = assertRepresentation(jEntity.getJSONObject("representation"), EXPECTED_DOAP_FIELDS, null);
    //test values of two properties we will update in a following test
    Set<List<String>> pmcValues = data.get("http://projects.apache.org/ns/asfext#pmc");
    Assert.assertNotNull(pmcValues);
    Assert.assertEquals(1, pmcValues.size());
    Assert.assertEquals("http://incubator.apache.org", pmcValues.iterator().next().get(0));
    Set<List<String>> downloadValues = data.get("http://usefulinc.com/ns/doap#download-page");
    Assert.assertNotNull(downloadValues);
    Assert.assertEquals(1, downloadValues.size());
    Assert.assertEquals("http://stanbol.apache.org", downloadValues.iterator().next().get(0));
}
Also used : Set(java.util.Set) JSONObject(org.codehaus.jettison.json.JSONObject) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 23 with RequestExecutor

use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.

the class EntityhubTest method testEntityCreation.

private void testEntityCreation() throws IOException {
    InputStream in = EntityhubTest.class.getClassLoader().getResourceAsStream("doap_Stanbol.rdf");
    Assert.assertNotNull("Unable to load test resource '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, true, stanbolProjectUri));
    //assert that the entity was created
    test.assertStatus(201);
}
Also used : InputStream(java.io.InputStream) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor)

Example 24 with RequestExecutor

use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.

the class EntityhubTest method testEntityUpdated.

private void testEntityUpdated() throws IOException, JSONException {
    String id = "http://stanbol.apache.org";
    RequestExecutor re = executor.execute(builder.buildGetRequest("/entityhub/entity", "id", id).withHeader("Accept", "application/json"));
    re.assertStatus(200);
    JSONObject jEntity = assertEntity(re.getContent(), id, "entityhub");
    Map<String, Set<List<String>>> data = assertRepresentation(jEntity.getJSONObject("representation"), EXPECTED_DOAP_FIELDS, null);
    Set<List<String>> pmcValues = data.get("http://projects.apache.org/ns/asfext#pmc");
    Assert.assertNotNull(pmcValues);
    Assert.assertEquals(1, pmcValues.size());
    Assert.assertEquals("http://stanbol.apache.org", pmcValues.iterator().next().get(0));
    Set<List<String>> downloadValues = data.get("http://usefulinc.com/ns/doap#download-page");
    Assert.assertNotNull(downloadValues);
    Assert.assertEquals(1, downloadValues.size());
    Assert.assertEquals("http://stanbol.apache.org/downloads/", downloadValues.iterator().next().get(0));
}
Also used : Set(java.util.Set) JSONObject(org.codehaus.jettison.json.JSONObject) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 25 with RequestExecutor

use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.

the class EntityhubTest method testEntityDeleteAll.

private void testEntityDeleteAll() throws IOException {
    Request request = builder.buildOtherRequest(new HttpDelete(builder.buildUrl("/entityhub/entity", "id", "*")));
    RequestExecutor re = executor.execute(request);
    re.assertStatus(200);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) Request(org.apache.stanbol.commons.testing.http.Request) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) 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