Commits

Anonymous committed 631d977

AUTOPLAN-7 Added functionality for Test Groups

This commit add supports for test groups the api is backed using sets.

git-svn-id: https://adaptavist.jira.com/svn/AUTOPLAN/trunk@8730e6edf6fb-f266-4316-afb4-e53d95876a76

Comments (0)

Files changed (11)

src/main/java/com/adaptavist/bamboo/autoplan/Includes.java

+package com.adaptavist.bamboo.autoplan;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+public class Includes implements Collection<String> {
+    Set<String> values = new HashSet<String>();
+
+    @Override
+    public int size() {
+        return values.size();
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return values.isEmpty();
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        return values.contains(o);
+    }
+
+    @Override
+    public Iterator<String> iterator() {
+        return values.iterator();
+    }
+
+    @Override
+    public Object[] toArray() {
+        return values.toArray();
+    }
+
+    @Override
+    public <T> T[] toArray(T[] ts) {
+        return values.toArray(ts);
+    }
+
+    @Override
+    public boolean add(String s) {
+        return values.add(s);
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        return values.remove(o);
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> objects) {
+        return values.containsAll(objects);
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends String> strings) {
+        return values.addAll(strings);
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> objects) {
+        return values.retainAll(objects);
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> objects) {
+        return values.removeAll(objects);
+    }
+
+    @Override
+    public void clear() {
+        values.clear();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return values.equals(o);
+    }
+
+    @Override
+    public int hashCode() {
+        return values.hashCode();
+    }
+}

src/main/java/com/adaptavist/bamboo/autoplan/Pom.java

     String getScmLocation();
     String getProjectName();
     String getDescription();
+
+    TestGroups getTestGroups();
+
+
 }

src/main/java/com/adaptavist/bamboo/autoplan/PomImpl.java

         return getTextValueOfElement("description");
     }
 
