Skip to content

Commit

Permalink
Added test with @Alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Sep 25, 2013
1 parent 20f851f commit b187928
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
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";
}
}
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());
}

}

0 comments on commit b187928

Please sign in to comment.