abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r503579 - in /incubator/abdera/java/trunk: client/src/test/java/org/apache/abdera/test/client/app/AppTest.java protocol/src/main/java/org/apache/abdera/protocol/EntityTag.java
Date Mon, 05 Feb 2007 08:01:40 GMT
Author: jmsnell
Date: Mon Feb  5 00:01:39 2007
New Revision: 503579

URL: http://svn.apache.org/viewvc?view=rev&rev=503579
Log:
Some cleanup and adding a test case

Modified:
    incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/app/AppTest.java
    incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/EntityTag.java

Modified: incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/app/AppTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/app/AppTest.java?view=diff&rev=503579&r1=503578&r2=503579
==============================================================================
--- incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/app/AppTest.java
(original)
+++ incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/app/AppTest.java
Mon Feb  5 00:01:39 2007
@@ -41,6 +41,7 @@
 import org.apache.abdera.model.Workspace;
 import org.apache.abdera.parser.Parser;
 import org.apache.abdera.parser.ParserOptions;
+import org.apache.abdera.protocol.EntityTag;
 import org.apache.abdera.protocol.client.Client;
 import org.apache.abdera.protocol.client.CommonsClient;
 import org.apache.abdera.protocol.client.RequestOptions;
@@ -589,5 +590,29 @@
     }
 
     // YAY! We can handle media link entries 
+  }
+  
+  public void testEntityTag() throws Exception {
+    EntityTag tag1 = new EntityTag("tag");
+    EntityTag tag2 = new EntityTag("tag",true); // weak;
+    assertFalse(tag1.isWeak());
+    assertTrue(tag2.isWeak());
+    assertFalse(EntityTag.matches(tag1, tag2));
+    assertTrue(EntityTag.matches(tag1, tag2, true));
+    assertFalse(EntityTag.matchesAny(tag1, new EntityTag[] {tag2}));
+    assertTrue(EntityTag.matchesAny(tag1, new EntityTag[] {tag2}, true));
+    assertEquals(tag1.toString(), "\"tag\"");
+    assertEquals(tag2.toString(), "W/\"tag\"");
+    tag1 = EntityTag.parse("\"tag\"");
+    assertFalse(tag1.isWeak());
+    assertEquals(tag1.getTag(), "tag");
+    tag2 = EntityTag.parse("W/\"tag\"");
+    assertTrue(tag2.isWeak());
+    assertEquals(tag2.getTag(), "tag");    
+    EntityTag[] tags = EntityTag.parseTags("\"tag1\", W/\"tag2\"");
+    assertFalse(tags[0].isWeak());
+    assertEquals(tags[0].getTag(), "tag1");
+    assertTrue(tags[1].isWeak());
+    assertEquals(tags[1].getTag(), "tag2");
   }
 }

Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/EntityTag.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/EntityTag.java?view=diff&rev=503579&r1=503578&r2=503579
==============================================================================
--- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/EntityTag.java
(original)
+++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/EntityTag.java
Mon Feb  5 00:01:39 2007
@@ -25,12 +25,14 @@
  */
 public class EntityTag {
 
+  private static final String INVALID_ENTITY_TAG = "Invalid Entity Tag";
+
   public static EntityTag parse(String entity_tag) {
     if (entity_tag == null || entity_tag.length() == 0) 
-      throw new IllegalArgumentException("Invalid Entity Tag");;    
+      throw new IllegalArgumentException(INVALID_ENTITY_TAG);    
     boolean weak = entity_tag.startsWith("W/");
     if (!weak && !entity_tag.startsWith("\"")) 
-      throw new IllegalArgumentException("Invalid Entity Tag");
+      throw new IllegalArgumentException(INVALID_ENTITY_TAG);
     String tag = entity_tag.substring((weak)?3:1, entity_tag.length() - 1);
     return new EntityTag(tag, weak);
   }
@@ -117,7 +119,7 @@
   
   private void checkTag(String tag) {
     if (tag.contains("\"")) 
-      throw new IllegalArgumentException("Invalid Entity Tag");
+      throw new IllegalArgumentException(INVALID_ENTITY_TAG);
   }
   
   public String getTag() {
@@ -131,9 +133,9 @@
   public String toString() {
     StringBuffer buf = new StringBuffer();
     if (weak) buf.append("W/");
-    buf.append("\"");
+    buf.append('"');
     buf.append(tag);
-    buf.append("\"");
+    buf.append('"');
     return buf.toString();
   }
   



Mime
View raw message