+    @Override
+    public TestGroups getTestGroups() {
+        return createTestGroups();
+    }
+
+    private TestGroups createTestGroups() {
+        TestGroupsImpl testGroups = new TestGroupsImpl();
+
+         String textValue;
+        try {
+            XPath x = XPath.newInstance("//def:testGroups/def:testGroup");
+            x.addNamespace(def);
+            x.addNamespace(xsi);
+            List<Element> list = (List<Element>) x.selectNodes(doc);
+            for (Element element : list) {
+                Element id = element.getChild("id",def);
+                TestGroupImpl testGroup = new TestGroupImpl(id.getText());
+
+                Element includes = element.getChild("includes", def);
+                List<Element> includesList = includes.getChildren("include",def);
+                for(Element include : includesList) {
+                    testGroup.addInclude(include.getText());
+                }
+
+                Element productIds = element.getChild("productIds",def);
+                List<Element> productIdsList = productIds.getChildren("productId",def);
+                for(Element productId : productIdsList) {
+                    testGroup.addProductId(productId.getText());
+                }
+
+                testGroups.addTestGroup(testGroup);
+            }
+        } catch (JDOMException e) {
+            logger.error(e.getMessage());
+            textValue = "";
+        }
+
+
+
+        return testGroups;
+    }
+
+
     private String getTextValueOfElement(String elementName) {
         assert elementName != null;
 

src/main/java/com/adaptavist/bamboo/autoplan/ProductIds.java

+package com.adaptavist.bamboo.autoplan;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+public class ProductIds implements Collection<String> {
+    Set<String> values = new HashSet<String>();
+
+    @Override
+    public int size() {
+        return values.size();
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return values.isEmpty();
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        return values.contains(o);
+    }
+
+    @Override
+    public Iterator<String> iterator() {
+        return values.iterator();
+    }
+
+    @Override
+    public Object[] toArray() {
+        return values.toArray();
+    }
+
+    @Override
+    public <T> T[] toArray(T[] ts) {
+        return values.toArray(ts);
+    }
+
+    @Override
+    public boolean add(String s) {
+        return values.add(s);
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        return values.remove(o);
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> objects) {
+        return values.containsAll(objects);
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends String> strings) {
+        return values.addAll(strings);
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> objects) {
+        return values.retainAll(objects);
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> objects) {
+        return values.removeAll(objects);
+    }
+
+    @Override
+    public void clear() {
+        values.clear();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return values.equals(o);
+    }
+
+    @Override
+    public int hashCode() {
+        return values.hashCode();
+    }
+}

src/main/java/com/adaptavist/bamboo/autoplan/TestGroup.java

+package com.adaptavist.bamboo.autoplan;
+
+public interface TestGroup {
+    ProductIds getProductIds();
+
+    Includes getIncludes();
+}

src/main/java/com/adaptavist/bamboo/autoplan/TestGroupImpl.java

+package com.adaptavist.bamboo.autoplan;
+
+public class TestGroupImpl implements TestGroup {
+    String id;
+    ProductIds productIds =  new ProductIds();
+    Includes includes = new Includes();
+
+    public TestGroupImpl(String id){
+        this.id = id;
+    };
+
+    @Override
+    public ProductIds getProductIds() {
+        return productIds;
+    }
+
+    @Override
+    public Includes getIncludes() {
+        return includes;
+    }
+
+
+    public void addInclude(String include) {
+        includes.add(include);
+    }
+
+    public void addProductId(String productId) {
+        productIds.add(productId);
+    }
+}

src/main/java/com/adaptavist/bamboo/autoplan/TestGroups.java

+package com.adaptavist.bamboo.autoplan;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+interface TestGroups extends Iterable<TestGroup>, Collection<TestGroup> {
+    @Override
+    public Iterator<TestGroup> iterator();
+}

src/main/java/com/adaptavist/bamboo/autoplan/TestGroupsImpl.java

+package com.adaptavist.bamboo.autoplan;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+public class TestGroupsImpl implements TestGroups {
+    private final Set<TestGroup> testGroups=new HashSet<TestGroup>();
+
+    @Override
+    public Iterator<TestGroup> iterator() {
+        return testGroups.iterator();
+    }
+
+    @Override
+    public Object[] toArray() {
+        return testGroups.toArray();
+    }
+
+    @Override
+    public <T> T[] toArray(T[] ts) {
+        return testGroups.toArray(ts);
+    }
+
+    @Override
+    public boolean add(TestGroup testGroup) {
+        return testGroups.add(testGroup);
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        return testGroups.remove(o);
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> objects) {
+        return testGroups.containsAll(objects);
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends TestGroup> testGroups) {
+        return this.testGroups.addAll(testGroups);
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> objects) {
+        return testGroups.retainAll(objects);
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> objects) {
+        return testGroups.removeAll(objects);
+    }
+
+    public void addTestGroup(TestGroup testGroup){
+        testGroups.add(testGroup);
+    }
+
+    @Override
+    public int size() {
+        return testGroups.size();
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return testGroups.isEmpty();
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        return testGroups.contains(o);
+    }
+
+    @Override
+    public void clear() {
+        testGroups.clear();
+    }
+}

src/test/java/com/adaptavist/bamboo/autoplan/PomImplTest.java

 
 import org.junit.Test;
 
+import java.util.Iterator;
+
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 public class PomImplTest {
     @Test
         assertEquals("scm:svn:https://adaptavist.jira.com/svn/SIMPLE/trunk", pom.getScmLocation());
     }
 
+    @Test
+    public void testThatTestGroupsAreNotNull(){
+        Pom pom = createNewSimplePom();
+        TestGroups testGroups = pom.getTestGroups();
+        assertNotNull(testGroups);
+    }
+
+    @Test
+    public void testThatTestGroupsAreReturnedCorrectly(){
+        Pom pom = createNewSimplePom();
+        TestGroups testGroups = pom.getTestGroups();
+        Iterator<TestGroup> tgi = testGroups.iterator();
+        assertTrue(tgi.hasNext());
+    }
+
+    @Test
+    public void testThatAValidTestGroupExists(){
+        Pom pom = createNewSimplePom();
+        TestGroups testGroups = pom.getTestGroups();
+        Iterator<TestGroup> tgi = testGroups.iterator();
+        assertTrue(tgi.hasNext());
+        TestGroup tg = tgi.next();
+        assertNotNull(tg.getIncludes());
+        assertNotNull(tg.getProductIds());
+    }
+
 
     private Pom createNewSimplePom(){
         String pomFilename = "src/test/resources/simple-pom.xml";

src/test/java/com/adaptavist/bamboo/autoplan/TestGroupsImplTest.java

+package com.adaptavist.bamboo.autoplan;
+
+import org.junit.Test;
+
+public class TestGroupsImplTest {
+
+
+
+}

src/test/resources/simple-pom.xml

                 <configuration>
                     <productVersion>${confluence.version}</productVersion>
                     <productDataVersion>${confluence.data.version}</productDataVersion>
+                <testGroups>
+                       <testGroup>
+                           <id>confluence4-0</id>
+                           <productIds>
+                               <productId>confluence4-0</productId>
+                           </productIds>
+                           <includes>
+                               <include>it/**</include>
+                           </includes>
+                       </testGroup>
+                   </testGroups>
+
+
                 </configuration>
             </plugin>
             <plugin>