Skip to content
Browse files

new test cases

  • Loading branch information...
1 parent e2613fe commit 85404ec4b0901944d135bbeee976c4ce18ff67fb @mepeisen mepeisen committed Apr 29, 2012
Showing with 1,243 additions and 0 deletions.
  1. +236 −0 branches/2.0-SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/LookupHintTest.java
  2. +50 −0 ...es/2.0-SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/LookupServiceTest.java
  3. +89 −0 branches/2.0-SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/LookupTest.java
  4. +187 −0 ...2.0-SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/LookupWithFilterTest.java
  5. +87 −0 ...SHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/LookupWithoutBuildConfigTest.java
  6. +81 −0 ...-SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/LookupWithoutConfigTest.java
  7. +100 −0 ...SHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/comp/SomeComponentWithFilter.java
  8. +100 −0 ...APSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/comp/SomeComponentWithPath.java
  9. +97 −0 ...en-php-plugin-test/src/test/java/org/phpmaven/core/test/comp/SomeComponentWithoutBuildConfig.java
  10. +90 −0 ...T/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/comp/SomeComponentWithoutConfig.java
  11. +35 −0 branches/2.0-SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/srv/BarService.java
  12. +35 −0 branches/2.0-SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/srv/FooService.java
  13. +29 −0 ...hes/2.0-SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/srv/ISomeService.java
  14. +27 −0 ...OT/maven-php-plugin-test/src/test/resources/org/phpmaven/test/projects/core/pom-with-path/pom.xml
