Skip to content

Commit

Permalink
FURNACE-35: PostStartup is not called for every deployed addon
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej Briskar committed Mar 24, 2015
1 parent 9ff4048 commit e669812
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,14 +21,30 @@
public class ContainerLifecycleEventObserver
{
private boolean observedPerform;
private Map<String,Integer> 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;
}

public boolean isObservedPerform()
{
return observedPerform;
}

public Map<String,Integer> getPostStartupMap() {
return postStartupMap;
}

public int getSetSize() {
return postStartupMap.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 <a href="mailto:[email protected]">Lincoln Baxter, III</a>
*/
@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;
}

Expand All @@ -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<String, Integer> entry: observer.getPostStartupMap().entrySet()) {
if(entry.getValue() > 1) {
Assert.fail("Multiple PostStartup events for a single addon");
}
}
}

@Test
Expand Down

0 comments on commit e669812

Please sign in to comment.