summaryrefslogtreecommitdiffstats
path: root/branches/sca-equinox/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--branches/sca-equinox/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java1647
1 files changed, 831 insertions, 816 deletions
diff --git a/branches/sca-equinox/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java b/branches/sca-equinox/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java
index bb5f6d5a8b..50022e9663 100644
--- a/branches/sca-equinox/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java
+++ b/branches/sca-equinox/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingCacheTestCase.java
@@ -29,7 +29,10 @@ import java.util.Date;
import junit.framework.TestCase;
-import org.apache.tuscany.sca.host.embedded.SCADomain;
+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;
/**
* HTTP binding unit tests.
@@ -37,819 +40,831 @@ import org.apache.tuscany.sca.host.embedded.SCADomain;
* @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();
- }
- }
- }
+ // 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 Node node;
+
+ @Override
+ protected void setUp() throws Exception {
+ String contribution = ContributionLocationHelper.getContributionLocation(HTTPBindingCacheTestCase.class);
+ node = NodeFactory.newInstance().createNode("testCache.composite", new Contribution("test", contribution));
+ node.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ node.stop();
+ node.destroy();
+ }
+
+ /**
+ * 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();
+ }
+ }
+ }
}