Package org.apache.abdera.protocol.client

Examples of org.apache.abdera.protocol.client.ClientResponse


        RequestOptions opts = new RequestOptions();
        String contentType = "application/atom+xml; type=entry";
        opts.setContentType(contentType);
        IRI colUri = new IRI(providerURI).resolve("customer");
        ClientResponse res = client.post(colUri.toString(), entry, opts);

        // Feed request with predicates
        opts = new RequestOptions();
        contentType = "application/atom+xml";
        opts.setContentType(contentType);
        opts.setHeader( "If-None-Match", eTag);

        res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            // Should return 304 - Feed not provided since it matches ETag.
            Assert.assertEquals(304, res.getStatus());
            // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", "   ", res );
            // System.out.println("Feed response content:");
            // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
        } finally {
            res.release();
        }
    }   
View Full Code Here


        RequestOptions opts = new RequestOptions();
        final String contentType = "application/atom+xml";
        opts.setContentType(contentType);
        opts.setHeader( "If-Match", eTag);

        ClientResponse res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            String thisETag = res.getHeader("ETag");
            Assert.assertNotNull( thisETag );
            Date thisLastModified = res.getLastModified();
            Assert.assertNotNull( thisLastModified );

            // Should return 200 - value since feed is changed
            Assert.assertEquals(200, res.getStatus());
            Assert.assertEquals(ResponseType.SUCCESS, res.getType());

            // AtomTestCaseUtils.printResponseHeaders( "Feed modified if-none-match response headers:", "   ", res );
            // System.out.println("Feed response content:");
            // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
        } finally {
            res.release();
        }
    }   
View Full Code Here

        RequestOptions opts = new RequestOptions();
        final String contentType = "application/atom+xml";
        opts.setContentType(contentType);
        opts.setHeader( "If-Unmodified-Since", dateFormat.format( new Date() ));

        ClientResponse res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            // Should return 304 - Feed not provided since feed is modified since.     
            Assert.assertEquals(304, res.getStatus());
        } finally {
            res.release();
        }
    }   
View Full Code Here

        RequestOptions opts = new RequestOptions();
        final String contentType = "application/atom+xml";
        opts.setContentType(contentType);
        opts.setHeader( "If-Modified-Since", dateFormat.format( lastModified ));

        ClientResponse res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            // Should return 200 - Feed provided since feed is changed.
            Assert.assertEquals(200, res.getStatus());
            Assert.assertEquals(ResponseType.SUCCESS, res.getType());

            String thisETag = res.getHeader("ETag");
            Assert.assertNotNull( thisETag );
            Date thisLastModified = res.getLastModified();
            Assert.assertNotNull( thisLastModified );                       
        } finally {
            res.release();
        }
    }   
View Full Code Here

        final String contentType = "application/atom+xml; type=entry";
        opts.setContentType(contentType);
        // AtomTestCaseUtils.printRequestHeaders( "Post request headers", "   ", opts );
        IRI colUri = new IRI(providerURI).resolve("customer");
        // res = client.post(colUri.toString() + "?test=foo", entry, opts);
        ClientResponse res = client.post(colUri.toString(), entry, opts);

        // Assert response status code is 201-OK.
        // Assert response header Content-Type: application/atom+xml; charset=UTF-8
        Assert.assertEquals(201, res.getStatus());
        String returnedContentType = res.getContentType().toString().trim();
        Assert.assertEquals(contentType, returnedContentType );

        String eTag = res.getHeader( "ETag" );
        if ( eTag != null)
            lastId = eTag.substring( 1, eTag.length()-1);

        // AtomTestCaseUtils.printResponseHeaders( "Entry post response headers:", "   ", res );
        // System.out.println("Entry post response content:");
View Full Code Here

        //System.out.println(">>>ContentNegotiationTest.testXMLEntryGet");
        RequestOptions opts = new RequestOptions();
        opts.setHeader( "Accept", "application/atom+xml" );

        IRI colUri = new IRI(providerURI).resolve("customer");
        ClientResponse res = client.get(colUri.toString() + "/" + lastId, opts);
        Assert.assertEquals(200, res.getStatus());
        String returnedContentType = res.getContentType().toString().trim();
        // Assert.assertEquals(contentType, returnedContentType );
        res.release();     
    }
