summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.5/modules/binding-http-runtime/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'branches/sca-java-1.5/modules/binding-http-runtime/src/test')
-rw-r--r--branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java855
-rw-r--r--branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingTestCase.java147
-rw-r--r--branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/NotModifiedException.java44
-rw-r--r--branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/PreconditionFailedException.java44
-rw-r--r--branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestBindingCacheImpl.java241
-rw-r--r--branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestGetImpl.java37
-rw-r--r--branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceCacheImpl.java61
-rw-r--r--branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceImpl.java61
-rw-r--r--branches/sca-java-1.5/modules/binding-http-runtime/src/test/resources/content/test.html21
-rw-r--r--branches/sca-java-1.5/modules/binding-http-runtime/src/test/resources/test.composite47
-rw-r--r--branches/sca-java-1.5/modules/binding-http-runtime/src/test/resources/testCache.composite33
11 files changed, 1591 insertions, 0 deletions
diff --git a/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java
new file mode 100644
index 0000000000..bb5f6d5a8b
--- /dev/null
+++ b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java
@@ -0,0 +1,855 @@
+/*
+ * 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.http;
+
+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.TestCase;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+
+/**
+ * HTTP binding unit tests.
+ *
+ * @version $Rev$ $Date$
+ */
+public class HTTPBindingCacheTestCase extends TestCase {
+ // 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 SCADomain scaDomain;
+
+ @Override
+ protected void setUp() throws Exception {
+ scaDomain = SCADomain.newInstance("testCache.composite");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ scaDomain.close();
+ }
+
+ /**
+ * Test invoking a POJO get method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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);
+ assertTrue(document.indexOf("<body><p>item=" + index) != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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
+ assertTrue(document.indexOf("<body><p>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
+ */
+ 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("<body><p>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
+ */
+ 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
+ assertTrue(document.indexOf("<body><p>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
+ */
+ 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("<body><p>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
+ */
+ 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("<body><p>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
+ */
+ 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
+ assertTrue(document.indexOf("<body><p>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
+ */
+ 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
+ assertTrue(document.indexOf("<body><p>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
+ */
+ 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("<body><p>item=" + index) != -1);
+ // Should return code 412 PreconditionFailed.
+ assertTrue(document.indexOf("HTTP/1.1 412") != -1);
+ }
+
+ /**
+ * Test invoking a POJO get method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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);
+ assertTrue(document.indexOf("deleted item=" + index) != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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
+ 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
+ */
+ 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.
+ assertTrue(document.indexOf("HTTP/1.1 304") != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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
+ 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
+ */
+ 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.
+ assertTrue(document.indexOf("HTTP/1.1 412") != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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.
+ assertTrue(document.indexOf("HTTP/1.1 412") != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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
+ 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
+ */
+ 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
+ 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
+ */
+ 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.
+ assertTrue(document.indexOf("HTTP/1.1 412") != -1);
+ }
+
+ /**
+ * Test invoking a POJO get method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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);
+ assertTrue(document.indexOf("HTTP/1.1 200 OK") != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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);
+ 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
+ */
+ 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.
+ assertTrue(document.indexOf("HTTP/1.1 304") != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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
+ 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
+ */
+ 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.
+ assertTrue(document.indexOf("HTTP/1.1 412") != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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.
+ 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
+ */
+ 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.
+ assertTrue(document.indexOf("HTTP/1.1 412") != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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
+ 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
+ */
+ 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.
+ assertTrue(document.indexOf("HTTP/1.1 412") != -1);
+ }
+
+ /**
+ * Test invoking a POJO get method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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);
+ assertTrue(document.indexOf("updated item=" + index) != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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
+ 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
+ */
+ 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.
+ assertTrue(document.indexOf("HTTP/1.1 304") != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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
+ 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
+ */
+ 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.
+ assertTrue(document.indexOf("HTTP/1.1 412") != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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.
+ assertTrue(document.indexOf("HTTP/1.1 412") != -1);
+ }
+
+ /**
+ * Test invoking a conditional method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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
+ 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
+ */
+ 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
+ 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
+ */
+ 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.
+ 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/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingTestCase.java b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingTestCase.java
new file mode 100644
index 0000000000..e5cad080a6
--- /dev/null
+++ b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingTestCase.java
@@ -0,0 +1,147 @@
+/*
+ * 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.http;
+
+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.TestCase;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+
+/**
+ * HTTP binding unit tests.
+ *
+ * @version $Rev$ $Date$
+ */
+public class HTTPBindingTestCase extends TestCase {
+
+ 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 SCADomain scaDomain;
+
+ @Override
+ protected void setUp() throws Exception {
+ scaDomain = SCADomain.newInstance("test.composite");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ scaDomain.close();
+ }
+
+ /**
+ * Test invoking a POJO service implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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);
+ assertTrue(document.indexOf("<body><p>hey</body>") != -1);
+ }
+
+ /**
+ * Test invoking a POJO get method implementation using the HTTP binding.
+ * @throws Exception
+ */
+ 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);
+ assertTrue(document.indexOf("<body><p>item=" + index) != -1);
+ }
+
+ /**
+ * Test getting a static resource provided using the HTTP binding.
+ * @throws Exception
+ */
+ 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);
+ assertTrue(document.indexOf("<body><p>hello</body>") != -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/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/NotModifiedException.java b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/NotModifiedException.java
new file mode 100644
index 0000000000..1d6efea2a1
--- /dev/null
+++ b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/NotModifiedException.java
@@ -0,0 +1,44 @@
+/*
+ * 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.http;
+
+/**
+ * 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/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/PreconditionFailedException.java b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/PreconditionFailedException.java
new file mode 100644
index 0000000000..5728899ebe
--- /dev/null
+++ b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/PreconditionFailedException.java
@@ -0,0 +1,44 @@
+/*
+ * 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.http;
+
+/**
+ * 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/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestBindingCacheImpl.java b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestBindingCacheImpl.java
new file mode 100644
index 0000000000..f2456f3175
--- /dev/null
+++ b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestBindingCacheImpl.java
@@ -0,0 +1,241 @@
+/*
+ * 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.http;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Date;
+
+/**
+ * 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(
+ ("<html><body><p>item=" + id + "</body></html>").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(
+ ("<html><body><p>item=" + id + "</body></html>").getBytes());
+ }
+
+ /**
+ * Implements the HTTP delete method of the collection implementation.
+ * @param id
+ * @return
+ */
+ public InputStream delete(String id) {
+ return new ByteArrayInputStream(
+ ("<html><body><p>deleted item=" + id + "</body></html>")
+ .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(
+ ("<html><body><p>deleted item=" + id + "</body></html>")
+ .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(
+ ("<html><body><p>posted item=" + id + "</body></html>")
+ .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(
+ ("<html><body><p>updated item=" + id + "</body></html>")
+ .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(
+ ("<html><body><p>updated item=" + id + "</body></html>")
+ .getBytes());
+ }
+
+}
diff --git a/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestGetImpl.java b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestGetImpl.java
new file mode 100644
index 0000000000..333bacbab3
--- /dev/null
+++ b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestGetImpl.java
@@ -0,0 +1,37 @@
+/*
+ * 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.http;
+
+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(("<html><body><p>item=" + id + "</body></html>").getBytes());
+
+ }
+
+}
diff --git a/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceCacheImpl.java b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceCacheImpl.java
new file mode 100644
index 0000000000..ed846c1127
--- /dev/null
+++ b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceCacheImpl.java
@@ -0,0 +1,61 @@
+/*
+ * 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.http;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Test service implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+
+@Service(Servlet.class)
+public class TestServiceCacheImpl 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("<html><body><p>hey</body></html>");
+ }
+
+ public void destroy() {
+ }
+
+ public ServletConfig getServletConfig() {
+ return null;
+ }
+
+ public String getServletInfo() {
+ return null;
+ }
+
+}
diff --git a/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceImpl.java b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceImpl.java
new file mode 100644
index 0000000000..11945c8cd1
--- /dev/null
+++ b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceImpl.java
@@ -0,0 +1,61 @@
+/*
+ * 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.http;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.osoa.sca.annotations.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("<html><body><p>hey</body></html>");
+ }
+
+ public void destroy() {
+ }
+
+ public ServletConfig getServletConfig() {
+ return null;
+ }
+
+ public String getServletInfo() {
+ return null;
+ }
+
+}
diff --git a/branches/sca-java-1.5/modules/binding-http-runtime/src/test/resources/content/test.html b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/resources/content/test.html
new file mode 100644
index 0000000000..f4b79d7f01
--- /dev/null
+++ b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/resources/content/test.html
@@ -0,0 +1,21 @@
+<html>
+<!--
+ * 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.
+-->
+<body><p>hello</body>
+</html> \ No newline at end of file
diff --git a/branches/sca-java-1.5/modules/binding-http-runtime/src/test/resources/test.composite b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/resources/test.composite
new file mode 100644
index 0000000000..62c4af4e22
--- /dev/null
+++ b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/resources/test.composite
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://sample/test"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sr="http://sample/test"
+ name="test">
+
+ <component name="ResourceServiceComponent">
+ <tuscany:implementation.resource location="content"/>
+ <service name="Resource">
+ <tuscany:binding.http uri="http://localhost:8085/webcontent"/>
+ </service>
+ </component>
+
+ <component name="HTTPServiceComponent">
+ <implementation.java class="org.apache.tuscany.sca.binding.http.TestServiceImpl"/>
+ <service name="Servlet">
+ <tuscany:binding.http uri="http://localhost:8085/httpservice"/>
+ </service>
+ </component>
+
+ <component name="HTTPGetComponent">
+ <implementation.java class="org.apache.tuscany.sca.binding.http.TestGetImpl"/>
+ <service name="TestGetImpl">
+ <tuscany:binding.http uri="http://localhost:8085/httpget"/>
+ </service>
+ </component>
+
+</composite>
diff --git a/branches/sca-java-1.5/modules/binding-http-runtime/src/test/resources/testCache.composite b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/resources/testCache.composite
new file mode 100644
index 0000000000..d805402c4f
--- /dev/null
+++ b/branches/sca-java-1.5/modules/binding-http-runtime/src/test/resources/testCache.composite
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://sample/test"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sr="http://sample/test"
+ name="test">
+
+ <component name="HTTPBindingComponent">
+ <implementation.java class="org.apache.tuscany.sca.binding.http.TestBindingCacheImpl"/>
+ <service name="TestBindingCacheImpl">
+ <tuscany:binding.http uri="http://localhost:8085/httpbinding"/>
+ </service>
+ </component>
+
+</composite>