Package org.mortbay.jetty.testing

Examples of org.mortbay.jetty.testing.HttpTester


    @Test
    public void testContentNegotiationForTurtleAlias() throws Exception {
        content = "<html><body><div class=\"vcard fn\">Joe</div></body></html>";
        acceptHeader = "application/x-turtle";
        HttpTester response = doGetRequest("/best/http://foo.com");
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("http://foo.com", requestedURI);
        assertContains("a vcard:VCard", response.getContent());
    }
View Full Code Here


    @Test
    public void testContentNegotiationForRDFXML() throws Exception {
        content = "<html><body><div class=\"vcard fn\">Joe</div></body></html>";
        acceptHeader = "application/rdf+xml";
        HttpTester response = doGetRequest("/best/http://foo.com");
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("http://foo.com", requestedURI);
        assertContains("<rdf:RDF", response.getContent());
    }
View Full Code Here

    @Test
    public void testContentNegotiationForNTriples() throws Exception {
        content = "<html><body><div class=\"vcard fn\">Joe</div></body></html>";
        acceptHeader = "text/plain";
        HttpTester response = doGetRequest("/best/http://foo.com");
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("http://foo.com", requestedURI);
        assertContains("<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>", response.getContent());
    }
View Full Code Here

    public void testResponseWithReport() throws Exception {
        content = new FileDocumentSource(
                new File("src/test/resources/org/apache/any23/servlet/missing-og-namespace.html")
        ).readStream();
        acceptHeader = "text/plain";
        HttpTester response = doGetRequest("/best/http://foo.com?validation-mode=validate-fix&report=on");
        Assert.assertEquals(200, response.getStatus());
        final String content = response.getContent();
        assertContainsTag("response"        , content);
        assertContainsTag("extractors"      , content);
        assertContainsTag("report"          , content);
        assertContainsTag("message", true, 1 , content);
        assertContainsTag("error"  , true, 1 , content);
View Full Code Here

    }

    @Test
    public void testJSONResponseFormat() throws Exception {
        String body = "<http://sub/1> <http://pred/1> \"123\"^^<http://datatype> <http://graph/1>.";
        HttpTester response = doPostRequest("/json", body, "text/n-quads");
        Assert.assertEquals(200, response.getStatus());
        final String EXPECTED_JSON =
                "[" +
                "{ \"type\" : \"uri\", \"value\" : \"http://sub/1\"}, " +
                "\"http://pred/1\", " +
                "{\"type\" : \"literal\", \"value\" : \"123\", \"lang\" : null, \"datatype\" : \"http://datatype\"}, " +
                "\"http://graph/1\"" +
                "]";
        assertContains(EXPECTED_JSON, response.getContent());
    }
View Full Code Here

    }

    @Test
    public void testTriXResponseFormat() throws Exception {
        String body = "<http://sub/1> <http://pred/1> \"123\"^^<http://datatype> <http://graph/1>.";
        HttpTester response = doPostRequest("/trix", body, "text/n-quads");
        Assert.assertEquals(200, response.getStatus());
        final String content = response.getContent();
        assertContainsTag("graph" , false, 1, content);
        assertContainsTag("uri"   , false, 3, content);
        assertContainsTag("triple", false, 1, content);
    }
View Full Code Here

    private HttpTester doGetRequest(String path) throws Exception {
        return doRequest(path, "GET");
    }

    private HttpTester doPostRequest(String path, String content, String contentType) throws Exception {
        HttpTester response = new HttpTester();
        HttpTester request = new HttpTester();

        request.setMethod("POST");
        request.setVersion("HTTP/1.0");
        request.setHeader("Host", "tester");
        request.setContent(content);
        if (contentType != null) {
            request.setHeader("Content-Type", contentType);
        }
        request.setURI(path);
        response.parse(tester.getResponses(request.generate()));
        return response;
    }
View Full Code Here

        response.parse(tester.getResponses(request.generate()));
        return response;
    }

    private HttpTester doRequest(String path, String method) throws Exception {
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();

        request.setMethod(method);
        request.setVersion("HTTP/1.0");
        request.setHeader("Host", "tester");
        if (acceptHeader != null) {
            request.setHeader("Accept", acceptHeader);
        }

        request.setURI(path);
        response.parse(tester.getResponses(request.generate()));
        return response;
    }
View Full Code Here

        tester = null;
    }

    @Test
    public void testGETOnlyFormat() throws Exception {
        HttpTester response = doGetRequest("/xml");
        Assert.assertEquals(404, response.getStatus());
        assertContains("Missing URI", response.getContent());
    }
View Full Code Here

        assertContains("Missing URI", response.getContent());
    }

    @Test
    public void testGETWrongFormat() throws Exception {
        HttpTester response = doGetRequest("/dummy/foo.com");
        Assert.assertEquals(400, response.getStatus());
        assertContains("Invalid format", response.getContent());
    }
View Full Code Here

TOP

Related Classes of org.mortbay.jetty.testing.HttpTester

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.