From 04dcd09976ecc5aa2948993b9a9a2d90d239ee44 Mon Sep 17 00:00:00 2001 From: antelder Date: Thu, 28 Jul 2011 10:58:07 +0000 Subject: Delete old beta3 branch as its going to be recreated from the current trunk git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1151789 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/binding/rest/NotModifiedException.java | 44 - .../binding/rest/PreconditionFailedException.java | 44 - .../sca/binding/rest/RESTBindingCacheTestCase.java | 903 --------------------- .../sca/binding/rest/RESTBindingTestCase.java | 163 ---- .../sca/binding/rest/TestBindingCacheImpl.java | 199 ----- .../tuscany/sca/binding/rest/TestGetImpl.java | 37 - .../tuscany/sca/binding/rest/TestServiceImpl.java | 60 -- .../sca/binding/rest/rpc/EchoServiceTestCase.java | 145 ---- .../wireformat/binary/BinaryServiceTestCase.java | 106 --- .../wireformat/json/CatalogServiceTestCase.java | 150 ---- .../wireformat/xml/CustomerServiceTestCase.java | 123 --- 11 files changed, 1974 deletions(-) delete mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/NotModifiedException.java delete mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/PreconditionFailedException.java delete mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingCacheTestCase.java delete mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingTestCase.java delete mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/TestBindingCacheImpl.java delete mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/TestGetImpl.java delete mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/TestServiceImpl.java delete mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/rpc/EchoServiceTestCase.java delete mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/binary/BinaryServiceTestCase.java delete mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java delete mode 100644 sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java (limited to 'sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding') diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/NotModifiedException.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/NotModifiedException.java deleted file mode 100644 index 49e7d67a76..0000000000 --- a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/NotModifiedException.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.rest; - -/** - * Indicates that a resource was not modified. - * - * @version $Rev$ $Date$ - */ -public class NotModifiedException extends Exception { - private static final long serialVersionUID = -5046027674128627383L; - - public NotModifiedException() { - } - - public NotModifiedException(String message) { - super(message); - } - - public NotModifiedException(Throwable cause) { - super(cause); - } - - public NotModifiedException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/PreconditionFailedException.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/PreconditionFailedException.java deleted file mode 100644 index 1463e1a5db..0000000000 --- a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/PreconditionFailedException.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.rest; - -/** - * Indicates that a resource was not modified. - * - * @version $Rev$ $Date$ - */ -public class PreconditionFailedException extends Exception { - private static final long serialVersionUID = -5046027674128627383L; - - public PreconditionFailedException() { - } - - public PreconditionFailedException(String message) { - super(message); - } - - public PreconditionFailedException(Throwable cause) { - super(cause); - } - - public PreconditionFailedException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingCacheTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingCacheTestCase.java deleted file mode 100644 index 4db7fd64dc..0000000000 --- a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingCacheTestCase.java +++ /dev/null @@ -1,903 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.binding.rest; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.Socket; -import java.text.MessageFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -import junit.framework.Assert; - -import org.apache.tuscany.sca.node.Contribution; -import org.apache.tuscany.sca.node.ContributionLocationHelper; -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.NodeFactory; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * HTTP binding unit tests. - * - * @version $Rev$ $Date$ - */ -public class RESTBindingCacheTestCase { - // RFC 822 date time - protected static final SimpleDateFormat dateFormat = new SimpleDateFormat( - "EEE, dd MMM yyyy HH:mm:ss Z"); - - // Request with no predicates in header. - private static final String REQUEST1 = "{0} /httpbinding/{1} HTTP/1.0\n" - + "Host: localhost\n" + "Content-Type: text/xml\n" - + "Connection: close\n" + "Content-Length: {2}" + "\n\n{3}"; - - // Request with predicates in header - private static final String REQUEST2 = "{0} /httpbinding/{1} HTTP/1.0\n" - + "Host: localhost\n" + "Content-Type: text/xml\n" + "{2}: {3}\n" // predicate (If-Match, If-None-Match, If-Modified-Since, If-NotModified-Since): value (date or ETag) - + "Connection: close\n" + "Content-Length: {4}" + "\n\n{5}"; - - private static final int HTTP_PORT = 8085; - - private static Node node; - - @BeforeClass - public static void setUp() throws Exception { - try { - String contribution = ContributionLocationHelper.getContributionLocation(RESTBindingCacheTestCase.class); - node = NodeFactory.newInstance().createNode("testCache.composite", new Contribution("test", contribution)); - node.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @AfterClass - public static void tearDown() throws Exception { - node.stop(); - } - - /** - * Test invoking a POJO get method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testGet() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST1, "GET", index, content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - Assert.assertTrue(document.indexOf("

item=" + index) != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalGetIfModifiedNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "GET", index, - "If-Modified-Since", dateFormat.format(new Date(0)), - content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - Assert.assertTrue(document.indexOf("

item=" + index) != -1); - // Should return code 304 Not Modified. - // assertTrue(document.indexOf("HTTP/1.1 304") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalGetIfModifiedPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "GET", index, - "If-Modified-Since", dateFormat.format(new Date(0)), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("

item=" + index) != -1); - // Should return code 304 Not Modified. - Assert.assertTrue(document.indexOf("HTTP/1.1 304") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalGetIfUnmodifiedNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "GET", index, - "If-Unmodified-Since", dateFormat.format(new Date()), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - Assert.assertTrue(document.indexOf("

item=" + index) != -1); - // Should return code 304 Not Modified. - // assertTrue(document.indexOf("HTTP/1.1 304") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalGetIfUnmodifiedPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "GET", index, - "If-Unmodified-Since", dateFormat.format(new Date(0)), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("

item=" + index) != -1); - // Should return code 412 PreconditionFailed. - Assert.assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalGetIfMatchNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "GET", index, - "If-Match", "eTagXXX", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("

item=" + index) != -1); - // Should return code 412 precondition failed. - Assert.assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalGetIfMatchPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "GET", index, - "If-Match", "eTagXXX", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - Assert.assertTrue(document.indexOf("

item=" + index) != -1); - // Should return code 412 PreconditionFailed. - // assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalGetIfNoneMatchNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "GET", index, - "If-None-Match", "eTagXXX", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - Assert.assertTrue(document.indexOf("

item=" + index) != -1); - // Should return code 412 precondition failed. - // assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalGetIfNoneMatchPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "GET", index, - "If-None-Match", "eTagXXX", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("

item=" + index) != -1); - // Should return code 412 PreconditionFailed. - Assert.assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a POJO get method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testDelete() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST1, "DELETE", index, - content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - Assert.assertTrue(document.indexOf("deleted item=" + index) != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalDeleteIfModifiedNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "DELETE", index, - "If-Modified-Since", dateFormat.format(new Date(0)), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - Assert.assertTrue(document.indexOf("deleted item=" + index) != -1); - // Should return code 304 Not Modified. - // assertTrue(document.indexOf("HTTP/1.1 304") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalDeleteIfModifiedPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "DELETE", index, - "If-Modified-Since", dateFormat.format(new Date(0)), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("deleted item=" + index) != -1); - // Should return code 304 Not Modified. - Assert.assertTrue(document.indexOf("HTTP/1.1 304") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalDeleteIfUnmodifiedNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "DELETE", index, - "If-Unmodified-Since", dateFormat.format(new Date()), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - Assert.assertTrue(document.indexOf("deleted item=" + index) != -1); - // Should return code 304 Not Modified. - // assertTrue(document.indexOf("HTTP/1.1 304") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalDeleteIfUnmodifiedPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "DELETE", index, - "If-Unmodified-Since", dateFormat.format(new Date(0)), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("deleted item=" + index) != -1); - // Should return code 412 PreconditionFailed. - Assert.assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalDeleteIfMatchNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "DELETE", index, - "If-Match", "eTagXXX", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("deleted item=" + index) != -1); - // Should return code 412 precondition failed. - Assert.assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalDeleteIfMatchPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "DELETE", index, - "If-Match", "eTagXXX", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - Assert.assertTrue(document.indexOf("deleted item=" + index) != -1); - // Should return code 412 PreconditionFailed. - // assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalDeleteIfNoneMatchNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "DELETE", index, - "If-None-Match", "eTagXXX", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - Assert.assertTrue(document.indexOf("deleted item=" + index) != -1); - // Should return code 412 precondition failed. - // assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalDeleteIfNoneMatchPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "DELETE", index, - "If-None-Match", "eTagXXX", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("deleted item=" + index) != -1); - // Should return code 412 PreconditionFailed. - Assert.assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a POJO get method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testPost() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST1, "POST", index, content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - Assert.assertTrue(document.indexOf("HTTP/1.1 200 OK") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPostIfModifiedNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "POST", index, - "If-Modified-Since", dateFormat.format(new Date()), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return code 200 OK - // assertTrue(document.indexOf("posted item=" + index) != -1); - Assert.assertTrue(document.indexOf("HTTP/1.1 200 OK") != -1); - // Should return code 304 Not Modified. - // assertTrue(document.indexOf("HTTP/1.1 304") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPostIfModifiedPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "POST", index, - "If-Modified-Since", dateFormat.format(new Date(0)), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("posted item=" + index) != -1); - // Should return code 304 Not Modified. - Assert.assertTrue(document.indexOf("HTTP/1.1 304") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPostIfUnmodifiedNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "POST", index, - "If-Unmodified-Since", dateFormat.format(new Date()), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return code 200 OK - Assert.assertTrue(document.indexOf("HTTP/1.1 200 OK") != -1); - // Should return code 304 Not Modified. - // assertTrue(document.indexOf("HTTP/1.1 304") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPostIfUnmodifiedPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "POST", index, - "If-Unmodified-Since", dateFormat.format(new Date(0)), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("posted item=" + index) != -1); - // Should return code 412 PreconditionFailed. - Assert.assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPostIfMatchNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "POST", index, - "If-Match", "eTagMatch", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return code 200 OK. - Assert.assertTrue(document.indexOf("HTTP/1.1 200 OK") != -1); - // Should return code 412 precondition failed. - // assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPostIfMatchPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat - .format(REQUEST2, "POST", index, "If-Match", "eTagNoneMatch", - content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("posted item=" + index) != -1); - // Should return code 412 PreconditionFailed. - Assert.assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPostIfNoneMatchNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "POST", index, - "If-None-Match", "eTagNoneMatch", content.getBytes().length, - content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return code 200 OK - Assert.assertTrue(document.indexOf("HTTP/1.1 200 OK") != -1); - // Should return code 412 precondition failed. - // assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPostIfNoneMatchPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "POST", index, - "If-None-Match", "eTagMatch", content.getBytes().length, - content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("posted item=" + index) != -1); - // Should return code 412 PreconditionFailed. - Assert.assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a POJO get method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testPut() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST1, "PUT", index, content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - Assert.assertTrue(document.indexOf("updated item=" + index) != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPutIfModifiedNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "PUT", index, - "If-Modified-Since", dateFormat.format(new Date(0)), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - Assert.assertTrue(document.indexOf("updated item=" + index) != -1); - // Should return code 304 Not Modified. - // assertTrue(document.indexOf("HTTP/1.1 304") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPutIfModifiedPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "PUT", index, - "If-Modified-Since", dateFormat.format(new Date(0)), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("updated item=" + index) != -1); - // Should return code 304 Not Modified. - Assert.assertTrue(document.indexOf("HTTP/1.1 304") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPutIfUnmodifiedNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "PUT", index, - "If-Unmodified-Since", dateFormat.format(new Date()), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - Assert.assertTrue(document.indexOf("updated item=" + index) != -1); - // Should return code 304 Not Modified. - // assertTrue(document.indexOf("HTTP/1.1 304") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPutIfUnmodifiedPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "PUT", index, - "If-Unmodified-Since", dateFormat.format(new Date(0)), content - .getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("updated item=" + index) != -1); - // Should return code 412 PreconditionFailed. - Assert.assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPutIfMatchNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "PUT", index, - "If-Match", "eTagXXX", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("updated item=" + index) != -1); - // Should return code 412 precondition failed. - Assert.assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPutIfMatchPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "PUT", index, - "If-Match", "eTagXXX", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - Assert.assertTrue(document.indexOf("updated item=" + index) != -1); - // Should return code 412 PreconditionFailed. - // assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPutIfNoneMatchNegative() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 1; - String content = ""; - String request = MessageFormat.format(REQUEST2, "PUT", index, - "If-None-Match", "eTagXXX", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - Assert.assertTrue(document.indexOf("updated item=" + index) != -1); - // Should return code 412 precondition failed. - // assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Test invoking a conditional method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testConditionalPutIfNoneMatchPositive() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String content = ""; - String request = MessageFormat.format(REQUEST2, "PUT", index, - "If-None-Match", "eTagXXX", content.getBytes().length, content); - os.write(request.getBytes()); - os.flush(); - - String document = read(client); - // Should return item - // assertTrue(document.indexOf("updated item=" + index) != -1); - // Should return code 412 PreconditionFailed. - Assert.assertTrue(document.indexOf("HTTP/1.1 412") != -1); - } - - /** - * Read response stream from the given socket. - * @param socket - * @return - * @throws IOException - */ - private static String read(Socket socket) throws IOException { - BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader(socket - .getInputStream())); - StringBuffer sb = new StringBuffer(); - String str; - while ((str = reader.readLine()) != null) { - sb.append(str); - } - return sb.toString(); - } finally { - if (reader != null) { - reader.close(); - } - } - } -} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingTestCase.java deleted file mode 100644 index e08069f479..0000000000 --- a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/RESTBindingTestCase.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.binding.rest; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.Socket; -import java.text.MessageFormat; - -import junit.framework.Assert; - -import org.apache.tuscany.sca.node.Contribution; -import org.apache.tuscany.sca.node.ContributionLocationHelper; -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.NodeFactory; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -/** - * HTTP binding unit tests. - * - * @version $Rev$ $Date$ - */ -public class RESTBindingTestCase { - - private static final String REQUEST1_HEADER = - "GET /httpservice/test HTTP/1.0\n" + "Host: localhost\n" - + "Content-Type: text/xml\n" - + "Connection: close\n" - + "Content-Length: "; - private static final String REQUEST1_CONTENT = ""; - private static final String REQUEST1 = - REQUEST1_HEADER + REQUEST1_CONTENT.getBytes().length + "\n\n" + REQUEST1_CONTENT; - - private static final String REQUEST2_HEADER = - "GET /webcontent/test.html HTTP/1.0\n" + "Host: localhost\n" - + "Content-Type: text/xml\n" - + "Connection: close\n" - + "Content-Length: "; - private static final String REQUEST2_CONTENT = ""; - private static final String REQUEST2 = - REQUEST2_HEADER + REQUEST2_CONTENT.getBytes().length + "\n\n" + REQUEST2_CONTENT; - - private static final String REQUEST3_HEADER = - "GET /httpget/{0} HTTP/1.0\n" + "Host: localhost\n" - + "Content-Type: text/xml\n" - + "Connection: close\n" - + "Content-Length: "; - private static final String REQUEST3_CONTENT = ""; - private static final String REQUEST3 = - REQUEST3_HEADER + REQUEST3_CONTENT.getBytes().length + "\n\n" + REQUEST3_CONTENT; - - private static final int HTTP_PORT = 8085; - - private static Node node; - - @BeforeClass - public static void setUp() throws Exception { - try { - String contribution = ContributionLocationHelper.getContributionLocation(RESTBindingCacheTestCase.class); - node = NodeFactory.newInstance().createNode("test.composite", new Contribution("test", contribution)); - node.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @AfterClass - public static void tearDown() throws Exception { - node.stop(); - } - - /** - * Test invoking a POJO service implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testServiceImplementation() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - os.write(REQUEST1.getBytes()); - os.flush(); - - String document = read(client); - Assert.assertTrue(document.indexOf("

hey") != -1); - } - - /** - * Test invoking a POJO get method implementation using the HTTP binding. - * @throws Exception - */ - @Test - public void testGetImplementation() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String request = MessageFormat.format( REQUEST3, index ); - os.write( request.getBytes()); - os.flush(); - - String document = read(client); - Assert.assertTrue(document.indexOf("

item=" + index) != -1); - } - - /** - * Test getting a static resource provided using the HTTP binding. - * @throws Exception - */ - @Ignore("Implementation resource not available") - public void testStaticResourceImplementation() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - os.write(REQUEST2.getBytes()); - os.flush(); - - String document = read(client); - Assert.assertTrue(document.indexOf("

hello") != -1); - } - - /** - * Read response stream from the given socket. - * @param socket - * @return - * @throws IOException - */ - private static String read(Socket socket) throws IOException { - BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); - StringBuffer sb = new StringBuffer(); - String str; - while ((str = reader.readLine()) != null) { - sb.append(str); - } - return sb.toString(); - } finally { - if (reader != null) { - reader.close(); - } - } - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/TestBindingCacheImpl.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/TestBindingCacheImpl.java deleted file mode 100644 index 5c5e4db8ed..0000000000 --- a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/TestBindingCacheImpl.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.rest; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.Date; - -import org.apache.tuscany.sca.common.http.HTTPCacheContext; - -/** - * Test service implementation that implements a various conditional HTTP - * methods. For testing, the id==0 items are very old (Date(0)), not modified, - * and always match ETags and the id==1 items are always brand new (Date()), - * modified, and never match ETags. Using these ids one can test the - * LastModified and ETag headers of the requests. - * - * @version $Rev$ $Date$ - */ -public class TestBindingCacheImpl { - - /** - * Implements the HTTP get method of the collection implementation. - * @param id - * @return - */ - public InputStream get(String id) { - return new ByteArrayInputStream(("

item=" + id + "").getBytes()); - } - - /** - * Implements the HTTP conditional get method of the collection implementation. - * @param id - * @return - */ - public InputStream conditionalGet(String id, HTTPCacheContext cacheContext) throws NotModifiedException, - PreconditionFailedException { - - if (cacheContext != null) { - if (cacheContext.ifModifiedSince) { - if ((id.equals("1")) && (0 > cacheContext.lastModifiedDate.compareTo(new Date()))) - throw new NotModifiedException("item 1 was modified on " + new Date()); - } - if (cacheContext.ifUnmodifiedSince) { - if ((id.equals("0")) && (0 > cacheContext.lastModifiedDate.compareTo(new Date()))) - throw new PreconditionFailedException("item 0 was modified on " + new Date(0)); - } - if (cacheContext.ifMatch) { - if (id.equals("1")) - throw new PreconditionFailedException("item 1 eTag does not match " + cacheContext.getETag()); - } - if (cacheContext.ifNoneMatch) { - if (id.equals("0")) - throw new PreconditionFailedException("item 0 eTag matches " + cacheContext.getETag()); - } - } - return new ByteArrayInputStream(("

item=" + id + "").getBytes()); - } - - /** - * Implements the HTTP delete method of the collection implementation. - * @param id - * @return - */ - public InputStream delete(String id) { - return new ByteArrayInputStream(("

deleted item=" + id + "").getBytes()); - } - - /** - * Implements the HTTP conditional delete method of the collection implementation. - * @param id - * @return - */ - public InputStream conditionalDelete(String id, HTTPCacheContext cacheContext) throws NotModifiedException, - PreconditionFailedException { - - if (cacheContext != null) { - if (cacheContext.ifModifiedSince) { - if ((id.equals("1")) && (0 > cacheContext.lastModifiedDate.compareTo(new Date()))) - throw new NotModifiedException("item 1 was modified on " + new Date()); - } - if (cacheContext.ifUnmodifiedSince) { - if ((id.equals("0")) && (0 > cacheContext.lastModifiedDate.compareTo(new Date()))) - throw new PreconditionFailedException("item 0 was modified on " + new Date(0)); - } - if (cacheContext.ifMatch) { - if (id.equals("1")) - throw new PreconditionFailedException("item 1 eTag does not match " + cacheContext.getETag()); - } - if (cacheContext.ifNoneMatch) { - if (id.equals("0")) - throw new PreconditionFailedException("item 0 eTag matches " + cacheContext.getETag()); - } - } - return new ByteArrayInputStream(("

deleted item=" + id + "").getBytes()); - } - - /** - * Implements the HTTP post method of the collection implementation. - * @param id - * @return - */ - public InputStream post() { - int id = (new java.util.Random()).nextInt(Integer.MAX_VALUE); - return new ByteArrayInputStream(("

posted item=" + id + "").getBytes()); - } - - /** - * Implements the HTTP conditional post method of the collection implementation. - * @param id - * @return - */ - public HTTPCacheContext conditionalPost(HTTPCacheContext cacheContext) throws NotModifiedException, - PreconditionFailedException { - String id = "" + (new java.util.Random()).nextInt(Integer.MAX_VALUE); - - if (cacheContext != null) { - if (cacheContext.ifModifiedSince) { - if (0 >= cacheContext.lastModifiedDate.compareTo(new Date(0))) - throw new NotModifiedException("item was modified on " + new Date()); - } - if (cacheContext.ifUnmodifiedSince) { - if ((0 >= cacheContext.lastModifiedDate.compareTo(new Date(0)))) - throw new PreconditionFailedException("item was modified on " + new Date(0)); - } - if (cacheContext.ifMatch) { - if (cacheContext.getETag().equalsIgnoreCase("ETagNoneMatch")) - throw new PreconditionFailedException("item eTag does not match " + cacheContext.getETag()); - } - if (cacheContext.ifNoneMatch) { - if (cacheContext.getETag().equalsIgnoreCase("ETagMatch")) - throw new PreconditionFailedException("item eTag matches " + cacheContext.getETag()); - } - } - - // Return the ETag and LastModfied fields by serialize to a byte array - HTTPCacheContext returnContext = new HTTPCacheContext(); - returnContext.setETag("ETag" + (new java.util.Random()).nextInt(Integer.MAX_VALUE)); - returnContext.setLastModified(new Date()); - return returnContext; - } - - /** - * Implements the HTTP update/put method of the collection implementation. - * @param id - * @return - */ - public InputStream put(String id) { - return new ByteArrayInputStream(("

updated item=" + id + "").getBytes()); - } - - /** - * Implements the HTTP conditional update/put method of the collection implementation. - * @param id - * @return - */ - public InputStream conditionalPut(String id, HTTPCacheContext cacheContext) throws NotModifiedException, - PreconditionFailedException { - - if (cacheContext != null) { - if (cacheContext.ifModifiedSince) { - if ((id.equals("1")) && (0 > cacheContext.lastModifiedDate.compareTo(new Date()))) - throw new NotModifiedException("item 1 was modified on " + new Date()); - } - if (cacheContext.ifUnmodifiedSince) { - if ((id.equals("0")) && (0 > cacheContext.lastModifiedDate.compareTo(new Date()))) - throw new PreconditionFailedException("item 0 was modified on " + new Date(0)); - } - if (cacheContext.ifMatch) { - if (id.equals("1")) - throw new PreconditionFailedException("item 1 eTag does not match " + cacheContext.getETag()); - } - if (cacheContext.ifNoneMatch) { - if (id.equals("0")) - throw new PreconditionFailedException("item 0 eTag matches " + cacheContext.getETag()); - } - } - - return new ByteArrayInputStream(("

updated item=" + id + "").getBytes()); - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/TestGetImpl.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/TestGetImpl.java deleted file mode 100644 index 4cb1bce73f..0000000000 --- a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/TestGetImpl.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.rest; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; - -/** - * Test service implementation that implements a get method. - * - * @version $Rev$ $Date$ - */ -public class TestGetImpl { - - public InputStream get(String id) { - return new ByteArrayInputStream(("

item=" + id + "").getBytes()); - - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/TestServiceImpl.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/TestServiceImpl.java deleted file mode 100644 index 6b21d6094f..0000000000 --- a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/TestServiceImpl.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.rest; - -import java.io.IOException; - -import javax.servlet.Servlet; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import org.oasisopen.sca.annotation.Service; - -/** - * Test service implementation. - * - * @version $Rev$ $Date$ - */ - -@Service(Servlet.class) -public class TestServiceImpl implements Servlet { - - public void init(ServletConfig config) throws ServletException { - } - - public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { - //HttpServletResponse httpResponse = (HttpServletResponse)response; - response.getOutputStream().print("

hey"); - } - - public void destroy() { - } - - public ServletConfig getServletConfig() { - return null; - } - - public String getServletInfo() { - return null; - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/rpc/EchoServiceTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/rpc/EchoServiceTestCase.java deleted file mode 100644 index a96f8ebb03..0000000000 --- a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/rpc/EchoServiceTestCase.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.rest.rpc; - -import java.net.Socket; - -import org.apache.tuscany.sca.node.Contribution; -import org.apache.tuscany.sca.node.ContributionLocationHelper; -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.NodeFactory; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.meterware.httpunit.GetMethodWebRequest; -import com.meterware.httpunit.WebConversation; -import com.meterware.httpunit.WebRequest; -import com.meterware.httpunit.WebResponse; - -public class EchoServiceTestCase { - private static final String SERVICE_URL_JSON = "http://localhost:8085/EchoService/json"; - private static final String SERVICE_URL_XML = "http://localhost:8085/EchoService/xml"; - - private static final String XML_RESPONSE = "" + - "" + - "Hello RPC"; - - private static Node node; - - @BeforeClass - public static void init() throws Exception { - try { - String contribution = ContributionLocationHelper.getContributionLocation(EchoServiceTestCase.class); - node = NodeFactory.newInstance().createNode("echo.composite", new Contribution("echo", contribution)); - node.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @AfterClass - public static void destroy() throws Exception { - if(node != null) { - node.stop(); - } - } - - @Test - public void testPing() throws Exception { - new Socket("127.0.0.1", 8085); - // System.in.read(); - } - - @Test - public void testJSONRPCGetOperationWithString() throws Exception { - String queryString = "?method=echo&msg=Hello RPC"; - - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest(SERVICE_URL_JSON + queryString); - request.setHeaderField("Content-Type", "application/json"); - WebResponse response = wc.getResource(request); - - Assert.assertEquals(200, response.getResponseCode()); - Assert.assertEquals("Hello RPC", response.getText()); - } - - @Test - public void testJSONRPCGetOperationWithInt() throws Exception { - String queryString = "?method=echoInt¶m=1000"; - - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest(SERVICE_URL_JSON + queryString); - request.setHeaderField("Content-Type", "application/json"); - WebResponse response = wc.getResource(request); - - Assert.assertEquals(200, response.getResponseCode()); - Assert.assertEquals("1000", response.getText()); - } - - @Test - public void testRPCGetArrayOperationWithString() throws Exception { - String queryString = "?method=echoArrayString&msgArray=Hello RPC1&msgArray=Hello RPC2"; - - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest(SERVICE_URL_JSON + queryString); - request.setHeaderField("Content-Type", "application/json"); - WebResponse response = wc.getResource(request); - - Assert.assertEquals(200, response.getResponseCode()); - Assert.assertEquals("[\"Hello RPC1\",\"Hello RPC2\"]", response.getText()); - } - - @Test - public void testRPCGetArrayOperationWithInt() throws Exception { - String queryString = "?method=echoArrayInt&intArray=1000&intArray=2000"; - - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest(SERVICE_URL_JSON + queryString); - request.setHeaderField("Content-Type", "application/json"); - WebResponse response = wc.getResource(request); - - Assert.assertEquals(200, response.getResponseCode()); - Assert.assertEquals("[1000,2000]", response.getText()); - } - - - @Test - public void testXMLRPCGetOperation() throws Exception { - String queryString = "?method=echo&msg=Hello RPC"; - - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest(SERVICE_URL_XML + queryString); - request.setHeaderField("Content-Type", "application/xml"); - WebResponse response = wc.getResource(request); - - //System.out.println("Expected>>" + XML_RESPONSE); - //System.out.println("Received>>" + response.getText()); - - Assert.assertEquals(200, response.getResponseCode()); - Assert.assertEquals(XML_RESPONSE, response.getText()); - } - - -} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/binary/BinaryServiceTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/binary/BinaryServiceTestCase.java deleted file mode 100644 index 2ca662ec4e..0000000000 --- a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/binary/BinaryServiceTestCase.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.rest.wireformat.binary; - -import java.io.ByteArrayInputStream; -import java.net.Socket; - -import org.apache.tuscany.sca.node.Contribution; -import org.apache.tuscany.sca.node.ContributionLocationHelper; -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.NodeFactory; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.meterware.httpunit.GetMethodWebRequest; -import com.meterware.httpunit.PostMethodWebRequest; -import com.meterware.httpunit.PutMethodWebRequest; -import com.meterware.httpunit.WebConversation; -import com.meterware.httpunit.WebRequest; -import com.meterware.httpunit.WebResponse; - -public class BinaryServiceTestCase { - private static final String SERVICE_URL = "http://localhost:8085/Binary"; - - private static final String CONTENT = "ABCDefgh"; - private static final String UPDATED_CONTENT = "abcdEFGH"; - - private static Node node; - - @BeforeClass - public static void init() throws Exception { - try { - String contribution = ContributionLocationHelper.getContributionLocation(BinaryServiceTestCase.class); - node = NodeFactory.newInstance().createNode("binary.composite", new Contribution("binary", contribution)); - node.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @AfterClass - public static void destroy() throws Exception { - if (node != null) { - node.stop(); - } - } - - @Test - public void testPing() throws Exception { - new Socket("127.0.0.1", 8085); - //System.in.read(); - } - - @Test - public void testMethods() throws Exception { - WebConversation wc = new WebConversation(); - - // Create content - WebRequest request = - new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(CONTENT.getBytes("UTF-8")), - "application/octet-stream"); - WebResponse response = wc.getResource(request); - - Assert.assertEquals(204, response.getResponseCode()); - - // Read the content - request = new GetMethodWebRequest(SERVICE_URL); - response = wc.getResource(request); - - Assert.assertEquals(200, response.getResponseCode()); - Assert.assertEquals(CONTENT, response.getText()); - - request = - new PutMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(UPDATED_CONTENT.getBytes("UTF-8")), - "application/octet-stream"); - response = wc.getResource(request); - - Assert.assertEquals(204, response.getResponseCode()); - - //read new results and expect to get new item back in the response - request = new GetMethodWebRequest(SERVICE_URL); - response = wc.getResource(request); - - Assert.assertEquals(200, response.getResponseCode()); - Assert.assertEquals(UPDATED_CONTENT, response.getText()); - } -} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java deleted file mode 100644 index 2aa59af508..0000000000 --- a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.rest.wireformat.json; - -import java.io.ByteArrayInputStream; -import java.net.Socket; - -import org.apache.tuscany.sca.node.Contribution; -import org.apache.tuscany.sca.node.ContributionLocationHelper; -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.NodeFactory; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.meterware.httpunit.GetMethodWebRequest; -import com.meterware.httpunit.PostMethodWebRequest; -import com.meterware.httpunit.WebConversation; -import com.meterware.httpunit.WebRequest; -import com.meterware.httpunit.WebResponse; - -public class CatalogServiceTestCase { - private static final String SERVICE_URL = "http://localhost:8085/Catalog"; - - private static final String GET_RESPONSE = "{\"items\":[{\"price\":\"$1.55\",\"name\":\"Pear\"},{\"price\":\"$2.99\",\"name\":\"Apple\"},{\"price\":\"$3.55\",\"name\":\"Orange\"}]}"; - private static final String NEW_ITEM = "{\"price\":\"$4.35\",\"name\":\"Grape\"}\""; - private static final String GET_NEW_RESPONSE = "{\"items\":[{\"price\":\"$1.55\",\"name\":\"Pear\"},{\"price\":\"$2.99\",\"name\":\"Apple\"},{\"price\":\"$3.55\",\"name\":\"Orange\"},{\"price\":\"$4.35\",\"name\":\"Grape\"}]}"; - private static final String UPDATED_ITEM = "{\"price\":\"$1.35\",\"name\":\"Grape\"}\""; - private static final String GET_UPDATED_RESPONSE = "{\"items\":[{\"price\":\"$1.55\",\"name\":\"Pear\"},{\"price\":\"$2.99\",\"name\":\"Apple\"},{\"price\":\"$3.55\",\"name\":\"Orange\"},{\"price\":\"$1.35\",\"name\":\"Grape\"}]}"; - - private static Node node; - - @BeforeClass - public static void init() throws Exception { - try { - String contribution = ContributionLocationHelper.getContributionLocation(CatalogServiceTestCase.class); - node = NodeFactory.newInstance().createNode("store.composite", new Contribution("catalog", contribution)); - node.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @AfterClass - public static void destroy() throws Exception { - if(node != null) { - node.stop(); - } - } - - @Test - public void testPing() throws Exception { - new Socket("127.0.0.1", 8085); - //System.in.read(); - } - - @Test - public void testGetInvocation() throws Exception { - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest(SERVICE_URL); - request.setHeaderField("Content-Type", "application/json"); - WebResponse response = wc.getResource(request); - - Assert.assertEquals(200, response.getResponseCode()); - Assert.assertNotNull(response.getText()); - Assert.assertTrue(validateJsonResponse(GET_RESPONSE,response.getText())); - } - - - @Test - public void testPostInvocation() throws Exception { - //Add new item to catalog - WebConversation wc = new WebConversation(); - WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(NEW_ITEM.getBytes("UTF-8")),"application/json"); - request.setHeaderField("Content-Type", "application/json"); - WebResponse response = wc.getResource(request); - - Assert.assertEquals(204, response.getResponseCode()); - - //read new results and expect to get new item back in the response - request = new GetMethodWebRequest(SERVICE_URL); - request.setHeaderField("Content-Type", "application/json"); - response = wc.getResource(request); - - //for debug purposes - //System.out.println(">>>" + GET_UPDATED_RESPONSE); - //System.out.println(">>>" + response.getText()); - - Assert.assertEquals(200, response.getResponseCode()); - Assert.assertNotNull(response.getText()); - Assert.assertTrue(validateJsonResponse(GET_NEW_RESPONSE,response.getText())); - } - - @Test - public void testPutInvocation() throws Exception { - //Add new item to catalog - WebConversation wc = new WebConversation(); - WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(UPDATED_ITEM.getBytes("UTF-8")),"application/json"); - request.setHeaderField("Content-Type", "application/json"); - WebResponse response = wc.getResource(request); - - Assert.assertEquals(204, response.getResponseCode()); - - //read new results and expect to get new item back in the response - request = new GetMethodWebRequest(SERVICE_URL); - request.setHeaderField("Content-Type", "application/json"); - response = wc.getResource(request); - - //for debug purposes - //System.out.println(">>>" + GET_UPDATED_RESPONSE); - //System.out.println(">>>" + response.getText()); - - Assert.assertEquals(200, response.getResponseCode()); - Assert.assertNotNull(response.getText()); - Assert.assertTrue(validateJsonResponse(GET_UPDATED_RESPONSE,response.getText())); - } - - - private boolean validateJsonResponse(String expected, String actual) throws JSONException { - JSONObject jsonExpected = new JSONObject(expected); - JSONObject jsonActual = new JSONObject(actual); - - if(jsonExpected.getJSONArray("items").length() != jsonActual.getJSONArray("items").length()) { - return false; - } - - return true; - - } -} diff --git a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java b/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java deleted file mode 100644 index 9e1b99c9bc..0000000000 --- a/sca-java-2.x/branches/2.0-Beta3/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.rest.wireformat.xml; - -import java.io.ByteArrayInputStream; -import java.net.Socket; - -import org.apache.tuscany.sca.node.Contribution; -import org.apache.tuscany.sca.node.ContributionLocationHelper; -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.NodeFactory; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.meterware.httpunit.GetMethodWebRequest; -import com.meterware.httpunit.PostMethodWebRequest; -import com.meterware.httpunit.WebConversation; -import com.meterware.httpunit.WebRequest; -import com.meterware.httpunit.WebResponse; - -public class CustomerServiceTestCase { - private static final String SERVICE_URL = "http://localhost:8085/Customer"; - - private static final String GET_RESPONSE = "john@domain.comJohnJohn"; - private static final String UPDATED_ITEM = "john@updated-domain.comJohnJohn"; - private static final String GET_UPDATED_RESPONSE = "john@updated-domain.comJohnJohn"; - - private static Node node; - - @BeforeClass - public static void init() throws Exception { - try { - String contribution = ContributionLocationHelper.getContributionLocation(CustomerServiceTestCase.class); - node = NodeFactory.newInstance().createNode("customer.composite", new Contribution("customer", contribution)); - node.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @AfterClass - public static void destroy() throws Exception { - if(node != null) { - node.stop(); - } - } - - @Test - public void testPing() throws Exception { - new Socket("127.0.0.1", 8085); - //System.in.read(); - } - - @Test - public void testGetInvocation() throws Exception { - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest(SERVICE_URL+"/John"); - request.setHeaderField("Content-Type", "application/xml"); - WebResponse response = wc.getResource(request); - - //for debug purposes - System.out.println(">>>" + GET_RESPONSE); - System.out.println(">>>" + response.getText()); - - Assert.assertEquals(200, response.getResponseCode()); - Assert.assertEquals("no-cache", response.getHeaderField("Cache-Control")); - Assert.assertEquals("tuscany", response.getHeaderField("X-Tuscany")); - Assert.assertEquals(GET_RESPONSE, response.getText()); - - } - - @Test - public void testGetInvocationNotFound() throws Exception { - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest(SERVICE_URL+"/Foo"); - request.setHeaderField("Content-Type", "application/xml"); - WebResponse response = wc.getResource(request); - - Assert.assertEquals(404, response.getResponseCode()); - } - - @Test - public void testPutInvocation() throws Exception { - //Add new item to catalog - WebConversation wc = new WebConversation(); - WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(UPDATED_ITEM.getBytes("UTF-8")),"application/xml"); - WebResponse response = wc.getResource(request); - - Assert.assertEquals(201, response.getResponseCode()); - System.out.println(response.getHeaderField("Location")); - - //read new results and expect to get new item back in the response - request = new GetMethodWebRequest(SERVICE_URL); - request.setHeaderField("Content-Type", "application/xml"); - response = wc.getResource(request); - - //for debug purposes - //System.out.println(">>>" + GET_UPDATED_RESPONSE); - //System.out.println(">>>" + response.getText()); - - Assert.assertEquals(200, response.getResponseCode()); - Assert.assertEquals(GET_UPDATED_RESPONSE, response.getText()); - } -} -- cgit v1.2.3