abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ckopp...@apache.org
Subject svn commit: r944731 - in /abdera/java/trunk/core/src/test/java/org/apache/abdera: model/ test/core/ util/
Date Sat, 15 May 2010 21:58:47 GMT
Author: ckoppelt
Date: Sat May 15 21:58:46 2010
New Revision: 944731

URL: http://svn.apache.org/viewvc?rev=944731&view=rev
Log:
minor refactoring of unit tests; adopt test structure to src structure

Added:
    abdera/java/trunk/core/src/test/java/org/apache/abdera/util/ConfigurationTest.java
    abdera/java/trunk/core/src/test/java/org/apache/abdera/util/EntityTagTest.java
    abdera/java/trunk/core/src/test/java/org/apache/abdera/util/MimeTypeHelperTest.java
    abdera/java/trunk/core/src/test/java/org/apache/abdera/util/XmlRestrictedCharReaderTest.java
Removed:
    abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/EntityTagTest.java
Modified:
    abdera/java/trunk/core/src/test/java/org/apache/abdera/model/AtomDateTest.java
    abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java

Modified: abdera/java/trunk/core/src/test/java/org/apache/abdera/model/AtomDateTest.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/test/java/org/apache/abdera/model/AtomDateTest.java?rev=944731&r1=944730&r2=944731&view=diff
==============================================================================
--- abdera/java/trunk/core/src/test/java/org/apache/abdera/model/AtomDateTest.java (original)
+++ abdera/java/trunk/core/src/test/java/org/apache/abdera/model/AtomDateTest.java Sat May
15 21:58:46 2010
@@ -5,6 +5,7 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotSame;
 
+import java.util.Calendar;
 import java.util.Date;
 
 import org.junit.Test;
@@ -66,5 +67,40 @@ public class AtomDateTest {
     assertEquals(ad, adClone);
     assertNotSame(ad, adClone);
   }
-
+  
+  @Test
+  public void testAtomDate() {
+    Date now = new Date();
+    AtomDate atomNow = AtomDate.valueOf(now);
+    String rfc3339 = atomNow.getValue();
+    atomNow = AtomDate.valueOf(rfc3339);
+    Date parsed = atomNow.getDate();
+    assertEquals(now, parsed);
+  }
+  
+  @Test
+  public void testAtomDate2() {
+    String date = "2007-12-13T14:15:16.123Z";
+    AtomDate atomDate = new AtomDate(date);
+    Calendar calendar = atomDate.getCalendar();
+    atomDate = new AtomDate(calendar);
+    assertEquals(date,atomDate.toString());
+  }
+  
+  
+  @Test
+  public void testAtomDate3() {
+    long date = System.currentTimeMillis();
+    AtomDate atomDate = new AtomDate(date);
+    Calendar calendar = atomDate.getCalendar();
+    atomDate = new AtomDate(calendar);
+    assertEquals(date,atomDate.getTime());
+  }
+  
+  @Test (expected=IllegalArgumentException.class)
+  public void testIllegalDateFormat() {
+    String date = "";
+    AtomDate atomDate = new AtomDate(date);
+  }
+  
 }

Modified: abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java?rev=944731&r1=944730&r2=944731&view=diff
==============================================================================
--- abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java (original)
+++ abdera/java/trunk/core/src/test/java/org/apache/abdera/test/core/CoreTest.java Sat May
15 21:58:46 2010
@@ -18,46 +18,18 @@
 package org.apache.abdera.test.core;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.StringReader;
-import java.util.Calendar;
-import java.util.Date;
 
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.i18n.text.io.CompressionUtil;
-import org.apache.abdera.model.AtomDate;
-import org.apache.abdera.model.Entry;
-import org.apache.abdera.model.Feed;
-import org.apache.abdera.util.AbderaConfiguration;
-import org.apache.abdera.util.Configuration;
-import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.MimeTypeHelper;
-import org.apache.abdera.util.XmlRestrictedCharReader;
-import org.easymock.EasyMock;
 import org.junit.Test;
 
 
