Skip to content

Commit

Permalink
Adding EJB integration testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
asoldano committed Nov 20, 2017
1 parent cd4e876 commit 91d19bf
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 0 deletions.
14 changes: 14 additions & 0 deletions modules/testsuite/pom.xml
Expand Up @@ -28,6 +28,8 @@
<org.littleshoot.littleproxy.version>1.0.0-beta2</org.littleshoot.littleproxy.version>
<gnu.getopt.version>1.0.13</gnu.getopt.version>
<bc.version>1.56</bc.version>
<interceptors.api.version>1.0.0.Final</interceptors.api.version>
<transaction.api.version>1.0.0.Final</transaction.api.version>
<resources-plugin-filters.version>1.1.0.Final</resources-plugin-filters.version>
<port-offset.cxf-tests.jboss>0</port-offset.cxf-tests.jboss>
<port-offset.cxf-tests.ssl-mutual-auth>5000</port-offset.cxf-tests.ssl-mutual-auth>
Expand Down Expand Up @@ -120,6 +122,18 @@
<version>${bc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.interceptor</groupId>
<artifactId>jboss-interceptors-api_1.2_spec</artifactId>
<version>${interceptors.api.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<version>${transaction.api.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
Expand Down
@@ -0,0 +1,88 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2016, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.jaxrs.integration.ejb;

import static org.junit.Assert.assertEquals;

import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.wsf.test.HttpRequest;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Tests injections of CDI beans into JAX-RS resources
*
* @author Stuart Douglas
* @author alessio.soldano@jboss.com
*/
@RunWith(Arquillian.class)
@RunAsClient
public class EJBInterceptorsTestCase
{

@ArquillianResource
private URL baseURL;

@Deployment(testable = false)
public static WebArchive createDeployments()
{
WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs-integration-ejb.war");
archive.addManifest().addClasses(EJBResource.class, EjbInterceptor.class, EjbInterface.class)
.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml")
.addAsWebInfResource(getWebXml(), "web.xml");
return archive;
}

private static StringAsset getWebXml()
{
return new StringAsset(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<web-app xmlns=\"http://java.sun.com/xml/ns/javaee\" "
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ "xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\" "
+ "version=\"3.0\"><servlet-mapping><servlet-name>javax.ws.rs.core.Application"
+ "</servlet-name><url-pattern>/myjaxrs/*</url-pattern></servlet-mapping></web-app>");
}

private String performCall(String urlPattern) throws Exception
{
return HttpRequest.get(baseURL + urlPattern, 10, TimeUnit.SECONDS);
}

@Test
public void testJaxRsWithNoApplication() throws Exception
{
String result = performCall("myjaxrs/ejbInterceptor");
assertEquals("Hello World", result);
}

}
@@ -0,0 +1,50 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.jaxrs.integration.ejb;

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.interceptor.Interceptors;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.TransactionSynchronizationRegistry;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("ejbInterceptor")
@Produces({"text/plain"})
@Stateless(name = "CustomName")
@Interceptors(EjbInterceptor.class)
public class EJBResource implements EjbInterface {

@Resource
private TransactionSynchronizationRegistry transactionSynchronizationRegistry;

@GET
public String getMessage() throws SystemException {
if(transactionSynchronizationRegistry.getTransactionStatus() != Status.STATUS_ACTIVE) {
throw new RuntimeException("Transaction not active, not an EJB invocation");
}
return "Hello";
}
}
@@ -0,0 +1,37 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.jaxrs.integration.ejb;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

/**
* @author Stuart Douglas
*/
public class EjbInterceptor {

@AroundInvoke
public Object intercept(final InvocationContext invocationContext) throws Exception {
return invocationContext.proceed().toString() + " World";
}

}
@@ -0,0 +1,10 @@
package org.jboss.test.jaxrs.integration.ejb;

import javax.transaction.SystemException;

/**
* @author Stuart Douglas
*/
public interface EjbInterface {
public String getMessage() throws SystemException;
}

0 comments on commit 91d19bf

Please sign in to comment.