-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
tests/src/main/java/test/org/jboss/forge/furnace/mocks/AlternativeServiceBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright 2013 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package test.org.jboss.forge.furnace.mocks; | ||
|
||
import javax.annotation.Priority; | ||
import javax.enterprise.inject.Alternative; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
@Priority(0) | ||
@Alternative | ||
public class AlternativeServiceBean implements ServiceInterface | ||
{ | ||
@Override | ||
public Object invoke() | ||
{ | ||
return "Alternative"; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
tests/src/test/java/test/org/jboss/forge/furnace/services/AlternativesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright 2013 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package test.org.jboss.forge.furnace.services; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.forge.arquillian.AddonDependency; | ||
import org.jboss.forge.arquillian.Dependencies; | ||
import org.jboss.forge.arquillian.archive.ForgeArchive; | ||
import org.jboss.forge.furnace.repositories.AddonDependencyEntry; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import test.org.jboss.forge.furnace.mocks.AlternativeServiceBean; | ||
import test.org.jboss.forge.furnace.mocks.ServiceBean; | ||
import test.org.jboss.forge.furnace.mocks.ServiceInterface; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class AlternativesTest | ||
{ | ||
@Deployment | ||
@Dependencies({ | ||
@AddonDependency(name = "org.jboss.forge.furnace.container:cdi") | ||
}) | ||
public static ForgeArchive getDeployment() | ||
{ | ||
ForgeArchive archive = ShrinkWrap | ||
.create(ForgeArchive.class) | ||
.addBeansXML( | ||
new StringAsset( | ||
"<beans><alternatives>" + AlternativeServiceBean.class.getName() | ||
+ "</alternatives></beans>")) | ||
.addClasses(ServiceInterface.class, ServiceBean.class, AlternativeServiceBean.class) | ||
.addAsAddonDependencies( | ||
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi") | ||
); | ||
return archive; | ||
} | ||
|
||
@Inject | ||
ServiceInterface service; | ||
|
||
@Test | ||
public void testAlternativeInjectionGlobal() throws Exception | ||
{ | ||
Assert.assertNotNull(service); | ||
Assert.assertEquals("Alternative", service.invoke()); | ||
} | ||
|
||
} |