diff --git a/tests/src/test/java/test/org/jboss/forge/furnace/events/ContainerLifecycleEventObserver.java b/tests/src/test/java/test/org/jboss/forge/furnace/events/ContainerLifecycleEventObserver.java index 7681221..3c343fb 100644 --- a/tests/src/test/java/test/org/jboss/forge/furnace/events/ContainerLifecycleEventObserver.java +++ b/tests/src/test/java/test/org/jboss/forge/furnace/events/ContainerLifecycleEventObserver.java @@ -6,6 +6,9 @@ */ package test.org.jboss.forge.furnace.events; +import java.util.HashMap; +import java.util.Map; + import javax.enterprise.event.Observes; import javax.inject.Singleton; @@ -18,9 +21,17 @@ public class ContainerLifecycleEventObserver { private boolean observedPerform; + private Map postStartupMap = new HashMap<>(); public void perform(@Observes PostStartup event) { + String addonName= event.getAddon().getId().getName().toString(); + if(postStartupMap.containsKey(addonName)) { + Integer myInt = postStartupMap.get(addonName); + postStartupMap.put(addonName, myInt); + } else { + postStartupMap.put(addonName,1); + } this.observedPerform = true; } @@ -28,4 +39,12 @@ public boolean isObservedPerform() { return observedPerform; } + + public Map getPostStartupMap() { + return postStartupMap; + } + + public int getSetSize() { + return postStartupMap.size(); + } } diff --git a/tests/src/test/java/test/org/jboss/forge/furnace/events/ContainerLifecycleEventsTest.java b/tests/src/test/java/test/org/jboss/forge/furnace/events/ContainerLifecycleEventsTest.java index 07c8ab7..07b1789 100644 --- a/tests/src/test/java/test/org/jboss/forge/furnace/events/ContainerLifecycleEventsTest.java +++ b/tests/src/test/java/test/org/jboss/forge/furnace/events/ContainerLifecycleEventsTest.java @@ -6,6 +6,8 @@ */ package test.org.jboss.forge.furnace.events; +import java.util.Map.Entry; + import javax.inject.Inject; import javax.xml.xpath.XPathFactory; @@ -17,28 +19,65 @@ import org.jboss.forge.furnace.repositories.AddonDependencyEntry; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; /** + * @author Matej Briškár * @author Lincoln Baxter, III */ @RunWith(Arquillian.class) public class ContainerLifecycleEventsTest { - @Deployment + + @Deployment(order = 3) @AddonDeployments({ - @AddonDeployment(name = "org.jboss.forge.furnace.container:cdi") + @AddonDeployment(name = "org.jboss.forge.furnace.container:cdi") }) - public static AddonArchive getDeployment() + public static AddonArchive getDeployment1() + { + AddonArchive archive = ShrinkWrap.create(AddonArchive.class) + .addAsAddonDependencies( + AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi"), + AddonDependencyEntry.create("dep2"), + AddonDependencyEntry.create("dep3"), + AddonDependencyEntry.create("dep4") + ).addBeansXML(); + return archive; + } + + + @Deployment(name = "dep2,1", testable = false, order = 2) + public static AddonArchive getDeploymentDep2() + { + AddonArchive archive = ShrinkWrap.create(AddonArchive.class) + .addClass(ContainerLifecycleEventObserver.class) + .addAsAddonDependencies( + AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi") + ) + .addBeansXML(); + return archive; + } + + @Deployment(name = "dep3,1", testable = false, order = 1) + public static AddonArchive getDeploymentDep3() + { + AddonArchive archive = ShrinkWrap.create(AddonArchive.class) + .addAsAddonDependencies( + AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi") + ) + .addBeansXML(); + return archive; + } + @Deployment(name = "dep4,1", testable = false, order = 0) + public static AddonArchive getDeploymentDep4() { AddonArchive archive = ShrinkWrap.create(AddonArchive.class) - .addClasses(ContainerLifecycleEventObserver.class) .addAsAddonDependencies( AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi") ) .addBeansXML(); - return archive; } @@ -49,6 +88,12 @@ public static AddonArchive getDeployment() public void testContainerStartup() { Assert.assertTrue(observer.isObservedPerform()); + Assert.assertTrue("PostStartup should be called for each installed addon. Only " + observer.getPostStartupMap().size() + " calls were registered.", observer.getPostStartupMap().size() > 3); + for( Entry entry: observer.getPostStartupMap().entrySet()) { + if(entry.getValue() > 1) { + Assert.fail("Multiple PostStartup events for a single addon"); + } + } } @Test