Merge r1025776 TUSCANY-3742: Fix time comparison for If-Modified-Since and If-Unmodified-Since; also merge r1025533 Fix typos

git-svn-id: https://svn.apache.org/repos/asf/tuscany/sca-java-1.x/trunk@1027658 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java b/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
index 5ba07f5..3975fe1 100644
--- a/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
+++ b/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
@@ -278,7 +278,7 @@
                     if ( predicate != null ) {
                         try {
                             Date predicateDate = dateFormat.parse( predicate ); 
-                            if ( predicateDate.compareTo( feedUpdated ) < 0 ) {
+                            if ( predicateDate.compareTo( exactSeconds(feedUpdated) ) < 0 ) {
                                 // Match, should short circuit
                                 response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                                 return;
@@ -291,7 +291,7 @@
                     if ( predicate != null ) {
                         try {
                             Date predicateDate = dateFormat.parse( predicate ); 
-                            if ( predicateDate.compareTo( feedUpdated ) > 0 ) {
+                            if ( predicateDate.compareTo( exactSeconds(feedUpdated) ) >= 0 ) {
                                 // Match, should short circuit
                                 response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                                 return;
@@ -910,5 +910,13 @@
         }
     }
 
-    
+    /**
+     * Round a date down to an exact number of seconds
+     * @param date with millisecond precision
+     * @return date rounded down to nearest second
+     */
+    private Date exactSeconds(Date date) {
+        return new Date(date.getTime() / 1000 * 1000);
+    }
+
 }
diff --git a/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java b/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java
index 42edeb8..fd60ec4 100644
--- a/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java
+++ b/modules/binding-atom-abdera/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java
@@ -176,8 +176,9 @@
 		ClientResponse res = client.get(providerURI, opts);
 		Assert.assertNotNull(res);
 		try {
-			// Should return 304 - Feed not provided since feed is modified since.
-			Assert.assertEquals(304, res.getStatus());
+            // Should return 200 - Feed provided since feed is unmodified since.
+            Assert.assertEquals(200, res.getStatus());
+            Assert.assertEquals(ResponseType.SUCCESS, res.getType());
 		} finally {
 			res.release();
 		}
@@ -265,7 +266,7 @@
 			Date thisLastModified = res.getLastModified();
 			Assert.assertNotNull( thisLastModified );
                         
-			// Should return 200 - value since feed is changed
+			// Should return 200 - value since feed matches eTag
 			Assert.assertEquals(200, res.getStatus());
 			Assert.assertEquals(ResponseType.SUCCESS, res.getType());
 			
@@ -279,12 +280,12 @@
 
 	@Test
     public void testModifiedGetIfUnModified() throws Exception {		
-		System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfUnModified");
+		System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedModifiedGetIfUnModified");
 		// Feed request with predicates
 		RequestOptions opts = new RequestOptions();
 		final String contentType = "application/atom+xml"; 
 		opts.setContentType(contentType);
-		opts.setHeader( "If-Unmodified-Since", dateFormat.format( new Date() ));
+		opts.setHeader( "If-Unmodified-Since", dateFormat.format( previousSecond(lastModified) ));
 		
 		ClientResponse res = client.get(providerURI, opts);
 		Assert.assertNotNull(res);
@@ -298,12 +299,12 @@
 
 	@Test
     public void testModifiedGetIfModified() throws Exception {		
-		System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfModified");
+		System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedModifiedGetIfModified");
 		// Feed request with predicates
 		RequestOptions opts = new RequestOptions();
 		final String contentType = "application/atom+xml"; 
 		opts.setContentType(contentType);
-		opts.setHeader( "If-Modified-Since", dateFormat.format( lastModified ));
+		opts.setHeader( "If-Modified-Since", dateFormat.format( previousSecond(lastModified) ));
 		
 		ClientResponse res = client.get(providerURI, opts);
 		Assert.assertNotNull(res);
@@ -372,4 +373,13 @@
 			}
 		}
 	}
+
+    /**
+     * Subtract one second from a date
+     * @param date with millisecond precision
+     * @return date with one second subtracted
+     */
+    private Date previousSecond(Date date) {
+        return new Date(date.getTime() - 1000);
+    }
 }