Skip to content

Commit

Permalink
Adding testcase for EAR/EJB integration
Browse files Browse the repository at this point in the history
  • Loading branch information
asoldano committed Nov 20, 2017
1 parent e98ecae commit 3e7f19b
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 0 deletions.
@@ -0,0 +1,100 @@
/*
* 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.deployment.ear;

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.StringAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.wsf.test.HttpRequest;
import org.jboss.wsf.test.JBossWSTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Tests a JAX-RS deployment with an application bundled, that has no @ApplicationPath annotation.
* <p/>
* The container should register a servlet with the name that matches the application name
* <p/>
* It is the app providers responsibility to provide a mapping for the servlet
* <p/>
* JAX-RS 1.1 2.3.2 bullet point 3
*
* @author Stuart Douglas
* @author <a href="mailto:alessio.soldano@jboss.com">Alessio Soldano</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
public class EarApplicationIntegrationTestCase extends JBossWSTest
{
@ArquillianResource
private URL baseURL;

@Deployment(testable = false)
public static EnterpriseArchive createDeployments()
{
EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class,"jaxrs-deployment-ear-app.ear");

JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "jaxrs-deployment-inner-app.jar");
jar.addClasses(HelloWorldResource.class, HelloWorldApplication.class);
ear.addAsModule(jar);

WebArchive war = ShrinkWrap.create(WebArchive.class,"jaxrs-deployment-ear-app.war");
war.addAsWebInfResource(getWebXml(), "web.xml");
ear.addAsModule(war);

return ear;
}

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>" + HelloWorldApplication.class.getName()
+ "</servlet-name><url-pattern>/hello/*</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("hello/helloworld");
Assert.assertEquals("Hello World!", result);
}

}
@@ -0,0 +1,31 @@
/*
* 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.deployment.ear;

import javax.ws.rs.core.Application;

/**
* Application with no path
* @author Stuart Douglas
*/
public class HelloWorldApplication extends Application {
}
@@ -0,0 +1,51 @@
/*
* 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.deployment.ear;

import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("helloworld")
@Produces(
{"text/plain"})
@Stateless
public class HelloWorldResource
{

private String message;

@PostConstruct
public void postConstruct()
{

message = "Hello World!";
}

@GET
public String getMessage()
{
return message;
}
}

0 comments on commit 3e7f19b

Please sign in to comment.