Commits

Anonymous committed caf7ccf

AUTOPLAN-4: integration test tasks are created for each test group

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

Comments (0)

Files changed (7)

             <groupId>org.jdom</groupId>
             <artifactId>jdom</artifactId>
             <version>1.1</version>
+            <scope>provided</scope>
         </dependency>
 
         <dependency>

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

 package com.adaptavist.bamboo.autoplan;
 
+import com.atlassian.bamboo.repository.MavenPomAccessorCapableRepository;
+import com.atlassian.bamboo.util.BambooFileUtils;
 import com.atlassian.bamboo.ww2.actions.admin.ImportMavenPlanCheckoutPomAction;
 import com.atlassian.spring.container.ContainerManager;
+import com.opensymphony.webwork.ServletActionContext;
+
+import javax.servlet.http.HttpSession;
+import java.io.File;
 
 public class CheckoutAction extends ImportMavenPlanCheckoutPomAction {
     // for some reason unknown to me the bamboo action doesn't get fully injected unless explicitly autowire it from the ContainerManager
     public CheckoutAction() {
         ContainerManager.autowireComponent(this);
     }
+
+    @Override
+    public String doExecute() throws Exception {
+        File tempDirectory = null;
+        MavenPomAccessorCapableRepository pomAccessorRepository = (MavenPomAccessorCapableRepository) repositoryManager.getNewRepositoryInstance(getSelectedRepositoryKey());
+        if (pomAccessorRepository == null)
+        {
+            throw new NullPointerException("Null reference to pomAccessorRepository - shall not happen");
+        }
+
+        pomAccessorRepository.populateFromConfig(getBuildConfiguration());
+
+        tempDirectory = BambooFileUtils.createTempDirectory(this);
+        File pomFile = pomAccessorRepository.getMavenPomAccessor().checkoutMavenPom(tempDirectory);
+        HttpSession session = ServletActionContext.getRequest().getSession(true);
+        session.setAttribute("pomfilename", pomFile.getAbsolutePath());
+        session.setAttribute("pomtmpdirectory", tempDirectory.getAbsolutePath());
+        return super.doExecute();
+    }
 }

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

 import com.atlassian.bamboo.fieldvalue.TaskConfigurationUtils;
 import com.atlassian.bamboo.notification.NotificationRule;
 import com.atlassian.bamboo.plan.PlanKeys;
+import com.atlassian.bamboo.repository.MavenPomAccessorCapableRepository;
 import com.atlassian.bamboo.task.TaskConfigConstants;
 import com.atlassian.bamboo.task.TaskDefinition;
 import com.atlassian.bamboo.task.TaskDefinitionImpl;
+import com.atlassian.bamboo.util.BambooFileUtils;
 import com.atlassian.bamboo.v2.build.trigger.DependencyBlockingStrategy;
 import com.atlassian.bamboo.webwork.util.ActionParametersMapImpl;
 import com.atlassian.bamboo.ww2.actions.admin.ImportMavenPlanCreatePlanAction;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import com.opensymphony.webwork.ServletActionContext;
 import com.opensymphony.xwork.ActionContext;
 import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.io.FileUtils;
 
+import javax.servlet.http.HttpSession;
+import java.io.File;
 import java.util.List;
 import java.util.Map;
 
 
         String chainKey = chainCreationService.createPlan(chainBuildConfiguration, actionParametersMap, enablePlan);
 
+        Pom pom = null;
+        HttpSession session = ServletActionContext.getRequest().getSession(true);
+        try {
+            session.getAttribute("pomfilename");
+            pom = new PomImpl((String)session.getAttribute("pomfilename"));
+        } finally {
+            File tempDirectory = new File((String)session.getAttribute("pomtmpdirectory"));
+            FileUtils.deleteDirectory(tempDirectory);
+        }
+
 
         fullPlanKey = createNewStageWithJob(chainKey, "Package", "PACKAGE", "Package Stage", "clean package", JobCreationService.NEW_STAGE_MARKER);
-        createNewStageWithJob(chainKey, "Integration Test", "INTTEST", "Integration Test Stage", "clean verify -DtestGroups=blah", JobCreationService.NEW_STAGE_MARKER);
-        createNewStageWithJob(chainKey, "Integration Test2", "INTTEST2", "Integration Test Stage", "clean verify -DtestGroups=blah", "Integration Test Stage");
+        boolean first = true;
+        for (TestGroup group : pom.getTestGroups()) {
+            final String id = group.getId().replaceAll("-", "");
+            createNewStageWithJob(chainKey, "Integration Test " + group.getId(), "INTTEST" + id, "Integration Test Stage", "clean verify -DtestGroups=" + group.getId(), first ? JobCreationService.NEW_STAGE_MARKER : "Integration Test Stage");
+            first = false;
+        }
         createNewStageWithJob(chainKey, "Deploy", "Deploy", "Deploy Stage", "clean deploy", JobCreationService.NEW_STAGE_MARKER);
 
 

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

                 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());
+                if (includes != null) {
+                    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());
+                if (productIds != null) {
+                    List<Element> productIdsList = productIds.getChildren("productId",def);
+                    for(Element productId : productIdsList) {
+                        testGroup.addProductId(productId.getText());
+                    }
                 }
 
                 testGroups.addTestGroup(testGroup);

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

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

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

 
     public TestGroupImpl(String id){
         this.id = id;
-    };
+    }
+
+    public String getId() {
+        return id;
+    }
 
     @Override
     public ProductIds getProductIds() {

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

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