repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/servlet/TestListenerServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.support.servlet; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.IOException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.jboss.as.test.integration.ee.injection.support.AroundConstructInterceptor; import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptor; @SuppressWarnings("serial") @WebServlet("/TestListenerServlet") public class TestListenerServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String mode = req.getParameter("mode"); resp.setContentType("text/plain"); if ("field".equals(mode)) { assertEquals("Listener field not injected", "true", req.getAttribute("field.injected").toString()); } else if ("method".equals(mode)) { assertEquals("Listener setter not injected", "true", req.getAttribute("setter.injected").toString()); } else if ("constructor".equals(mode)) { assertTrue("Listener constructor not injected", getNameFromRequest(req).contains("Joe")); } else if ("interceptorReset".equals(mode)) { ComponentInterceptor.resetInterceptions(); assertEquals(0, ComponentInterceptor.getInterceptions().size()); resp.getWriter().append("" + ComponentInterceptor.getInterceptions().size()); } else if ("aroundInvokeVerify".equals(mode)) { assertEquals("Listener invocation not intercepted", 2, ComponentInterceptor.getInterceptions().size()); assertEquals("requestDestroyed", ComponentInterceptor.getInterceptions().get(0).getMethodName()); assertEquals("requestInitialized", ComponentInterceptor.getInterceptions().get(1).getMethodName()); resp.getWriter().append("" + ComponentInterceptor.getInterceptions().size()); } else if ("aroundConstructVerify".equals(mode)) { assertTrue("AroundConstruct interceptor method not invoked", AroundConstructInterceptor.aroundConstructCalled); String name = getNameFromRequest(req); assertNotNull(name); assertTrue(name.contains("AroundConstructInterceptor#")); resp.getWriter().append(name); } else { resp.setStatus(404); } } private static String getNameFromRequest(HttpServletRequest req) { return req.getAttribute("name").toString(); } }
3,785
46.924051
123
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/ztatic/StaticInjectionTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.ztatic; import jakarta.ejb.EJB; 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.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests static field and method injection for EE apps. * * @author Eduardo Martins * */ @RunWith(Arquillian.class) public class StaticInjectionTestCase { private static final String DEPLOYMENT_NAME = "static-injection-test-du"; @EJB(mappedName = "java:global/" + DEPLOYMENT_NAME + "/FieldTestEJB") FieldTestEJB fieldTestEJB; @EJB(mappedName = "java:global/" + DEPLOYMENT_NAME + "/MethodTestEJB") MethodTestEJB methodTestEJB; @Deployment public static WebArchive createFieldTestDeployment() { final WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME + ".war"); war.addPackage(StaticInjectionTestCase.class.getPackage()); war.addAsWebInfResource(StaticInjectionTestCase.class.getPackage(), "web.xml", "web.xml"); return war; } @Test public void testStaticInjection() { Assert.assertTrue("Static field should not be injected", !fieldTestEJB.isStaticResourceInjected()); Assert.assertTrue("Static method should not be injected", !methodTestEJB.isStaticResourceInjected()); } }
2,486
36.681818
109
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/ztatic/FieldTestEJB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.ztatic; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; /** * An EJB that "asks" for the forbidden static field injection. * * @author Eduardo Martins * */ @Stateless public class FieldTestEJB { @Resource(name = "simpleString") private static String simpleStringFromDeploymentDescriptor; public boolean isStaticResourceInjected() { return simpleStringFromDeploymentDescriptor != null; } }
1,515
33.454545
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/ztatic/MethodTestEJB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.ztatic; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; /** * An EJB that "asks" for the forbidden static method injection. * * @author Eduardo Martins * */ @Stateless public class MethodTestEJB { private static String simpleStringFromDeploymentDescriptor; @Resource(name = "simpleString") private static void setSimpleStringFromDeploymentDescriptor(String s) { simpleStringFromDeploymentDescriptor = s; } public boolean isStaticResourceInjected() { return simpleStringFromDeploymentDescriptor != null; } }
1,651
32.714286
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/producer/SimpleBeanServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.producer; import java.io.IOException; import java.io.Writer; import jakarta.annotation.Resource; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @SuppressWarnings("serial") @WebServlet(name = "SimpleBeanServlet", urlPatterns = { "/simple" }) public class SimpleBeanServlet extends HttpServlet { @Resource SimpleManagedBean bean; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { Writer writer = resp.getWriter(); writer.write(bean.getDriverName()); writer.close(); } }
1,790
36.3125
95
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/producer/SimpleManagedBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.producer; import jakarta.annotation.ManagedBean; import jakarta.inject.Inject; /** * @author [email protected] * @since 09-Jul-2012 */ @ManagedBean public class SimpleManagedBean { @Inject String driverName; public String getDriverName() { return driverName; } }
1,380
33.525
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/producer/ProducerInjectionTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.producer; import java.net.URL; import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; 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.test.integration.common.HttpRequest; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Test @Resource injection into producer bean. * * @author [email protected] * @since 09-Jul-2012 */ @RunAsClient @RunWith(Arquillian.class) public class ProducerInjectionTestCase { private static final String SIMPLE_EAR = "simple.ear"; private static final String SIMPLE_WAR = "simple.war"; private static final String SIMPLE_CDI_JAR = "simple-cdi.jar"; @ArquillianResource URL targetURL; @Deployment(name = SIMPLE_EAR, testable = false) public static Archive<?> getSimpleEar() { WebArchive war = ShrinkWrap.create(WebArchive.class, SIMPLE_WAR); war.addClasses(SimpleBeanServlet.class); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, SIMPLE_CDI_JAR); jar.addClasses(SimpleManagedBean.class, SimpleProducerBean.class); jar.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, SIMPLE_EAR); ear.addAsModule(war); ear.addAsModule(jar); return ear; } @Test @OperateOnDeployment(SIMPLE_EAR) public void testSimpleEar() throws Exception { Assert.assertEquals("H2 JDBC Driver", performCall("simple", null)); } private String performCall(String pattern, String param) throws Exception { String urlspec = targetURL.toExternalForm(); URL url = new URL(urlspec + pattern + (param != null ? "?input=" + param : "")); return HttpRequest.get(url.toExternalForm(), 10, TimeUnit.SECONDS); } }
3,413
37.795455
88
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/producer/SimpleProducerBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, 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.producer; import java.sql.Connection; import java.sql.SQLException; import jakarta.annotation.ManagedBean; import jakarta.annotation.Resource; import jakarta.enterprise.inject.Produces; import javax.sql.DataSource; /** * @author [email protected] * @since 09-Jul-2012 */ @ManagedBean public class SimpleProducerBean { @Resource(lookup = "java:jboss/datasources/ExampleDS") DataSource dataSource; @Produces public String getDriverName() { try { Connection con = dataSource.getConnection(); try { return con.getMetaData().getDriverName(); } finally { con.close(); } } catch (SQLException ex) { return ex.toString(); } } }
1,854
32.125
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/superclass/Bean1.java
/* * 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.as.test.integration.ee.injection.resource.superclass; import jakarta.annotation.ManagedBean; /** * @author Stuart Douglas */ @ManagedBean("bean1") public class Bean1 extends SuperBean { public SimpleManagedBean getBean() { return simpleManagedBean; } /** * We override the superclass method. These should be no injection done * @param simpleString */ public void setSimpleString(final String simpleString) { super.setSimpleString(simpleString); } }
1,540
34.022727
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/superclass/SuperBean.java
/* * 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.as.test.integration.ee.injection.resource.superclass; import jakarta.annotation.Resource; /** * @author Stuart Douglas */ public class SuperBean { /** * This should create a binding for java:module/env/org.jboss.as.test.integration.injection.resource.superclass.SuperBean/simpleManagedBean */ @Resource(lookup = "java:module/simpleManagedBean") protected SimpleManagedBean simpleManagedBean; private String simpleString; public String getSimpleString() { return simpleString; } @Resource(lookup = "java:module/string1") public void setSimpleString(final String simpleString) { this.simpleString = simpleString; } }
1,720
34.122449
143
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/superclass/SuperClassInjectionTestCase.java
/* * 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.as.test.integration.ee.injection.resource.superclass; 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.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests that @Resource bindings on interceptors that are applied to multiple * components without their own naming context work properly, and do not try * and create two duplicate bindings in the same namespace. * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class SuperClassInjectionTestCase { @Deployment public static Archive<?> deployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, "multiple-bindings-superclass.war"); war.addClasses(Bean1.class, Bean2.class, SuperClassInjectionTestCase.class, SuperBean.class, SimpleManagedBean.class); war.addAsWebInfResource(SuperClassInjectionTestCase.class.getPackage(), "web.xml", "web.xml"); return war; } @Test public void testCorrectBinding() throws NamingException { InitialContext context = new InitialContext(); Object result = context.lookup("java:module/env/" + SuperBean.class.getName() + "/simpleManagedBean"); Assert.assertTrue(result instanceof SimpleManagedBean); } @Test public void testSubClass1Injected() throws NamingException { InitialContext context = new InitialContext(); Bean1 result = (Bean1) context.lookup("java:module/bean1"); Assert.assertTrue(result.getBean() instanceof SimpleManagedBean); } @Test public void testSubClass2Injected() throws NamingException { InitialContext context = new InitialContext(); Bean2 result = (Bean2) context.lookup("java:module/bean2"); Assert.assertTrue(result.getBean() instanceof SimpleManagedBean); } //AS7-6500 @Test public void testOverridenInjectionIsNotInjected() throws NamingException { InitialContext context = new InitialContext(); Bean2 result = (Bean2) context.lookup("java:module/bean2"); Assert.assertEquals("string2", result.getSimpleString()); Assert.assertEquals(1, result.getSetCount()); } @Test public void testNoInjectionOnOverride() throws NamingException { InitialContext context = new InitialContext(); Bean1 result = (Bean1) context.lookup("java:module/bean1"); Assert.assertNull(result.getSimpleString()); } }
3,708
38.88172
126
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/superclass/SimpleManagedBean.java
/* * 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.as.test.integration.ee.injection.resource.superclass; import jakarta.annotation.ManagedBean; /** * @author Stuart Douglas */ @ManagedBean("simpleManagedBean") public class SimpleManagedBean { }
1,232
37.53125
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/superclass/Bean2.java
/* * 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.as.test.integration.ee.injection.resource.superclass; import jakarta.annotation.ManagedBean; import jakarta.annotation.Resource; /** * @author Stuart Douglas */ @ManagedBean("bean2") public class Bean2 extends SuperBean { public SimpleManagedBean getBean() { return simpleManagedBean; } int setCount = 0; @Resource(lookup = "java:module/string2") public void setSimpleString(final String simpleString) { super.setSimpleString(simpleString); //keep a count to make sure this is not injected twice ++setCount; } public int getSetCount() { return setCount; } }
1,672
32.46
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/substitution/SimpleMDB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.substitution; import jakarta.annotation.Resource; import jakarta.ejb.ActivationConfigProperty; import jakarta.ejb.MessageDriven; import jakarta.jms.Connection; import jakarta.jms.Destination; import jakarta.jms.JMSException; import jakarta.jms.MapMessage; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.jms.MessageProducer; import jakarta.jms.QueueConnectionFactory; import jakarta.jms.Session; import org.jboss.logging.Logger; /** * @author wangchao * */ @MessageDriven(name = "TestMD", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/queue/testQueue") }) public class SimpleMDB implements MessageListener { private static final Logger log = Logger.getLogger(SimpleMDB.class); @Resource(mappedName = "${resource.mappedname.connectionfactory}") private QueueConnectionFactory connectionFactory; @Resource(name = "${resource.name}") private String replyMessage; @Override public void onMessage(Message msg) { log.trace("OnMessage working..."); try { Destination destination = msg.getJMSReplyTo(); Connection conn = connectionFactory.createConnection(); try { Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer replyProducer = session.createProducer(destination); MapMessage replyMsg = session.createMapMessage(); replyMsg.setJMSCorrelationID(msg.getJMSMessageID()); replyMsg.setString("replyMsg", replyMessage); replyProducer.send(replyMsg); } finally { conn.close(); } } catch (JMSException e) { throw new RuntimeException(e); } } }
3,015
37.177215
112
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/substitution/SimpleSLSB.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.substitution; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; /** * User: jpai */ @Stateless public class SimpleSLSB { @Resource(name = "${resource.name}") private String resourceByName; @Resource(lookup = "${resource.lookup}") private Object resourceByLookupName; @Resource(mappedName = "${resource.mappedname}") private Object resourceByMappedName; public boolean isResourceWithNameInjected() { return this.resourceByName != null; } public boolean isResourceWithMappedNameInjected() { return this.resourceByMappedName != null; } public boolean isResourceWithLookupNameInjected() { return this.resourceByLookupName != null; } public Object getResourceByMappedName() { return resourceByMappedName; } }
1,903
31.271186
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/substitution/SimpleCDIBean.java
/* * * * JBoss, Home of Professional Open Source. * * Copyright $year Red Hat, Inc., and individual contributors * * as indicated by the @author tags. * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * */ package org.jboss.as.test.integration.ee.injection.resource.substitution; import jakarta.annotation.PostConstruct; import jakarta.annotation.Resource; import jakarta.enterprise.context.RequestScoped; @RequestScoped public class SimpleCDIBean { @Resource(name = "${resource.name}") private String resourceByName; @Resource(lookup = "${resource.lookup}") private Object resourceByLookupName; @Resource(mappedName = "${resource.mappedname}") private Object resourceByMappedName; @PostConstruct public void postConstruct() { if (resourceByName == null) { throw new IllegalStateException("resourceByName"); } if (resourceByLookupName == null) { throw new IllegalStateException("resourceByLookupName"); } if (resourceByMappedName == null) { throw new IllegalStateException("resourceByMappedName"); } } public boolean isResourceWithNameInjected() { return this.resourceByName != null; } public boolean isResourceWithMappedNameInjected() { return this.resourceByMappedName != null; } public boolean isResourceWithLookupNameInjected() { return this.resourceByLookupName != null; } }
2,011
30.4375
78
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/substitution/SimpleSFSB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.substitution; import jakarta.annotation.Resource; import jakarta.ejb.Stateful; /** * @author wangchao * */ @Stateful public class SimpleSFSB { @Resource(name = "${resource.name}") private String resourceByName; @Resource(lookup = "${resource.lookup}") private Object resourceByLookupName; @Resource(mappedName = "${resource.mappedname}") private Object resourceByMappedName; public boolean isResourceWithNameInjected() { return this.resourceByName != null; } public boolean isResourceWithMappedNameInjected() { return this.resourceByMappedName != null; } public boolean isResourceWithLookupNameInjected() { return this.resourceByLookupName != null; } }
1,820
31.517857
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/substitution/ResourceInjectionSubstitutionTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.substitution; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION; import org.jboss.logging.Logger; import jakarta.inject.Inject; import jakarta.jms.Connection; import jakarta.jms.ConnectionFactory; import jakarta.jms.Destination; import jakarta.jms.MapMessage; import jakarta.jms.MessageConsumer; import jakarta.jms.MessageProducer; import jakarta.jms.Queue; import jakarta.jms.Session; import jakarta.jms.TextMessage; import javax.naming.Context; import javax.naming.InitialContext; 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.api.ServerSetup; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.client.helpers.ClientConstants; import org.jboss.as.test.integration.common.jms.JMSOperations; import org.jboss.as.test.integration.common.jms.JMSOperationsProvider; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests that the Resource injection with substitution works as expected * * @author wangchao */ @RunWith(Arquillian.class) @ServerSetup({ ResourceInjectionSubstitutionTestCase.SystemPropertySetup.class }) public class ResourceInjectionSubstitutionTestCase { private static final Logger logger = Logger.getLogger(ResourceInjectionSubstitutionTestCase.class.getName()); @ArquillianResource InitialContext ctx; private SimpleSLSB slsb; private SimpleSFSB sfsb; @Inject private SimpleCDIBean cdiBean; static class SystemPropertySetup implements ServerSetupTask { private JMSOperations jmsAdminOperations; @Override public void setup(ManagementClient managementClient, String containerId) throws Exception { jmsAdminOperations = JMSOperationsProvider.getInstance(managementClient); jmsAdminOperations.createJmsQueue("queue/testQueue", "java:jboss/queue/testQueue"); final ModelNode enableSubstitutionOp = new ModelNode(); enableSubstitutionOp.get(OP_ADDR).set(SUBSYSTEM, "ee"); enableSubstitutionOp.get(OP).set(WRITE_ATTRIBUTE_OPERATION); enableSubstitutionOp.get(NAME).set("annotation-property-replacement"); enableSubstitutionOp.get(VALUE).set(true); // @Resource(name="${resource.name}") final ModelNode setResourceNameOp = new ModelNode(); setResourceNameOp.get(ClientConstants.OP).set(ClientConstants.ADD); setResourceNameOp.get(ClientConstants.OP_ADDR).add("system-property", "resource.name"); setResourceNameOp.get("value").set("simpleString"); // @Resource(lookup = "${resource.lookup}") final ModelNode setResourceLookupOp = new ModelNode(); setResourceLookupOp.get(ClientConstants.OP).set(ClientConstants.ADD); setResourceLookupOp.get(ClientConstants.OP_ADDR).add("system-property", "resource.lookup"); setResourceLookupOp.get("value").set("java:comp/env/ResourceFromWebXml"); // @Resource(mappedName="${resource.mappedname}") final ModelNode setResourceMappedNameOp = new ModelNode(); setResourceMappedNameOp.get(ClientConstants.OP).set(ClientConstants.ADD); setResourceMappedNameOp.get(ClientConstants.OP_ADDR).add("system-property", "resource.mappedname"); setResourceMappedNameOp.get("value").set("java:comp/env/ResourceFromWebXml"); // @Resource(mappedName = "${resource.mappedname.connectionfactory}") final ModelNode setResourceMappedNameConnectionFactoryOp = new ModelNode(); setResourceMappedNameConnectionFactoryOp.get(ClientConstants.OP).set(ClientConstants.ADD); setResourceMappedNameConnectionFactoryOp.get(ClientConstants.OP_ADDR).add("system-property", "resource.mappedname.connectionfactory"); setResourceMappedNameConnectionFactoryOp.get("value").set("java:/ConnectionFactory"); try { applyUpdate(managementClient, enableSubstitutionOp); applyUpdate(managementClient, setResourceNameOp); applyUpdate(managementClient, setResourceLookupOp); applyUpdate(managementClient, setResourceMappedNameOp); applyUpdate(managementClient, setResourceMappedNameConnectionFactoryOp); } catch (Exception e) { throw new RuntimeException(e); } } @Override public void tearDown(ManagementClient managementClient, String containerId) throws Exception { if (jmsAdminOperations != null) { jmsAdminOperations.removeJmsQueue("queue/testQueue"); jmsAdminOperations.close(); } // @Resource(name="${resource.name}") final ModelNode removeResourceNameOp = new ModelNode(); removeResourceNameOp.get(ClientConstants.OP).set("remove"); removeResourceNameOp.get(ClientConstants.OP_ADDR).add("system-property", "resource.name"); // @Resource(lookup = "${resource.lookup}") final ModelNode removeResourceLookupOp = new ModelNode(); removeResourceLookupOp.get(ClientConstants.OP).set("remove"); removeResourceLookupOp.get(ClientConstants.OP_ADDR).add("system-property", "resource.lookup"); // @Resource(mappedName="${resource.mappedname}") final ModelNode removeResourceMappedNameOp = new ModelNode(); removeResourceMappedNameOp.get(ClientConstants.OP).set("remove"); removeResourceMappedNameOp.get(ClientConstants.OP_ADDR).add("system-property", "resource.mappedname"); // @Resource(mappedName = "${resource.mappedname.conncetionfactory}") final ModelNode removeResourceMappedNameConnectionFactoryOp = new ModelNode(); removeResourceMappedNameConnectionFactoryOp.get(ClientConstants.OP).set("remove"); removeResourceMappedNameConnectionFactoryOp.get(ClientConstants.OP_ADDR).add("system-property", "resource.mappedname.conncetionfactory"); final ModelNode disableSubstitutionOp = new ModelNode(); disableSubstitutionOp.get(OP_ADDR).set(SUBSYSTEM, "ee"); disableSubstitutionOp.get(OP).set(WRITE_ATTRIBUTE_OPERATION); disableSubstitutionOp.get(NAME).set("annotation-property-replacement"); disableSubstitutionOp.get(VALUE).set(false); try { applyUpdate(managementClient, removeResourceNameOp); applyUpdate(managementClient, removeResourceLookupOp); applyUpdate(managementClient, removeResourceMappedNameOp); applyUpdate(managementClient, removeResourceMappedNameConnectionFactoryOp); applyUpdate(managementClient, disableSubstitutionOp); } catch (Exception e) { throw new RuntimeException(e); } } private void applyUpdate(final ManagementClient managementClient, final ModelNode update) throws Exception { ModelNode result = managementClient.getControllerClient().execute(update); if (result.hasDefined(ClientConstants.OUTCOME) && ClientConstants.SUCCESS.equals(result.get(ClientConstants.OUTCOME).asString())) { } else if (result.hasDefined(ClientConstants.FAILURE_DESCRIPTION)) { final String failureDesc = result.get(ClientConstants.FAILURE_DESCRIPTION).toString(); throw new RuntimeException(failureDesc); } else { throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome")); } } } @Before public void beforeTest() throws Exception { Context ctx = new InitialContext(); slsb = (SimpleSLSB) ctx.lookup("java:module/" + SimpleSLSB.class.getSimpleName() + "!" + SimpleSLSB.class.getName()); sfsb = (SimpleSFSB) ctx.lookup("java:module/" + SimpleSFSB.class.getSimpleName() + "!" + SimpleSFSB.class.getName()); } @Deployment public static WebArchive createWebDeployment() { final WebArchive war = ShrinkWrap.create(WebArchive.class, "resource-injection-substitution-test.war"); war.addPackage(SimpleSLSB.class.getPackage()).addPackage(JMSOperations.class.getPackage()); war.addAsWebInfResource(ResourceInjectionSubstitutionTestCase.class.getPackage(), "web.xml", "web.xml"); return war; } /** * Test resource injection with SLSB */ @Test public void testResourceInjectionSubstitutionSlsb() { Assert.assertTrue("@Resource with name wasn't injected in SLSB", slsb.isResourceWithNameInjected()); Assert.assertTrue("@Resource with lookup wasn't injected in SLSB", slsb.isResourceWithLookupNameInjected()); Assert.assertTrue("@Resource with mappedName wasn't injected in SLSB", slsb.isResourceWithMappedNameInjected()); } /** * Test resource injection with SFSB */ @Test public void testResourceInjectionSubstitutionSfsb() { Assert.assertTrue("@Resource with name wasn't injected in SFSB", sfsb.isResourceWithNameInjected()); Assert.assertTrue("@Resource with lookup wasn't injected in SFSB", sfsb.isResourceWithLookupNameInjected()); Assert.assertTrue("@Resource with mappedName wasn't injected in SFSB", sfsb.isResourceWithMappedNameInjected()); } /** * Test resource injection with MDB */ @Test public void testResourceInjectionSubstitutionMdb() throws Exception { // ConnectionFactory and Reply message are injected in SimpleMDB ConnectionFactory factory = (ConnectionFactory) ctx.lookup("ConnectionFactory"); Connection con = factory.createConnection(); try { Destination dest = (Destination) ctx.lookup("java:jboss/queue/testQueue"); Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(dest); Queue replyQueue = session.createTemporaryQueue(); MessageConsumer consumer = session.createConsumer(replyQueue); con.start(); TextMessage msg = session.createTextMessage(); msg.setJMSReplyTo(replyQueue); msg.setText("This is message one"); producer.send(msg); MapMessage replyMsg = (MapMessage) consumer.receive(5000); Assert.assertNotNull(replyMsg); Assert.assertEquals("It's Friday!!!", replyMsg.getString("replyMsg")); } finally { con.close(); } } /** * Test resource injection with SFSB */ @Test public void testResourceInjectionSubstitutionCDI() { Assert.assertTrue("@Resource with name wasn't injected in CDI bean", cdiBean.isResourceWithNameInjected()); Assert.assertTrue("@Resource with lookup wasn't injected in CDI bean", cdiBean.isResourceWithLookupNameInjected()); Assert.assertTrue("@Resource with mappedName wasn't injected in CDI bean", cdiBean.isResourceWithMappedNameInjected()); } }
13,041
47.303704
149
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/persistencecontextref/PcManagedBean.java
/* * 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.as.test.integration.ee.injection.resource.persistencecontextref; import jakarta.annotation.ManagedBean; import jakarta.ejb.EJB; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; /** * Managed bean with persistence unit definitions. * @author Stuart Douglas */ @ManagedBean("pcManagedBean") public class PcManagedBean { @PersistenceContext(unitName = "mypc") private EntityManager mypc; //this one will be overridden via deployment descriptor to be otherpu @PersistenceContext(unitName = "mypc", name = "otherPcBinding") private EntityManager otherpc; @EJB SFSB sfsb; //this one is injected via deployment descriptor private EntityManager mypc2; public EntityManager getMypc2() { return mypc2; } public EntityManager getMypc() { return mypc; } public EntityManager getOtherpc() { return otherpc; } public boolean unsynchronizedIsNotJoinedToTX() { return sfsb.unsynchronizedIsNotJoinedToTX(); } public boolean synchronizedIsJoinedToTX() { return sfsb.synchronizedIsJoinedToTX(); } }
2,186
29.802817
82
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/persistencecontextref/PersistenceContextRefTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2011, Red Hat Middleware LLC, 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.as.test.integration.ee.injection.resource.persistencecontextref; import static org.junit.Assert.assertNotNull; 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.shrinkwrap.api.Archive; 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; /** * @author Stuart Douglas */ @RunWith(Arquillian.class) public class PersistenceContextRefTestCase { private static final String ARCHIVE_NAME = "persistence-context-ref"; private static final String persistence_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + "<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\" version=\"1.0\">" + " <persistence-unit name=\"mypc\">" + " <description>Persistence Unit." + " </description>" + " <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>" + " <exclude-unlisted-classes>true</exclude-unlisted-classes>" + " <class>" + PcMyEntity.class.getName() + "</class>" + "<properties> <property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/></properties>" + " </persistence-unit>" + " <persistence-unit name=\"otherpc\">" + " <description>Persistence Unit." + " </description>" + " <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>" + " <exclude-unlisted-classes>true</exclude-unlisted-classes>" + " <class>" + PcOtherEntity.class.getName() + "</class>" + "<properties> <property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/></properties>" + " </persistence-unit>" + "</persistence>"; @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME + ".war"); war.addPackage(PersistenceContextRefTestCase.class.getPackage()); war.addAsResource(new StringAsset(persistence_xml), "META-INF/persistence.xml"); war.addAsWebInfResource(getWebXml(), "web.xml"); return war; } @Test public void testCorrectPersistenceUnitInjectedFromAnnotation() throws NamingException { PcManagedBean bean = getManagedBean(); bean.getMypc().getMetamodel().entity(PcMyEntity.class); } @Test public void testCorrectPersistenceUnitInjectedFromAnnotation2() throws NamingException { try { PcManagedBean bean = getManagedBean(); bean.getMypc().getMetamodel().entity(PcOtherEntity.class); Assert.fail(); } catch (IllegalArgumentException expected) { } } @Test public void testCorrectPersistenceUnitInjectedFromPersistenceUnitRef() throws NamingException { try { PcManagedBean bean = getManagedBean(); bean.getOtherpc().getMetamodel().entity(PcMyEntity.class); Assert.fail(); } catch (IllegalArgumentException expected) { } } @Test public void testCorrectPersistenceUnitInjectedFromPersistenceUnitRef2() throws NamingException { PcManagedBean bean = getManagedBean(); bean.getOtherpc().getMetamodel().entity(PcOtherEntity.class); } @Test public void testCorrectPersistenceUnitInjectedFromRefInjectionTarget() throws NamingException { PcManagedBean bean = getManagedBean(); bean.getMypc2().getMetamodel().entity(PcMyEntity.class); } @Test public void testCorrectPersistenceUnitInjectedFromRefInjectionTarget2() throws NamingException { try { PcManagedBean bean = getManagedBean(); bean.getMypc2().getMetamodel().entity(PcOtherEntity.class); Assert.fail(); } catch (IllegalArgumentException expected) { } } @Test public void testUnsynchronizedPCisNotJoinedToTransaction() throws NamingException { PcManagedBean bean = getManagedBean(); boolean isJoined = bean.unsynchronizedIsNotJoinedToTX(); Assert.assertFalse("Unsynchronized entity manager should not of been joined to the JTA transaction but was",isJoined); } @Test public void testSynchronizedPCisJoinedToTransaction() throws NamingException { PcManagedBean bean = getManagedBean(); boolean isJoined = bean.synchronizedIsJoinedToTX(); Assert.assertTrue("Synchronized entity manager should of been joined to the JTA transaction but was not",isJoined); } private PcManagedBean getManagedBean() throws NamingException { InitialContext initialContext = new InitialContext(); PcManagedBean bean = (PcManagedBean) initialContext.lookup("java:module/pcManagedBean"); assertNotNull(bean); return bean; } 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" + " <persistence-context-ref>\n" + " <persistence-context-ref-name>otherPcBinding</persistence-context-ref-name>\n" + " <persistence-unit-name>otherpc</persistence-unit-name>\n" + " </persistence-context-ref>\n" + "\n" + " <persistence-context-ref>\n" + " <persistence-context-ref-name>unsyncPcBinding</persistence-context-ref-name>\n" + " <persistence-unit-name>otherpc</persistence-unit-name>\n" + " <persistence-context-synchronization>Unsynchronized</persistence-context-synchronization>\n" + " </persistence-context-ref>\n" + "\n" + " <persistence-context-ref>\n" + " <persistence-context-ref-name>AnotherPuBinding</persistence-context-ref-name>\n" + " <persistence-unit-name>mypc</persistence-unit-name>\n" + " <injection-target>" + " <injection-target-class>" + PcManagedBean.class.getName() + "</injection-target-class>" + " <injection-target-name>mypc2</injection-target-name>" + " </injection-target>\n" + " </persistence-context-ref>\n" + "\n" + "</web-app>"); } }
8,223
43.939891
137
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/persistencecontextref/PcMyEntity.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.persistencecontextref; import java.io.Serializable; import jakarta.persistence.Entity; import jakarta.persistence.Id; /** * @author <a href="mailto:[email protected]">William DeCoste</a> */ @Entity public class PcMyEntity implements Serializable { private Integer id; private String name; public PcMyEntity() { } public PcMyEntity(String name) { this.name = name; } @Id public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String toString() { return "MyEntity:id=" + id + ",name=" + name; } }
1,852
27.075758
82
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/persistencecontextref/SFSB.java
package org.jboss.as.test.integration.ee.injection.resource.persistencecontextref; import jakarta.ejb.Stateful; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; /** * SFSB * * @author Scott Marlow */ @Stateful public class SFSB { //this one will be overridden via deployment descriptor to be otherpu @PersistenceContext(unitName = "mypc", name = "otherPcBinding") private EntityManager otherpc; @PersistenceContext(unitName = "mypc", name = "unsyncPcBinding") private EntityManager unSynchronizedPc; public boolean unsynchronizedIsNotJoinedToTX() { return unSynchronizedPc.isJoinedToTransaction(); } public boolean synchronizedIsJoinedToTX() { return otherpc.isJoinedToTransaction(); } }
791
24.548387
82
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/persistencecontextref/PcOtherEntity.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.persistencecontextref; import java.io.Serializable; import jakarta.persistence.Entity; import jakarta.persistence.Id; /** * @author <a href="mailto:[email protected]">William DeCoste</a> */ @Entity public class PcOtherEntity implements Serializable { private Integer id; private String name; public PcOtherEntity() { } public PcOtherEntity(String name) { this.name = name; } @Id public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String toString() { return "OtherEntity:id=" + id + ",name=" + name; } }
1,864
27.257576
82
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/noncomponent/ComponentResourceInjection.java
/* * 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.as.test.integration.ee.injection.resource.noncomponent; import jakarta.annotation.ManagedBean; import jakarta.annotation.Resource; import jakarta.transaction.UserTransaction; /** * This class is a managed bean, and it's resource injection should be able to be looked up * * @author Stuart Douglas */ @ManagedBean public class ComponentResourceInjection { @Resource private UserTransaction userTransaction; }
1,458
35.475
91
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/noncomponent/NonComponentResourceInjection.java
/* * 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.as.test.integration.ee.injection.resource.noncomponent; import jakarta.annotation.Resource; import jakarta.ejb.EJB; import jakarta.mail.Session; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.PersistenceContext; import jakarta.persistence.PersistenceUnit; import jakarta.transaction.UserTransaction; import jakarta.xml.ws.WebServiceRef; /** * This class is not a component, and not used as an interceptor, and as such any resources * it defines should not be able to be looked up in JNDI. * * @author Stuart Douglas */ public class NonComponentResourceInjection { @Resource private UserTransaction userTransaction; /** * This should not fail the deployment, even though it is completely bogus */ @Resource private NonComponentResourceInjectionTestCase randomInjection; @PersistenceContext(unitName = "bogus") private EntityManager entityManager; @PersistenceContext private EntityManager entityManagerDefault; @PersistenceUnit(unitName = "bogus") private EntityManagerFactory entityManagerFactory; @PersistenceUnit private EntityManagerFactory entityManagerFactoryDefault; @EJB private NonComponentResourceInjection notReal; @WebServiceRef private NonComponentResourceInjection nonExitantWebService; @Resource(mappedName = "java:/Mail") public Session mailSessionJndiDefault; @Resource(mappedName = "java:jboss/mail/foo/MyMailServer1") public Session mailSessionJndiCustom; @Resource public Session mailSession; }
2,641
32.025
91
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/noncomponent/NonComponentResourceInjectionTestCase.java
/* * 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.as.test.integration.ee.injection.resource.noncomponent; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import javax.naming.InitialContext; import javax.naming.NamingException; /** * Tests that @Resource annotations on classes that are not managed by the container are ignored. * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class NonComponentResourceInjectionTestCase { @Deployment public static Archive<?> deployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, "non-component.war"); war.addPackage(NonComponentResourceInjectionTestCase.class.getPackage()); return war; } @Test public void testBindingDoesNotExist() throws NamingException { try { InitialContext context = new InitialContext(); Object result = context.lookup("java:module/env/" + NonComponentResourceInjectionTestCase.class.getName() + "/userTransaction"); Assert.fail(); } catch (NamingException expected) { } } @Test public void testBindingExists() throws NamingException { InitialContext context = new InitialContext(); Object result = context.lookup("java:module/env/" + ComponentResourceInjection.class.getName() + "/userTransaction"); Assert.assertNotNull(result); } }
2,635
36.126761
140
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/mail/MailUnitTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright (c) 2010, JBoss 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.as.test.integration.ee.injection.resource.mail; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Testing injection of mail service and its definition in xml file. * Part migration of tests from EJB testsuite (mail/Mail) [JIRA JBQA-5483]. * * @author Darran Lofthouse, Ondrej Chaloupka */ @RunWith(Arquillian.class) public class MailUnitTestCase { @ArquillianResource InitialContext ctx; @Deployment public static Archive<?> deploy() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "mail-injection-test.jar"); jar.addClasses(MailUnitTestCase.class, StatelessMail.class, StatelessMailBean.class); jar.addAsManifestResource(MailUnitTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml"); return jar; } @Test public void testMailInjection() throws Exception { StatelessMail bean = (StatelessMail) ctx.lookup("java:module/StatelessMailBean"); Assert.assertNotNull(bean); bean.testMail(); bean.testMailInjection(); } }
2,447
36.661538
101
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/mail/StatelessMail.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.mail; import javax.naming.NamingException; /** * @author <a href="mailto:[email protected]">William DeCoste</a> */ public interface StatelessMail { void testMail() throws NamingException; void testMailInjection(); }
1,314
36.571429
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/mail/StatelessMailBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.mail; import jakarta.annotation.Resource; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; import jakarta.mail.Session; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; /** * @author <a href="mailto:[email protected]">William DeCoste</a> */ @Stateless @Remote(StatelessMail.class) public class StatelessMailBean implements StatelessMail { @Resource(name = "MyDefaultMail") private Session mailSession; @Resource(lookup = "java:jboss/mail/Default") private Session session; // injected via xml descriptor private Session dsSession; public void testMail() throws NamingException { Context initCtx = new InitialContext(); Context myEnv = (Context) initCtx.lookup("java:comp/env"); // JavaMail Session Object obj = myEnv.lookup("MyDefaultMail"); if ((obj instanceof jakarta.mail.Session) == false) { throw new NamingException("DefaultMail is not a jakarta.mail.Session"); } } public void testMailInjection() { mailSession.getProperties(); session.getProperties(); dsSession.getProperties(); } }
2,261
32.761194
135
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/ejblocalref/EjbLocalRefInjectionServlet.java
/* * 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.as.test.integration.ee.injection.resource.ejblocalref; import java.io.IOException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * @author Stuart Douglas */ @WebServlet(name="ejbLocalRef",urlPatterns = {"/ejbLocalRef"}) public class EjbLocalRefInjectionServlet extends HttpServlet { private Hello named; private Hello simpleHelloBean; public void setSimple(Hello hello) { simpleHelloBean = hello; } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if(req.getParameter("type").equals("named")) { resp.getWriter().append(named.sayHello()).flush(); } else { resp.getWriter().append(simpleHelloBean.sayHello()); } resp.getWriter().close(); } }
2,030
34.631579
113
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/ejblocalref/NamedSLSB.java
/* * 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.as.test.integration.ee.injection.resource.ejblocalref; import jakarta.ejb.Stateless; /** * @author Stuart Douglas */ @Stateless(name = "namedBean") public class NamedSLSB implements Hello{ @Override public String sayHello() { return "Named Hello"; } }
1,312
33.552632
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/ejblocalref/SimpleSLSB.java
/* * 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.as.test.integration.ee.injection.resource.ejblocalref; import jakarta.ejb.Stateless; /** * @author Stuart Douglas */ @Stateless public class SimpleSLSB implements Hello { @Override public String sayHello() { return "Simple Hello"; } }
1,293
34.944444
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/ejblocalref/EjbLocalRefNoInjectionTestCase.java
/* * 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()); } }
2,234
39.636364
144
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/ejblocalref/Hello.java
/* * 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.as.test.integration.ee.injection.resource.ejblocalref; import jakarta.ejb.Local; /** * @author Stuart Douglas */ @Local public interface Hello { String sayHello(); }
1,209
34.588235
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/ejblocalref/EjbLocalRefInjectionTestCase.java
/* * 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 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 EjbLocalRefInjectionTestCase { @ArquillianResource private ManagementClient managementClient; @Deployment public static WebArchive deployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, "war-example.war"); war.addClasses(EjbLocalRefInjectionServlet.class, NamedSLSB.class, SimpleSLSB.class, Hello.class); war.addAsWebInfResource(EjbLocalRefInjectionTestCase.class.getPackage(), "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 testLookup() throws Exception { String result = performCall("ejbLocalRef?type=simple"); assertEquals("Simple Hello", result); } @Test public void testEjbLink() throws Exception { String result = performCall("ejbLocalRef?type=named"); assertEquals("Named Hello", result); } }
2,835
37.324324
113
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/multipleinterceptors/MyInterceptor.java
/* * 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.as.test.integration.ee.injection.resource.multipleinterceptors; import jakarta.annotation.Resource; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.InvocationContext; /** * @author Stuart Douglas */ public class MyInterceptor { /** * This should create a binding for java:module/env/org.jboss.as.test.integration.injection.resource.multiple.MyInterceptor/simpleManagedBean */ @Resource(lookup="java:module/simpleManagedBean") private SimpleManagedBean simpleManagedBean; @AroundInvoke public Object intercept(InvocationContext context ) throws Exception { return context.proceed(); } }
1,688
37.386364
145
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/multipleinterceptors/Bean1.java
/* * 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.as.test.integration.ee.injection.resource.multipleinterceptors; import jakarta.annotation.ManagedBean; import jakarta.interceptor.Interceptors; /** * @author Stuart Douglas */ @ManagedBean("bean1") @Interceptors(MyInterceptor.class) public class Bean1 { }
1,294
37.088235
81
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/multipleinterceptors/SimpleManagedBean.java
/* * 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.as.test.integration.ee.injection.resource.multipleinterceptors; import jakarta.annotation.ManagedBean; /** * @author Stuart Douglas */ @ManagedBean("simpleManagedBean") public class SimpleManagedBean { }
1,242
37.84375
81
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/multipleinterceptors/Bean2.java
/* * 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.as.test.integration.ee.injection.resource.multipleinterceptors; import jakarta.annotation.ManagedBean; import jakarta.interceptor.Interceptors; /** * @author Stuart Douglas */ @ManagedBean("bean2") @Interceptors(MyInterceptor.class) public class Bean2 { }
1,294
37.088235
81
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/multipleinterceptors/BindingsOnInterceptorTestCase.java
/* * 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.as.test.integration.ee.injection.resource.multipleinterceptors; 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.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests that @Resource bindings on interceptors that are applied to multiple * components without their own naming context work properly, and do not try * and create two duplicate bindings in the same namespace. * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class BindingsOnInterceptorTestCase { @Deployment public static Archive<?> deployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, "multiple-bindings-interceptors.war"); war.addClasses(Bean1.class, Bean2.class, BindingsOnInterceptorTestCase.class, MyInterceptor.class, SimpleManagedBean.class); return war; } @Test public void testCorrectBinding() throws NamingException { InitialContext context = new InitialContext(); Object result = context.lookup("java:module/env/" + MyInterceptor.class.getName() + "/simpleManagedBean"); Assert.assertTrue(result instanceof SimpleManagedBean); } }
2,454
39.245902
132
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/persistenceunitref/PuManagedBean.java
/* * 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.as.test.integration.ee.injection.resource.persistenceunitref; import jakarta.annotation.ManagedBean; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.PersistenceUnit; /** * Managed bean with persistence unit definitions. * @author Stuart Douglas */ @ManagedBean("puManagedBean") public class PuManagedBean { @PersistenceUnit(unitName = "mypc") private EntityManagerFactory mypu; //this one will be overridden via deployment descriptor to be otherpc @PersistenceUnit(unitName = "mypc", name = "otherPcBinding") private EntityManagerFactory otherpc; //this one is injected via deployment descriptor private EntityManagerFactory mypu2; public EntityManagerFactory getMypu2() { return mypu2; } public EntityManagerFactory getMypu() { return mypu; } public EntityManagerFactory getOtherpc() { return otherpc; } }
1,956
33.333333
79
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/persistenceunitref/PersistenceUnitRefTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2011, Red Hat Middleware LLC, 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.as.test.integration.ee.injection.resource.persistenceunitref; import static org.junit.Assert.assertNotNull; 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.shrinkwrap.api.Archive; 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; /** * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class PersistenceUnitRefTestCase { private static final String ARCHIVE_NAME = "persistence-unit-ref"; private static final String persistence_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + "<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\" version=\"1.0\">" + " <persistence-unit name=\"mypc\">" + " <description>Persistence Unit." + " </description>" + " <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>" + " <exclude-unlisted-classes>true</exclude-unlisted-classes>" + " <class>" + PuMyEntity.class.getName() + "</class>" + "<properties> <property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/></properties>" + " </persistence-unit>" + " <persistence-unit name=\"otherpc\">" + " <description>Persistence Unit." + " </description>" + " <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>" + " <exclude-unlisted-classes>true</exclude-unlisted-classes>" + " <class>" + PuOtherEntity.class.getName() + "</class>" + "<properties> <property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/></properties>" + " </persistence-unit>" + "</persistence>"; @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME + ".war"); war.addPackage(PersistenceUnitRefTestCase.class.getPackage()); war.addAsResource(new StringAsset(persistence_xml), "META-INF/persistence.xml"); war.addAsWebInfResource(getWebXml(),"web.xml"); return war; } @Test public void testCorrectPersistenceUnitInjectedFromAnnotation() throws NamingException { PuManagedBean bean = getManagedBean(); bean.getMypu().getMetamodel().entity(PuMyEntity.class); } @Test public void testCorrectPersistenceUnitInjectedFromAnnotation2() throws NamingException { try { PuManagedBean bean = getManagedBean(); bean.getMypu().getMetamodel().entity(PuOtherEntity.class); } catch (IllegalArgumentException e) { //all is fine! return; } Assert.fail("IllegalArgumentException should occur but didn't!"); } @Test public void testCorrectPersistenceUnitInjectedFromPersistenceUnitRef() throws NamingException { try { PuManagedBean bean = getManagedBean(); bean.getOtherpc().getMetamodel().entity(PuMyEntity.class); } catch (IllegalArgumentException e) { //all is fine! return; } Assert.fail("IllegalArgumentException should occur but didn't!"); } @Test public void testCorrectPersistenceUnitInjectedFromPersistenceUnitRef2() throws NamingException { PuManagedBean bean = getManagedBean(); bean.getOtherpc().getMetamodel().entity(PuOtherEntity.class); } @Test public void testCorrectPersistenceUnitInjectedFromRefInjectionTarget() throws NamingException { PuManagedBean bean = getManagedBean(); bean.getMypu2().getMetamodel().entity(PuMyEntity.class); } @Test public void testCorrectPersistenceUnitInjectedFromRefInjectionTarget2() throws NamingException { try { PuManagedBean bean = getManagedBean(); bean.getMypu2().getMetamodel().entity(PuOtherEntity.class); } catch (IllegalArgumentException e) { //all is fine! return; } Assert.fail("IllegalArgumentException should occur but didn't!"); } private PuManagedBean getManagedBean() throws NamingException { InitialContext initialContext = new InitialContext(); PuManagedBean bean = (PuManagedBean) initialContext.lookup("java:module/puManagedBean"); assertNotNull(bean); return bean; } 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" + " <persistence-unit-ref>\n" + " <persistence-unit-ref-name>otherPcBinding</persistence-unit-ref-name>\n" + " <persistence-unit-name>otherpc</persistence-unit-name>\n" + " </persistence-unit-ref>\n" + "\n" + " <persistence-unit-ref>\n" + " <persistence-unit-ref-name>AnotherPuBinding</persistence-unit-ref-name>\n" + " <persistence-unit-name>mypc</persistence-unit-name>\n" + " <injection-target>" + " <injection-target-class>"+ PuManagedBean.class.getName()+"</injection-target-class>"+ " <injection-target-name>mypu2</injection-target-name>" + " </injection-target>\n" + " </persistence-unit-ref>\n" + "\n" + "</web-app>"); } }
7,212
41.680473
137
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/persistenceunitref/PuOtherEntity.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.persistenceunitref; import java.io.Serializable; import jakarta.persistence.Entity; import jakarta.persistence.Id; /** * @author <a href="mailto:[email protected]">William DeCoste</a> */ @Entity public class PuOtherEntity implements Serializable { private Integer id; private String name; public PuOtherEntity() { } public PuOtherEntity(String name) { this.name = name; } @Id public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String toString() { return "OtherEntity:id=" + id + ",name=" + name; } }
1,861
27.212121
79
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/persistenceunitref/PuMyEntity.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat Middleware LLC, 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.persistenceunitref; import java.io.Serializable; import jakarta.persistence.Entity; import jakarta.persistence.Id; /** * @author <a href="mailto:[email protected]">William DeCoste</a> */ @Entity public class PuMyEntity implements Serializable { private Integer id; private String name; public PuMyEntity() { } public PuMyEntity(String name) { this.name = name; } @Id public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String toString() { return "MyEntity:id=" + id + ",name=" + name; } }
1,849
27.030303
79
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/url/URLConnectionFactoryResourceInjectionTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.url; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Test; import org.junit.runner.RunWith; import javax.naming.InitialContext; /** * Test for EE's resource injection for URLs * * @author Eduardo Martins */ @RunWith(Arquillian.class) public class URLConnectionFactoryResourceInjectionTestCase { @Deployment public static Archive<?> getDeployment() { return ShrinkWrap.create(JavaArchive.class, URLConnectionFactoryResourceInjectionTestCase.class.getSimpleName() + ".jar") .addClasses(URLConnectionFactoryResourceInjectionTestCase.class, URLConnectionFactoryResourceInjectionTestEJB.class) .addAsManifestResource(URLConnectionFactoryResourceInjectionTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml"); } @Test public void testResourceInjection() throws Exception { final URLConnectionFactoryResourceInjectionTestEJB testEJB = (URLConnectionFactoryResourceInjectionTestEJB) new InitialContext().lookup("java:module/" + URLConnectionFactoryResourceInjectionTestEJB.class.getSimpleName()); testEJB.validateResourceInjection(); } }
2,417
42.178571
229
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/url/URLConnectionFactoryResourceInjectionTestEJB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.url; import static org.wildfly.common.Assert.checkNotNullParamWithNullPointerException; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import java.net.URL; /** * @author Eduardo Martins */ @Stateless public class URLConnectionFactoryResourceInjectionTestEJB { @Resource(name = "overrideLookupURL", lookup = "http://www.wildfly.org") private URL url1; @Resource(name = "lookupURL", lookup = "http://www.wildfly.org") private URL url2; /** * * @throws Exception */ public void validateResourceInjection() throws Exception { checkNotNullParamWithNullPointerException("url1", url1); checkNotNullParamWithNullPointerException("url2", url2); } }
1,811
33.188679
82
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/basic/CommonBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.basic; import jakarta.ejb.LocalBean; import jakarta.ejb.Stateless; /** * User: jpai */ @Stateless @LocalBean public class CommonBean { public static final String HELLO_GREETING_PREFIX = "Hello "; public String sayHello(String user) { return HELLO_GREETING_PREFIX + user; } }
1,385
32.804878
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/basic/CheckORBRemote.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.basic; import jakarta.ejb.Remote; /** * @author carlo */ @Remote public interface CheckORBRemote { void checkForInjectedORB(); void checkForORBInEnvironment(); }
1,259
34
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/basic/OtherSLSB.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.basic; import jakarta.ejb.Stateless; /** * User: jpai */ @Stateless public class OtherSLSB extends Parent { }
1,198
35.333333
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/basic/SimpleSLSB.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.basic; import jakarta.annotation.Resource; import jakarta.ejb.EJB; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; import jakarta.ejb.TimerService; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NameNotFoundException; import javax.naming.NamingException; import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; import java.net.URL; /** * User: jpai */ @Stateless public class SimpleSLSB extends Parent { // injected via the setter private Parent otherBean; @Resource private TimerService timerService; @Resource private SessionContext sessionContext; @Resource(name = "simpleString") private String simpleStringFromDeploymentDescriptor; public static final int DEFAULT_UNINJECTED_INT_VAL = 4; public static final String DEFAULT_UNINJECTED_STRING_VAL = "This is the default value!!!! ###"; @Resource(name = "missingEnvEntryValIntResource") private int wontBeInjected = DEFAULT_UNINJECTED_INT_VAL; // @Resource is used on the setter private String wontBeInjectedString = DEFAULT_UNINJECTED_STRING_VAL; @Resource(name = "url1") private URL url1; @Resource(lookup = "http://jboss.org") private URL url2; @Resource(lookup = "file://dev/null") private Object url3; @Resource(lookup = "java:comp/env/url1") private URL url4; @Resource(name = "ldapContext1") private LdapContext ldapContext1; @Resource(lookup = "ldap://localhost:389") private DirContext ldapContext2; @Resource(lookup = "java:comp/env") private Context context1; @Resource(lookup = "java:comp/null") private Context context2; public String sayHello(String user) { return this.commonBean.sayHello(user); } public Class<?> getInvokedBusinessInterface() { SessionContext sessionContext = (SessionContext) this.ejbContext; return sessionContext.getInvokedBusinessInterface(); } @EJB(beanInterface = OtherSLSB.class) public void setOtherBean(Parent otherBean) { this.otherBean = otherBean; } public String getInjectedString() { return this.simpleStringFromDeploymentDescriptor; } public int getUnInjectedInt() { return this.wontBeInjected; } @Resource(name = "missingEnvEntryValStringResource") public void setUnInjectedString(String val) { this.wontBeInjectedString = val; } public String getUnInjectedString() { return this.wontBeInjectedString; } public boolean isUnInjectedIntEnvEntryPresentInEnc() { Context ctx = null; try { ctx = new InitialContext(); ctx.lookup("java:comp/env/missingEnvEntryValIntResource"); return true; } catch (NameNotFoundException nnfe) { return false; } catch (NamingException ne) { throw new RuntimeException(ne); } } public boolean isUnInjectedStringEnvEntryPresentInEnc() { Context ctx = null; try { ctx = new InitialContext(); ctx.lookup("java:comp/env/missingEnvEntryValStringResource"); return true; } catch (NameNotFoundException nnfe) { return false; } catch (NamingException ne) { throw new RuntimeException(ne); } } public boolean isTimerServiceInjected() { return this.timerService != null; } public boolean validURLInjections() { return this.url1 != null && this.url2 != null && url3 != null && url4 != null; } public boolean validContextInjections() { return this.context1 != null && this.context2 == null; } }
4,818
29.308176
99
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/basic/ResourceInjectionTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.basic; import org.jboss.logging.Logger; import javax.naming.Context; 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.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests that the Resource injection as specified by Jakarta EE spec works as expected * <p/> * User: Jaikiran Pai */ @RunWith(Arquillian.class) public class ResourceInjectionTestCase { private static final Logger logger = Logger.getLogger(ResourceInjectionTestCase.class.getName()); private SimpleSLSB slsb; @Before public void beforeTest() throws Exception { Context ctx = new InitialContext(); this.slsb = (SimpleSLSB) ctx.lookup("java:module/" + SimpleSLSB.class.getSimpleName() + "!" + SimpleSLSB.class.getName()); } @Deployment public static WebArchive createWebDeployment() { final WebArchive war = ShrinkWrap.create(WebArchive.class, "resource-injection-test.war"); war.addPackage(SimpleSLSB.class.getPackage()); war.addAsWebInfResource(ResourceInjectionTestCase.class.getPackage(), "web.xml", "web.xml"); return war; } /** * Tests simple resource injection in EJB */ @Test public void testResourceInjectionInEJB() { final String user = "Charlie Sheen"; final String greeting = this.slsb.sayHello(user); Assert.assertEquals("Unepxected greeting received from bean", CommonBean.HELLO_GREETING_PREFIX + user, greeting); Class<?> invokedBusinessInterface = this.slsb.getInvokedBusinessInterface(); Assert.assertEquals("Unexpected invoked business interface returned by bean", SimpleSLSB.class, invokedBusinessInterface); } /** * Test env-entry injection in EJB */ @Test public void testEnvEntryInjection() { final String envEntryString = this.slsb.getInjectedString(); Assert.assertEquals("Unexpected value injected for env-entry of type String", "It's Friday!!!", envEntryString); } /** * Test scenario: * <p/> * A @Resource backed by an env-entry should be injected only if the corresponding env-entry has an env-entry-value specified. * If the env-entry-value is missing, then the injection of @Resource should not happen. */ @Test public void testOptionalEnvEntryInjection() { int defaultInt = this.slsb.getUnInjectedInt(); Assert.assertEquals("env-entry of type int without a value was *not* expected to be injected", defaultInt, SimpleSLSB.DEFAULT_UNINJECTED_INT_VAL); String defaultString = this.slsb.getUnInjectedString(); Assert.assertEquals("env-entry of type String without a value was *not* expected to be injected", defaultString, SimpleSLSB.DEFAULT_UNINJECTED_STRING_VAL); } /** * Test scenario: * <p/> * A @Resource backed by an env-entry should be made available in ENC only if the corresponding env-entry has an * env-entry-value specified. If the env-entry-value is missing, then there should be no corresponding ENC entry for that * env-entry */ @Test public void testOptionalEnvEntryEncAvailability() { boolean intEnvEntryAvailableInEnc = this.slsb.isUnInjectedIntEnvEntryPresentInEnc(); Assert.assertFalse("env-entry of type int, without an env-entry-value was *not* expected to be available in ENC", intEnvEntryAvailableInEnc); boolean stringEnvEntryAvailableInEnc = this.slsb.isUnInjectedStringEnvEntryPresentInEnc(); Assert.assertFalse("env-entry of type String, without an env-entry-value was *not* expected to be available in ENC", stringEnvEntryAvailableInEnc); } /** * Tests that an EJB with a @Resource of type {@link jakarta.ejb.TimerService} deploys fine and the * {@link jakarta.ejb.TimerService} is injected in the bean */ @Test public void testTimerServiceInjection() { Assert.assertTrue("Timerservice was not injected in bean", this.slsb.isTimerServiceInjected()); } /** * Test if an ORB can be properly located (EJB3 16.13). Part migration of tests from EJB testsuite [JIRA JBQA-5483]. * Ondrej Chaloupka * * @throws Exception */ @Test public void testOrbEnvironment() throws Exception { Context ctx = new InitialContext(); CheckORBRemote bean = (CheckORBRemote) ctx.lookup("java:module/" + CheckORBBean.class.getSimpleName() + "!" + CheckORBRemote.class.getName()); bean.checkForORBInEnvironment(); } /** * Test if an ORB can be properly located (EJB3 16.13). Part migration of tests from EJB testsuite [JIRA JBQA-5483]. * * @throws Exception */ @Test public void testInjection() throws Exception { Context ctx = new InitialContext(); CheckORBRemote bean = (CheckORBRemote) ctx.lookup("java:module/" + CheckORBBean.class.getSimpleName() + "!" + CheckORBRemote.class.getName()); bean.checkForInjectedORB(); } /** * Tests that a EJB with a URL Connection Factory @Resource deploys fine and is injected as expected */ @Test public void testURLInjection() { Assert.assertTrue("URL injection not valid", this.slsb.validURLInjections()); } /** * Tests that a EJB with several Context (and sub classes) @Resource deploys fine and is injected as expected */ @Test public void testContextInjection() { Assert.assertTrue("Context injection not valid", this.slsb.validContextInjections()); } }
6,945
38.242938
130
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/basic/Parent.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.basic; import jakarta.annotation.Resource; import jakarta.ejb.EJB; import jakarta.ejb.EJBContext; /** * User: jpai */ public class Parent { @Resource protected EJBContext ejbContext; protected CommonBean commonBean; @EJB protected void setCommonBean(CommonBean commonBean) { this.commonBean = commonBean; } }
1,432
31.568182
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/basic/CheckORBBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.basic; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import javax.naming.InitialContext; import javax.naming.NamingException; import org.omg.CORBA.ORB; import org.omg.CORBA.ORBPackage.InvalidName; import org.omg.PortableServer.POA; /** * This beans checks both methods of getting an ORB. * * @author carlo */ @Stateless public class CheckORBBean implements CheckORBRemote { @Resource private ORB orb; public void checkForInjectedORB() { if (this.orb == null) throw new IllegalStateException("ORB was not injected"); checkORB(orb); } public void checkForORBInEnvironment() { try { InitialContext ctx = new InitialContext(); ORB orb = (ORB) ctx.lookup("java:comp/ORB"); checkORB(orb); } catch (NamingException e) { throw new IllegalStateException("Can't lookup java:comp/ORB", e); } } private void checkORB(ORB orb) { try { POA poa = (POA) orb.resolve_initial_references("RootPOA"); if (poa == null) throw new IllegalStateException("RootPOA is null"); } catch (InvalidName e) { throw new IllegalStateException("Can't resolve RootPOA", e); } } }
2,365
32.8
77
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/jndi/bad/Constants.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.jndi.bad; /** * @author baranowb */ public interface Constants { String TEST_MODULE_NAME = "BadDonkeyModule"; String TEST_MODULE_NAME_FULL = "test." + TEST_MODULE_NAME; String TESTED_DU_NAME = "BadTest"; String TESTED_ARCHIVE_NAME = TESTED_DU_NAME + ".jar"; String JNDI_NAME_GLOBAL = "java:global/" + TESTED_DU_NAME + "/ResourceEJBImpl"; String JNDI_NAME_BAD = "java:jboss:/" + TESTED_DU_NAME + "/ResourceEJBImpl"; String ERROR_MESSAGE = "WFLYNAM0033"; }
1,575
36.52381
83
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/jndi/bad/SampleEJB.java
package org.jboss.as.test.integration.ee.injection.resource.jndi.bad; public interface SampleEJB { String sayHello() throws Exception; }
142
22.833333
69
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/jndi/bad/SampleEJBImpl.java
package org.jboss.as.test.integration.ee.injection.resource.jndi.bad; import jakarta.annotation.Resource; import jakarta.annotation.Resources; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; @Resources({@Resource( name = Constants.JNDI_NAME_BAD, type = org.jboss.as.test.integration.ee.injection.resource.jndi.bad.ResourceEJB.class, lookup = Constants.JNDI_NAME_GLOBAL)}) @Stateless @Remote(SampleEJB.class) public class SampleEJBImpl implements SampleEJB { @Resource(lookup = Constants.JNDI_NAME_GLOBAL) ResourceEJB resEJB; @Override public String sayHello() throws Exception { return null; } }
653
27.434783
133
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/jndi/bad/ResourceEJBImpl.java
package org.jboss.as.test.integration.ee.injection.resource.jndi.bad; import jakarta.ejb.Stateless; @Stateless public class ResourceEJBImpl implements ResourceEJB { @Override public String echo(String param) { return param + "......" + param + "..." + param; } }
288
18.266667
69
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/jndi/bad/ResourceEJB.java
package org.jboss.as.test.integration.ee.injection.resource.jndi.bad; public interface ResourceEJB { String echo(String param); }
136
18.571429
69
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/jndi/bad/BadResourceTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, 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.jndi.bad; import org.hamcrest.MatcherAssert; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.controller.client.OperationBuilder; import org.jboss.as.controller.client.helpers.Operations; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.operations.common.Util; import org.jboss.as.test.shared.TestSuiteEnvironment; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import static org.hamcrest.CoreMatchers.containsString; /** * @author baranowb */ @RunWith(Arquillian.class) @RunAsClient public class BadResourceTestCase { private static ModelControllerClient controllerClient = TestSuiteEnvironment.getModelControllerClient(); public static Archive<?> getTestedArchive() throws Exception { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, Constants.TESTED_ARCHIVE_NAME); jar.addClasses(SampleEJBImpl.class, ResourceEJBImpl.class); jar.addClasses(Constants.class, SampleEJB.class, ResourceEJB.class); return jar; } @Before public void createDeployment() throws Exception { final ModelNode addDeploymentOp = new ModelNode(); addDeploymentOp.get(ModelDescriptionConstants.ADDRESS).add(ModelDescriptionConstants.DEPLOYMENT, Constants.TESTED_DU_NAME); addDeploymentOp.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); addDeploymentOp.get(ModelDescriptionConstants.CONTENT).get(0).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0); final OperationBuilder ob = new OperationBuilder(addDeploymentOp, true); ob.addInputStream(getTestedArchive().as(ZipExporter.class).exportAsInputStream()); final ModelNode result = controllerClient.execute(ob.build()); // just to blow up Assert.assertTrue("Failed to deploy: " + result, Operations.isSuccessfulOutcome(result)); } @After public void removeDeployment() throws Exception { final ModelNode remove = Util.getEmptyOperation(ModelDescriptionConstants.REMOVE, new ModelNode().add(ModelDescriptionConstants.DEPLOYMENT, Constants.TESTED_DU_NAME)); final OperationBuilder ob = new OperationBuilder(remove, true); final ModelNode result = controllerClient.execute(ob.build()); // just to blow up Assert.assertTrue("Failed to deploy: " + result, Operations.isSuccessfulOutcome(result)); } @Test public void testBadDU() throws Exception { final ModelNode deployOp = new ModelNode(); deployOp.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.DEPLOY); deployOp.get(ModelDescriptionConstants.ADDRESS).add(ModelDescriptionConstants.DEPLOYMENT, Constants.TESTED_DU_NAME); deployOp.get(ModelDescriptionConstants.ENABLED).set(true); final OperationBuilder ob = new OperationBuilder(deployOp, true); final ModelNode result = controllerClient.execute(ob.build()); // just to blow up Assert.assertTrue("Failed to deploy: " + result, !Operations.isSuccessfulOutcome(result)); // asserts String failureDescription = result.get(ModelDescriptionConstants.FAILURE_DESCRIPTION).toString(); MatcherAssert.assertThat(String.format("Results doesn't contain correct error code (%s): %s", Constants.ERROR_MESSAGE, result.toString()), failureDescription, containsString(Constants.ERROR_MESSAGE)); MatcherAssert.assertThat(String.format("Results doesn't contain correct JNDI in error message (%s): %s", Constants.JNDI_NAME_BAD, result.toString()), failureDescription, containsString(Constants.JNDI_NAME_BAD)); } }
5,214
45.150442
157
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/resourceref/StatelessBeanRemote.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.resourceref; /** * @author Jaikiran Pai */ public interface StatelessBeanRemote { boolean isEJBContextAvailableThroughResourceEnvRef(); boolean isUserTransactionAvailableThroughResourceEnvRef(); boolean isOtherResourceAvailableThroughResourceEnvRef(); }
1,356
36.694444
72
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/resourceref/ResUrlCheckerBean.java
/* * JBoss, Home of Professional Open Source * Copyright 2007, Red Hat Middleware LLC, 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.as.test.integration.ee.injection.resource.resourceref; import java.net.URL; import jakarta.annotation.Resource; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; /** * Let's see what we can do with resources of the URL breed. * * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @Stateless @Remote(ResUrlChecker.class) public class ResUrlCheckerBean implements ResUrlChecker { // coming in via res-url @Resource(name = "url2") private URL url2; public URL getURL1() { return null; } public URL getURL2() { return url2; } public URL getURL3() { return null; } }
1,702
30.537037
83
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/resourceref/StatelessBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.resourceref; import jakarta.annotation.Resource; import jakarta.ejb.EJBContext; import jakarta.ejb.SessionContext; import jakarta.jms.Queue; import jakarta.transaction.UserTransaction; /** * @author Jaikiran Pai */ public class StatelessBean implements StatelessBeanRemote { @Resource private SessionContext sessionContext; public boolean isEJBContextAvailableThroughResourceEnvRef() { // resource-env-ref which setups up the EJBContext to be // available (also) under java:comp/env/EJBContext EJBContext ejbContext = (EJBContext) this.sessionContext.lookup("MyEJBContext"); // successful if found. An exception (eg: NameNotFound) will be // thrown otherwise return ejbContext != null; } public boolean isUserTransactionAvailableThroughResourceEnvRef() { // resource-env-ref which setups up the UserTransaction to be // available (also) under java:comp/env/UserTransaction UserTransaction userTransaction = (UserTransaction) this.sessionContext.lookup("MyUserTransaction"); // successful if found. An exception (eg: NameNotFound) will be // thrown otherwise return userTransaction != null; } public boolean isOtherResourceAvailableThroughResourceEnvRef() { // resource-env-ref which setups up the Queue to be // available under java:comp/env/MyQueue Queue queue = (Queue) this.sessionContext.lookup("MyQueue"); // successful if found. An exception (eg: NameNotFound) will be // thrown otherwise return queue != null; } }
2,690
39.164179
108
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/resourceref/DatasourceManagedBean.java
/* * 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.resourceref; import jakarta.annotation.ManagedBean; import javax.sql.DataSource; /** * @author Stuart Douglas */ @ManagedBean("datasourceManagedBean") public class DatasourceManagedBean { private DataSource ds; public DataSource getDataSource() { return ds; } }
1,376
33.425
72
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/resourceref/ResourceRefTestCase.java
/* * 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.resourceref; import java.net.URL; import javax.naming.InitialContext; import javax.naming.NameNotFoundException; import javax.naming.NamingException; import javax.sql.DataSource; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.jms.auxiliary.CreateQueueSetupTask; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests that @Resource bindings on interceptors that are applied to multiple * components without their own naming context work properly, and do not try * and create two duplicate bindings in the same namespace. * * Migration test from EJB Testsuite (ejbthree-1823, ejbthree-1858) to AS7 [JIRA JBQA-5483]. * - ResourceHandler when resource-ref type is not specified. * - EJBContext is configured through ejb-jar.xml as a resource-env-ref. * * @author Stuart Douglas, Jaikiran Pai, Ondrej Chaloupka */ @RunWith(Arquillian.class) @ServerSetup(CreateQueueSetupTask.class) public class ResourceRefTestCase { @Deployment public static Archive<?> deployment() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "resourcerref.ear"); WebArchive war = ShrinkWrap.create(WebArchive.class, "managed-bean.war"); war.addAsWebInfResource(ResourceRefTestCase.class.getPackage(),"web.xml", "web.xml"); war.addAsWebInfResource(ResourceRefTestCase.class.getPackage(),"jboss-web.xml", "jboss-web.xml"); war.addClasses(ResourceRefTestCase.class, DatasourceManagedBean.class, CreateQueueSetupTask.class); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "resource-ref-test.jar"); jar.addClasses(ResourceRefBean.class, ResourceRefRemote.class, StatelessBean.class, StatelessBeanRemote.class, ResUrlChecker.class, ResUrlCheckerBean.class); jar.addAsManifestResource(ResourceRefTestCase.class.getPackage(),"jboss-ejb3.xml", "jboss-ejb3.xml"); jar.addAsManifestResource(ResourceRefTestCase.class.getPackage(),"ejb-jar.xml", "ejb-jar.xml"); ear.addAsModule(jar); ear.addAsModule(war); return ear; } @Test public void testCorrectBinding() throws NamingException { InitialContext context = new InitialContext(); Object result = context.lookup("java:module/env/ds"); Assert.assertTrue(result instanceof DataSource); } @Test(expected = NameNotFoundException.class) public void testIgnoredDependency() throws NamingException { InitialContext context = new InitialContext(); context.lookup("java:module/env/ds-ignored"); } @Test public void testInjection() throws NamingException { InitialContext context = new InitialContext(); DatasourceManagedBean bean = (DatasourceManagedBean)context.lookup("java:module/datasourceManagedBean"); Assert.assertNotNull(bean.getDataSource()); } /** * Test that a resource-ref entry with a res-type does not throw an NPE. Furthermore, the test additional provides a * mappedName for the resource-ref in which case the resource ref will be created in the ENC. * * @throws Exception */ @Test public void testResourceRefEntriesWithoutResType() throws Exception { // lookup the bean InitialContext context = new InitialContext(); ResourceRefRemote bean = (ResourceRefRemote) context.lookup("java:app/resource-ref-test/" + ResourceRefBean.class.getSimpleName() + "!" + ResourceRefRemote.class.getName()); Assert.assertNotNull("Bean returned from JNDI is null", bean); // test datasource resource-ref which does not have a res-type specified boolean result = bean.isDataSourceAvailableInEnc(); Assert.assertTrue("Datasource not bound in ENC of the bean", result); } /** * Test that the resources configured through resource-env-ref are bound * correctly * * @throws Exception */ @Test public void testResourceEnvRefWithoutInjectionTarget() throws Exception { InitialContext context = new InitialContext(); StatelessBeanRemote bean = (StatelessBeanRemote) context.lookup("java:app/resource-ref-test/"+StatelessBean.class.getSimpleName() + "!" + StatelessBeanRemote.class.getName()); // check EJBContext through resource-env-ref was handled Assert.assertTrue("resource-env-ref did not handle EJBContext", bean.isEJBContextAvailableThroughResourceEnvRef()); // check UserTransaction through resource-env-ref was handled Assert.assertTrue("resource-env-ref did not handle UserTransaction", bean .isUserTransactionAvailableThroughResourceEnvRef()); // check some other resource through resource-env-ref was handled Assert.assertTrue("resource-env-ref did not setup the other resource in java:comp/env of the bean", bean .isOtherResourceAvailableThroughResourceEnvRef()); } @Test public void test2() throws Exception { ResUrlChecker bean = (ResUrlChecker) new InitialContext().lookup("java:app/resource-ref-test/ResUrlCheckerBean"); // defined in jboss.xml URL expected = new URL("http://somewhere/url2"); URL actual = bean.getURL2(); Assert.assertEquals(expected, actual); } }
6,707
44.020134
182
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/resourceref/ResUrlChecker.java
/* * JBoss, Home of Professional Open Source * Copyright 2007, Red Hat Middleware LLC, 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.as.test.integration.ee.injection.resource.resourceref; import java.net.URL; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ public interface ResUrlChecker { URL getURL1(); URL getURL2(); URL getURL3(); }
1,293
34.944444
83
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/resourceref/ResourceRefRemote.java
/* * 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.resourceref; import jakarta.ejb.Remote; import javax.naming.NamingException; /** * ResourceRefRemote * * @author Jaikiran Pai */ @Remote public interface ResourceRefRemote { boolean isDataSourceAvailableInEnc() throws NamingException; }
1,335
35.108108
72
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/resourceref/ResourceRefBean.java
/* * 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.resourceref; import jakarta.ejb.Stateless; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; import org.jboss.logging.Logger; /** * ResourceRefBean * <p> * This bean will be used to test the EJBTHREE-1823 issue. * <p> * Brief description of the issue: If a resource-ref entry is available in jboss.xml, but there is no corresponding resource-ref * entry neither in ejb-jar.xml nor a @Resource in the bean, then because of the non-availability of the "res-type" information, * a NullPointerException gets thrown when the {@link ResourceHandler} tries to process the entries to be made in ENC. * * @author Jaikiran Pai */ @Stateless public class ResourceRefBean implements ResourceRefRemote { private static Logger logger = Logger.getLogger(ResourceRefBean.class); /** * Looks up a datasource within the ENC of this bean. The datasource is expected to be configured through the deployment * descriptors and should be available at java:comp/env/EJBTHREE-1823_DS * <p> * The "res-type" of this datasource resource-ref will not be provided through ejb-jar.xml nor through a @Resource * annotation. */ public boolean isDataSourceAvailableInEnc() throws NamingException { boolean ret = false; Context ctx = new InitialContext(); String encJndiName = "java:comp/env/EJBTHREE-1823_DS"; DataSource ds = (DataSource) ctx.lookup(encJndiName); ret = ds != null; logger.trace("Datasource was found: " + ret + ", on: " + encJndiName); return ret; } }
2,722
40.257576
128
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/TestEnvEntry.java
/* * JBoss, Home of Professional Open Source. * Copyright 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 javax.naming.NamingException; /** * @author <a href="mailto:[email protected]">William DeCoste</a> * @version <tt>$Revision: 80158 $</tt> */ public interface TestEnvEntry { int checkJNDI() throws NamingException; int getMaxExceptions(); int getMinExceptions(); int getNumExceptions(); }
1,414
33.512195
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/TestEnvEntryBeanBase.java
/* * JBoss, Home of Professional Open Source. * Copyright 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 jakarta.ejb.SessionContext; import javax.naming.InitialContext; import javax.naming.NamingException; /** * Common base class for "enventry" test EJBs * * @author <a href="mailto:[email protected]">ALR</a> */ public abstract class TestEnvEntryBeanBase implements TestEnvEntry { public int checkJNDI() throws NamingException { InitialContext ctx = new InitialContext(); int rtn = (Integer) ctx.lookup("java:comp/env/maxExceptions"); if (rtn != (Integer) getSessionContext().lookup("maxExceptions")) throw new RuntimeException("Failed to match env lookup"); return rtn; } public abstract int getMaxExceptions(); public abstract int getNumExceptions(); public abstract int getMinExceptions(); public abstract SessionContext getSessionContext(); }
1,931
36.153846
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/EnvEntryManagedBean.java
/* * 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.as.test.integration.ee.injection.resource.enventry; import jakarta.annotation.ManagedBean; import jakarta.annotation.Resource; /** * @author Stuart Douglas */ @ManagedBean public class EnvEntryManagedBean { @Resource private String nonExistentString = "hi"; @Resource private String existingString = "hi"; private byte byteField; public String getNonExistentString() { return nonExistentString; } public String getExistingString() { return existingString; } public byte getByteField() { return byteField; } }
1,621
29.603774
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/TestEnvEntryBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 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 jakarta.annotation.Resource; import jakarta.ejb.Remote; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; /** * @author <a href="mailto:[email protected]">William DeCoste</a> */ @Stateless(name = "TestEnvEntry") @Remote(TestEnvEntry.class) public class TestEnvEntryBean extends TestEnvEntryBeanBase implements TestEnvEntry { @Resource(name = "maxExceptions") private int maxExceptions = 4; @Resource private int numExceptions = 3; @Resource SessionContext sessionCtx; private int minExceptions = 1; public int getMaxExceptions() { return this.maxExceptions; } public int getNumExceptions() { return this.numExceptions; } public int getMinExceptions() { return this.minExceptions; } public SessionContext getSessionContext() { return this.sessionCtx; } }
1,975
29.875
84
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/DuplicateGlobalBindingInjectionTestCase.java
/* * 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 org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.junit.Arquillian; 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 javax.naming.InitialContext; /** * A test that two deployments can declare the same global en-entry * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class DuplicateGlobalBindingInjectionTestCase { @Deployment(name = "dep1", managed = true, testable = true) public static WebArchive deployment1() { WebArchive war = ShrinkWrap.create(WebArchive.class, "dep1.war"); war.addClasses( EnvEntryInjectionServlet.class, EnvEntryManagedBean.class, DuplicateGlobalBindingInjectionTestCase.class); war.addAsWebInfResource(getWebXml(), "web.xml"); return war; } @Deployment(name = "dep2", managed = true, testable = true) public static WebArchive deployment2() { WebArchive war = ShrinkWrap.create(WebArchive.class, "dep2.war"); war.addPackage(HttpRequest.class.getPackage()); // war.addPackage(DuplicateGlobalBindingInjectionTestCase.class.getPackage()); war.addClasses( EnvEntryInjectionServlet.class, EnvEntryManagedBean.class, DuplicateGlobalBindingInjectionTestCase.class); war.addAsWebInfResource(getWebXml(), "web.xml"); return war; } @Test @OperateOnDeployment("dep1") public void testGlobalBound1() throws Exception { final String globalValue = (String) new InitialContext().lookup("java:global/foo"); Assert.assertEquals("injection!", globalValue); } @Test @OperateOnDeployment("dep2") public void testGlobalBound2() throws Exception { final String globalValue = (String) new InitialContext().lookup("java:global/foo"); Assert.assertEquals("injection!", globalValue); } 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>java:global/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" + "</web-app>"); } }
4,872
42.900901
137
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/EnvEntryInjectionTestCase.java
/* * 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 javax.naming.InitialContext; import javax.naming.NamingException; 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.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * A test for injection via env-entry in web.xml * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class EnvEntryInjectionTestCase { @Deployment public static WebArchive deployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, "war-example.war"); war.addClasses( EnvEntryInjectionServlet.class, EnvEntryManagedBean.class, EnvEntryInjectionTestCase.class ); war.addAsWebInfResource(EnvEntryInjectionTestCase.class.getPackage(), "EnvEntryInjectionTestCase-web.xml", "web.xml"); return war; } @Test public void testEnvEntryInjectionIntoManagedBean() throws NamingException { final InitialContext initialContext = new InitialContext(); final EnvEntryManagedBean bean = (EnvEntryManagedBean) initialContext.lookup("java:module/" + EnvEntryManagedBean.class.getName()); Assert.assertEquals("bye", bean.getExistingString()); } @Test public void testEnvEntryNonExistentManagedBean() throws NamingException { final InitialContext initialContext = new InitialContext(); final EnvEntryManagedBean bean = (EnvEntryManagedBean) initialContext.lookup("java:module/" + EnvEntryManagedBean.class.getName()); Assert.assertEquals("hi", bean.getNonExistentString()); } @Test public void testNonExistentResourceCannotBeLookedUp() throws NamingException { try { final InitialContext initialContext = new InitialContext(); initialContext.lookup("java:module/env/" + EnvEntryManagedBean.class.getName() + "/nonExistentString"); Assert.fail(); } catch (NamingException expected) { } } @Test public void testBoxedUnboxedMismatch() throws NamingException { final InitialContext initialContext = new InitialContext(); final EnvEntryManagedBean bean = (EnvEntryManagedBean) initialContext.lookup("java:module/" + EnvEntryManagedBean.class.getName()); Assert.assertEquals(10, bean.getByteField()); } }
3,543
39.735632
139
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/TestEnvEntryMDBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 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 jakarta.annotation.Resource; import jakarta.ejb.ActivationConfigProperty; import jakarta.ejb.MessageDriven; import jakarta.jms.Connection; import jakarta.jms.Destination; import jakarta.jms.JMSException; import jakarta.jms.MapMessage; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.jms.MessageProducer; import jakarta.jms.QueueConnectionFactory; import jakarta.jms.Session; import org.jboss.logging.Logger; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @MessageDriven(name = "TestEnvEntryMD", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/queue/testEnvEntry") }) public class TestEnvEntryMDBean implements MessageListener { private static final Logger log = Logger.getLogger(TestEnvEntryMDBean.class); @Resource(mappedName = "java:/ConnectionFactory") private QueueConnectionFactory connectionFactory; @Resource(name = "maxExceptions") private int maxExceptions = 4; @Resource private int numExceptions = 3; private int minExceptions = 1; public void onMessage(Message msg) { log.trace("OnMessage working..."); try { Destination destination = msg.getJMSReplyTo(); Connection conn = connectionFactory.createConnection(); try { Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer replyProducer = session.createProducer(destination); MapMessage replyMsg = session.createMapMessage(); replyMsg.setJMSCorrelationID(msg.getJMSMessageID()); replyMsg.setInt("maxExceptions", maxExceptions); replyMsg.setInt("numExceptions", numExceptions); replyMsg.setInt("minExceptions", minExceptions); // System.err.println("reply to: " + destination); // System.err.println("maxExceptions: " + maxExceptions); // System.err.println("numExceptions: " + numExceptions); // System.err.println("minExceptions: " + minExceptions); replyProducer.send(replyMsg); } finally { conn.close(); } } catch (JMSException e) { throw new RuntimeException(e); } } }
3,557
38.977528
115
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/ExtendedTestEnvEntryBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 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 jakarta.annotation.Resource; import jakarta.ejb.Remote; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; /** * @author <a href="mailto:[email protected]">William DeCoste</a> */ @Stateless(name = "ExtendedTestEnvEntry") @Remote(TestEnvEntry.class) public class ExtendedTestEnvEntryBean extends TestEnvEntryBeanBase { @Resource(name = "maxExceptions") private int maxExceptions = 3; @Resource private int numExceptions = 2; @Resource SessionContext sessionCtx; private int minExceptions = 0; public int getMaxExceptions() { return maxExceptions; } public int getNumExceptions() { return numExceptions; } public int getMinExceptions() { return minExceptions; } public SessionContext getSessionContext() { return this.sessionCtx; } }
1,952
29.515625
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/OptionalEnvEntry.java
/* * JBoss, Home of Professional Open Source. * Copyright 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; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ public interface OptionalEnvEntry { void checkLookup(); Double getEntry(); }
1,258
37.151515
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/EnvEntryTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 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 jakarta.jms.Connection; import jakarta.jms.ConnectionFactory; import jakarta.jms.Destination; import jakarta.jms.MapMessage; import jakarta.jms.MessageConsumer; import jakarta.jms.MessageProducer; import jakarta.jms.Queue; import jakarta.jms.Session; import jakarta.jms.TextMessage; import javax.naming.InitialContext; 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.api.ServerSetup; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.common.jms.JMSOperations; import org.jboss.as.test.integration.common.jms.JMSOperationsProvider; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Migration test from EJB Testsuite (ejbthree-985 + enventry) to AS7 [JIRA JBQA-5483]. * Test to see if optional env-entry-value works (16.4.1.3). * Testing of behaviour of environment variables in ejb-jar.xml. * * @author Carlo de Wolf, William DeCoste, Ondrej Chaloupka */ @RunWith(Arquillian.class) @ServerSetup({EnvEntryTestCase.JmsQueueSetup.class}) public class EnvEntryTestCase { @ArquillianResource InitialContext ctx; static class JmsQueueSetup implements ServerSetupTask { private JMSOperations jmsAdminOperations; @Override public void setup(ManagementClient managementClient, String containerId) throws Exception { jmsAdminOperations = JMSOperationsProvider.getInstance(managementClient); jmsAdminOperations.createJmsQueue("queue/testEnvEntry", "java:jboss/queue/testEnvEntry"); } @Override public void tearDown(ManagementClient managementClient, String containerId) throws Exception { if (jmsAdminOperations != null) { jmsAdminOperations.removeJmsQueue("queue/testEnvEntry"); jmsAdminOperations.close(); } } } @Deployment public static Archive<?> deploymentOptional() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "env-entry-test.jar") .addClasses( ExtendedTestEnvEntryBean.class, OptionalEnvEntry.class, OptionalEnvEntryBean.class, TestEnvEntry.class, TestEnvEntryBean.class, TestEnvEntryBeanBase.class, TestEnvEntryMDBean.class, EnvEntryTestCase.class, JmsQueueSetup.class) .addPackage(JMSOperations.class.getPackage()); jar.addAsManifestResource(EnvEntryTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml"); return jar; } // Deployment optional private OptionalEnvEntry lookupEnvEntryBean() throws Exception { return (OptionalEnvEntry) ctx.lookup("java:module/OptionalEnvEntryBean"); } @Test public void test() throws Exception { OptionalEnvEntry bean = lookupEnvEntryBean(); Double actual = bean.getEntry(); // 1.1 is defined in OptionalEnvEntryBean Assert.assertEquals(new Double(1.1), actual); } @Test public void testLookup() throws Exception { OptionalEnvEntry bean = lookupEnvEntryBean(); bean.checkLookup(); } // Deployment enventry @Test public void testEnvEntries() throws Exception { TestEnvEntry test = (TestEnvEntry) ctx.lookup("java:module/TestEnvEntry!" + TestEnvEntry.class.getName()); Assert.assertNotNull(test); int maxExceptions = test.getMaxExceptions(); Assert.assertEquals(15, maxExceptions); int minExceptions = test.getMinExceptions(); Assert.assertEquals(5, minExceptions); int numExceptions = test.getNumExceptions(); Assert.assertEquals(10, numExceptions); TestEnvEntry etest = (TestEnvEntry) ctx.lookup("java:module/ExtendedTestEnvEntry!" + TestEnvEntry.class.getName()); Assert.assertNotNull(etest); maxExceptions = etest.getMaxExceptions(); Assert.assertEquals(14, maxExceptions); minExceptions = etest.getMinExceptions(); Assert.assertEquals(6, minExceptions); numExceptions = etest.getNumExceptions(); Assert.assertEquals(11, numExceptions); } @Test public void testEnvEntriesMDB() throws Exception { ConnectionFactory factory = (ConnectionFactory) ctx.lookup("ConnectionFactory"); Connection con = factory.createConnection(); try { Destination dest = (Destination) ctx.lookup("java:jboss/queue/testEnvEntry"); Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(dest); Queue replyQueue = session.createTemporaryQueue(); MessageConsumer consumer = session.createConsumer(replyQueue); con.start(); TextMessage msg = session.createTextMessage(); msg.setJMSReplyTo(replyQueue); msg.setText("This is message one"); producer.send(msg); MapMessage replyMsg = (MapMessage) consumer.receive(5000); Assert.assertNotNull(replyMsg); Assert.assertEquals(16, replyMsg.getInt("maxExceptions")); Assert.assertEquals(12, replyMsg.getInt("numExceptions")); Assert.assertEquals(7, replyMsg.getInt("minExceptions")); } finally { con.close(); } } @Test public void testJNDI() throws Exception { TestEnvEntry test = (TestEnvEntry) ctx.lookup("java:module/TestEnvEntry!" + TestEnvEntry.class.getName()); Assert.assertNotNull(test); Assert.assertEquals(15, test.checkJNDI()); } }
7,176
37.379679
123
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/EnvEntryInjectionServlet.java
/* * 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.as.test.integration.ee.injection.resource.enventry; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; /** * @author Stuart Douglas */ @WebServlet(name="envEntry",urlPatterns = {"/envEntry"}) public class EnvEntryInjectionServlet extends HttpServlet { private String field; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().append(field).flush(); resp.getWriter().close(); } }
1,739
36.826087
113
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/OptionalEnvEntryBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 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 jakarta.ejb.Remote; import jakarta.ejb.Stateless; import javax.naming.InitialContext; import javax.naming.NameNotFoundException; import javax.naming.NamingException; /** * Return the value of a buried env entry. * * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @Stateless @Remote(OptionalEnvEntry.class) public class OptionalEnvEntryBean implements OptionalEnvEntry { // @Resource(name="entry") private Double entry = 1.1; public void checkLookup() { try { InitialContext ctx = new InitialContext(); ctx.lookup("java:comp/env/entry"); throw new RuntimeException("Should have thrown a NameNotFoundException"); } catch (NameNotFoundException e) { // okay } catch (NamingException e) { throw new RuntimeException(e); } } public Double getEntry() { return entry; } }
2,020
33.844828
85
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/EnvEntryInjectionServletTestCase.java
/* * 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); } }
2,672
38.895522
133
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/shared/SharedBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.shared; import jakarta.ejb.Stateless; import jakarta.annotation.Resource; /** * @author <a href="mailto:[email protected]">Bill Burke</a> */ @Stateless public class SharedBean implements Shared { @Resource(name = "strWho") String strWho; public String doit() { return strWho; } }
1,399
34
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/shared/BEJBBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.shared; import jakarta.ejb.Stateless; import jakarta.ejb.EJB; /** * @author <a href="mailto:[email protected]">Bill Burke</a> */ @Stateless public class BEJBBean implements BEJB { @EJB Shared shared; public String doit() { return shared.doit(); } }
1,368
33.225
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/shared/Shared.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.shared; import jakarta.ejb.Local; /** * @author <a href="mailto:[email protected]">Bill Burke</a> */ @Local public interface Shared { String doit(); }
1,249
35.764706
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/shared/AEJBBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.shared; import jakarta.ejb.Stateless; import jakarta.ejb.EJB; /** * @author <a href="mailto:[email protected]">Bill Burke</a> */ @Stateless public class AEJBBean implements AEJB { @EJB Shared shared; public String doit() { return shared.doit(); } }
1,368
33.225
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/shared/AEJB.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.shared; import jakarta.ejb.Remote; /** * @author <a href="mailto:[email protected]">Bill Burke</a> */ @Remote public interface AEJB { String doit(); }
1,249
35.764706
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/shared/BEJB.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.shared; import jakarta.ejb.Remote; /** * @author <a href="mailto:[email protected]">Bill Burke</a> */ @Remote public interface BEJB { String doit(); }
1,249
35.764706
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/resource/enventry/shared/SharedBeanInEarsUnitTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.shared; import java.util.Hashtable; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; 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.logging.Logger; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Migrated from EJB3 testsuite [JBQA-5483] from ejbthree454. * Test EJBs of the same name and code that are deployed in different ears. * * @author <a href="mailto:[email protected]">Bill Burke</a> */ @RunWith(Arquillian.class) @RunAsClient public class SharedBeanInEarsUnitTestCase { private static final Logger log = Logger.getLogger(SharedBeanInEarsUnitTestCase.class); private static String APP_A = "ear-a"; private static String MOD_A_SHARED = "jar-a-shared"; private static String MOD_A = "jar-a"; private static String APP_B = "ear-b"; private static String MOD_B_SHARED = "jar-b-shared"; private static String MOD_B = "jar-b"; @Deployment(name = "a", testable = false, managed = true) public static Archive<?> deployA() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_A + ".ear"); JavaArchive jarA = ShrinkWrap.create(JavaArchive.class, MOD_A + ".jar"); jarA.addClasses(AEJB.class, AEJBBean.class); JavaArchive jarAshared = ShrinkWrap.create(JavaArchive.class, MOD_A_SHARED + ".jar"); jarAshared.addClasses(Shared.class, SharedBean.class); jarAshared.addAsManifestResource(SharedBeanInEarsUnitTestCase.class.getPackage(), "ejb-jar-a.xml", "ejb-jar.xml"); ear.addAsModule(jarA); ear.addAsModule(jarAshared); ear.addAsManifestResource(SharedBeanInEarsUnitTestCase.class.getPackage(), "application-a.xml", "application.xml"); return ear; } @Deployment(name = "b", testable = false, managed = true) public static Archive<?> deployB() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_B + ".ear"); JavaArchive jarB = ShrinkWrap.create(JavaArchive.class, MOD_B + ".jar"); jarB.addClasses(BEJB.class, BEJBBean.class); JavaArchive jarBshared = ShrinkWrap.create(JavaArchive.class, MOD_B_SHARED + ".jar"); jarBshared.addClasses(Shared.class, SharedBean.class); jarBshared.addAsManifestResource(SharedBeanInEarsUnitTestCase.class.getPackage(), "ejb-jar-b.xml", "ejb-jar.xml"); ear.addAsModule(jarB); ear.addAsModule(jarBshared); ear.addAsManifestResource(SharedBeanInEarsUnitTestCase.class.getPackage(), "application-b.xml", "application.xml"); return ear; } private InitialContext getInitialContext() throws NamingException { final Hashtable<String, String> jndiProperties = new Hashtable<String, String>(); jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory"); jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); return new InitialContext(jndiProperties); } @Test public void testScopedClassLoaders() throws Exception { AEJB aremote = (AEJB) getInitialContext().lookup("ejb:" + APP_A + "/" + MOD_A + "//" + AEJBBean.class.getSimpleName() + "!" + AEJB.class.getName()); Assert.assertEquals("A", aremote.doit()); BEJB bremote = (BEJB) getInitialContext().lookup("ejb:" + APP_B + "/" + MOD_B + "//" + BEJBBean.class.getSimpleName() + "!" + BEJB.class.getName()); Assert.assertEquals("B", bremote.doit()); } }
4,946
44.805556
156
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/remotelookup/LookupTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.remotelookup; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.assertNotNull; import java.net.SocketPermission; import jakarta.jms.Connection; import jakarta.jms.ConnectionFactory; import javax.naming.Context; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.junit.InSequence; import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.test.shared.TestSuiteEnvironment; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Ondrej Chaloupka */ @RunWith(Arquillian.class) public class LookupTestCase { @ContainerResource private Context remoteContext; @Deployment(name = "test") public static Archive<?> deployment() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "deploy.jar"); jar.addClass(StatelessBean.class); jar.addAsManifestResource(createPermissionsXmlAsset( new SocketPermission(TestSuiteEnvironment.getHttpAddress() + ":" + TestSuiteEnvironment.getHttpPort(), "resolve") ), "permissions.xml"); return jar; } @Test @OperateOnDeployment("test") @InSequence(1) public void testServerLocalLookup() throws Exception { InitialContext context = new InitialContext(); lookupConnectionFactory(context, "java:jboss/exported/jms/RemoteConnectionFactory"); context.close(); } @Test @RunAsClient @InSequence(2) public void testClientRemoteLookup() throws Exception { lookupConnectionFactory(remoteContext, "jms/RemoteConnectionFactory"); } private void lookupConnectionFactory(Context context, String name) throws Exception { ConnectionFactory cf = (ConnectionFactory) context.lookup(name); assertNotNull(cf); //"java.net.SocketPermission" "localhost" "resolve" Connection conn = cf.createConnection("guest", "guest"); conn.close(); } }
3,432
35.913978
133
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/remotelookup/StatelessBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, 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.remotelookup; import jakarta.ejb.Stateless; @Stateless public class StatelessBean { public void hello() { // hi, father } }
1,207
35.606061
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/globalmodules/GlobalModulesTestCase.java
/* * 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.as.test.integration.ee.globalmodules; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.nio.file.Files; import java.sql.SQLException; 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.api.ServerSetup; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.dmr.ModelNode; import org.jboss.jandex.Index; import org.jboss.jandex.IndexWriter; import org.jboss.jandex.Indexer; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.ByteArrayAsset; import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Stuart Douglas */ @RunWith(Arquillian.class) @ServerSetup(GlobalModulesTestCase.GlobalModulesTestCaseServerSetup.class) public class GlobalModulesTestCase { static class GlobalModulesTestCaseServerSetup implements ServerSetupTask { @Override public void setup(final ManagementClient managementClient, final String containerId) throws Exception { final ModelNode value = new ModelNode(); ModelNode module = new ModelNode(); module.get("name").set("org.jboss.test.globalModule"); module.get("annotations").set(true); value.add(module); final ModelNode op = new ModelNode(); op.get(OP_ADDR).set(SUBSYSTEM, "ee"); op.get(OP).set(WRITE_ATTRIBUTE_OPERATION); op.get(NAME).set("global-modules"); op.get(VALUE).set(value); managementClient.getControllerClient().execute(op); File testModuleRoot = new File(getModulePath(), "org/jboss/test/globalModule"); File file = testModuleRoot; while (!getModulePath().equals(file.getParentFile())) file = file.getParentFile(); deleteRecursively(file); createTestModule(testModuleRoot); } @Override public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception { final ModelNode op = new ModelNode(); op.get(OP_ADDR).set(SUBSYSTEM, "ee"); op.get(OP).set(UNDEFINE_ATTRIBUTE_OPERATION); op.get(NAME).set("global-modules"); managementClient.getControllerClient().execute(op); File testModuleRoot = new File(getModulePath(), "org/jboss/test/globalModule"); File file = testModuleRoot; while (!getModulePath().equals(file.getParentFile())) file = file.getParentFile(); deleteRecursively(file); } private static void deleteRecursively(File file) { if (file.exists()) { if (file.isDirectory()) { for (String name : file.list()) { deleteRecursively(new File(file, name)); } } file.delete(); } } private static void createTestModule(File testModuleRoot) throws IOException { if (testModuleRoot.exists()) { throw new IllegalArgumentException(testModuleRoot + " already exists"); } File file = new File(testModuleRoot, "main"); if (!file.mkdirs()) { throw new IllegalArgumentException("Could not create " + file); } URL url = GlobalModulesTestCase.class.getResource("module.xml"); if (url == null) { throw new IllegalStateException("Could not find module.xml"); } copyFile(new File(file, "module.xml"), url.openStream()); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "globalTest.jar"); jar.addClasses(GlobalModuleEjb.class, GlobalModuleInterceptor.class); final ClassLoader cl = GlobalModulesTestCase.class.getClassLoader(); //create annotation index Indexer indexer = new Indexer(); indexer.index(cl.getResourceAsStream(GlobalModuleEjb.class.getName().replace(".","/") + ".class")); indexer.index(cl.getResourceAsStream(GlobalModuleInterceptor.class.getName().replace(".", "/") + ".class")); final Index index = indexer.complete(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); IndexWriter writer = new IndexWriter(out); writer.write(index); jar.addAsManifestResource(new ByteArrayAsset(out.toByteArray()), "jandex.idx"); FileOutputStream jarFile = new FileOutputStream(new File(file, "globalTest.jar")); try { jar.as(ZipExporter.class).exportTo(jarFile); } finally { jarFile.flush(); jarFile.close(); } } } private static void copyFile(File target, InputStream src) throws IOException { Files.copy(src, target.toPath()); } private static File getModulePath() { String modulePath = System.getProperty("module.path", null); if (modulePath == null) { String jbossHome = System.getProperty("jboss.home", null); if (jbossHome == null) { throw new IllegalStateException("Neither -Dmodule.path nor -Djboss.home were set"); } modulePath = jbossHome + File.separatorChar + "modules"; } else { modulePath = modulePath.split(File.pathSeparator)[0]; } File moduleDir = new File(modulePath); if (!moduleDir.exists()) { throw new IllegalStateException("Determined module path does not exist"); } if (!moduleDir.isDirectory()) { throw new IllegalStateException("Determined module path is not a dir"); } return moduleDir; } @Deployment public static Archive<?> deploy() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "testglobal.jar"); jar.addClass(GlobalModulesTestCase.class); return jar; } @ArquillianResource private InitialContext ctx; @Test public void testDataSourceDefinition() throws NamingException, SQLException { GlobalModuleEjb bean = (GlobalModuleEjb) ctx.lookup("java:module/" + GlobalModuleEjb.class.getSimpleName()); Assert.assertEquals(GlobalModuleInterceptor.class.getSimpleName() + GlobalModuleEjb.class.getSimpleName(), bean.getName()); } }
8,609
40.594203
131
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/globalmodules/GlobalModuleInterceptor.java
package org.jboss.as.test.integration.ee.globalmodules; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.InvocationContext; /** * @author Stuart Douglas */ public class GlobalModuleInterceptor { @AroundInvoke public Object intercept(final InvocationContext context) throws Exception { return getClass().getSimpleName() + context.proceed(); } }
390
20.722222
79
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/globalmodules/GlobalModuleEjb.java
package org.jboss.as.test.integration.ee.globalmodules; import jakarta.ejb.Stateless; import jakarta.interceptor.Interceptors; /** * @author Stuart Douglas */ @Stateless @Interceptors(GlobalModuleInterceptor.class) public class GlobalModuleEjb { public String getName() { return GlobalModuleEjb.class.getSimpleName(); } }
346
16.35
55
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/lifecycle/LifecycleCallbackBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.lifecycle; import jakarta.annotation.PostConstruct; import jakarta.ejb.Stateless; import jakarta.interceptor.Interceptors; /** * User: jpai */ @Stateless @Interceptors(SimpleInterceptor.class) public class LifecycleCallbackBean { private boolean postConstructInvoked; @PostConstruct private void onConstruct() { this.postConstructInvoked = true; } public boolean wasPostConstructInvoked() { return this.postConstructInvoked; } }
1,541
31.808511
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/lifecycle/Child.java
/* * 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.lifecycle; import jakarta.annotation.PostConstruct; import jakarta.ejb.Stateful; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @Stateful public class Child extends Parent { static boolean postConstructCalled = false; @PostConstruct private void postConstruct() { postConstructCalled = true; } }
1,417
35.358974
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/lifecycle/AS859TestCase.java
/* * 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.lifecycle; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import javax.naming.NamingException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.common.Naming; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * [AS7-859] On same named private lifecycle callbacks the super class callback is not called * * https://issues.jboss.org/browse/AS7-859 * * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @RunWith(Arquillian.class) public class AS859TestCase { @Deployment public static Archive<?> deployment() { // using JavaArchive doesn't work, because of a bug in Arquillian, it only deploys wars properly WebArchive deployment = ShrinkWrap.create(WebArchive.class, "as859.war") .addPackage(Child.class.getPackage()) .addPackage(Naming.class.getPackage()); return deployment; } @Test public void testPostConstruct() throws NamingException { final Child bean = Naming.lookup("java:global/as859/Child", Child.class); assertNotNull(bean); assertTrue("Child @PostConstruct has not been called", Child.postConstructCalled); assertTrue("Parent @PostConstruct has not been called", Parent.postConstructCalled); } }
2,594
38.318182
104
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/lifecycle/Parent.java
/* * 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.lifecycle; import jakarta.annotation.PostConstruct; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ public class Parent { static boolean postConstructCalled = false; @PostConstruct private void postConstruct() { postConstructCalled = true; } }
1,364
35.891892
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/lifecycle/SimpleInterceptor.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.lifecycle; import jakarta.annotation.PostConstruct; import jakarta.interceptor.InvocationContext; /** * User: jpai */ public class SimpleInterceptor { @PostConstruct private void onConstruct(final InvocationContext invocationContext) throws Exception { if (invocationContext.getMethod() != null) { throw new RuntimeException("InvocationContext#getMethod() is expected to return null on lifecycle callback methods"); } invocationContext.proceed(); } }
1,569
37.292683
129
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/lifecycle/InvocationContextLifecycleCallbackTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 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.lifecycle; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * User: jpai */ @RunWith(Arquillian.class) public class InvocationContextLifecycleCallbackTestCase { @Deployment public static Archive createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class); jar.addPackage(SimpleInterceptor.class.getPackage()); return jar; } @Test public void testInvocationContextGetMethodOnLifecycleMethod() throws Exception { final LifecycleCallbackBean bean = InitialContext.doLookup("java:module/" + LifecycleCallbackBean.class.getSimpleName()); Assert.assertTrue("@PostConstruct was not invoked on bean", bean.wasPostConstructInvoked()); } }
2,101
36.535714
129
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/lifecycle/servlet/RemoteFilter.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.lifecycle.servlet; import java.io.IOException; import jakarta.servlet.Filter; import jakarta.servlet.FilterChain; import jakarta.servlet.FilterConfig; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; import jakarta.servlet.annotation.WebFilter; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @LifecycleCallbackBinding @WebFilter("/RemoteFilter") public class RemoteFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void destroy() { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; String event = req.getParameter("event"); if ("postConstructVerify".equals(event)) { resp.setContentType("text/plain"); resp.getWriter().append("" + LifecycleCallbackInterceptor.getPostConstructIncations()); } else { resp.setStatus(404); } } }
2,321
35.28125
132
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/lifecycle/servlet/FilterLifecycleCallbackInterceptionTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.lifecycle.servlet; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.net.URL; import java.net.URLEncoder; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.junit.InSequence; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Matus Abaffy */ @RunAsClient @RunWith(Arquillian.class) public class FilterLifecycleCallbackInterceptionTestCase extends LifecycleInterceptionTestCase { @Deployment(name = REMOTE, managed = false, testable = false) public static WebArchive createRemoteTestArchive() { return createRemoteTestArchiveBase().addClass(RemoteFilter.class); } @Deployment(testable = false) public static WebArchive createMainTestArchive() { return createMainTestArchiveBase(); } /** * This is not a real test method. */ @Test @InSequence(1) public void deployRemoteArchive() { // In order to use @ArquillianResource URL from the unmanaged deployment we need to deploy the test archive first deployer.deploy(REMOTE); } @Test @InSequence(2) public void testFilterPostConstructInterception( @ArquillianResource @OperateOnDeployment(REMOTE) URL remoteContextPath) throws IOException, ExecutionException, TimeoutException { assertEquals("PostConstruct interceptor method not invoked for filter", "1", doGetRequest(remoteContextPath + "/RemoteFilter?event=postConstructVerify")); } @Test @InSequence(3) public void testFilterPreDestroyInterception( @ArquillianResource(InitServlet.class) @OperateOnDeployment(REMOTE) URL remoteContextPath) throws IOException, ExecutionException, TimeoutException { // set the context in InfoClient so that it can send request to InfoServlet doGetRequest(remoteContextPath + "/InitServlet?url=" + URLEncoder.encode(infoContextPath.toExternalForm(), "UTF-8")); deployer.undeploy(REMOTE); assertEquals("PreDestroy interceptor method not invoked for filter", "1", doGetRequest(infoContextPath + "/InfoServlet?event=preDestroyVerify")); } }
3,647
38.225806
125
java