Permalink
Browse files

Add support for anonymous EJBs injection

  • Loading branch information...
hasalex committed Nov 13, 2012
1 parent 9d69607 commit 2c31cd22a244337babc433cf233215cd0b2f7adb
View
@@ -65,12 +65,6 @@
</dependency> </dependency>
<!-- AS7 Deployment Ping --> <!-- AS7 Deployment Ping -->
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-server</artifactId>
<version>${version.jboss_as}</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.jboss.spec.javax.servlet</groupId> <groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId> <artifactId>jboss-servlet-api_3.0_spec</artifactId>
@@ -0,0 +1,17 @@
package org.jboss.arquillian.container.cloudbees.client;
import org.jboss.arquillian.container.cloudbees.server.CloudbeesRemoteExtension;
import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
import org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
public class ArchiveAppender implements AuxiliaryArchiveAppender {
@Override
public Archive<?> createAuxiliaryArchive() {
return ShrinkWrap.create(JavaArchive.class, "arquillian-cloudbees.jar")
.addPackage(CloudbeesRemoteExtension.class.getPackage())
.addAsServiceProvider(RemoteLoadableExtension.class, CloudbeesRemoteExtension.class);
}
}
@@ -1,4 +1,4 @@
package org.jboss.arquillian.container.cloudbees; package org.jboss.arquillian.container.cloudbees.client;
import com.cloudbees.api.*; import com.cloudbees.api.*;
@@ -1,4 +1,4 @@
package org.jboss.arquillian.container.cloudbees; package org.jboss.arquillian.container.cloudbees.client;
import org.jboss.arquillian.container.spi.ConfigurationException; import org.jboss.arquillian.container.spi.ConfigurationException;
import org.jboss.arquillian.container.spi.client.container.ContainerConfiguration; import org.jboss.arquillian.container.spi.client.container.ContainerConfiguration;
@@ -1,4 +1,4 @@
package org.jboss.arquillian.container.cloudbees; package org.jboss.arquillian.container.cloudbees.client;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -121,4 +121,4 @@ private ProtocolMetaData buildEarMetadata(CloudbeesConfiguration conf) {
metaData.addContext(context); metaData.addContext(context);
return metaData; return metaData;
} }
} }
@@ -1,6 +1,7 @@
package org.jboss.arquillian.container.cloudbees; package org.jboss.arquillian.container.cloudbees.client;
import org.jboss.arquillian.container.spi.client.container.DeployableContainer; import org.jboss.arquillian.container.spi.client.container.DeployableContainer;
import org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
import org.jboss.arquillian.core.spi.LoadableExtension; import org.jboss.arquillian.core.spi.LoadableExtension;
/** /**
@@ -13,5 +14,6 @@
@Override @Override
public void register(ExtensionBuilder builder) { public void register(ExtensionBuilder builder) {
builder.service(DeployableContainer.class, CloudbeesContainer.class); builder.service(DeployableContainer.class, CloudbeesContainer.class);
builder.service(AuxiliaryArchiveAppender.class, ArchiveAppender.class);
} }
} }
@@ -1,4 +1,4 @@
package org.jboss.arquillian.container.cloudbees; package org.jboss.arquillian.container.cloudbees.client;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@@ -0,0 +1,60 @@
package org.jboss.arquillian.container.cloudbees.server;
import org.jboss.arquillian.core.spi.Validate;
import org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher;
import java.text.MessageFormat;
import java.util.logging.Logger;
public class CloudbeesEJBInjectionEnricher extends EJBInjectionEnricher {
private static final Logger log = Logger.getLogger(CloudbeesEJBInjectionEnricher.class.getName());
@Override
protected String[] resolveJNDINames(Class<?> fieldType, String mappedName, String beanName) {
log.info("My own enricher");
MessageFormat msg = new MessageFormat(
"Trying to resolve JNDI name for field \"{0}\" with mappedName=\"{1}\" and beanName=\"{2}\"");
log.finer(msg.format(new Object[]
{fieldType, mappedName, beanName}));
Validate.notNull(fieldType, "EJB enriched field cannot to be null.");
boolean isMappedNameSet = hasValue(mappedName);
boolean isBeanNameSet = hasValue(beanName);
if (isMappedNameSet && isBeanNameSet)
{
throw new IllegalStateException(
"@EJB annotation attributes 'mappedName' and 'beanName' cannot be specified at the same time.");
}
String[] jndiNames;
// If set, use only mapped name or bean name to lookup the EJB.
if (isMappedNameSet)
{
jndiNames = new String[]
{mappedName};
}
else if (isBeanNameSet)
{
jndiNames = new String[]
{"java:module/" + beanName + "!" + fieldType.getName()};
}
else
{
jndiNames = new String[] {
"java:global/app/webapp/" + fieldType.getSimpleName()
};
}
return jndiNames;
}
private boolean hasValue(String value) {
if (value != null && (!value.trim().equals(""))) {
return true;
} else {
return false;
}
}
}
@@ -0,0 +1,18 @@
package org.jboss.arquillian.container.cloudbees.server;
import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
import org.jboss.arquillian.core.spi.LoadableExtension;
import org.jboss.arquillian.test.spi.TestEnricher;
/**
* Cloudbees server-side extension
*
* @author <a href="mailto:alexis@sewatech.org">Alexis Hassler</a>
*/
public class CloudbeesRemoteExtension implements RemoteLoadableExtension {
@Override
public void register(LoadableExtension.ExtensionBuilder builder) {
builder.service(TestEnricher.class, CloudbeesEJBInjectionEnricher.class);
}
}
@@ -1 +1 @@
org.jboss.arquillian.container.cloudbees.CloudbeesExtension org.jboss.arquillian.container.cloudbees.client.CloudbeesExtension
@@ -36,7 +36,7 @@
@EJB(beanName="EchoService") @EJB(beanName="EchoService")
EchoService namedBean; EchoService namedBean;
@Test @Ignore // It fails :-( @Test // It fails :-(
public void shouldEjbBeInjected() { public void shouldEjbBeInjected() {
assertNotNull("Anonymous bean has not bean injected", bean); assertNotNull("Anonymous bean has not bean injected", bean);
} }
@@ -35,7 +35,7 @@
@EJB(beanName="EchoService") @EJB(beanName="EchoService")
EchoService namedBean; EchoService namedBean;
@Test @Ignore // It fails :-( @Test
public void shouldEjbBeInjected() { public void shouldEjbBeInjected() {
assertNotNull("Anonymous bean has not bean injected", bean); assertNotNull("Anonymous bean has not bean injected", bean);
} }

0 comments on commit 2c31cd2

Please sign in to comment.