You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by rl...@apache.org on 2013/03/23 20:55:35 UTC

svn commit: r1460219 - in /oodt/trunk: CHANGES.txt webapp/fmprod/src/test/org/apache/oodt/cas/product/rss/ webapp/fmprod/src/test/org/apache/oodt/cas/product/rss/RSSConfigReaderTest.java

Author: rlaidlaw
Date: Sat Mar 23 19:55:35 2013
New Revision: 1460219

URL: http://svn.apache.org/r1460219
Log:
OODT-583: Added JUnit test class for RSSConfigReader.

Added:
    oodt/trunk/webapp/fmprod/src/test/org/apache/oodt/cas/product/rss/
    oodt/trunk/webapp/fmprod/src/test/org/apache/oodt/cas/product/rss/RSSConfigReaderTest.java   (with props)
Modified:
    oodt/trunk/CHANGES.txt

Modified: oodt/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1460219&r1=1460218&r2=1460219&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Sat Mar 23 19:55:35 2013
@@ -3,6 +3,8 @@ Apache OODT Change Log
 Release 0.6 - Current Development
 --------------------------------------------
 
+* OODT-583 Added JUnit test class for RSSConfigReader (rlaidlaw)
+
 * OODT-582 Fix for oodt.cas.product.rss.RSSConfigReader.readTags() for detection
   of source attribute for tags defined in the RSS configuration file (rlaidlaw)
 

