You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by rd...@apache.org on 2011/11/29 20:40:08 UTC

svn commit: r1208044 - in /incubator/rat/whisker/trunk/apache-whisker-xml/src: main/java/org/apache/rat/whisker/fromxml/ main/java/org/apache/rat/whisker/out/ test/java/org/apache/rat/whisker/fromxml/

Author: rdonkin
Date: Tue Nov 29 19:40:07 2011
New Revision: 1208044

URL: http://svn.apache.org/viewvc?rev=1208044&view=rev
Log:
Collect child resources

Added:
    incubator/rat/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/rat/whisker/fromxml/JDomBuilderByOrganisationTest.java   (with props)
Modified:
    incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/fromxml/JDomBuilder.java
    incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/out/ByOrganisation.java

Modified: incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/fromxml/JDomBuilder.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/fromxml/JDomBuilder.java?rev=1208044&r1=1208043&r2=1208044&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/fromxml/JDomBuilder.java (original)
+++ incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/fromxml/JDomBuilder.java Tue Nov 29 19:40:07 2011
@@ -18,6 +18,11 @@
  */
 package org.apache.rat.whisker.fromxml;
 
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.TreeSet;
+
 import org.apache.commons.lang3.StringUtils;
 import org.apache.rat.whisker.model.Organisation;
 import org.apache.rat.whisker.model.Resource;
@@ -77,4 +82,16 @@ public class JDomBuilder {
         }
     }
 
+    /**
+     * @param element
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    public Collection<Resource> collectResources(Element element) {
+        final Collection<Resource> resources = new TreeSet<Resource>();
+        for (Element resourceElement: (List<Element>) element.getChildren("resource")) {
+            resources.add(new JDomBuilder().resource(resourceElement));
+        }
+        return Collections.unmodifiableCollection(resources);
+    }
 }

Modified: incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/out/ByOrganisation.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/out/ByOrganisation.java?rev=1208044&r1=1208043&r2=1208044&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/out/ByOrganisation.java (original)
+++ incubator/rat/whisker/trunk/apache-whisker-xml/src/main/java/org/apache/rat/whisker/out/ByOrganisation.java Tue Nov 29 19:40:07 2011
@@ -45,18 +45,7 @@ public class ByOrganisation implements C
         return organisations.get(element.getAttributeValue("id"));
     }
    
-    /**
-     * @param element
-     * @return
-     */
-    @SuppressWarnings("unchecked")
-    private static Collection<Resource> resources(Element element) {
-        final Collection<Resource> resources = new TreeSet<Resource>();
-        for (Element resourceElement: (List<Element>) element.getChildren("resource")) {
-            resources.add(new JDomBuilder().resource(resourceElement));
-        }
-        return Collections.unmodifiableCollection(resources);
-    }
+
     
     private final Organisation organisation;
     private final Collection<Resource> resources;
@@ -72,7 +61,7 @@ public class ByOrganisation implements C
     public ByOrganisation(Element element, Organisation organisation) {
         super();
         this.organisation = organisation;
-        this.resources = resources(element);
+        this.resources = new JDomBuilder().collectResources(element);
     }
 
     public String getName() {

Added: incubator/rat/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/rat/whisker/fromxml/JDomBuilderByOrganisationTest.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/rat/whisker/fromxml/JDomBuilderByOrganisationTest.java?rev=1208044&view=auto
==============================================================================
--- incubator/rat/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/rat/whisker/fromxml/JDomBuilderByOrganisationTest.java (added)
+++ incubator/rat/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/rat/whisker/fromxml/JDomBuilderByOrganisationTest.java Tue Nov 29 19:40:07 2011
@@ -0,0 +1,89 @@
+/**
+ * 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.rat.whisker.fromxml;
+
+import java.util.Collection;
+
+import org.apache.rat.whisker.model.Resource;
+import org.jdom.Element;
+
+import junit.framework.TestCase;
+
+/**
+ * 
+ */
+public class JDomBuilderByOrganisationTest extends TestCase {
+    private JDomBuilder subject;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        subject = new JDomBuilder();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testBuildResourcesFromNoResources() throws Exception {
+        final Collection<Resource> results = subject.collectResources(new Element("by-organisation"));
+        assertNotNull("Expected empty collection to be returned", results);
+        assertEquals("Expected collection to be empty", 0, results.size());
+    }
+    
+
+    public void testCollectResourcesNumbered1() throws Exception {
+        checkCollectResourcesNumbered(1);
+    }
+
+    public void testCollectResourcesNumbered2() throws Exception {
+        checkCollectResourcesNumbered(2);
+    }
+    
+    public void testCollectResourcesNumbered3() throws Exception {
+        checkCollectResourcesNumbered(3);
+    }
+    
+    public void testCollectResourcesNumbered4() throws Exception {
+        checkCollectResourcesNumbered(4);
+    }
+
+    /**
+     * @param numberOfResources
+     */
+    private void checkCollectResourcesNumbered(final int numberOfResources) {
+        final Collection<Resource> results = subject.collectResources(withChildResources(numberOfResources));
+        assertNotNull("Expected empty collection to be returned", results);
+        assertEquals("Expected collection to be empty", numberOfResources, results.size());
+    }
+
+    /**
+     * @return
+     */
+    private Element withChildResources(int children) {
+        final Element result = new Element("by-organisation");
+        for (int i=0;i<children;i++) {
+                result.addContent(new Element("resource").setAttribute("name", "name" + i))
+                .addContent(new Element("whatever"));
+        }
+        return result;
+    }
+    
+}

Propchange: incubator/rat/whisker/trunk/apache-whisker-xml/src/test/java/org/apache/rat/whisker/fromxml/JDomBuilderByOrganisationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native