ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlboud...@apache.org
Subject svn commit: r1544430 - in /ant/easyant/core/trunk/src: main/java/org/apache/easyant/tasks/SearchModule.java test/java/org/apache/easyant/tasks/GoOfflineTest.java test/java/org/apache/easyant/tasks/SearchModuleTest.java
Date Fri, 22 Nov 2013 08:14:09 GMT
Author: jlboudart
Date: Fri Nov 22 08:14:08 2013
New Revision: 1544430

URL: http://svn.apache.org/r1544430
Log:
Add SearchModule unit tests

Added:
    ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/SearchModuleTest.java
Modified:
    ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SearchModule.java
    ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/GoOfflineTest.java

Modified: ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SearchModule.java
URL: http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SearchModule.java?rev=1544430&r1=1544429&r2=1544430&view=diff
==============================================================================
--- ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SearchModule.java (original)
+++ ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/SearchModule.java Fri Nov
22 08:14:08 2013
@@ -103,7 +103,7 @@ public class SearchModule extends IvyTas
                 log(sb.toString());
             }
         }
-        if (choices.size() == 0) {
+        if (choices.isEmpty()) {
             throw new BuildException("No matching module were found !");
         }
 

Modified: ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/GoOfflineTest.java
URL: http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/GoOfflineTest.java?rev=1544430&r1=1544429&r2=1544430&view=diff
==============================================================================
--- ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/GoOfflineTest.java (original)
+++ ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/GoOfflineTest.java Fri Nov
22 08:14:08 2013
@@ -45,8 +45,6 @@ public class GoOfflineTest extends AntTa
 
     private static final String EASYANT_BUILDSCOPE_REP = "easyant-buildscope-rep";
 
-    private File cache;
-
     private GoOffline goOffline;
 
     private File easyantBuildScopeRepoFolder;
@@ -59,7 +57,7 @@ public class GoOfflineTest extends AntTa
 
     @Before
     public void setUp() throws URISyntaxException, IOException {
-        cache = folder.newFolder("build-cache");
+        File cache = folder.newFolder("build-cache");
 
         Project project = new Project();
         ProjectUtils.configureProjectHelper(project);

Added: ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/SearchModuleTest.java
URL: http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/SearchModuleTest.java?rev=1544430&view=auto
==============================================================================
--- ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/SearchModuleTest.java (added)
+++ ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/SearchModuleTest.java Fri
Nov 22 08:14:08 2013
@@ -0,0 +1,180 @@
+/*
+ *  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.easyant.tasks;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+import org.apache.easyant.core.EasyAntMagicNames;
+import org.apache.easyant.core.ant.ProjectUtils;
+import org.apache.easyant.core.ivy.IvyInstanceHelper;
+import org.apache.ivy.ant.IvyConfigure;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Location;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.input.InputHandler;
+import org.apache.tools.ant.input.InputRequest;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
+
+public class SearchModuleTest {
+
+    private SearchModule searchModule = new SearchModule();
+
+    private FakeInputHandler fakeInputHandler = new FakeInputHandler();
+
+    @Rule
+    public TemporaryFolder folder = new TemporaryFolder();
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    @Before
+    public void setUp() throws URISyntaxException, IOException {
+        File cache = folder.newFolder("build-cache");
+
+        Project project = new Project();
+        ProjectUtils.configureProjectHelper(project);
+        project.setProperty("ivy.cache.dir", cache.getAbsolutePath());
+
+        IvyConfigure configure = new IvyConfigure();
+        configure.setSettingsId(EasyAntMagicNames.EASYANT_IVY_INSTANCE);
+        configure.setProject(project);
+        configure.setFile(new File(this.getClass().getResource("/repositories/easyant-ivysettings-test.xml").toURI()));
+        configure.execute();
+
+        project.setBaseDir(new File(this.getClass().getResource("simple").toURI()));
+        project.setInputHandler(fakeInputHandler);
+
+        searchModule.setProject(project);
+        searchModule.setOwningTarget(ProjectUtils.createTopLevelTarget());
+        searchModule.setLocation(new Location(ProjectUtils.emulateMainScript(project).getAbsolutePath()));
+        searchModule.setSettingsRef(IvyInstanceHelper.buildEasyAntIvyReference(project));
+
+    }
+
+    @Test
+    public void shouldFailIfNoOrganisationIsGiven() {
+        expectedException.expectMessage("no organisation provided for SearchModule task");
+        searchModule.execute();
+    }
+
+    @Test
+    public void shouldFailIfNoModuleIsGiven() {
+        expectedException.expectMessage("no module name provided for SearchModule task");
+
+        searchModule.setOrganisation("foo");
+        searchModule.execute();
+    }
+
+    @Test
+    public void shouldFailIfNoRevisionIsGiven() {
+        expectedException.expectMessage("no revision provided for SearchModule task");
+
+        searchModule.setOrganisation("foo");
+        searchModule.setModule("bar");
+        searchModule.execute();
+    }
+
+    @Test
+    public void shouldFailIfNoPropertyPrefixIsGiven() {
+        expectedException.expectMessage("no property prefix provided provided for SearchModule
task");
+
+        searchModule.setRevision("1.0");
+        searchModule.setOrganisation("foo");
+        searchModule.setModule("bar");
+        searchModule.execute();
+    }
+
+    @Test
+    public void shouldFailIfModuleNotFound() {
+        expectedException.expectMessage("No matching module were found !");
+
+        searchModule.setOrganisation("foo");
+        searchModule.setModule("bar");
+        searchModule.setRevision("1.0");
+        searchModule.setPropertyPrefix("mysearch");
+        searchModule.execute();
+    }
+
+    @Test
+    public void shouldFindExistingModuleWithExactParameter() {
+        searchModule.setOrganisation("mycompany");
+        searchModule.setModule("simpleplugin");
+        searchModule.setRevision("0.1");
+        searchModule.setPropertyPrefix("mysearch");
+        fakeInputHandler.setInput("0");
+        searchModule.execute();
+        assertThat(searchModule.getProject().getProperty("mysearch.org"), is("mycompany"));
+        assertThat(searchModule.getProject().getProperty("mysearch.module"), is("simpleplugin"));
+        assertThat(searchModule.getProject().getProperty("mysearch.rev"), is("0.1"));
+    }
+
+    @Test
+    public void shouldFindExistingModuleWithRegexpParameter() {
+        searchModule.setOrganisation("mycompany");
+        searchModule.setModule("*");
+        searchModule.setRevision("*");
+        searchModule.setPropertyPrefix("mysearch");
+        fakeInputHandler.setInput("0");
+        searchModule.execute();
+        assertThat(searchModule.getProject().getProperty("mysearch.org"), is("mycompany"));
+        assertThat(searchModule.getProject().getProperty("mysearch.module"), is("simpleplugin"));
+        assertThat(searchModule.getProject().getProperty("mysearch.rev"), is("0.1"));
+    }
+
+    @Test
+    public void shouldFindExistingModuleOnGivenResolver() {
+        searchModule.setOrganisation("mycompany");
+        searchModule.setModule("simpleplugin");
+        searchModule.setRevision("0.1");
+        searchModule.setPropertyPrefix("mysearch");
+        searchModule.setResolver("test-plugin");
+        fakeInputHandler.setInput("0");
+        searchModule.execute();
+        assertThat(searchModule.getProject().getProperty("mysearch.org"), is("mycompany"));
+        assertThat(searchModule.getProject().getProperty("mysearch.module"), is("simpleplugin"));
+        assertThat(searchModule.getProject().getProperty("mysearch.rev"), is("0.1"));
+    }
+
+    public static class FakeInputHandler implements InputHandler {
+
+        private String input = "";
+
+        public void handleInput(InputRequest request) throws BuildException {
+            request.setInput(input);
+        }
+
+        public String getInput() {
+            return input;
+        }
+
+        public void setInput(String input) {
+            this.input = input;
+        }
+
+    }
+
+}



Mime
View raw message