Skip to content

Commit

Permalink
WFLY-5179 Some tests are unable to init arquillian protocol with secu…
Browse files Browse the repository at this point in the history
…rity manager
  • Loading branch information
OndrejKotek committed Sep 30, 2015
1 parent faf0f51 commit 5fb8f04
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 178 deletions.
Expand Up @@ -22,20 +22,16 @@
package org.jboss.as.test.integration.ee.injection.resource.ejblocalref;

import java.util.concurrent.TimeUnit;

import javax.naming.InitialContext;

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.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.common.HttpRequest;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;

/**
Expand All @@ -44,17 +40,18 @@
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
@RunAsClient
public class EjbLocalRefInjectionTestCase {

@ArquillianResource
private ManagementClient managementClient;


@Deployment
public static WebArchive deployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "war-example.war");
war.addPackage(HttpRequest.class.getPackage());
war.addClasses(EjbLocalRefInjectionTestCase.class, EjbLocalRefInjectionServlet.class, NamedSLSB.class, SimpleSLSB.class, Hello.class);
war.addAsWebInfResource(getWebXml(), "web.xml");
war.addClasses(EjbLocalRefInjectionServlet.class, NamedSLSB.class, SimpleSLSB.class, Hello.class);
war.addAsWebInfResource(EjbLocalRefInjectionTestCase.class.getPackage(), "web.xml", "web.xml");
return war;
}

Expand All @@ -73,45 +70,4 @@ public void testEjbLink() throws Exception {
String result = performCall("ejbLocalRef?type=named");
assertEquals("Named Hello", result);
}

@Test
public void testNoInjectionPoint() throws Exception {
Hello bean = (Hello) new InitialContext().lookup("java:comp/env/noInjection");
assertEquals("Simple Hello", bean.sayHello());
}


private static StringAsset getWebXml() {
return new StringAsset("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"\n" +
"<web-app version=\"3.0\"\n" +
" xmlns=\"http://java.sun.com/xml/ns/javaee\"\n" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\"\n" +
" metadata-complete=\"false\">\n" +
"\n" +
" <ejb-local-ref>\n" +
" <ejb-ref-name>simple</ejb-ref-name>\n" +
" <lookup-name>java:module/SimpleSLSB</lookup-name>\n" +
" <injection-target>" +
" <injection-target-class>" + EjbLocalRefInjectionServlet.class.getName() + "</injection-target-class>" +
" <injection-target-name>simple</injection-target-name>" +
" </injection-target>\n" +
" </ejb-local-ref>\n" +
" <ejb-local-ref>\n" +
" <ejb-ref-name>noInjection</ejb-ref-name>\n" +
" <lookup-name>java:module/SimpleSLSB</lookup-name>\n" +
" <local>" + SimpleSLSB.class.getName() + "</local>" +
" </ejb-local-ref>\n" +
" <ejb-local-ref>\n" +
" <ejb-ref-name>named</ejb-ref-name>\n" +
" <ejb-link>namedBean</ejb-link>\n" +
" <injection-target>" +
" <injection-target-class>" + EjbLocalRefInjectionServlet.class.getName() + "</injection-target-class>" +
" <injection-target-name>named</injection-target-name>" +
" </injection-target>\n" +
" </ejb-local-ref>\n" +
"\n" +
"</web-app>");
}
}
@@ -0,0 +1,54 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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.as.test.integration.ee.injection.resource.ejblocalref;

import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;

/**
* A test for injection via env-entry in web.xml
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class EjbLocalRefNoInjectionTestCase {

@Deployment
public static WebArchive deployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "war-example.war");
war.addClasses(EjbLocalRefNoInjectionTestCase.class, EjbLocalRefInjectionServlet.class, NamedSLSB.class, SimpleSLSB.class, Hello.class);
war.addAsWebInfResource(EjbLocalRefNoInjectionTestCase.class.getPackage(), "web.xml", "web.xml");
return war;
}

@Test
public void testNoInjectionPoint() throws Exception {
Hello bean = (Hello) new InitialContext().lookup("java:comp/env/noInjection");
assertEquals("Simple Hello", bean.sayHello());
}
}
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0"
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"
metadata-complete="false">

<ejb-local-ref>
<ejb-ref-name>simple</ejb-ref-name>
<lookup-name>java:module/SimpleSLSB</lookup-name>
<injection-target>
<injection-target-class>org.jboss.as.test.integration.ee.injection.resource.ejblocalref.EjbLocalRefInjectionServlet</injection-target-class>
<injection-target-name>simple</injection-target-name>
</injection-target>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>noInjection</ejb-ref-name>
<lookup-name>java:module/SimpleSLSB</lookup-name>
<local>org.jboss.as.test.integration.ee.injection.resource.ejblocalref.SimpleSLSB</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>named</ejb-ref-name>
<ejb-link>namedBean</ejb-link>
<injection-target>
<injection-target-class>org.jboss.as.test.integration.ee.injection.resource.ejblocalref.EjbLocalRefInjectionServlet</injection-target-class>
<injection-target-name>named</injection-target-name>
</injection-target>
</ejb-local-ref>

</web-app>
@@ -0,0 +1,66 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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.as.test.integration.ee.injection.resource.enventry;

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.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.common.HttpRequest;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;

/**
* A test for injection via env-entry in web.xml
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
@RunAsClient
public class EnvEntryInjectionServletTestCase {

@ArquillianResource
private ManagementClient managementClient;

@Deployment
public static WebArchive deployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "war-example.war");
war.addClasses(EnvEntryInjectionServlet.class, EnvEntryManagedBean.class);
war.addAsWebInfResource(EnvEntryInjectionServletTestCase.class.getPackage(), "EnvEntryInjectionTestCase-web.xml", "web.xml");
return war;
}

private String performCall(String urlPattern) throws Exception {
return HttpRequest.get(managementClient.getWebUri() + "/war-example/" + urlPattern, 5, TimeUnit.SECONDS);
}

@Test
public void testEnvEntryInjectionIntoServlet() throws Exception {
String result = performCall("envEntry");
assertEquals("injection!", result);
}
}
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0"
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"
metadata-complete="false">

<env-entry>
<env-entry-name>foo</env-entry-name>
<env-entry-value>injection!</env-entry-value>
<injection-target>
<injection-target-class>org.jboss.as.test.integration.ee.injection.resource.enventry.EnvEntryInjectionServlet</injection-target-class>
<injection-target-name>field</injection-target-name>
</injection-target>
</env-entry>

<env-entry>
<env-entry-name>org.jboss.as.test.integration.ee.injection.resource.enventry.EnvEntryManagedBean/existingString</env-entry-name>
<env-entry-value>bye</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>


<env-entry>
<env-entry-name>otherByte</env-entry-name>
<env-entry-value>10</env-entry-value>
<env-entry-type>java.lang.Byte</env-entry-type>
<injection-target>
<injection-target-class>org.jboss.as.test.integration.ee.injection.resource.enventry.EnvEntryManagedBean</injection-target-class>
<injection-target-name>byteField</injection-target-name>
</injection-target>
</env-entry>

</web-app>
Expand Up @@ -21,25 +21,16 @@
*/
package org.jboss.as.test.integration.ee.injection.resource.enventry;

