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

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


            this.request = request;
            this.tracker = tracker;
        }
        @Override
        public void run() {
            RequestExecutor executor = new RequestExecutor(pooledHttpClient);
            long start = System.currentTimeMillis();
            Long rtt;
            try {
                executor.execute(request).assertStatus(200);
                content = null; //do not store content for successfull resutls
                rtt = System.currentTimeMillis()-start;
            } catch (Throwable e) {
                log.warn("Error while sending Request ",e);
                tracker.failed(request,content,executor);
                rtt = null;
                return;
            }
            IndexedMGraph graph = new IndexedMGraph();
            try {
                rdfParser.parse(graph,executor.getStream(), executor.getContentType().getMimeType());
            } catch (Exception e) {
                log.warn("Exception while parsing Enhancement Response",e);
                tracker.failed(request, content, executor);
                return;
            }
            Iterator<Triple> ciIt = graph.filter(null, Properties.ENHANCER_EXTRACTED_FROM, null);
            Assert.assertTrue("Enhancement Results do not caontain a single Enhancement",ciIt.hasNext());
            Resource contentItemUri = ciIt.next().getObject();
            Assert.assertTrue("ContentItem URI is not an UriRef but an instance of "
                    + contentItemUri.getClass().getSimpleName(), contentItemUri instanceof UriRef);
            tracker.succeed(request, (UriRef) contentItemUri, graph, rtt, executor.getContent().length());
        }
View Full Code Here


        return " %$&+,/:;=?@<>#%".indexOf(ch) >= 0;
    }

    @Test
    public void testCRUD() throws Exception {
        RequestExecutor request;

        // The needed Web resources to GET from.
        executor.execute(builder.buildGetRequest(SESSION_URI).withHeader("Accept", KRFormat.TURTLE))
                .assertStatus(200);
        log.info("Request: " + SESSION_URI + " ... DONE");

        String tempScopeUri = SESSION_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

    @Test
    public void testRemovalOfAccept() throws IOException, JSONException {
        //now test the removal of headers
        //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,
                "header_Accept","") //empty value to remove
            .withHeader("Accept", "application/rdf+xml")); //MUST override the rdf+xml
        re.assertStatus(200);
        //The default format (JSON) is expected
        assertEntity(re.getContent(), id, DBPEDIA_SITE_ID);
    }
View Full Code Here

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

        test.assertStatus(201);
    }

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

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

        assertEntity(test.getContent(), stanbolProjectUri, "entityhub");
    }

    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());
View Full Code Here

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

        return " %$&+,/:;=?@<>#%".indexOf(ch) >= 0;
    }

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

        re.assertStatus(200);
    }

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