Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FURNACE-35: PostStartup is not called for every deployed addon #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,35 @@
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+1);
}
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")
})
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)
.addClasses(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)
.addClass(ContainerLifecycleEventObserver.class)
.addAsAddonDependencies(
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi")
)
.addBeansXML();
return archive;
}

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

@Test
Expand Down