-public class CoreTest implements Constants {
-
-  @Test
-  public void testDefaultConfigurationProperties() {
-    Configuration config = new AbderaConfiguration();
-    assertEquals("org.apache.abdera.parser.stax.FOMFactory",
-      config.getConfigurationOption(CONFIG_FACTORY, DEFAULT_FACTORY)
-      );
-    assertEquals("org.apache.abdera.parser.stax.FOMParser",
-      config.getConfigurationOption(CONFIG_PARSER, DEFAULT_PARSER)
-      );
-    assertEquals("org.apache.abdera.parser.stax.FOMXPath",
-      config.getConfigurationOption(CONFIG_XPATH, DEFAULT_XPATH)
-      );
-  }
+public class CoreTest {
   
   @Test
   public void testUriNormalization() {
@@ -83,64 +55,6 @@ public class CoreTest implements Constan
     }
   }
   
-  @Test
-  public void testAtomDate() {
-    Date now = new Date();
-    AtomDate atomNow = AtomDate.valueOf(now);
-    String rfc3339 = atomNow.getValue();
-    atomNow = AtomDate.valueOf(rfc3339);
-    Date parsed = atomNow.getDate();
-    assertEquals(now, parsed);
-  }
-  
-  @Test
-  public void testAtomDate2() {
-    String date = "2007-12-13T14:15:16.123Z";
-    AtomDate atomDate = new AtomDate(date);
-    Calendar calendar = atomDate.getCalendar();
-    atomDate = new AtomDate(calendar);
-    assertEquals(date,atomDate.toString());
-  }
-  
-  @Test
-  public void testAtomDate3() {
-    long date = System.currentTimeMillis();
-    AtomDate atomDate = new AtomDate(date);
-    Calendar calendar = atomDate.getCalendar();
-    atomDate = new AtomDate(calendar);
-    assertEquals(date,atomDate.getTime());
-  }
-  
-  @Test
-  public void testXmlRestrictedCharReader() throws Exception {
-    String s = "\u0001abcdefghijklmnop\u0002";
-    StringReader r = new StringReader(s);
-    XmlRestrictedCharReader x = new XmlRestrictedCharReader(r);
-    char[] chars = new char[s.length()+1];
-    int n = x.read(chars);  // the first and last characters should never show up
-    assertEquals(s.length()-2,n);
-    assertEquals("abcdefghijklmnop",new String(chars,0,n));
-  }
-  
-  @Test
-  public void testMimeTypeHelper() throws Exception {
-    assertTrue(MimeTypeHelper.isApp("application/atomsvc+xml"));
-    assertFalse(MimeTypeHelper.isApp("application/atomserv+xml"));
-    assertTrue(MimeTypeHelper.isAtom("application/atom+xml"));
-    assertTrue(MimeTypeHelper.isAtom("application/atom+xml;type=\"entry\""));
-    assertTrue(MimeTypeHelper.isAtom("application/atom+xml;type=\"feed\""));
-    assertTrue(MimeTypeHelper.isEntry("application/atom+xml;type=\"entry\""));
-    assertTrue(MimeTypeHelper.isFeed("application/atom+xml;type=\"feed\""));
-    assertTrue(MimeTypeHelper.isText("text/plain"));
-    assertTrue(MimeTypeHelper.isXml("application/xml"));
-    
-    String[] types = MimeTypeHelper.condense("image/png","image/gif","image/png","image/*");
-    assertEquals(1, types.length);
-    assertEquals("image/*",types[0]);
-    
-    assertTrue(MimeTypeHelper.isEntry(MimeTypeHelper.getMimeType(EasyMock.createMock(Entry.class))));
-    assertTrue(MimeTypeHelper.isFeed(MimeTypeHelper.getMimeType(EasyMock.createMock(Feed.class))));
-  }
   
   @Test
   public void testCompressionUtil() throws Exception {

Added: abdera/java/trunk/core/src/test/java/org/apache/abdera/util/ConfigurationTest.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/test/java/org/apache/abdera/util/ConfigurationTest.java?rev=944731&view=auto
==============================================================================
--- abdera/java/trunk/core/src/test/java/org/apache/abdera/util/ConfigurationTest.java (added)
+++ abdera/java/trunk/core/src/test/java/org/apache/abdera/util/ConfigurationTest.java Sat
May 15 21:58:46 2010
@@ -0,0 +1,40 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class ConfigurationTest {
+    
+    @Test
+    public void testDefaultConfigurationProperties() {
+      Configuration config = new AbderaConfiguration();
+      assertEquals("org.apache.abdera.parser.stax.FOMFactory",
+        config.getConfigurationOption(Constants.CONFIG_FACTORY, Constants.DEFAULT_FACTORY)
+        );
+      assertEquals("org.apache.abdera.parser.stax.FOMParser",
+        config.getConfigurationOption(Constants.CONFIG_PARSER, Constants.DEFAULT_PARSER)
+        );
+      assertEquals("org.apache.abdera.parser.stax.FOMXPath",
+        config.getConfigurationOption(Constants.CONFIG_XPATH, Constants.DEFAULT_XPATH)
+        );
+    }
+
+}

Added: abdera/java/trunk/core/src/test/java/org/apache/abdera/util/EntityTagTest.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/test/java/org/apache/abdera/util/EntityTagTest.java?rev=944731&view=auto
==============================================================================
--- abdera/java/trunk/core/src/test/java/org/apache/abdera/util/EntityTagTest.java (added)
+++ abdera/java/trunk/core/src/test/java/org/apache/abdera/util/EntityTagTest.java Sat May
15 21:58:46 2010
@@ -0,0 +1,80 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.abdera.util.EntityTag;
+import org.junit.Test;
+
+public class EntityTagTest {
+
+  @Test
+  public void testEntityTag() throws Exception {
+    String[] tags = {
+      "hello",
+      "\"hello\"",
+      "W/\"hello\"",
+      "*"
+    };
+    EntityTag[] etags = new EntityTag[tags.length];
+    for (int n = 0; n < tags.length; n++) {
+      etags[n] = new EntityTag(tags[n]);
+    }
+    assertFalse(etags[0].isWeak());
+    assertFalse(etags[0].isWild());
+    assertFalse(etags[1].isWeak());
+    assertFalse(etags[1].isWild());
+    assertTrue(etags[2].isWeak());
+    assertFalse(etags[2].isWild());
+    assertFalse(etags[3].isWeak());
+    assertTrue(etags[3].isWild());
+    assertEquals("hello", etags[0].getTag());
+    assertEquals("hello", etags[1].getTag());
+    assertEquals("hello", etags[2].getTag());
+    assertEquals("*", etags[3].getTag());
+    assertEquals(tags[1], etags[0].toString());
+    assertEquals(tags[1], etags[1].toString());
+    assertEquals(tags[2], etags[2].toString());
+    assertEquals(tags[3], etags[3].toString());
+    
+    assertTrue(EntityTag.matches(etags[3], etags[0]));
+    assertTrue(EntityTag.matches(etags[3], etags[1]));
+    assertTrue(EntityTag.matches(etags[3], etags[2]));
+    assertTrue(EntityTag.matches(etags[3], etags[3]));
+
+    assertTrue(EntityTag.matches(etags[0], etags[1]));
+    assertFalse(EntityTag.matches(etags[0], etags[2]));
+    
+    assertTrue(EntityTag.matchesAny(etags[3], new EntityTag[] {etags[0], etags[1], etags[2]}));
+    assertTrue(EntityTag.matchesAny(etags[0], new EntityTag[] {etags[3], etags[1], etags[2]}));
+    assertTrue(EntityTag.matchesAny(etags[1], new EntityTag[] {etags[0], etags[3], etags[2]}));
+    assertTrue(EntityTag.matchesAny(etags[2], new EntityTag[] {etags[0], etags[1], etags[3]}));
+    
+    java.util.Arrays.sort(etags);
+    assertEquals(tags[3],etags[0].toString());
+    assertEquals(tags[1],etags[1].toString());
+    assertEquals(tags[1],etags[2].toString());
+    assertEquals(tags[2],etags[3].toString());
+    EntityTag etag = EntityTag.generate("a","b","c","d");
+    assertEquals("\"e2fc714c4727ee9395f324cd2e7f331f\"", etag.toString());
+  }
+  
+}

Added: abdera/java/trunk/core/src/test/java/org/apache/abdera/util/MimeTypeHelperTest.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/test/java/org/apache/abdera/util/MimeTypeHelperTest.java?rev=944731&view=auto
==============================================================================
--- abdera/java/trunk/core/src/test/java/org/apache/abdera/util/MimeTypeHelperTest.java (added)
+++ abdera/java/trunk/core/src/test/java/org/apache/abdera/util/MimeTypeHelperTest.java Sat
May 15 21:58:46 2010
@@ -0,0 +1,51 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class MimeTypeHelperTest {
+    
+    @Test
+    public void testMimeTypeHelper() throws Exception {
+      assertTrue(MimeTypeHelper.isApp("application/atomsvc+xml"));
+      assertFalse(MimeTypeHelper.isApp("application/atomserv+xml"));
+      assertTrue(MimeTypeHelper.isAtom("application/atom+xml"));
+      assertTrue(MimeTypeHelper.isAtom("application/atom+xml;type=\"entry\""));
+      assertTrue(MimeTypeHelper.isAtom("application/atom+xml;type=\"feed\""));
+      assertTrue(MimeTypeHelper.isEntry("application/atom+xml;type=\"entry\""));
+      assertTrue(MimeTypeHelper.isFeed("application/atom+xml;type=\"feed\""));
+      assertTrue(MimeTypeHelper.isText("text/plain"));
+      assertTrue(MimeTypeHelper.isXml("application/xml"));
+      
+      String[] types = MimeTypeHelper.condense("image/png","image/gif","image/png","image/*");
+      assertEquals(1, types.length);
+      assertEquals("image/*",types[0]);
+      
+      assertTrue(MimeTypeHelper.isEntry(MimeTypeHelper.getMimeType(EasyMock.createMock(Entry.class))));
+      assertTrue(MimeTypeHelper.isFeed(MimeTypeHelper.getMimeType(EasyMock.createMock(Feed.class))));
+    }
+
+}

Added: abdera/java/trunk/core/src/test/java/org/apache/abdera/util/XmlRestrictedCharReaderTest.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/test/java/org/apache/abdera/util/XmlRestrictedCharReaderTest.java?rev=944731&view=auto
==============================================================================
--- abdera/java/trunk/core/src/test/java/org/apache/abdera/util/XmlRestrictedCharReaderTest.java
(added)
+++ abdera/java/trunk/core/src/test/java/org/apache/abdera/util/XmlRestrictedCharReaderTest.java
Sat May 15 21:58:46 2010
@@ -0,0 +1,39 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.util;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.StringReader;
+
+import org.junit.Test;
+
+public class XmlRestrictedCharReaderTest {
+    
+    @Test
+    public void testXmlRestrictedCharReader() throws Exception {
+      String s = "\u0001abcdefghijklmnop\u0002";
+      StringReader r = new StringReader(s);
+      XmlRestrictedCharReader x = new XmlRestrictedCharReader(r);
+      char[] chars = new char[s.length()+1];
+      int n = x.read(chars);  // the first and last characters should never show up
+      assertEquals(s.length()-2,n);
+      assertEquals("abcdefghijklmnop",new String(chars,0,n));
+    }
+
+}



Mime
View raw message