Package org.apache.stanbol.commons.testing.http

Examples of org.apache.stanbol.commons.testing.http.RequestExecutor


        re.assertStatus(404);
    }
    private void testEntityDeleteAll() throws IOException {
        Request request = builder.buildOtherRequest(new HttpDelete(
            builder.buildUrl("/entityhub/entity", "id", "*")));
        RequestExecutor re = executor.execute(request);
        re.assertStatus(200);
    }
View Full Code Here


        // We won't test here if deletion succeeded.
    }

    @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");
    }
View Full Code Here

        RequestExecutor re = executor.execute(request);
        re.assertStatus(200);
    }
    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);
    }
View Full Code Here

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

    }
View Full Code Here

        }
        Assert.assertNotNull(f.isFile());
        ZipFile archive = new ZipFile(f);
        for(Enumeration<? extends ZipEntry> e = archive.entries();e.hasMoreElements();){
            ZipEntry entry = e.nextElement();
            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(status == 200 || status == 304);
        }
       
        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);

    }
View Full Code Here

                    "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);
        List<String> expected = resultList.subList(2, 4); //3rd and 4th element
        List<String> excluded = new ArrayList<String>(); //all other
View Full Code Here

    @Before
    public void waitForServerReady() throws Exception {
        // initialize instance request builder and HTTP client
        builder = new RequestBuilder(serverBaseUrl);
        httpClient = new DefaultHttpClient();
        executor = new RequestExecutor(httpClient);

        if (serverReady) {
            return;
        }
View Full Code Here

     * @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);

    }
View Full Code Here

     * @throws JSONException
     */
    @Test
    public void testRetrievel() throws IOException, JSONException {
        String id = "http://dbpedia.org/resource/Paris";
        RequestExecutor re = executor.execute(
            builder.buildGetRequest(SITES_MANAGER_PATH+"/entity",
                "id",id)
            .withHeader("Accept", "application/json"));
        re.assertStatus(200);
        //do not check for the site of the entity, because this might change
        JSONObject jEntity = assertEntity(re.getContent(), id, null);
        assertRepresentation(jEntity.getJSONObject("representation"),
            DBPEDIA_DEFAULTDATA_REQUIRED_FIELDS,
            DBPEDIA_DEFAULTDATA_OPTIONAL_FIELDS);
    }
View Full Code Here

     */
    @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\">",
            "<rdfs:label xml:lang=\"en\">Paris</rdfs:label>");
        //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);
    }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.commons.testing.http.RequestExecutor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.