Refactor tests to use test plugins
git-svn-id: https://svn.apache.org/repos/asf/ant/easyant/core/trunk@1554782 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/test/java/org/apache/easyant/core/EasyAntBaseTest.java b/src/test/java/org/apache/easyant/core/EasyAntBaseTest.java
index e304946..552559d 100755
--- a/src/test/java/org/apache/easyant/core/EasyAntBaseTest.java
+++ b/src/test/java/org/apache/easyant/core/EasyAntBaseTest.java
@@ -24,6 +24,7 @@
import static org.junit.Assert.fail;
import java.io.File;
+import java.io.IOException;
import java.io.PrintStream;
import java.net.URISyntaxException;
import java.net.URL;
@@ -36,6 +37,8 @@
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.LogLevel;
import org.junit.After;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
/**
* A EasyAntBaseTest is a TestCase which executes targets from an easyant module for testing.
@@ -45,7 +48,7 @@
*/
public abstract class EasyAntBaseTest {
- protected static final String EASYANT_CACHE_DIR = "easyant.default.cache.dir";
+ protected static final String EASYANT_CACHE_DIR = "ivy.cache.dir";
protected Project project;
protected EasyAntConfiguration conf;
@@ -55,6 +58,9 @@
private StringBuffer errBuffer;
private BuildException buildException;
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+
/**
* Automatically calls the target called "tearDown" from the build file tested if it exits.
*
@@ -75,7 +81,6 @@
if (project.getTargets().containsKey(tearDown)) {
project.executeTarget(tearDown);
}
- cleanCache();
cleanTargetDirectory();
}
@@ -373,10 +378,15 @@
// to avoid side effects due to user settings we ignore this setting by
// default for test
conf.getDefinedProps().put(EasyAntMagicNames.IGNORE_USER_IVYSETTINGS, "true");
+ conf.getDefinedProps().put(EasyAntMagicNames.PROJECT_IVY_INSTANCE, EasyAntMagicNames.EASYANT_IVY_INSTANCE);
// Configure easyant ivy instance
- conf.setEasyantIvySettingsUrl(this.getClass().getResource("/ivysettings-test.xml"));
-
+ conf.setEasyantIvySettingsUrl(this.getClass().getResource("/repositories/easyant-ivysettings-test.xml"));
+ try {
+ conf.getDefinedProps().put("ivy.cache.dir", folder.newFolder().getAbsolutePath());
+ } catch (IOException e) {
+ throw new BuildException(e);
+ }
File projectModule = new File(filename);
if (!projectModule.exists()) {
throw new BuildException("Project " + projectModule.getAbsolutePath() + " does not exists");
@@ -398,11 +408,6 @@
// init the new project instance
project = new Project();
project.addBuildListener(new AntTestListener(conf.getMsgOutputLevel()));
- try {
- project.setBaseDir(new File(this.getResource(".").toURI()));
- } catch (URISyntaxException e) {
- throw new RuntimeException("Can't configure basedir");
- }
EasyAntEngine eaEngine = new EasyAntEngine(conf);
eaEngine.initProject(project);
}
diff --git a/src/test/java/org/apache/easyant/core/EasyAntEngineTest.java b/src/test/java/org/apache/easyant/core/EasyAntEngineTest.java
index ea7f411..e75fb89 100644
--- a/src/test/java/org/apache/easyant/core/EasyAntEngineTest.java
+++ b/src/test/java/org/apache/easyant/core/EasyAntEngineTest.java
@@ -108,15 +108,15 @@
@Test
public void shouldFindFileInCurrentDirectory() throws URISyntaxException {
- File startFile = new File(this.getClass().getResource("multimodule/myapp-hello-world").toURI());
+ File startFile = new File(this.getClass().getResource("multimodule/myapp-core").toURI());
File foundFile = easyantEngine.findBuildModule(startFile.getAbsolutePath(), "module.ivy");
assertThat(foundFile.getName(), is("module.ivy"));
- assertThat(foundFile.getParentFile().getName(), is("myapp-hello-world"));
+ assertThat(foundFile.getParentFile().getName(), is("myapp-core"));
}
@Test
public void shouldFindFileInParentDirectory() throws URISyntaxException {
- File startFile = new File(this.getClass().getResource("multimodule/myapp-hello-world").toURI());
+ File startFile = new File(this.getClass().getResource("multimodule/myapp-core").toURI());
File foundFile = easyantEngine.findBuildModule(startFile.getAbsolutePath(), "parent.ivy");
assertThat(foundFile.getName(), is("parent.ivy"));
assertThat(foundFile.getParentFile().getName(), is("multimodule"));
@@ -125,7 +125,7 @@
@Test
public void shouldFailIfNotFound() throws URISyntaxException {
expectedException.expectMessage("Could not locate a build file!");
- File startFile = new File(this.getClass().getResource("multimodule/myapp-hello-world").toURI());
+ File startFile = new File(this.getClass().getResource("multimodule/myapp-core").toURI());
easyantEngine.findBuildModule(startFile.getAbsolutePath(), "a-missing-file");
}
diff --git a/src/test/java/org/apache/easyant/core/ModuleInheritanceTest.java b/src/test/java/org/apache/easyant/core/ModuleInheritanceTest.java
index 0ee7bce..9bb8ae5 100644
--- a/src/test/java/org/apache/easyant/core/ModuleInheritanceTest.java
+++ b/src/test/java/org/apache/easyant/core/ModuleInheritanceTest.java
@@ -18,7 +18,6 @@
package org.apache.easyant.core;
import org.apache.tools.ant.Project;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -37,20 +36,19 @@
@Test
public void shouldInheritPluginWithScopeChild() {
- executeTarget("source-jar:init");
+ executeTarget("modulewithtarget:mytarget");
}
@Test
public void shouldNotInheritElements() {
- expectBuildException("documentation:init",
- "Target \"documentation:init\" does not exist in the project \"myapp-core\"");
- expectPropertyUnset("validate", "my.property");
+ expectPropertyUnset("package", "aproperty");
}
@Test
public void shouldInheritBindTarget() {
- // this property is loaded by source-jar:init and should be bind to validate extensionPoint only if bindtarget
+ // this property is loaded by modulewithtarget:mytarget and should be bind to validate extensionPoint only if
+ // bindtarget
// has been inherited
- expectPropertySet("validate", "src.publish.conf", "source");
+ expectPropertySet("package", "apropertyinmytarget", "foobar");
}
}
diff --git a/src/test/java/org/apache/easyant/core/PropertiesAsAttributesTest.java b/src/test/java/org/apache/easyant/core/PropertiesAsAttributesTest.java
index 40f0985..c76d8f2 100644
--- a/src/test/java/org/apache/easyant/core/PropertiesAsAttributesTest.java
+++ b/src/test/java/org/apache/easyant/core/PropertiesAsAttributesTest.java
@@ -17,8 +17,10 @@
*/
package org.apache.easyant.core;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
import org.apache.tools.ant.Project;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -46,7 +48,7 @@
@Test
public void shouldHandlePropertiesInConfigureProject() {
- Assert.assertEquals("dist", project.getDefaultTarget());
+ assertThat(project.getDefaultTarget(), is("package"));
assertPropertyEquals("my.property.inconfigureproject", "true");
}
diff --git a/src/test/java/org/apache/easyant/core/StandardJavaProjectTest.java b/src/test/java/org/apache/easyant/core/StandardJavaProjectTest.java
index fcfc941..090c3ed 100644
--- a/src/test/java/org/apache/easyant/core/StandardJavaProjectTest.java
+++ b/src/test/java/org/apache/easyant/core/StandardJavaProjectTest.java
@@ -30,13 +30,8 @@
}
@Test
- public void shouldInvokeClean() {
- executeTarget("clean");
- }
-
- @Test
- public void shouldInvokeCompile() {
- executeTarget("compile");
+ public void shouldInvokeMyTarget() {
+ executeTarget("modulewithtarget:mytarget");
}
@Test
@@ -45,26 +40,21 @@
}
@Test
- public void shouldInvokeVerify() {
- executeTarget("verify");
- }
-
- @Test
public void shouldImportWithoutAsAttribute() {
- // <ea:plugin module="javadoc" revision="0.1"/>
+ // <ea:plugin organisation="mycompany" module="modulewithtarget:mytarget" revision="0.1"/>
// no "as" attribute is specified, easyant should prefix all targets with "module" value by default
- executeTarget("javadoc:javadoc");
+ executeTarget("modulewithtarget:mytarget");
}
@Test
public void shouldImportWithAsAttribute() {
- // <ea:plugin module="javadoc" revision="0.1" as="foobar"/>
- executeTarget("foobarjavadoc:javadoc");
+ // <ea:plugin organisation="mycompany" module="modulewithtarget:mytarget" revision="0.1" as="foobar"/>
+ executeTarget("foobarmodulewithtarget:mytarget");
}
@Test
public void shouldOverrideExistingProperty() {
- assertPropertyEquals("default.build.number", "10");
+ assertPropertyEquals("myproperty", "newvalue");
}
}
diff --git a/src/test/java/org/apache/easyant/core/ant/helper/ModuleIvyProjectHelperTest.java b/src/test/java/org/apache/easyant/core/ant/helper/ModuleIvyProjectHelperTest.java
index b5a6b20..93e606a 100644
--- a/src/test/java/org/apache/easyant/core/ant/helper/ModuleIvyProjectHelperTest.java
+++ b/src/test/java/org/apache/easyant/core/ant/helper/ModuleIvyProjectHelperTest.java
@@ -17,18 +17,28 @@
*/
package org.apache.easyant.core.ant.helper;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+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.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.ProjectHelperRepository;
-import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
public class ModuleIvyProjectHelperTest {
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+
@Before
public void setUp() {
// ProjectHelperRepository.getInstance().registerProjectHelper("org.apache.easyant.core.ant.EasyAntProjectHelper");
@@ -38,14 +48,18 @@
}
@Test
- public void shouldHandleModuleIvyFile() throws URISyntaxException {
- File f = new File(this.getClass().getResource("../../standardJavaProject.ivy").toURI());
+ public void shouldHandleModuleIvyFile() throws URISyntaxException, IOException {
+ File f = new File(this.getClass().getResource("../../simpleproject.ivy").toURI());
Project p = new Project();
- p.setBaseDir(new File(this.getClass().getResource(".").toURI()));
+ // disable project ivy instance
+ p.setNewProperty(EasyAntMagicNames.PROJECT_IVY_INSTANCE, EasyAntMagicNames.EASYANT_IVY_INSTANCE);
p.setNewProperty(EasyAntMagicNames.IGNORE_USER_IVYSETTINGS, "true");
p.setNewProperty(EasyAntMagicNames.GLOBAL_EASYANT_IVYSETTINGS,
- this.getClass().getResource("/ivysettings-test.xml").toString());
+ this.getClass().getResource("/repositories/easyant-ivysettings-test.xml").toString());
+ p.setProperty("ivy.cache.dir", folder.newFolder("build-cache").getAbsolutePath());
ProjectHelper.configureProject(p, f);
- Assert.assertNotNull(p.getTargets().get("clean"));
+ assertThat(p.getTargets().get("complexplugin:mytarget"), is(notNullValue()));
+ assertThat(p.getProperty("myproperty"), is("foobar"));
+
}
}
diff --git a/src/test/resources/org/apache/easyant/core/multimodule/module.ivy b/src/test/resources/org/apache/easyant/core/multimodule/module.ivy
deleted file mode 100644
index 46737b9..0000000
--- a/src/test/resources/org/apache/easyant/core/multimodule/module.ivy
+++ /dev/null
@@ -1,21 +0,0 @@
-<!--
- 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.
--->
-<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
- <info organisation="org.apache.easyant" module="myapp-orchestrator" revision="0.2" status="integration" >
- <ea:build module="meta-build" revision="0.9"/>
- </info>
-</ivy-module>
diff --git a/src/test/resources/org/apache/easyant/core/multimodule/myapp-core/module.ivy b/src/test/resources/org/apache/easyant/core/multimodule/myapp-core/module.ivy
index 068a964..3903801 100644
--- a/src/test/resources/org/apache/easyant/core/multimodule/myapp-core/module.ivy
+++ b/src/test/resources/org/apache/easyant/core/multimodule/myapp-core/module.ivy
@@ -17,6 +17,6 @@
<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
<info organisation="org.apache.easyant" module="myapp-core" revision="0.2" status="integration">
<extends organisation="org.apache.easyant" module="myapp-parent" revision="latest.revision" location="../parent.ivy"/>
- <ea:build module="build-std-java" revision="0.9"/>
+ <ea:build organisation="mycompany" module="complexplugin" revision="0.1"/>
</info>
</ivy-module>
diff --git a/src/test/resources/org/apache/easyant/core/multimodule/parent.ivy b/src/test/resources/org/apache/easyant/core/multimodule/parent.ivy
index 6bb982e..f8c5d28 100644
--- a/src/test/resources/org/apache/easyant/core/multimodule/parent.ivy
+++ b/src/test/resources/org/apache/easyant/core/multimodule/parent.ivy
@@ -17,9 +17,9 @@
<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
<info organisation="org.apache.easyant" module="myapp-parent" revision="0.2" status="integration" >
<ea:property name="test.property" value="myvalue"/>
- <ea:plugin module="source-jar" revision="0.9" inherit-scope="child" />
- <ea:plugin module="documentation" revision="0.9" inheritable="false" my.property="myvalue"/>
- <ea:bindtarget target="source-jar:init" extensionOf="validate" inherit-scope="child"/>
+ <ea:plugin organisation="mycompany" module="modulewithtarget" revision="0.1" inherit-scope="child" />
+ <ea:plugin organisation="mycompany" module="simplepluginwithproperties" revision="0.1" inheritable="false" my.property="myvalue"/>
+ <ea:bindtarget target="modulewithtarget:mytarget" extensionOf="package" inherit-scope="child"/>
</info>
<configurations>
<conf name="default" visibility="public" description="runtime dependencies and master artifact can be used with this conf"/>
diff --git a/src/test/resources/org/apache/easyant/core/propertiesAsAttributes.ivy b/src/test/resources/org/apache/easyant/core/propertiesAsAttributes.ivy
index 2734a99..f9a7dc3 100644
--- a/src/test/resources/org/apache/easyant/core/propertiesAsAttributes.ivy
+++ b/src/test/resources/org/apache/easyant/core/propertiesAsAttributes.ivy
@@ -16,9 +16,9 @@
-->
<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
<info organisation="org.apache.easyant" module="standard-java-app" status="integration" >
- <ea:build mrid="org.apache.easyant.buildtypes#build-std-java;0.9" my.property.inbuildtype="true"/>
- <ea:plugin module="javadoc" revision="0.9" my.property.inplugin="true"/>
- <ea:plugin module="javadoc" revision="0.9" my-dashes="true" my.property.inconf="true" conf="myBuild"/>
+ <ea:build organisation="mycompany" module="complexplugin" revision="0.1" my.property.inbuildtype="true"/>
+ <ea:plugin organisation="mycompany" module="simpleplugin" revision="0.1" my.property.inplugin="true"/>
+ <ea:plugin organisation="mycompany" module="simpleplugin" revision="0.1" my-dashes="true" my.property.inconf="true" conf="myBuild"/>
<ea:configure-project defaulttarget="package" my.property.inconfigureproject="true"/>
</info>
<configurations>
diff --git a/src/test/resources/org/apache/easyant/core/multimodule/myapp-hello-world/module.ivy b/src/test/resources/org/apache/easyant/core/simpleproject.ivy
similarity index 73%
rename from src/test/resources/org/apache/easyant/core/multimodule/myapp-hello-world/module.ivy
rename to src/test/resources/org/apache/easyant/core/simpleproject.ivy
index fe8fa14..7042aca 100644
--- a/src/test/resources/org/apache/easyant/core/multimodule/myapp-hello-world/module.ivy
+++ b/src/test/resources/org/apache/easyant/core/simpleproject.ivy
@@ -15,17 +15,11 @@
limitations under the License.
-->
<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
- <info organisation="org.apache.easyant" module="myapp-hello-world" revision="0.2" status="integration" >
- <ea:build module="build-std-java" revision="0.9">
- <ea:property name="run.main.classname" value="org.apache.easyant.example.Example"/>
- </ea:build>
-
- </info>
+ <info organisation="mycompany" module="simpleproject-app" status="integration" >
+ <ea:plugin organisation="mycompany" module="complexplugin" revision="0.1"/>
+ </info>
<configurations>
<conf name="default" visibility="public" description="runtime dependencies and master artifact can be used with this conf"/>
<conf name="test" visibility="private" description="this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases."/>
</configurations>
- <dependencies>
- <dependency org="org.apache.easyant" name="myapp-core" rev="latest.revision" conf="default->default"/>
- </dependencies>
</ivy-module>
diff --git a/src/test/resources/org/apache/easyant/core/standardJavaProject.ivy b/src/test/resources/org/apache/easyant/core/standardJavaProject.ivy
index a59c468..f0850fb 100644
--- a/src/test/resources/org/apache/easyant/core/standardJavaProject.ivy
+++ b/src/test/resources/org/apache/easyant/core/standardJavaProject.ivy
@@ -16,11 +16,11 @@
-->
<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
<info organisation="org.apache.easyant" module="standard-java-app" status="integration" >
- <ea:build mrid="org.apache.easyant.buildtypes#build-std-java;0.9">
- <ea:property name="default.build.number" value="10"/>
+ <ea:build organisation="mycompany" module="complexplugin" revision="0.1">
+ <ea:property name="myproperty" value="newvalue"/>
</ea:build>
- <ea:plugin module="javadoc" revision="0.9"/>
- <ea:plugin module="javadoc" revision="0.9" as="foobar" mode="include"/>
+ <ea:plugin organisation="mycompany" module="modulewithtarget" revision="0.1"/>
+ <ea:plugin organisation="mycompany" module="modulewithtarget" revision="0.1" as="foobar" mode="include"/>
</info>
<configurations>
<conf name="default" visibility="public" description="runtime dependencies and master artifact can be used with this conf"/>
diff --git a/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ants/modulewithtarget-0.1.ant b/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ants/modulewithtarget-0.1.ant
index 16007a7..cf1c9bb 100644
--- a/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ants/modulewithtarget-0.1.ant
+++ b/src/test/resources/repositories/plugins/mycompany/modulewithtarget/ants/modulewithtarget-0.1.ant
@@ -17,5 +17,6 @@
<project name="mycompany#modulewithtarget">
<target name="modulewithtarget:mytarget">
<echo>a message from mytarget</echo>
+ <property name="apropertyinmytarget" value="foobar"/>
</target>
</project>
\ No newline at end of file
diff --git a/src/test/resources/repositories/plugins/mycompany/simplepluginwithproperties/ants/simplepluginwithproperties-0.1.ant b/src/test/resources/repositories/plugins/mycompany/simplepluginwithproperties/ants/simplepluginwithproperties-0.1.ant
index 42a34f4..f57d0e1 100644
--- a/src/test/resources/repositories/plugins/mycompany/simplepluginwithproperties/ants/simplepluginwithproperties-0.1.ant
+++ b/src/test/resources/repositories/plugins/mycompany/simplepluginwithproperties/ants/simplepluginwithproperties-0.1.ant
@@ -19,4 +19,7 @@
<ea:parameter property="src.main.java" default="${basedir}/src/main/java" description="directory where sources to be compiled are" />
<echo>a simple plugin with properties</echo>
+ <target name="simplepluginwithproperties:init">
+ <property name="aproperty" value="avalue"/>
+ </target>
</project>
\ No newline at end of file