Added: oodt/trunk/webapp/fmprod/src/test/org/apache/oodt/cas/product/rss/RSSConfigReaderTest.java
URL: http://svn.apache.org/viewvc/oodt/trunk/webapp/fmprod/src/test/org/apache/oodt/cas/product/rss/RSSConfigReaderTest.java?rev=1460219&view=auto
==============================================================================
--- oodt/trunk/webapp/fmprod/src/test/org/apache/oodt/cas/product/rss/RSSConfigReaderTest.java (added)
+++ oodt/trunk/webapp/fmprod/src/test/org/apache/oodt/cas/product/rss/RSSConfigReaderTest.java Sat Mar 23 19:55:35 2013
@@ -0,0 +1,174 @@
+/*
+ * 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.oodt.cas.product.rss;
+
+import java.io.ByteArrayInputStream;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.oodt.commons.xml.XMLUtils;
+import org.w3c.dom.Document;
+
+/**
+ * Tests the {@link RSSConfigReader} class.
+ * @author rlaidlaw
+ * @version $Revision$
+ */
+public class RSSConfigReaderTest extends TestCase
+{
+  /**
+   * Tests the readNamespaces method.
+   */
+  public void testReadNamespaces()
+  {
+    String testXmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+        + "<rss:rssconf xmlns:rss=\"http://oodt.apache.org/ns/rss\">"
+        + "  <namespace prefix=\"cas\" uri=\"http://oodt.apache.org/ns/cas\"/>"
+        + "  <tag name=\"cas:source\" source=\"[ProductType]\"/>"
+        + "  <namespace prefix=\"pge\" uri=\"http://oodt.apache.org/ns/pge\"/>"
+        + "  <tag name=\"pge:tag\" source=\"[ProductType]\"/>"
+        + "  <namespace prefix=\"rss\" uri=\"http://oodt.apache.org/ns/rss\"/>"
+        + "  <tag name=\"rss:enclosure\">"
+        + "    <attribute name=\"x\" value=\"X\"/>"
+        + "    <attribute name=\"y\" value=\"Y\"/>"
+        + "    <attribute name=\"z\" value=\"Z\"/>"
+        + "  </tag>"
+        + "</rss:rssconf>";
+
+    Document testXmlDocument =
+        XMLUtils.getDocumentRoot(new ByteArrayInputStream(testXmlString
+            .getBytes()));
+
+    RSSConfig conf = new RSSConfig();
+    RSSConfigReader.readNamespaces(testXmlDocument.getDocumentElement(), conf);
+
+    List<RSSNamespace> namespaceList = conf.getNamespaces();
+    assertNotNull(namespaceList);
+    assertFalse(namespaceList.isEmpty());
+    assertEquals(3, namespaceList.size());
+
+    RSSNamespace namespaceA = namespaceList.get(0);
+    RSSNamespace namespaceB = namespaceList.get(1);
+    RSSNamespace namespaceC = namespaceList.get(2);
+
+    assertNotNull(namespaceA);
+    assertNotNull(namespaceB);
+    assertNotNull(namespaceC);
+
+    assertEquals("cas", namespaceA.getPrefix());
+    assertEquals("pge", namespaceB.getPrefix());
+    assertEquals("rss", namespaceC.getPrefix());
+
+    assertEquals("http://oodt.apache.org/ns/cas",
+        namespaceA.getUri());
+
+    assertEquals("http://oodt.apache.org/ns/pge",
+        namespaceB.getUri());
+
+    assertEquals("http://oodt.apache.org/ns/rss",
+        namespaceC.getUri());
+  }
+
+  /**
+   * Tests the readTags and readAttrs methods.
+   */
+  public void testReadTagsAndAttrs()
+  {
+    String testXmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+        + "<rss:rssconf xmlns:rss=\"http://oodt.apache.org/ns/rss\">"
+        + " <namespace prefix=\"cas\" uri=\"http://oodt.apache.org/ns/cas\"/>"
+        + " <tag name=\"cas:source\" source=\"[ProductType]\"/>"
+        + " <namespace prefix=\"georss\" uri=\"http://www.georss.org/georss\"/>"
+        + " <tag name=\"georss:point\" source=\"[Latitude] [Longitude]\">"
+        + "  <attribute name=\"one\" value=\"1\"/>"
+        + " </tag>"
+        + " <tag name=\"enclosure\" source=\"\">"
+        + "  <attribute name=\"two\" value=\"2\"/>"
+        + "  <attribute name=\"three\" value=\"3\"/>"
+        + " </tag>"
+        + " <tag name=\"enclosure\">"
+        + "  <attribute name=\"four\" value=\"4\"/>"
+        + "  <attribute name=\"five\" value=\"5\"/>"
+        + "  <attribute name=\"six\" value=\"6\"/>"
+        + " </tag>"
+        + "</rss:rssconf>";
+
+    Document testXmlDocument =
+        XMLUtils.getDocumentRoot(new ByteArrayInputStream(testXmlString
+            .getBytes()));
+
+    RSSConfig conf = new RSSConfig();
+    RSSConfigReader.readTags(testXmlDocument.getDocumentElement(), conf);
+
+    List<RSSTag> tagList = conf.getTags();
+    assertNotNull(tagList);
+    assertFalse(tagList.isEmpty());
+    assertEquals(4, tagList.size());
+
+    RSSTag tagA = tagList.get(0);
+    RSSTag tagB = tagList.get(1);
+    RSSTag tagC = tagList.get(2);
+    RSSTag tagD = tagList.get(3);
+
+    assertNotNull(tagA);
+    assertNotNull(tagB);
+    assertNotNull(tagC);
+    assertNotNull(tagD);
+
+    assertEquals("cas:source", tagA.getName());
+    assertEquals("georss:point", tagB.getName());
+    assertEquals("enclosure", tagC.getName());
+    assertEquals("enclosure", tagD.getName());
+
+    assertEquals("[ProductType]", tagA.getSource());
+    assertEquals("[Latitude] [Longitude]", tagB.getSource());
+    assertEquals("", tagC.getSource());
+    assertNull(tagD.getSource());
+
+    List<RSSTagAttribute> attributesA = tagA.getAttrs();
+    List<RSSTagAttribute> attributesB = tagB.getAttrs();
+    List<RSSTagAttribute> attributesC = tagC.getAttrs();
+    List<RSSTagAttribute> attributesD = tagD.getAttrs();
+
+    assertNotNull(attributesA);
+    assertNotNull(attributesB);
+    assertNotNull(attributesC);
+    assertNotNull(attributesD);
+
+    assertTrue(attributesA.isEmpty());
+    assertEquals(1, attributesB.size());
+    assertEquals(2, attributesC.size());
+    assertEquals(3, attributesD.size());
+
+    assertEquals("one", attributesB.get(0).getName());
+    assertEquals("two", attributesC.get(0).getName());
+    assertEquals("three", attributesC.get(1).getName());
+    assertEquals("four", attributesD.get(0).getName());
+    assertEquals("five", attributesD.get(1).getName());
+    assertEquals("six", attributesD.get(2).getName());
+
+    assertEquals("1", attributesB.get(0).getValue());
+    assertEquals("2", attributesC.get(0).getValue());
+    assertEquals("3", attributesC.get(1).getValue());
+    assertEquals("4", attributesD.get(0).getValue());
+    assertEquals("5", attributesD.get(1).getValue());
+    assertEquals("6", attributesD.get(2).getValue());
+  }
+}
+

Propchange: oodt/trunk/webapp/fmprod/src/test/org/apache/oodt/cas/product/rss/RSSConfigReaderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native