View
236 ...0-SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/LookupHintTest.java
@@ -60,6 +60,32 @@ public void testComponentLookupDefaults() throws Exception {
}
/**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentLookupDefaultsArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/empty-pom");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "hint1",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "fooBar-1").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("default-foo-1", component.getFoo());
+ assertEquals("default-bar-1", component.getBar());
+ }
+
+ /**
* Tests if the component lookup reads the project build config.
*
* @throws Exception thrown on errors
@@ -85,6 +111,32 @@ public void testComponentReadsProjectConfig() throws Exception {
}
/**
+ * Tests if the component lookup reads the project build config.
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentReadsProjectConfigArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "hint1",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("SpecialFoo", component.getFoo());
+ assertEquals("default-bar-1", component.getBar());
+ }
+
+ /**
* Tests if the component lookup reads the project build config from parent poms.
*
* @throws Exception thrown on errors
@@ -110,6 +162,32 @@ public void testComponentReadsParentProjectConfig() throws Exception {
}
/**
+ * Tests if the component lookup reads the project build config from parent poms.
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentReadsParentProjectConfigArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig-child");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "hint1",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("SpecialFoo", component.getFoo());
+ assertEquals("default-bar-1", component.getBar());
+ }
+
+ /**
* Tests if the component lookup reads the project build config from parent poms
* and overwrites a single value.
*
@@ -136,6 +214,33 @@ public void testComponentReadsParentProjectConfigOverwrite() throws Exception {
}
/**
+ * Tests if the component lookup reads the project build config from parent poms
+ * and overwrites a single value.
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentReadsParentProjectConfigOverwriteArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig-childoverwrite");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "hint1",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("OtherFoo", component.getFoo());
+ assertEquals("default-bar-1", component.getBar());
+ }
+
+ /**
* Tests if the component lookup initializes the defaults.
*
* @throws Exception thrown on errors
@@ -161,6 +266,32 @@ public void testComponentLookupDefaults2() throws Exception {
}
/**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentLookupDefaults2Array() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/empty-pom");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "hint2",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "fooBar-2").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("default-foo-2", component.getFoo());
+ assertEquals("default-bar-2", component.getBar());
+ }
+
+ /**
* Tests if the component lookup reads the project build config.
*
* @throws Exception thrown on errors
@@ -186,6 +317,32 @@ public void testComponentReadsProjectConfig2() throws Exception {
}
/**
+ * Tests if the component lookup reads the project build config.
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentReadsProjectConfig2Array() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "hint2",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("SpecialFoo", component.getFoo());
+ assertEquals("default-bar-2", component.getBar());
+ }
+
+ /**
* Tests if the component lookup reads the project build config from parent poms.
*
* @throws Exception thrown on errors
@@ -211,6 +368,32 @@ public void testComponentReadsParentProjectConfig2() throws Exception {
}
/**
+ * Tests if the component lookup reads the project build config from parent poms.
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentReadsParentProjectConfig2Array() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig-child");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "hint2",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("SpecialFoo", component.getFoo());
+ assertEquals("default-bar-2", component.getBar());
+ }
+
+ /**
* Tests if the component lookup reads the project build config from parent poms
* and overwrites a single value.
*
@@ -235,6 +418,33 @@ public void testComponentReadsParentProjectConfigOverwrite2() throws Exception {
assertEquals("OtherFoo", component.getFoo());
assertEquals("default-bar-2", component.getBar());
}
+
+ /**
+ * Tests if the component lookup reads the project build config from parent poms
+ * and overwrites a single value.
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentReadsParentProjectConfigOverwrite2Array() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig-childoverwrite");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "hint2",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("OtherFoo", component.getFoo());
+ assertEquals("default-bar-2", component.getBar());
+ }
/**
* Tests if the component fails without role hint (no default).
@@ -260,5 +470,31 @@ public void testComponentFailes() throws Exception {
}
// CHECKSTYLE:ON
}
+
+ /**
+ * Tests if the component fails without role hint (no default).
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentFailesArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig-childoverwrite");
+ // lookup the sample
+ try {
+ factory.lookup(
+ ISomeComponentHint.class,
+ (Xpp3Dom[]) null,
+ session);
+ fail("Exception expected");
+ // CHECKSTYLE:OFF
+ // checkstyle does not like empty catches
+ } catch (Exception ex) {
+ // ignore; we expect this exception
+ }
+ // CHECKSTYLE:ON
+ }
}
View
50 ...NAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/LookupServiceTest.java
@@ -0,0 +1,50 @@
+/**
+ * Copyright 2010-2012 by PHP-maven.org
+ *
+ * Licensed 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.phpmaven.core.test;
+
+import org.apache.maven.execution.MavenSession;
+import org.phpmaven.core.IComponentFactory;
+import org.phpmaven.core.test.srv.ISomeService;
+import org.phpmaven.test.AbstractTestCase;
+
+/**
+ * Test case for the IComponentFactory class.
+ *
+ * @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
+ * @since 2.0.1
+ */
+public class LookupServiceTest extends AbstractTestCase {
+
+ /**
+ * Tests if the service lookup.
+ *
+ * @throws Exception thrown on errors
+ */
+ public void testService() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/empty-pom");
+ // lookup the sample
+ final ISomeService[] services = factory.getServiceImplementations(ISomeService.class, session);
+ assertNotNull(services);
+ assertEquals(2, services.length);
+ assertTrue("foo".equals(services[0].getServiceName()) || "foo".equals(services[1].getServiceName()));
+ assertTrue("bar".equals(services[0].getServiceName()) || "bar".equals(services[1].getServiceName()));
+ }
+
+}
View
89 ...s/2.0-SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/LookupTest.java
@@ -56,6 +56,28 @@ public void testComponentLookupDefaults() throws Exception {
}
/**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentLookupDefaultsArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/empty-pom");
+ // lookup the sample
+ final ISomeComponent component = factory.lookup(ISomeComponent.class, (Xpp3Dom[]) null, session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "fooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("default-foo", component.getFoo());
+ assertEquals("default-bar", component.getBar());
+ }
+
+ /**
* Tests if the component lookup reads the project build config.
*
* @throws Exception thrown on errors
@@ -77,6 +99,28 @@ public void testComponentReadsProjectConfig() throws Exception {
}
/**
+ * Tests if the component lookup reads the project build config.
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentReadsProjectConfigArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig");
+ // lookup the sample
+ final ISomeComponent component = factory.lookup(ISomeComponent.class, (Xpp3Dom[]) null, session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("SpecialFoo", component.getFoo());
+ assertEquals("default-bar", component.getBar());
+ }
+
+ /**
* Tests if the component lookup reads the project build config from parent poms.
*
* @throws Exception thrown on errors
@@ -98,6 +142,28 @@ public void testComponentReadsParentProjectConfig() throws Exception {
}
/**
+ * Tests if the component lookup reads the project build config from parent poms.
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentReadsParentProjectConfigArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig-child");
+ // lookup the sample
+ final ISomeComponent component = factory.lookup(ISomeComponent.class, (Xpp3Dom[]) null, session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("SpecialFoo", component.getFoo());
+ assertEquals("default-bar", component.getBar());
+ }
+
+ /**
* Tests if the component lookup reads the project build config from parent poms
* and overwrites a single value.
*
@@ -119,4 +185,27 @@ public void testComponentReadsParentProjectConfigOverwrite() throws Exception {
assertEquals("default-bar", component.getBar());
}
+ /**
+ * Tests if the component lookup reads the project build config from parent poms
+ * and overwrites a single value.
+ *
+ * @throws Exception thrown on errors
+ * @since 2.0.1
+ */
+ public void testComponentReadsParentProjectConfigOverwriteArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig-childoverwrite");
+ // lookup the sample
+ final ISomeComponent component = factory.lookup(ISomeComponent.class, (Xpp3Dom[]) null, session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("OtherFoo", component.getFoo());
+ assertEquals("default-bar", component.getBar());
+ }
+
}
View
187 ...SHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/LookupWithFilterTest.java
@@ -0,0 +1,187 @@
+/**
+ * Copyright 2010-2012 by PHP-maven.org
+ *
+ * Licensed 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.phpmaven.core.test;
+
+import java.io.File;
+
+import org.apache.maven.execution.MavenSession;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.phpmaven.core.IComponentFactory;
+import org.phpmaven.core.test.comp.ISomeComponentHint;
+import org.phpmaven.test.AbstractTestCase;
+
+/**
+ * Test case for the IComponentFactory class.
+ *
+ * <p>Test the lookup methods with role-hints and with build configuration filter.</p>
+ *
+ * @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
+ * @since 2.0.1
+ */
+public class LookupWithFilterTest extends AbstractTestCase {
+
+ /**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ */
+ public void testComponentLookupDefaults() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "with-filter",
+ (Xpp3Dom) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("default-foo", component.getFoo());
+ assertEquals("default-bar", component.getBar());
+ }
+
+ /**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ */
+ public void testComponentLookupDefaultsArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "with-filter",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("default-foo", component.getFoo());
+ assertEquals("default-bar", component.getBar());
+ }
+
+ /**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ */
+ public void testComponentLookupPath() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-path");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "with-path",
+ (Xpp3Dom) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("default-foo", component.getFoo());
+ assertEquals("default-bar", component.getBar());
+ }
+
+ /**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ */
+ public void testComponentLookupPathEmpty() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/empty-pom");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "with-path",
+ (Xpp3Dom) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "fooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("default-foo", component.getFoo());
+ assertEquals("default-bar", component.getBar());
+ }
+
+ /**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ */
+ public void testComponentLookupPathArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-path");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "with-path",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "SomeFooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("default-foo", component.getFoo());
+ assertEquals("default-bar", component.getBar());
+ }
+
+ /**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ */
+ public void testComponentLookupPathEmptyArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/empty-pom");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "with-path",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "fooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("default-foo", component.getFoo());
+ assertEquals("default-bar", component.getBar());
+ }
+
+}
View
87 ...en-php-plugin-test/src/test/java/org/phpmaven/core/test/LookupWithoutBuildConfigTest.java
@@ -0,0 +1,87 @@
+/**
+ * Copyright 2010-2012 by PHP-maven.org
+ *
+ * Licensed 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.phpmaven.core.test;
+
+import java.io.File;
+
+import org.apache.maven.execution.MavenSession;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.phpmaven.core.IComponentFactory;
+import org.phpmaven.core.test.comp.ISomeComponentHint;
+import org.phpmaven.test.AbstractTestCase;
+
+/**
+ * Test case for the IComponentFactory class.
+ *
+ * <p>Test the lookup methods with role-hints and without build configuration.</p>
+ *
+ * @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
+ * @since 2.0.1
+ */
+public class LookupWithoutBuildConfigTest extends AbstractTestCase {
+
+ /**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ */
+ public void testComponentLookupDefaults() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "without-build-config",
+ (Xpp3Dom) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "fooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("default-foo", component.getFoo());
+ assertEquals("default-bar", component.getBar());
+ }
+
+ /**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ */
+ public void testComponentLookupDefaultsArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "without-build-config",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertEquals(
+ new File(session.getCurrentProject().getBasedir().getAbsolutePath(), "fooBar").getAbsolutePath(),
+ component.getFooBar().getAbsolutePath());
+ assertEquals("default-foo", component.getFoo());
+ assertEquals("default-bar", component.getBar());
+ }
+
+}
View
81 ...T/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/LookupWithoutConfigTest.java
@@ -0,0 +1,81 @@
+/**
+ * Copyright 2010-2012 by PHP-maven.org
+ *
+ * Licensed 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.phpmaven.core.test;
+
+import org.apache.maven.execution.MavenSession;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.phpmaven.core.IComponentFactory;
+import org.phpmaven.core.test.comp.ISomeComponentHint;
+import org.phpmaven.test.AbstractTestCase;
+
+/**
+ * Test case for the IComponentFactory class.
+ *
+ * <p>Test the lookup methods with role-hints and without build configuration.</p>
+ *
+ * @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
+ * @since 2.0.1
+ */
+public class LookupWithoutConfigTest extends AbstractTestCase {
+
+ /**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ */
+ public void testComponentLookupDefaults() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "without-config",
+ (Xpp3Dom) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertNull(component.getFooBar());
+ assertNull(component.getFoo());
+ assertNull(component.getBar());
+ }
+
+ /**
+ * Tests if the component lookup initializes the defaults.
+ *
+ * @throws Exception thrown on errors
+ */
+ public void testComponentLookupDefaultsArray() throws Exception {
+ // look up the component factory
+ final IComponentFactory factory = lookup(IComponentFactory.class);
+ // create the session
+ final MavenSession session = createSimpleSession("core/pom-with-buildconfig");
+ // lookup the sample
+ final ISomeComponentHint component = factory.lookup(
+ ISomeComponentHint.class,
+ "without-config",
+ (Xpp3Dom[]) null,
+ session);
+ assertNotNull(component);
+ // test defaults
+ assertNull(component.getFooBar());
+ assertNull(component.getFoo());
+ assertNull(component.getBar());
+ }
+
+}
View
100 ...en-php-plugin-test/src/test/java/org/phpmaven/core/test/comp/SomeComponentWithFilter.java
@@ -0,0 +1,100 @@
+/**
+ * Copyright 2010-2012 by PHP-maven.org
+ *
+ * Licensed 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.phpmaven.core.test.comp;
+
+import java.io.File;
+
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Configuration;
+import org.phpmaven.core.BuildPluginConfiguration;
+import org.phpmaven.core.ConfigurationParameter;
+
+
+/**
+ * A sample component.
+ *
+ * @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
+ * @since 2.0.1
+ */
+@Component(role = ISomeComponentHint.class, hint = "with-filter", instantiationStrategy = "per-lookup")
+@BuildPluginConfiguration(groupId = "org.phpmaven", artifactId = "maven-php-plugin-test", filter = {
+ "foo"
+ })
+public class SomeComponentWithFilter implements ISomeComponentHint {
+
+ /** foo. */
+ @Configuration(name = "foo", value = "default-foo")
+ private String foo;
+
+ /** bar. */
+ @Configuration(name = "bar", value = "default-bar")
+ @ConfigurationParameter(name = "bar", expression = "${bar}")
+ private String bar;
+
+ /** foobar. */
+ @ConfigurationParameter(name = "fooBar", expression = "${project.basedir}/fooBar")
+ private File fooBar;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getFoo() {
+ return this.foo;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getBar() {
+ return this.bar;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setBar(String bar) {
+ this.bar = bar;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public File getFooBar() {
+ return this.fooBar;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFooBar(File fooBar) {
+ this.fooBar = fooBar;
+ }
+
+}
View
100 ...aven-php-plugin-test/src/test/java/org/phpmaven/core/test/comp/SomeComponentWithPath.java
@@ -0,0 +1,100 @@
+/**
+ * Copyright 2010-2012 by PHP-maven.org
+ *
+ * Licensed 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.phpmaven.core.test.comp;
+
+import java.io.File;
+
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Configuration;
+import org.phpmaven.core.BuildPluginConfiguration;
+import org.phpmaven.core.ConfigurationParameter;
+
+
+/**
+ * A sample component.
+ *
+ * @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
+ * @since 2.0.1
+ */
+@Component(role = ISomeComponentHint.class, hint = "with-path", instantiationStrategy = "per-lookup")
+@BuildPluginConfiguration(groupId = "org.phpmaven", artifactId = "maven-php-plugin-test", filter = {
+ "foo"
+ }, path = "path1/path2")
+public class SomeComponentWithPath implements ISomeComponentHint {
+
+ /** foo. */
+ @Configuration(name = "foo", value = "default-foo")
+ private String foo;
+
+ /** bar. */
+ @Configuration(name = "bar", value = "default-bar")
+ @ConfigurationParameter(name = "bar", expression = "${bar}")
+ private String bar;
+
+ /** foobar. */
+ @ConfigurationParameter(name = "fooBar", expression = "${project.basedir}/fooBar")
+ private File fooBar;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getFoo() {
+ return this.foo;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getBar() {
+ return this.bar;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setBar(String bar) {
+ this.bar = bar;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public File getFooBar() {
+ return this.fooBar;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFooBar(File fooBar) {
+ this.fooBar = fooBar;
+ }
+
+}
View
97 ...lugin-test/src/test/java/org/phpmaven/core/test/comp/SomeComponentWithoutBuildConfig.java
@@ -0,0 +1,97 @@
+/**
+ * Copyright 2010-2012 by PHP-maven.org
+ *
+ * Licensed 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.phpmaven.core.test.comp;
+
+import java.io.File;
+
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Configuration;
+import org.phpmaven.core.ConfigurationParameter;
+
+
+/**
+ * A sample component.
+ *
+ * @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
+ * @since 2.0.1
+ */
+@Component(role = ISomeComponentHint.class, hint = "without-build-config",
+ instantiationStrategy = "per-lookup")
+public class SomeComponentWithoutBuildConfig implements ISomeComponentHint {
+
+ /** foo. */
+ @Configuration(name = "foo", value = "default-foo")
+ private String foo;
+
+ /** bar. */
+ @Configuration(name = "bar", value = "default-bar")
+ @ConfigurationParameter(name = "bar", expression = "${bar}")
+ private String bar;
+
+ /** foobar. */
+ @ConfigurationParameter(name = "fooBar", expression = "${project.basedir}/fooBar")
+ private File fooBar;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getFoo() {
+ return this.foo;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getBar() {
+ return this.bar;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setBar(String bar) {
+ this.bar = bar;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public File getFooBar() {
+ return this.fooBar;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFooBar(File fooBar) {
+ this.fooBar = fooBar;
+ }
+
+}
View
90 ...php-plugin-test/src/test/java/org/phpmaven/core/test/comp/SomeComponentWithoutConfig.java
@@ -0,0 +1,90 @@
+/**
+ * Copyright 2010-2012 by PHP-maven.org
+ *
+ * Licensed 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.phpmaven.core.test.comp;
+
+import java.io.File;
+
+import org.codehaus.plexus.component.annotations.Component;
+
+
+/**
+ * A sample component.
+ *
+ * @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
+ * @since 2.0.1
+ */
+@Component(role = ISomeComponentHint.class, hint = "without-config", instantiationStrategy = "per-lookup")
+public class SomeComponentWithoutConfig implements ISomeComponentHint {
+
+ /** foo. */
+ private String foo;
+
+ /** bar. */
+ private String bar;
+
+ /** foobar. */
+ private File fooBar;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getFoo() {
+ return this.foo;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getBar() {
+ return this.bar;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setBar(String bar) {
+ this.bar = bar;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public File getFooBar() {
+ return this.fooBar;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFooBar(File fooBar) {
+ this.fooBar = fooBar;
+ }
+
+}
View
35 ...0-SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/srv/BarService.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright 2010-2012 by PHP-maven.org
+ *
+ * Licensed 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.phpmaven.core.test.srv;
+
+import org.codehaus.plexus.component.annotations.Component;
+
+/**
+ * The foo service.
+ *
+ * @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
+ * @since 2.0.1
+ */
+@Component(role = ISomeService.class, hint = "bar", instantiationStrategy = "per-lookup")
+public class BarService implements ISomeService {
+
+ @Override
+ public String getServiceName() {
+ return "bar";
+ }
+
+}
View
35 ...0-SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/srv/FooService.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright 2010-2012 by PHP-maven.org
+ *
+ * Licensed 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.phpmaven.core.test.srv;
+
+import org.codehaus.plexus.component.annotations.Component;
+
+/**
+ * The foo service.
+ *
+ * @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
+ * @since 2.0.1
+ */
+@Component(role = ISomeService.class, instantiationStrategy = "per-lookup")
+public class FooService implements ISomeService {
+
+ @Override
+ public String getServiceName() {
+ return "foo";
+ }
+
+}
View
29 ...SNAPSHOT/maven-php-plugin-test/src/test/java/org/phpmaven/core/test/srv/ISomeService.java
@@ -0,0 +1,29 @@
+/**
+ * Copyright 2010-2012 by PHP-maven.org
+ *
+ * Licensed 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.phpmaven.core.test.srv;
+
+import org.phpmaven.core.IService;
+
+/**
+ * A service implementation.
+ *
+ * @author Martin Eisengardt <Martin.Eisengardt@googlemail.com>
+ * @since 2.0.1
+ */
+public interface ISomeService extends IService {
+
+}
View
27 ...-php-plugin-test/src/test/resources/org/phpmaven/test/projects/core/pom-with-path/pom.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.phpmaven.test</groupId>
+ <artifactId>core-pom-with-path</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.phpmaven</groupId>
+ <artifactId>maven-php-plugin-test</artifactId>
+ <configuration>
+ <path1><path2>
+ <foo>SpecialFoo</foo>
+ <fooBar>${project.basedir}/SomeFooBar</fooBar>
+ </path2></path1>
+ <foo>otherFoo</foo>
+ <foobar>${project.basedir}/OtherFooBar</foobar>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>

0 comments on commit 85404ec

Please sign in to comment.
Something went wrong with that request. Please try again.