View Full Code Here

        //System.out.println(">>>ContentNegotiationTest.testJSONEntryGet");
        RequestOptions opts = new RequestOptions();
        opts.setHeader( "Accept", "application/json" );

        IRI colUri = new IRI(providerURI).resolve("customer");
        ClientResponse res = client.get(colUri.toString() + "/" + lastId, opts);
        try {
            Assert.assertEquals(200, res.getStatus());
            // Abdera 0.4 throws exception on getContentType with application/json.     
            // System.out.println( "ContentNegotiationTest.testJSONEntryGet contentType=" + res.getContentType());
            String contentType = res.getHeader( "Content-Type");
            Assert.assertTrue( -1 < contentType.indexOf( "application/json" ));
            // Following is a poor man's JSONObject test to avoid dependency on JSON libs.
            // JSONObject jsonResp = new JSONObject(res.);
            // Assert.assertEquals(12345, jsonResp.getInt("result"));
            String responseBody = readResponse( res.getReader() );
            Assert.assertTrue( responseBody.startsWith( "{") );
            Assert.assertTrue( responseBody.endsWith( "}") );
            Assert.assertTrue( -1 < responseBody.indexOf( "\"id\"" ));
            Assert.assertTrue( -1 < responseBody.indexOf( "\"title\"" ));
            Assert.assertTrue( -1 < responseBody.indexOf( "\"updated\"" ));
            // AtomTestCaseUtils.printResponseHeaders( "JSON Entry response headers:", "   ", res );
            // System.out.println( "ContentNegotiationTest.testJSONEntryGet JSON entry body=" + responseBody );
        } finally {
            res.release();           
        }
    }
View Full Code Here

        //System.out.println(">>>ContentNegotiationTest.testXMLFeedGet");
        RequestOptions opts = new RequestOptions();
        opts.setHeader( "Accept", "application/atom+xml" );

        // Atom feed request
        ClientResponse res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            // Asser feed provided since no predicates
            Assert.assertEquals(200, res.getStatus());
            Assert.assertEquals(ResponseType.SUCCESS, res.getType());
            // AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", "   ", res );
            // System.out.println("Feed response content:");
            // AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());

            // Perform other tests on feed.
            Document<Feed> doc = res.getDocument();
            Assert.assertNotNull( doc );
            Feed feed = doc.getRoot();
            Assert.assertNotNull( feed );
            // RFC 4287 requires non-null id, title, updated elements
            Assert.assertNotNull( feed.getId() );
            Assert.assertNotNull( feed.getTitle() );
            Assert.assertNotNull( feed.getUpdated() );
            // AtomTestCaseUtils.printFeed( "Feed values", "   ", feed );
        } finally {
            res.release();
        }
    }   
View Full Code Here

        //System.out.println(">>>ContentNegotiationTest.testJSONFeedGet");
        RequestOptions opts = new RequestOptions();
        opts.setHeader( "Accept", "application/json" );

        // JSON feed request
        ClientResponse res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            // Assert feed provided since no predicates
            Assert.assertEquals(200, res.getStatus());
            // Abdera 0.4 throws exception on getContentType with application/json.     
            // System.out.println( "ContentNegotiationTest.testJSONEntryGet contentType=" + res.getContentType());
            String contentType = res.getHeader( "Content-Type");
            Assert.assertTrue( -1 < contentType.indexOf( "application/json" ));
            // Following is a poor man's JSONObject test to avoid dependency on JSON libs.
            // JSONObject jsonResp = new JSONObject(res.);
            // Assert.assertEquals(12345, jsonResp.getInt("result"));
            String responseBody = readResponse( res.getReader() );
            Assert.assertTrue( responseBody.startsWith( "{") );
            Assert.assertTrue( responseBody.endsWith( "}") );
            Assert.assertTrue( -1 < responseBody.indexOf( "\"id\"" ));
            Assert.assertTrue( -1 < responseBody.indexOf( "\"title\"" ));
            Assert.assertTrue( -1 < responseBody.indexOf( "\"updated\"" ));
            Assert.assertTrue( -1 < responseBody.indexOf( "\"entries\"" ));
            // AtomTestCaseUtils.printResponseHeaders( "JSON Entry response headers:", "   ", res );
            // System.out.println( "ContentNegotiationTest.testJSONEntryGet JSON entry body=" + responseBody );
        } finally {
            res.release();
        }
    }
View Full Code Here

        final String contentType = "application/atom+xml; type=entry";
        opts.setContentType(contentType);
        // AtomTestCaseUtils.printRequestHeaders( "Post request headers", "   ", opts );
        IRI colUri = new IRI(providerURI).resolve("customer");
        // res = client.post(colUri.toString() + "?test=foo", entry, opts);
        ClientResponse res = client.post(colUri.toString(), entry, opts);

        // Assert response status code is 201-OK.
        // Assert response header Content-Type: application/atom+xml; charset=UTF-8
        // Assert response header Location: http://example.org/edit/first-post.atom
        // Assert response header Content-Location: http://example.org/edit/first-post.atom
        // Assert response header ETag: "e180ee84f0671b1"
        // Assert response header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500     
        // Assert collection size is 1.
        Assert.assertEquals(201, res.getStatus());
        Assert.assertEquals(contentType, res.getContentType().toString().trim());
        // Assert.assertNotNull( res.getLocation().toString() );
        // Assert.assertEquals( "", res.getContentLocation().toString() );
        // Save eTag for subsequent tests;
        eTag = res.getHeader( "ETag" );
        Assert.assertNotNull( eTag );      
        lastModified = res.getLastModified();
        Assert.assertNotNull(lastModified);
    }
View Full Code Here

TOP

Related Classes of org.apache.abdera.protocol.client.ClientResponse

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.