diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-08 23:45:07 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-08 23:45:07 +0000 |
commit | 9f766005792dbd31f8c6d0306ddbbf5c68173104 (patch) | |
tree | 714e20e35653d89406a404f0af4590f1f9c1b2d7 /sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache | |
parent | da9db01ad297c43e4c2f05245bb9a3c712aaca29 (diff) |
Upgrade to Axis2 1.5.3, Axiom 1.2.10 and Abdera 1.1.1
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1043771 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache')
-rw-r--r-- | sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java | 156 |
1 files changed, 81 insertions, 75 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java index 6d4a173d30..57eacab0e2 100644 --- a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/MediaCollectionTestCase.java @@ -19,7 +19,6 @@ package org.apache.tuscany.sca.binding.atom; import java.io.File; -import java.io.FileInputStream; import java.text.SimpleDateFormat; import java.util.Date; @@ -32,11 +31,13 @@ import org.apache.abdera.model.Entry; import org.apache.abdera.model.Link; import org.apache.abdera.parser.Parser; import org.apache.abdera.protocol.client.AbderaClient; -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.methods.InputStreamRequestEntity; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.PutMethod; +import org.apache.http.Header; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.entity.FileEntity; +import org.apache.tuscany.sca.common.http.client.HttpClientFactory; import org.apache.tuscany.sca.node.Contribution; import org.apache.tuscany.sca.node.ContributionLocationHelper; import org.apache.tuscany.sca.node.Node; @@ -62,11 +63,11 @@ public class MediaCollectionTestCase { protected static CustomerClient testService; protected static Abdera abdera; protected static AbderaClient client; - protected static Parser abderaParser; + protected static Parser abderaParser; protected static String eTag; protected static Date lastModified; protected static String mediaId; - protected static final SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z" ); // RFC 822 date time + protected static final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"); // RFC 822 date time @BeforeClass public static void init() throws Exception { @@ -74,13 +75,15 @@ public class MediaCollectionTestCase { //System.out.println(">>>MediaCollectionTestCase.init"); String contribution = ContributionLocationHelper.getContributionLocation(MediaCollectionTestCase.class); - scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/ReceiptProvider.composite", new Contribution("provider", contribution)); + scaProviderNode = + NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/ReceiptProvider.composite", + new Contribution("provider", contribution)); scaProviderNode.start(); abdera = new Abdera(); client = new AbderaClient(abdera); abderaParser = Abdera.getNewParser(); - } catch(Exception e) { + } catch (Exception e) { e.printStackTrace(); } } @@ -96,7 +99,7 @@ public class MediaCollectionTestCase { @Test public void testPrelim() throws Exception { Assert.assertNotNull(scaProviderNode); - Assert.assertNotNull( client ); + Assert.assertNotNull(client); } @Test @@ -113,23 +116,25 @@ public class MediaCollectionTestCase { // Testing of entry creation String receiptName = "Auto Repair Bill"; String fileName = "target/test-classes/ReceiptToms.gif"; - File input = new File( fileName ); + File input = new File(fileName); boolean exists = input.exists(); - Assert.assertTrue( exists ); + Assert.assertTrue(exists); // Prepare HTTP post // PostMethod post = new PostMethod( colUri.toString() ); - PostMethod post = new PostMethod( providerURI ); - post.addRequestHeader( "Content-Type", "image/gif" ); - post.addRequestHeader( "Title", "Title " + receiptName + "" ); - post.addRequestHeader( "Slug", "Slug " + receiptName + "" ); - post.setRequestEntity( new InputStreamRequestEntity( new FileInputStream( input ), "image/gif" ) ); + HttpPost post = new HttpPost(providerURI); + post.addHeader("Content-Type", "image/gif"); + post.addHeader("Title", "Title " + receiptName + ""); + post.addHeader("Slug", "Slug " + receiptName + ""); + + post.setEntity(new FileEntity(input, "image/gif")); // Get HTTP client - HttpClient httpclient = new HttpClient(); + org.apache.http.client.HttpClient httpclient = new HttpClientFactory().createHttpClient(); try { // Execute request - int result = httpclient.executeMethod(post); + HttpResponse response = httpclient.execute(post); + int result = response.getStatusLine().getStatusCode(); // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) // Post response // Tuscany responds with proper media links. Note that the media is @@ -138,31 +143,31 @@ public class MediaCollectionTestCase { // HTTP/1.1 201 Created // Display status code // System.out.println("Response status code: " + result + ", status text=" + post.getStatusText() ); - Assert.assertEquals(201, result ); + Assert.assertEquals(201, result); // Display response // System.out.println("Response body: "); // System.out.println(post.getResponseBodyAsString()); // Warning: BodyAsString recommends BodyAsStream // Location: http://example.org/media/edit/the_beach.atom (REQUIRED) - // System.out.println( "Response Location=" + post.getResponseHeader( "Location" ).getValue() + "." ); - Header header = post.getResponseHeader( "Location" ); - Assert.assertNotNull( header ); - Assert.assertNotNull( header.getValue() ); + // System.out.println( "Response Location=" + response.getFirstHeader( "Location" ).getValue() + "." ); + Header header = response.getFirstHeader("Location"); + Assert.assertNotNull(header); + Assert.assertNotNull(header.getValue()); // ContentLocation: http://example.org/media/edit/the_beach.jpg (REQUIRED) - // System.out.println( "Response Content-Location=" + post.getResponseHeader( "Content-Location" ).getValue() ); - header = post.getResponseHeader( "Content-Location" ); - Assert.assertNotNull( header ); - Assert.assertNotNull( header.getValue() ); + // System.out.println( "Response Content-Location=" + response.getFirstHeader( "Content-Location" ).getValue() ); + header = response.getFirstHeader("Content-Location"); + Assert.assertNotNull(header); + Assert.assertNotNull(header.getValue()); // Content-Type: application/atom+xml;type=entry;charset="utf-8" - // System.out.println( "Response Content-Type=" + post.getResponseHeader( "Content-Type" ).getValue()); - header = post.getResponseHeader( "Content-Type" ); - Assert.assertNotNull( header ); - Assert.assertNotNull( header.getValue() ); + // System.out.println( "Response Content-Type=" + response.getFirstHeader( "Content-Type" ).getValue()); + header = response.getFirstHeader("Content-Type"); + Assert.assertNotNull(header); + Assert.assertNotNull(header.getValue()); // Content-Length: nnn (OPTIONAL) - // System.out.println( "Response Content-Length=" + post.getResponseHeader( "Content-Length" ).getValue() ); - header = post.getResponseHeader( "Content-Length" ); - Assert.assertNotNull( header ); - Assert.assertNotNull( header.getValue() ); + // System.out.println( "Response Content-Length=" + response.getFirstHeader( "Content-Length" ).getValue() ); + header = response.getFirstHeader("Content-Length"); + Assert.assertNotNull(header); + Assert.assertNotNull(header.getValue()); // <?xml version="1.0"?> // <entry xmlns="http://www.w3.org/2005/Atom"> // <title>The Beach</title> (REQUIRED) @@ -174,39 +179,39 @@ public class MediaCollectionTestCase { // <link rel="edit-media" href="http://media.example.org/edit/the_beach.png" /> // <link rel="edit" href="http://example.org/media/edit/the_beach.atom" /> // </entry> - Document<Entry> document = abderaParser.parse( post.getResponseBodyAsStream() ); + Document<Entry> document = abderaParser.parse(response.getEntity().getContent()); Entry entry = document.getRoot(); String title = entry.getTitle(); // System.out.println( "mediaPost entry.title=" + title ); - Assert.assertNotNull( title ); + Assert.assertNotNull(title); IRI id = entry.getId(); // System.out.println( "mediaPost entry.id=" + id ); - Assert.assertNotNull( id ); + Assert.assertNotNull(id); mediaId = id.toString(); - Assert.assertNotNull( mediaId ); // Save for put/update request + Assert.assertNotNull(mediaId); // Save for put/update request Date updated = entry.getUpdated(); // System.out.println( "mediaPost entry.updated=" + updated); - Assert.assertNotNull( updated ); + Assert.assertNotNull(updated); String summary = entry.getSummary(); // System.out.println( "mediaPost entry.summary=" + summary); - Assert.assertNotNull( summary ); + Assert.assertNotNull(summary); IRI contentSrc = entry.getContentSrc(); // System.out.println( "mediaPost entry.content.src=" + contentSrc + ", type=" + entry.getContentType()); - Assert.assertNotNull( contentSrc ); + Assert.assertNotNull(contentSrc); Link editLink = entry.getEditLink(); // System.out.println( "mediaPost entry.editLink" + " rel=" + editLink.getRel() + ", href=" + editLink.getHref() ); - Assert.assertNotNull( editLink ); - Assert.assertNotNull( editLink.getRel() ); - Assert.assertNotNull( editLink.getHref() ); + Assert.assertNotNull(editLink); + Assert.assertNotNull(editLink.getRel()); + Assert.assertNotNull(editLink.getHref()); Link editMediaLink = entry.getEditMediaLink(); // System.out.println( "mediaPost entry.editMediaLink" + " rel=" + editMediaLink.getRel() + ", href=" + editMediaLink.getHref() ); - Assert.assertNotNull( editMediaLink ); - Assert.assertNotNull( editMediaLink.getRel() ); - Assert.assertNotNull( editMediaLink.getHref() ); + Assert.assertNotNull(editMediaLink); + Assert.assertNotNull(editMediaLink.getRel()); + Assert.assertNotNull(editMediaLink.getHref()); } finally { // Release current connection to the connection pool once you are done - post.releaseConnection(); + // post.releaseConnection(); } } @@ -216,9 +221,9 @@ public class MediaCollectionTestCase { // Testing of entry update String receiptName = "Value Autoglass Bill"; String fileName = "target/test-classes/ReceiptValue.jpg"; - File input = new File( fileName ); + File input = new File(fileName); boolean exists = input.exists(); - Assert.assertTrue( exists ); + Assert.assertTrue(exists); // Prepare HTTP put request // PUT /edit/the_beach.png HTTP/1.1 @@ -226,28 +231,29 @@ public class MediaCollectionTestCase { // Content-Type: image/png // Content-Length: nnn // ...binary data... - PutMethod put = new PutMethod( providerURI + "/" + mediaId ); - put.addRequestHeader( "Content-Type", "image/jpg" ); - put.addRequestHeader( "Title", "Title " + receiptName + "" ); - put.addRequestHeader( "Slug", "Slug " + receiptName + "" ); - put.setRequestEntity( - new InputStreamRequestEntity( new FileInputStream( input ), "image/jpg" ) ); + HttpPut put = new HttpPut(providerURI + "/" + mediaId); + put.addHeader("Content-Type", "image/jpg"); + put.addHeader("Title", "Title " + receiptName + ""); + put.addHeader("Slug", "Slug " + receiptName + ""); + put.setEntity(new FileEntity(input, "image/jpg")); // Get HTTP client - HttpClient httpclient = new HttpClient(); + HttpClient httpclient = new HttpClientFactory().createHttpClient(); try { // Execute request - int result = httpclient.executeMethod(put); + HttpResponse response = httpclient.execute(put); + response.getEntity().consumeContent(); + int result = response.getStatusLine().getStatusCode(); // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) // Display status code // System.out.println("Response status code: " + result + ", status text=" + put.getStatusText() ); - Assert.assertEquals(200, result ); + Assert.assertEquals(200, result); // Display response. Should be empty for put. // System.out.println("Response body: "); // System.out.println(put.getResponseBodyAsString()); // Warning: BodyAsString recommends BodyAsStream } finally { // Release current connection to the connection pool once you are done - put.releaseConnection(); + // put.releaseConnection(); } } @@ -257,9 +263,9 @@ public class MediaCollectionTestCase { // Testing of entry update String receiptName = "Value Autoglass Bill"; String fileName = "target/test-classes/ReceiptValue.jpg"; - File input = new File( fileName ); + File input = new File(fileName); boolean exists = input.exists(); - Assert.assertTrue( exists ); + Assert.assertTrue(exists); // Prepare HTTP put request // PUT /edit/the_beach.png HTTP/1.1 @@ -267,28 +273,28 @@ public class MediaCollectionTestCase { // Content-Type: image/png // Content-Length: nnn // ...binary data... - PutMethod put = new PutMethod( providerURI + "/" + mediaId + "-bogus" ); // Does not exist. - put.addRequestHeader( "Content-Type", "image/jpg" ); - put.addRequestHeader( "Title", "Title " + receiptName + "" ); - put.addRequestHeader( "Slug", "Slug " + receiptName + "" ); - put.setRequestEntity( - new InputStreamRequestEntity( new FileInputStream( input ), "image/jpg" ) ); + HttpPut put = new HttpPut(providerURI + "/" + mediaId + "-bogus"); // Does not exist. + put.addHeader("Content-Type", "image/jpg"); + put.addHeader("Title", "Title " + receiptName + ""); + put.addHeader("Slug", "Slug " + receiptName + ""); + put.setEntity(new FileEntity(input, "image/jpg")); // Get HTTP client - HttpClient httpclient = new HttpClient(); + HttpClient httpclient = new HttpClientFactory().createHttpClient(); try { // Execute request - int result = httpclient.executeMethod(put); + HttpResponse response = httpclient.execute(put); + int result = response.getStatusLine().getStatusCode(); // Pseudo Code (see APP (http://tools.ietf.org/html/rfc5023#section-9.6) // Display status code // System.out.println("Response status code: " + result + ", status text=" + put.getStatusText() ); - Assert.assertEquals(404, result ); + Assert.assertEquals(404, result); // Display response. Should be empty for put. // System.out.println("Response body: "); // System.out.println(put.getResponseBodyAsString()); // Warning: BodyAsString recommends BodyAsStream } finally { // Release current connection to the connection pool once you are done - put.releaseConnection(); + // put.releaseConnection(); } } } |