import java.util.concurrent.TimeUnit;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.common.HttpRequest;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;

/**
* A test for injection via env-entry in web.xml
*
Expand All @@ -48,31 +39,18 @@
@RunWith(Arquillian.class)
public class EnvEntryInjectionTestCase {

@ArquillianResource
private ManagementClient managementClient;

@Deployment
public static WebArchive deployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "war-example.war");
war.addPackage(HttpRequest.class.getPackage());
war.addClasses(
EnvEntryInjectionServlet.class,
EnvEntryManagedBean.class,
EnvEntryInjectionTestCase.class
);
war.addAsWebInfResource(getWebXml(), "web.xml");
war.addAsWebInfResource(EnvEntryInjectionTestCase.class.getPackage(), "EnvEntryInjectionTestCase-web.xml", "web.xml");
return war;
}

private String performCall(String urlPattern) throws Exception {
return HttpRequest.get(managementClient.getWebUri() + "/war-example/" + urlPattern, 5, TimeUnit.SECONDS);
}

@Test
public void testEnvEntryInjectionIntoServlet() throws Exception {
String result = performCall("envEntry");
assertEquals("injection!", result);
}

@Test
public void testEnvEntryInjectionIntoManagedBean() throws NamingException {
Expand Down Expand Up @@ -105,42 +83,4 @@ public void testBoxedUnboxedMismatch() throws NamingException {
final EnvEntryManagedBean bean = (EnvEntryManagedBean) initialContext.lookup("java:module/" + EnvEntryManagedBean.class.getName());
Assert.assertEquals(10, bean.getByteField());
}

private static StringAsset getWebXml() {
return new StringAsset("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"\n" +
"<web-app version=\"3.0\"\n" +
" xmlns=\"http://java.sun.com/xml/ns/javaee\"\n" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\"\n" +
" metadata-complete=\"false\">\n" +
"\n" +
" <env-entry>\n" +
" <env-entry-name>foo</env-entry-name>\n" +
" <env-entry-value>injection!</env-entry-value>\n" +
" <injection-target>" +
" <injection-target-class>" + EnvEntryInjectionServlet.class.getName() + "</injection-target-class>" +
" <injection-target-name>field</injection-target-name>" +
" </injection-target>\n" +
" </env-entry>\n" +
"\n" +
" <env-entry>\n" +
" <env-entry-name>" + EnvEntryManagedBean.class.getName() + "/existingString</env-entry-name>\n" +
" <env-entry-value>bye</env-entry-value>\n" +
" <env-entry-type>java.lang.String</env-entry-type>\n" +
" </env-entry>\n" +
"\n" +
"\n" +
" <env-entry>\n" +
" <env-entry-name>otherByte</env-entry-name>\n" +
" <env-entry-value>10</env-entry-value>\n" +
" <env-entry-type>java.lang.Byte</env-entry-type>\n" +
" <injection-target>" +
" <injection-target-class>" + EnvEntryManagedBean.class.getName() + "</injection-target-class>" +
" <injection-target-name>byteField</injection-target-name>" +
" </injection-target>\n" +
" </env-entry>\n" +
"\n" +
"</web-app>");
}
}

0 comments on commit 5fb8f04

Please sign in to comment.