Search in sources :

Example 6 with RequestExecutor

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");
}
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 7 with RequestExecutor

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);
}
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)

Example 8 with RequestExecutor

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);
}
Also used : FindQueryTestCase(org.apache.stanbol.entityhub.test.query.FindQueryTestCase) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) ArrayList(java.util.ArrayList)

Example 9 with RequestExecutor

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);
}
Also used : ZipFile(java.util.zip.ZipFile) HttpDelete(org.apache.http.client.methods.HttpDelete) ZipEntry(java.util.zip.ZipEntry) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) URISyntaxException(java.net.URISyntaxException) ZipFile(java.util.zip.ZipFile) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 10 with RequestExecutor

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);
}
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