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/ejb/singleton/dependson/mdb/SetupModuleServerSetupTask.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.ejb.singleton.dependson.mdb; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.module.util.TestModule; import org.jboss.as.test.shared.ModuleUtils; /** * @author baranowb */ public class SetupModuleServerSetupTask implements ServerSetupTask { private volatile TestModule testModule; @Override public void setup(ManagementClient arg0, String arg1) throws Exception { testModule = ModuleUtils.createTestModuleWithEEDependencies(Constants.TEST_MODULE_NAME); testModule.addResource("module.jar").addClass(CallCounterInterface.class); testModule.create(); } @Override public void tearDown(ManagementClient arg0, String arg1) throws Exception { if (testModule != null) { testModule.remove(); } } }
1,928
36.096154
96
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/mdb/CallCounterSingleton.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.ejb.singleton.dependson.mdb; import jakarta.ejb.Singleton; /** * Counting ordering of calls. * * @author baranowb */ @Singleton public class CallCounterSingleton implements CallCounterInterface { private boolean postConstruct, preDestroy, message; /** * @return the postConstruct */ public boolean isPostConstruct() { return postConstruct; } /** * @param postConstruct the postConstruct to set */ public void setPostConstruct() { this.postConstruct = true; } /** * @return the preDestroy */ public boolean isPreDestroy() { return preDestroy; } /** * @param preDestroy the preDestroy to set */ public void setPreDestroy() { this.preDestroy = true; } /** * */ public void setMessage() { this.message = true; } /** * @return the message */ public boolean isMessage() { return message; } }
2,045
24.898734
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/mdb/MDBWhichDependsOn.java
package org.jboss.as.test.integration.ejb.singleton.dependson.mdb; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import jakarta.ejb.ActivationConfigProperty; import jakarta.ejb.DependsOn; import jakarta.ejb.EJB; import jakarta.ejb.MessageDriven; import jakarta.jms.Destination; import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.MessageListener; import org.jboss.as.test.integration.ejb.mdb.JMSMessagingUtil; import org.jboss.logging.Logger; @MessageDriven(name = "AnnoBasedBean", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "${destination}")}) @DependsOn("CallCounterProxy") public class MDBWhichDependsOn implements MessageListener { private static final Logger logger = Logger.getLogger(MDBWhichDependsOn.class); @EJB private CallCounterProxy counter; @EJB private JMSMessagingUtil jmsMessagingUtil; @PostConstruct public void postConstruct() { logger.trace("MDB.postConstruct"); this.counter.setPostConstruct(); } @PreDestroy public void preDestroy() { logger.trace("MDB.preDestroy"); this.counter.setPreDestroy(); } @Override public void onMessage(Message message) { logger.trace("MDB.message"); this.counter.setMessage(); try { final Destination replyTo = message.getJMSReplyTo(); if (replyTo == null) { return; } logger.trace("Sending a reply to destination " + replyTo); jmsMessagingUtil.reply(message); } catch (JMSException e) { throw new RuntimeException(e); } finally { } } }
1,847
29.295082
105
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/mdb/CallCounterProxy.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.ejb.singleton.dependson.mdb; import jakarta.ejb.Singleton; import javax.naming.InitialContext; import javax.naming.NamingException; /** * Proxy which is deployed with MDB. * * @author baranowb */ @Singleton public class CallCounterProxy { /** * @param postConstruct the postConstruct to set */ public void setPostConstruct() { this.getCounter().setPostConstruct(); } /** * @param preDestroy the preDestroy to set */ public void setPreDestroy() { this.getCounter().setPreDestroy(); } /** * */ public void setMessage() { this.getCounter().setMessage(); } private CallCounterInterface getCounter() { InitialContext ctx = null; try { ctx = new InitialContext(); return (CallCounterInterface) ctx.lookup(Constants.SINGLETON_EJB); } catch (Exception e) { throw new RuntimeException(e); } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { } } } } }
2,208
28.453333
78
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/mdb/JmsQueueServerSetupTask.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.ejb.singleton.dependson.mdb; 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; /** * @author baranowb */ public class JmsQueueServerSetupTask implements ServerSetupTask { private JMSOperations jmsAdminOperations; @Override public void setup(ManagementClient managementClient, String containerId) throws Exception { jmsAdminOperations = JMSOperationsProvider.getInstance(managementClient); jmsAdminOperations.createJmsQueue(Constants.QUEUE_NAME, Constants.QUEUE_JNDI_NAME); jmsAdminOperations.createJmsQueue(Constants.QUEUE_REPLY_NAME, Constants.QUEUE_REPLY_JNDI_NAME); jmsAdminOperations.setSystemProperties(Constants.SYS_PROP_KEY, Constants.SYS_PROP_VALUE); } @Override public void tearDown(ManagementClient managementClient, String containerId) throws Exception { if (jmsAdminOperations != null) { jmsAdminOperations.removeJmsQueue(Constants.QUEUE_NAME); jmsAdminOperations.removeJmsQueue(Constants.QUEUE_REPLY_NAME); jmsAdminOperations.removeSystemProperties(); jmsAdminOperations.close(); } } }
2,388
41.660714
103
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/mdb/CallCounterInterface.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.ejb.singleton.dependson.mdb; import jakarta.ejb.Local; /** * @author baranowb */ @Local public interface CallCounterInterface { boolean isPostConstruct(); void setPostConstruct(); boolean isPreDestroy(); void setPreDestroy(); void setMessage(); boolean isMessage(); }
1,363
30
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/reentrant/SingletonReentrantTestCase.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.ejb.singleton.reentrant; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import jakarta.ejb.IllegalLoopbackException; 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.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 reentrant calls on Singleton for container-managed concurrency (EJB3.1 4.8.5.1.1) * * @author Ondrej Chaloupka */ @RunWith(Arquillian.class) public class SingletonReentrantTestCase { private static final String ARCHIVE_NAME = "reentrant-test"; private static final int WAITING_S = 5; @ArquillianResource private InitialContext ctx; @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar"); jar.addPackage(SingletonReentrantTestCase.class.getPackage()); // Needed for ThreadPoolExecutor.shutdown() jar.addAsManifestResource(createPermissionsXmlAsset(new RuntimePermission("modifyThread")), "permissions.xml"); return jar; } protected <T> T lookup(String beanName, Class<T> interfaceType) throws NamingException { return interfaceType.cast(ctx.lookup("java:global/" + ARCHIVE_NAME + "/" + beanName + "!" + interfaceType.getName())); } @Test public void testWriteCall() throws Exception { final SingletonBean singleton = lookup(SingletonBean.class.getSimpleName(), SingletonBean.class); singleton.resetCalled(); ExecutorService pool = Executors.newSingleThreadExecutor(); ExecutorService pool2 = Executors.newSingleThreadExecutor(); final CountDownLatch waitForOtherOne = new CountDownLatch(1); CountDownLatch letsWait = new CountDownLatch(1); Future<?> firstOne = pool.submit(new SingletonCallableWrite(letsWait, waitForOtherOne)); letsWait.await(WAITING_S, TimeUnit.SECONDS); //first thread has to be first in singleton method letsWait = new CountDownLatch(1); Future<?> otherOne = pool2.submit(new SingletonCallableWrite(letsWait, null)); // first one could proceed - other one has to wait for end of work of first one waitForOtherOne.countDown(); Assert.assertEquals(new Integer(1), firstOne.get(WAITING_S, TimeUnit.SECONDS)); Assert.assertEquals(new Integer(2), otherOne.get(WAITING_S, TimeUnit.SECONDS)); pool.shutdown(); pool2.shutdown(); } @Test public void testReadCall() throws Exception { final SingletonBean singleton = lookup(SingletonBean.class.getSimpleName(), SingletonBean.class); singleton.resetCalled(); ExecutorService pool = Executors.newSingleThreadExecutor(); ExecutorService pool2 = Executors.newSingleThreadExecutor(); final CountDownLatch oneWaiting = new CountDownLatch(1); final CountDownLatch twoWaiting = new CountDownLatch(1); Future<?> firstOne = pool.submit(new SingletonCallableRead(oneWaiting)); Future<?> otherOne = pool2.submit(new SingletonCallableRead(twoWaiting)); // first one could proceed - other one has to wait for end of work of first one oneWaiting.countDown(); Assert.assertEquals(new Integer(1), firstOne.get(WAITING_S, TimeUnit.SECONDS)); twoWaiting.countDown(); Assert.assertEquals(new Integer(2), otherOne.get(WAITING_S, TimeUnit.SECONDS)); // Expecting exception - calling reentrant write method with read lock try { firstOne = pool.submit(new SingletonCallableRead(null)); firstOne.get(); Assert.fail("Supposing " + IllegalLoopbackException.class.getName()); } catch (IllegalLoopbackException ile) { // OK - supposed } catch (Exception e) { if (!hasCause(e, IllegalLoopbackException.class)) { Assert.fail("Supposed caused exception is " + IllegalLoopbackException.class.getName()); } } pool.shutdown(); pool2.shutdown(); } private final class SingletonCallableWrite implements Callable<Integer> { private CountDownLatch latch; private CountDownLatch downMe; SingletonCallableWrite(CountDownLatch downMe, CountDownLatch latch) { this.latch = latch; this.downMe = downMe; } @Override public Integer call() { try { final SingletonBean singleton = lookup(SingletonBean.class.getSimpleName(), SingletonBean.class); return singleton.methodWithWriteLock(downMe, latch); } catch (Exception e) { throw new RuntimeException(e); } } } private final class SingletonCallableRead implements Callable<Integer> { private CountDownLatch latch; SingletonCallableRead(CountDownLatch latch) { this.latch = latch; } @Override public Integer call() { try { final SingletonBean singleton = lookup(SingletonBean.class.getSimpleName(), SingletonBean.class); if (latch != null) { return singleton.methodWithReadLock(latch); } else { return singleton.methodWithReadLockException(); } } catch (Exception e) { throw new RuntimeException(e); } } } private boolean hasCause(Throwable causeException, Class<? extends Throwable> searchedException) { Throwable currentException = causeException; do { if (currentException.getClass() == searchedException) { return true; } currentException = currentException.getCause(); } while ((currentException != null)); return false; } }
7,505
39.793478
126
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/reentrant/SingletonBean.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.ejb.singleton.reentrant; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import jakarta.annotation.Resource; import jakarta.ejb.Lock; import jakarta.ejb.LockType; import jakarta.ejb.SessionContext; import jakarta.ejb.Singleton; import org.jboss.logging.Logger; @Singleton public class SingletonBean { private static final Logger log = Logger.getLogger(SingletonBean.class); private static final int METHOD_WAIT_MS = 2000; private static final int AWAIT_TIME_S = 2; private Integer called = 0; @Resource SessionContext ctx; @Lock(LockType.WRITE) public Integer methodWithWriteLock(CountDownLatch downMe, CountDownLatch waitingForOther) throws Exception { log.trace("methodwith write lock is here!"); downMe.countDown(); if (waitingForOther != null) { waitingForOther.await(AWAIT_TIME_S, TimeUnit.SECONDS); SingletonBean bean = (SingletonBean) ctx.lookup("java:module/" + SingletonBean.class.getSimpleName()); bean.reentrantRead(); bean.reentrantWrite(); } log.trace("methodWithWriteLock [" + called + "]"); return new Integer(++called); } @Lock(LockType.READ) public Integer methodWithReadLock(CountDownLatch waitingForOther) throws Exception { waitingForOther.await(AWAIT_TIME_S, TimeUnit.SECONDS); SingletonBean bean = (SingletonBean) ctx.lookup("java:module/" + SingletonBean.class.getSimpleName()); bean.reentrantRead(); log.trace("methodWithReadLock [" + called + "]"); return new Integer(++called); } @Lock(LockType.READ) public Integer methodWithReadLockException() throws Exception { SingletonBean bean = (SingletonBean) ctx.lookup("java:module/" + SingletonBean.class.getSimpleName()); bean.reentrantWrite(); log.trace("This should not occur [" + called + "]"); return new Integer(++called); } @Lock(LockType.READ) public void reentrantRead() throws InterruptedException { // sleeping to other thread would have change for action Thread.sleep(METHOD_WAIT_MS); } @Lock(LockType.WRITE) public void reentrantWrite() throws InterruptedException { // sleeping to other thread would have change for action Thread.sleep(METHOD_WAIT_MS); } public void resetCalled() { called = 0; } public Integer getCalled() { return called; } }
3,554
35.649485
114
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/creation/SingletonReentrantPostConstructTestCase.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.ejb.singleton.creation; import org.jboss.logging.Logger; import jakarta.annotation.PostConstruct; import jakarta.ejb.EJB; import jakarta.ejb.EJBException; 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; /** * Tests the fix to {@link org.jboss.as.ejb3.component.singleton.SingletonComponent#getComponentInstance())} that was made to * prevent stack overflows as described in <a href="https://issues.jboss.org/browse/AS7-5184">AS7-5184</a>. * <p> * The scenario itself is illegal because the business method {@link SingletonBeanOne#performSomething()} is being invoked from * {@link SingletonBeanTwo#initialise()} before SingletonBeanOne is "method-ready" - it's PostConstruct method is not yet * completed. * * @author steve.coy */ @RunWith(Arquillian.class) public class SingletonReentrantPostConstructTestCase { private static final Logger log = Logger.getLogger(SingletonReentrantPostConstructTestCase.class.getName()); @EJB(mappedName = "java:module/SingletonBeanOne") private SingletonBeanOne singletonBean; @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb3-reentrantly-created-singleton.jar"); jar.addPackage(SingletonReentrantPostConstructTestCase.class.getPackage()); return jar; } /** * Indirectly invokes the {@link PostConstruct} annotated {@link SingletonBeanOne#initialise()} method. */ @Test public void testReentrantPostConstruction() { // trigger the bean creation life-cycle try { singletonBean.start(); Assert.fail("Expected an EJBException"); } catch (EJBException expected) { final Throwable cause = expected.getCause(); Assert.assertTrue("Expected exception cause to be an java.lang.IllegalStateException, but it was a " + cause, cause instanceof IllegalStateException); } } }
3,281
40.025
127
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/creation/SingletonBeanOne.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.ejb.singleton.creation; import jakarta.annotation.PostConstruct; import jakarta.annotation.Resource; import jakarta.ejb.EJB; import jakarta.ejb.SessionContext; import jakarta.ejb.Singleton; import org.jboss.logging.Logger; /** * The test fixture for {@link SingletonReentrantPostConstructTestCase}. * * @author steve.coy */ @Singleton public class SingletonBeanOne { private static final Logger logger = Logger.getLogger(SingletonBeanOne.class); @EJB private SingletonBeanTwo beanTwo; @Resource private SessionContext sessionContext; public SingletonBeanOne() { } /** * Grabs a reference to it's own business interface and passes it to {@link #beanTwo}. */ @PostConstruct void initialise() { logger.trace("Initialising"); SingletonBeanOne thisBO = sessionContext.getBusinessObject(SingletonBeanOne.class); beanTwo.useBeanOne(thisBO); } /** * Stub method to start the bean life-cycle. */ public void start() { } /** * A business method for {@link SingletonBeanTwo} to call. */ public void performSomething() { logger.trace("Doing something"); } }
2,253
28.657895
91
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/creation/SingletonBeanTwo.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.ejb.singleton.creation; import jakarta.annotation.PostConstruct; import jakarta.ejb.Singleton; import org.jboss.logging.Logger; /** * Part of the test fixture for {@link SingletonReentrantPostConstructTestCase}. * * @author steve.coy */ @Singleton public class SingletonBeanTwo { private static final Logger logger = Logger.getLogger(SingletonBeanTwo.class); @PostConstruct void initialise() { logger.trace("initialised"); } /** * Performs a callback on beanOne. This method is called from {@link SingletonBeanOne#initialise()}, so the SingletonBeanOne * instance is not yet in the "method-ready" state, making the callback illegal. <p> * This resulted in a stack overflow prior to the AS7-5184 fix. * * @param beanOne */ public void useBeanOne(SingletonBeanOne beanOne) { beanOne.performSomething(); } }
1,952
33.263158
128
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/beanclass/validity/StatefulOnAInterface.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.ejb.beanclass.validity; import jakarta.ejb.Stateful; /** * Invalid use of @Stateful annotation on an interface * * User: Jaikiran Pai */ @Stateful public interface StatefulOnAInterface { }
1,257
34.942857
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/beanclass/validity/BeanClassValidityTestCase.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.ejb.beanclass.validity; 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; /** * Tests that deployments containing invalid bean classes (like a @Stateless on a *interface*) doesn't cause deployment * failures. * * @see https://issues.jboss.org/browse/AS7-1380 * User: Jaikiran Pai */ @RunWith(Arquillian.class) public class BeanClassValidityTestCase { private static final String JAR_NAME = "beanclass-validity-test"; @Deployment public static Archive createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, JAR_NAME + ".jar"); jar.addPackage(StatelessOnAInterface.class.getPackage()); return jar; } /** * Tests a simple invocation on a correct bean contained within the same deployment as an invalid bean class. * This test asserts that the presence of an invalid bean class doesn't prevent the correct bean from deploying. * * @throws Exception */ @Test public void testDeployment() throws Exception { ProperStatelessBean bean = InitialContext.doLookup("java:module/" + ProperStatelessBean.class.getSimpleName() + "!" + ProperStatelessBean.class.getName()); bean.doNothing(); } }
2,566
37.313433
163
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/beanclass/validity/FinalStatefulBean.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.ejb.beanclass.validity; import jakarta.ejb.Stateful; /** * User: jpai */ @Stateful public final class FinalStatefulBean { }
1,190
35.090909
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/beanclass/validity/ProperStatelessBean.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.ejb.beanclass.validity; import jakarta.ejb.LocalBean; import jakarta.ejb.Stateless; /** * User: jpai */ @Stateless @LocalBean public class ProperStatelessBean { public void doNothing() { } }
1,267
31.512821
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/beanclass/validity/AbstractStatelessBean.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.ejb.beanclass.validity; import jakarta.ejb.Stateless; /** * User: jpai */ @Stateless public abstract class AbstractStatelessBean { }
1,199
35.363636
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/beanclass/validity/StatelessOnAInterface.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.ejb.beanclass.validity; import jakarta.ejb.Stateless; /** * Invalid use of @Stateless annotation on an interface * * User: Jaikiran Pai */ @Stateless public interface StatelessOnAInterface { }
1,261
35.057143
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/beanclass/validity/SingletonOnAInterface.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.ejb.beanclass.validity; import jakarta.ejb.Singleton; /** * Invalid use of @Singleton annotation on an interface * * User: Jaikiran Pai */ @Singleton public interface SingletonOnAInterface { }
1,261
35.057143
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/beanclass/validity/MessageDrivenOnAInterface.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.ejb.beanclass.validity; import jakarta.ejb.MessageDriven; /** * Invalid use of {@link MessageDriven} annotation on an interface * * User: Jaikiran Pai */ @MessageDriven public interface MessageDrivenOnAInterface { }
1,284
35.714286
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/javapackage/ViewFromJavaPackageTestCase.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.ejb.view.javapackage; import java.util.concurrent.Callable; 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.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Stuart Douglas */ @RunWith(Arquillian.class) public class ViewFromJavaPackageTestCase { @Deployment public static JavaArchive createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb-java-package.jar"); jar.addPackage(ViewFromJavaPackageTestCase.class.getPackage()); return jar; } @Test public void testViewInJavaPackage() throws Exception { final Context ctx = new InitialContext(); final Callable t = (Callable) ctx.lookup("java:module/" + CallableEjb.class.getSimpleName()); Assert.assertEquals(CallableEjb.MESSAGE, t.call()); } }
2,126
35.050847
101
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/javapackage/CallableEjb.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.ejb.view.javapackage; import java.util.concurrent.Callable; import jakarta.ejb.Stateless; /** * @author Stuart Douglas */ @Stateless public class CallableEjb implements Callable<String> { public static final String MESSAGE = "Callable EJB"; @Override public String call() throws Exception { return MESSAGE; } }
1,403
33.243902
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/basic/NoInterfaceSuperclass.java
package org.jboss.as.test.integration.ejb.view.basic; /** * @author Stuart Douglas */ public class NoInterfaceSuperclass { protected String sayHello() { return "Hello"; } String sayGoodbye() { return "Goodbye"; } }
253
13.941176
53
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/basic/Two.java
package org.jboss.as.test.integration.ejb.view.basic; /** * @author: Jaikiran Pai */ public interface Two { }
113
13.25
53
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/basic/One.java
package org.jboss.as.test.integration.ejb.view.basic; /** * @author: Jaikiran Pai */ public interface One { }
113
13.25
53
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/basic/MultipleLocalViewBean.java
package org.jboss.as.test.integration.ejb.view.basic; import java.io.Externalizable; import java.io.Serializable; import jakarta.ejb.Local; import jakarta.ejb.Stateful; /** * @author: Jaikiran Pai */ @Stateful @Local public class MultipleLocalViewBean extends MultipleRemoteViewBean implements One, Two, Three, Serializable, Externalizable { }
349
20.875
124
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/basic/MyBean.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.ejb.view.basic; import jakarta.ejb.Local; import jakarta.ejb.Stateless; /** * User: jpai */ @Local @Stateless public class MyBean implements MyInterface { }
1,223
33.971429
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/basic/MultipleRemoteViewBean.java
package org.jboss.as.test.integration.ejb.view.basic; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.io.Serializable; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; /** * @author: Jaikiran Pai */ @Stateless @Remote public class MultipleRemoteViewBean implements One, Two, Three, Serializable, Externalizable { @Override public void writeExternal(ObjectOutput out) throws IOException { } @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { } }
608
22.423077
94
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/basic/ImplicitLocalBusinessInterfaceBean.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.ejb.view.basic; import jakarta.ejb.Stateless; /** * User: jpai */ @Stateless public class ImplicitLocalBusinessInterfaceBean implements MyInterface { }
1,218
35.939394
72
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/basic/MyInterface.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.ejb.view.basic; /** * User: jpai */ public interface MyInterface { }
1,134
36.833333
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/basic/BusinessViewAnnotationProcessorTestCase.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.ejb.view.basic; import java.io.Externalizable; import java.io.Serializable; import jakarta.ejb.EJBException; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NameNotFoundException; 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.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.assertNotNull; /** * Tests the number of views exposed by EJBs are correct * * @author Jaikiran Pai * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @RunWith(Arquillian.class) public class BusinessViewAnnotationProcessorTestCase { @Deployment public static JavaArchive createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb-view-test.jar"); jar.addPackage(MyBean.class.getPackage()); return jar; } /** * Tests a bean marked with an explicit view * * @throws Exception */ @Test public void testBeanWithExplicitView() throws Exception { final Context ctx = new InitialContext(); final MyInterface singleView = (MyInterface) ctx.lookup("java:module/" + MyBean.class.getSimpleName()); assertNotNull("View " + MyInterface.class.getName() + " not found", singleView); final MyInterface myInterfaceView = (MyInterface) ctx.lookup("java:module/" + MyBean.class.getSimpleName() + "!" + MyInterface.class.getName()); assertNotNull("View " + MyInterface.class.getName() + " not found", myInterfaceView); } /** * Tests a bean which has an implicit local business interface * * @throws Exception */ @Test public void testImplicitLocalBusinessInterface() throws Exception { final Context ctx = new InitialContext(); final MyInterface singleView = (MyInterface) ctx.lookup("java:module/" + ImplicitLocalBusinessInterfaceBean.class.getSimpleName()); assertNotNull("View " + MyInterface.class.getName() + " not found", singleView); final MyInterface myInterfaceView = (MyInterface) ctx.lookup("java:module/" + ImplicitLocalBusinessInterfaceBean.class.getSimpleName() + "!" + MyInterface.class.getName()); assertNotNull("View " + MyInterface.class.getName() + " not found", myInterfaceView); } /** * Tests a bean which has an implicit no-interface view * * @throws Exception */ @Test public void testImplicitNoInterface() throws Exception { final Context ctx = new InitialContext(); final ImplicitNoInterfaceBean singleView = (ImplicitNoInterfaceBean) ctx.lookup("java:module/" + ImplicitNoInterfaceBean.class.getSimpleName()); assertNotNull("View " + ImplicitNoInterfaceBean.class.getName() + " not found", singleView); final ImplicitNoInterfaceBean noInterfaceBean = (ImplicitNoInterfaceBean) ctx.lookup("java:module/" + ImplicitNoInterfaceBean.class.getSimpleName() + "!" + ImplicitNoInterfaceBean.class.getName()); assertNotNull("View " + MyInterface.class.getName() + " not found", noInterfaceBean); } /** * Tests a bean which has an implicit local business interface * * @throws Exception */ @Test public void testInvocationOnNonPublicMethod() throws Exception { final Context ctx = new InitialContext(); final ImplicitNoInterfaceBean singleView = (ImplicitNoInterfaceBean) ctx.lookup("java:module/" + ImplicitNoInterfaceBean.class.getSimpleName()); assertNotNull("View " + MyInterface.class.getName() + " not found", singleView); Assert.assertEquals("Hello", singleView.sayHello()); try { singleView.sayGoodbye(); Assert.fail("should have been disallowed"); } catch (EJBException expected) { } } /** * Tests that if a bean has a {@link jakarta.ejb.Remote} annotation without any specific value and if the bean implements n (valid) interfaces, then all those n (valid) interfaces are considered * as remote business interfaces * * @throws Exception */ @Test public void testEJB32MultipleRemoteViews() throws Exception { final Context ctx = new InitialContext(); final One interfaceOne = (One) ctx.lookup("java:module/" + MultipleRemoteViewBean.class.getSimpleName() + "!" + One.class.getName()); assertNotNull("View " + One.class.getName() + " not found", interfaceOne); final Two interfaceTwo = (Two) ctx.lookup("java:module/" + MultipleRemoteViewBean.class.getSimpleName() + "!" + Two.class.getName()); assertNotNull("View " + Two.class.getName() + " not found", interfaceTwo); final Three interfaceThree = (Three) ctx.lookup("java:module/" + MultipleRemoteViewBean.class.getSimpleName() + "!" + Three.class.getName()); assertNotNull("View " + Three.class.getName() + " not found", interfaceThree); try { final Object view = ctx.lookup("java:module/" + MultipleRemoteViewBean.class.getSimpleName() + "!" + Serializable.class.getName()); Assert.fail("Unexpected view found: " + view + " for interface " + Serializable.class.getName()); } catch (NameNotFoundException nnfe) { // expected } try { final Object view = ctx.lookup("java:module/" + MultipleRemoteViewBean.class.getSimpleName() + "!" + Externalizable.class.getName()); Assert.fail("Unexpected view found: " + view + " for interface " + Externalizable.class.getName()); } catch (NameNotFoundException nnfe) { // expected } } /** * Tests that if a bean has a {@link jakarta.ejb.Local} annotation without any specific value and if the bean implements n (valid) interfaces, then all those n (valid) interfaces are considered * as local business interfaces * * @throws Exception */ @Test public void testEJB32MultipleLocalViews() throws Exception { final Context ctx = new InitialContext(); final One interfaceOne = (One) ctx.lookup("java:module/" + MultipleLocalViewBean.class.getSimpleName() + "!" + One.class.getName()); assertNotNull("View " + One.class.getName() + " not found", interfaceOne); final Two interfaceTwo = (Two) ctx.lookup("java:module/" + MultipleLocalViewBean.class.getSimpleName() + "!" + Two.class.getName()); assertNotNull("View " + Two.class.getName() + " not found", interfaceTwo); final Three interfaceThree = (Three) ctx.lookup("java:module/" + MultipleLocalViewBean.class.getSimpleName() + "!" + Three.class.getName()); assertNotNull("View " + Three.class.getName() + " not found", interfaceThree); try { final Object view = ctx.lookup("java:module/" + MultipleLocalViewBean.class.getSimpleName() + "!" + Serializable.class.getName()); Assert.fail("Unexpected view found: " + view + " for interface " + Serializable.class.getName()); } catch (NameNotFoundException nnfe) { // expected } try { final Object view = ctx.lookup("java:module/" + MultipleLocalViewBean.class.getSimpleName() + "!" + Externalizable.class.getName()); Assert.fail("Unexpected view found: " + view + " for interface " + Externalizable.class.getName()); } catch (NameNotFoundException nnfe) { // expected } } }
8,648
43.353846
205
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/basic/Three.java
package org.jboss.as.test.integration.ejb.view.basic; /** * @author: Jaikiran Pai */ public interface Three { }
115
13.5
53
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/basic/ImplicitNoInterfaceBean.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.ejb.view.basic; import jakarta.ejb.Stateless; /** * User: jpai */ @Stateless public class ImplicitNoInterfaceBean extends NoInterfaceSuperclass { @Override public String sayHello() { return super.sayHello(); } }
1,299
33.210526
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/duplicateview/AnnotatedDoNothingBean.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.ejb.view.duplicateview; import jakarta.ejb.Local; import jakarta.ejb.Stateless; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @Stateless @Local(DoNothing.class) public class AnnotatedDoNothingBean extends DoNothingBean { }
1,317
37.764706
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/duplicateview/DoNothingBean.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.ejb.view.duplicateview; /** * Do not annotate this bean, that must happen in the individual test. * * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ public class DoNothingBean implements DoNothing { @Override public void doNothing() { // yep, it really does nothing } }
1,378
38.4
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/duplicateview/DuplicateViewDefinitionTestCase.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.ejb.view.duplicateview; import jakarta.ejb.EJB; 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; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @RunWith(Arquillian.class) public class DuplicateViewDefinitionTestCase { @Deployment public static Archive<?> deployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "ejb3as7-1012.jar") .addPackage(AnnotatedDoNothingBean.class.getPackage()) .addPackage(DoNothingBean.class.getPackage()) .addAsManifestResource(DuplicateViewDefinitionTestCase.class.getPackage(), "ejb-jar.xml"); return archive; } @EJB(mappedName = "java:global/ejb3as7-1012/AnnotatedDoNothingBean!org.jboss.as.test.integration.ejb.view.duplicateview.DoNothing") private DoNothing bean; @Test public void testDoNothing() { // if it deploys, we are good to go bean.doNothing(); } }
2,271
38.172414
135
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/view/duplicateview/DoNothing.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.ejb.view.duplicateview; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ public interface DoNothing { void doNothing(); }
1,216
39.566667
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/validation/DummyFlagImpl.java
/* * JBoss, Home of Professional Open Source * Copyright 2020, 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.ejb.validation; import jakarta.ejb.Singleton; import jakarta.ejb.Startup; @Startup @Singleton public class DummyFlagImpl implements DummyFlag { private boolean executedServiceCallFlag; public void setExecutedServiceCallFlag(boolean flag) { executedServiceCallFlag = flag; } @Override public void markAsExecuted() { executedServiceCallFlag = true; } @Override public void clearExecution() { executedServiceCallFlag = false; } public boolean getExecutedServiceCallFlag() { return executedServiceCallFlag; } }
1,643
31.88
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/validation/DummySubclass.java
/* * JBoss, Home of Professional Open Source * Copyright 2020, 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.ejb.validation; import jakarta.validation.constraints.NotNull; public class DummySubclass extends DummyAbstractClass { @NotNull private String direction; public int getSpeed() { return speed; } public String getDirection() { return direction; } public void setSpeed(int number) { this.speed = number; } public void setDirection(String direction) { this.direction = direction; } }
1,512
31.891304
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/validation/DummyFlag.java
/* * JBoss, Home of Professional Open Source * Copyright 2020, 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.ejb.validation; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; @Path("/") public interface DummyFlag { void setExecutedServiceCallFlag(boolean flag); @GET @Path("executed/mark") void markAsExecuted(); @GET @Path("executed/clear") void clearExecution(); @GET @Path("executed/status") public boolean getExecutedServiceCallFlag(); }
1,436
31.659091
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/validation/TestResource.java
/* * JBoss, Home of Professional Open Source * Copyright 2020, 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.ejb.validation; import jakarta.ejb.Stateless; import jakarta.validation.Valid; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotEmpty; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.core.MediaType; import java.util.List; import java.util.stream.Collectors; /** * @author <a href="mailto:[email protected]">Tomasz Adamski</a> * */ @Stateless @Path("/") public class TestResource { @POST @Path("put/list") @Consumes(MediaType.APPLICATION_JSON) public String putList(@NotEmpty List<String> a) { return a.stream().collect(Collectors.joining(", ")); } @Valid @GET @Path("validate/{id}") public String get(@PathParam("id") @Min(value=4) int id) { return String.valueOf(id); } }
1,944
31.416667
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/validation/EchoResourceImpl.java
/* * JBoss, Home of Professional Open Source * Copyright 2020, 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.ejb.validation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jakarta.ejb.Stateless; import jakarta.inject.Inject; import jakarta.ws.rs.core.Response; @Stateless public class EchoResourceImpl implements EchoResource { private static final Logger log = LoggerFactory.getLogger(EchoResourceImpl.class); @Inject private DummyFlag dummyFlag; @Override public Response validateEchoThroughAbstractClass(DummySubclass payload) { dummyFlag.setExecutedServiceCallFlag(true); return Response.ok(payload.getDirection()).build(); } @Override public Response validateEchoThroughClass(DummyClass payload) { dummyFlag.setExecutedServiceCallFlag(true); return Response.ok(payload.getDirection()).build(); } }
1,839
35.8
86
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/validation/EjbBeanValidationTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2020, 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.ejb.validation; 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.test.integration.common.HttpRequest; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import jakarta.ws.rs.ApplicationPath; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; import jakarta.ws.rs.client.Entity; import jakarta.ws.rs.client.WebTarget; import jakarta.ws.rs.core.Application; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; import java.net.URL; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** * @author <a href="mailto:[email protected]">Tomasz Adamski</a> * */ @RunWith(Arquillian.class) @RunAsClient public class EjbBeanValidationTestCase { @ApplicationPath("") public static class TestApplication extends Application { } @Deployment(testable = false) public static Archive<?> deploy() { return ShrinkWrap.create(WebArchive.class, "ejbvalidation.war") .addPackage(HttpRequest.class.getPackage()) .addClasses( EjbBeanValidationTestCase.class, TestApplication.class, TestResource.class, EchoResourceImpl.class, EchoResource.class, DummySubclass.class, DummyAbstractClass.class, DummyClass.class, DummyFlagImpl.class, DummyFlag.class); } @ArquillianResource private URL url; static Client client; @BeforeClass public static void setUpClient() { client = ClientBuilder.newClient(); } @AfterClass public static void close() { client.close(); } @Test public void testValidation() { Response response = client.target(url.toExternalForm() + "validate/1").request().get(); Assert.assertNotNull("Request should have been negatively validated", response.getMetadata().getFirst("validation-exception")); } /** * This test check whether the EJB proxy is being correctly normalized by {@link org.jboss.as.ejb3.validator.EjbProxyBeanMetaDataClassNormalizer}. * As the proxy does not support contain information about generics, without normalization validation would fail. */ @Test public void testProxyNormalization() { String result = client.target(url.toExternalForm() + "put/list") .request(MediaType.APPLICATION_JSON).post(Entity.json("[\"a\",\"b\",\"c\"]"), String.class); Assert.assertEquals("a, b, c", result); } @Test public void testObjectValidationOnConcreteClass() throws Exception { Client client = ClientBuilder.newBuilder().build(); WebTarget target = client.target(url.toURI().toString()); ResteasyWebTarget rtarget = (ResteasyWebTarget) target; EchoResource customerResource = rtarget.proxy(EchoResource.class); DummyFlag dummyFlag = rtarget.proxy(DummyFlag.class); // Create a concrete class with valid values DummyClass validDummyClass = new DummyClass(); validDummyClass.setSpeed(5); validDummyClass.setDirection("north"); // Create a concrete class with invalid values (direction is null and speed is less than 1) DummyClass invalidDummyClass = new DummyClass(); invalidDummyClass.setSpeed(0); Response response = customerResource.validateEchoThroughClass(validDummyClass); // Verify that we received a Bad Request Code from HTTP assertTrue(String.format("Return code should be 200. It was %d", response.getStatus()), 200 == response.getStatus()); // Verify that the service call has not been executed (flag set to false) assertTrue("Executed flag should be true", dummyFlag.getExecutedServiceCallFlag()); // Reset flag dummyFlag.clearExecution(); Response response2 = customerResource.validateEchoThroughClass(invalidDummyClass); // Verify that we received a Bad Request Code from HTTP assertTrue(String.format("Return code should either be 400 or 500, it was %d", response2.getStatus()), 400 == response2.getStatus() || 500 == response2.getStatus()); // Verify that the service call has not been executed (flag set to false) assertFalse("Executed flag should be false", dummyFlag.getExecutedServiceCallFlag()); } @Test public void testObjectValidationOnSubclassThatExtendsAbstractClass() throws Exception { Client client = ClientBuilder.newClient(); WebTarget target = client.target(url.toURI().toString()); ResteasyWebTarget rtarget = (ResteasyWebTarget) target; EchoResource customerResource = rtarget.proxy(EchoResource.class); DummyFlag dummyFlag = rtarget.proxy(DummyFlag.class); // Create subclass of DummyAbstractClass with valid values DummySubclass validDummySubclass = new DummySubclass(); validDummySubclass.setDirection("north"); validDummySubclass.setSpeed(10); // Create subclass of DummyAbstractClass with an invalid value (speed should be greater than 0) DummySubclass invalidDummySubclass = new DummySubclass(); invalidDummySubclass.setDirection("north"); invalidDummySubclass.setSpeed(0); Response response = customerResource.validateEchoThroughAbstractClass(validDummySubclass); // Verify that we received a Bad Request Code from HTTP assertTrue(String.format("Return code should be 200. It was %d", response.getStatus()), 200 == response.getStatus()); // Verify that the service call has not been executed (flag set to false) assertTrue("Executed flag should be true", dummyFlag.getExecutedServiceCallFlag()); dummyFlag.clearExecution(); Response response2 = customerResource.validateEchoThroughAbstractClass(invalidDummySubclass); // Verify that we received a Bad Request Code from HTTP assertTrue(String.format("Return code should either be 400 or 500. It was %d", response2.getStatus()), 400 == response2.getStatus() || 500 == response2.getStatus()); // Verify that the service call has not been executed (flag set to false) assertFalse("Executed flag should be false", dummyFlag.getExecutedServiceCallFlag()); } }
7,754
41.60989
173
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/validation/DummyAbstractClass.java
/* * JBoss, Home of Professional Open Source * Copyright 2020, 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.ejb.validation; import jakarta.validation.constraints.Min; public abstract class DummyAbstractClass { @Min(1) protected int speed; public abstract int getSpeed(); public abstract void setSpeed(int speed); }
1,281
36.705882
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/validation/DummyClass.java
/* * JBoss, Home of Professional Open Source * Copyright 2020, 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.ejb.validation; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; public class DummyClass { @NotNull private String direction; @Min(1) protected int speed; public int getSpeed() { return speed; } public void setSpeed(int number) { this.speed = number; } public String getDirection() { return direction; } public void setDirection(String direction) { this.direction = direction; } }
1,563
30.28
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/validation/EchoResource.java
/* * JBoss, Home of Professional Open Source * Copyright 2020, 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.ejb.validation; import jakarta.validation.Valid; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; @Path("/") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public interface EchoResource { @POST @Path("echoThroughAbstract") Response validateEchoThroughAbstractClass(@Valid DummySubclass payload); @POST @Path("echo") Response validateEchoThroughClass(@Valid DummyClass payload); }
1,630
36.068182
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/bmt/BMTStateless.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.ejb.transaction.bmt; import org.junit.Assert; import jakarta.annotation.Resource; import jakarta.ejb.EJBContext; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionManagement; import jakarta.ejb.TransactionManagementType; import jakarta.transaction.NotSupportedException; import jakarta.transaction.Status; import jakarta.transaction.SystemException; /** * * * @author Stuart Douglas */ @Stateless @TransactionManagement(TransactionManagementType.BEAN) public class BMTStateless { @Resource private EJBContext ejbContext; /** * This method leaks a transaction, and should result in an exception */ public void leakTransaction(){ try { Assert.assertEquals(Status.STATUS_NO_TRANSACTION, ejbContext.getUserTransaction().getStatus()); ejbContext.getUserTransaction().begin(); } catch (NotSupportedException e) { throw new RuntimeException(e); } catch (SystemException e) { throw new RuntimeException(e); } } }
2,089
32.709677
107
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/bmt/BeanManagedTransactionsTestCase.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.ejb.transaction.bmt; import jakarta.ejb.EJBException; import jakarta.inject.Inject; import jakarta.transaction.NotSupportedException; import jakarta.transaction.Status; import jakarta.transaction.SystemException; import jakarta.transaction.UserTransaction; 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.EmptyAsset; 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 BeanManagedTransactionsTestCase { @Inject private UserTransaction userTransaction; @Inject private BMTStateful bmtStateful; @Inject private BMTSingleton bmtSingleton; @Inject private BMTStateless bmtStateless; @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, "test-mandatory.war"); war.addPackage(BeanManagedTransactionsTestCase.class.getPackage()); war.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); return war; } @Test(expected = EJBException.class) public void testStatelessBeanLeaksTransactions() throws SystemException, NotSupportedException { try { //start a transaction. this transaction should be suspended before the invocation userTransaction.begin(); bmtStateless.leakTransaction(); } finally { userTransaction.rollback(); } } @Test(expected = EJBException.class) public void testSingletonBeanLeaksTransactions() { bmtSingleton.leakTransaction(); } @Test public void testStatefulBeanTransaction() throws SystemException { bmtStateful.createTransaction(); Assert.assertEquals(userTransaction.getStatus(), Status.STATUS_NO_TRANSACTION); bmtStateful.rollbackTransaction(); Assert.assertEquals(userTransaction.getStatus(), Status.STATUS_NO_TRANSACTION); } }
3,210
33.159574
100
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/bmt/BMTStateful.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.ejb.transaction.bmt; import org.junit.Assert; import jakarta.annotation.Resource; import jakarta.ejb.EJBContext; import jakarta.ejb.Stateful; import jakarta.ejb.TransactionManagement; import jakarta.ejb.TransactionManagementType; import jakarta.transaction.NotSupportedException; import jakarta.transaction.Status; import jakarta.transaction.SystemException; import jakarta.transaction.UserTransaction; /** * Stateful session bean that uses the same transaction over two method invocations * * @author Stuart Douglas */ @Stateful @TransactionManagement(TransactionManagementType.BEAN) public class BMTStateful { @Resource private EJBContext ejbContext; public void createTransaction() { try { final UserTransaction userTransaction = ejbContext.getUserTransaction(); Assert.assertEquals(Status.STATUS_NO_TRANSACTION, userTransaction.getStatus()); userTransaction.begin(); } catch (SystemException e) { throw new RuntimeException(e); } catch (NotSupportedException e) { throw new RuntimeException(e); } } public void rollbackTransaction() { try { final UserTransaction userTransaction = ejbContext.getUserTransaction(); Assert.assertEquals(Status.STATUS_ACTIVE, userTransaction.getStatus()); userTransaction.rollback(); } catch (SystemException e) { throw new RuntimeException(e); } } }
2,537
35.257143
91
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/bmt/BMTSingleton.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.ejb.transaction.bmt; import jakarta.annotation.Resource; import jakarta.ejb.EJBContext; import jakarta.ejb.Singleton; import jakarta.ejb.TransactionManagement; import jakarta.ejb.TransactionManagementType; import jakarta.transaction.NotSupportedException; import jakarta.transaction.SystemException; /** * * * @author Stuart Douglas */ @Singleton @TransactionManagement(TransactionManagementType.BEAN) public class BMTSingleton { @Resource private EJBContext ejbContext; /** * This method leaks a transaction, and should result in an exception */ public void leakTransaction(){ try { ejbContext.getUserTransaction().begin(); } catch (NotSupportedException e) { throw new RuntimeException(e); } catch (SystemException e) { throw new RuntimeException(e); } } }
1,920
32.12069
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/bmt/timeout/StatelessTimeoutTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2016, 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.ejb.transaction.bmt.timeout; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; 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.test.integration.transactions.RemoteLookups; import org.jboss.as.test.integration.transactions.TransactionCheckerSingleton; import org.jboss.as.test.integration.transactions.TxTestUtil; import org.jboss.as.test.shared.TimeoutUtil; 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.JavaArchive; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.transaction.client.ContextTransactionManager; import java.util.PropertyPermission; import jakarta.inject.Inject; import javax.naming.InitialContext; import javax.naming.NamingException; import jakarta.transaction.TransactionManager; /** * BMT test where transaction timeout is involved. * The bean uses mock XAResources to simulate to get 2PC happen. */ @RunWith(Arquillian.class) public class StatelessTimeoutTestCase { @ArquillianResource private InitialContext initCtx; @Inject private TransactionCheckerSingleton checker; @Deployment public static Archive<?> createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "stateless-btm-txn-timeout.jar") .addPackage(StatelessTimeoutTestCase.class.getPackage()) .addPackage(TxTestUtil.class.getPackage()) .addClasses(TimeoutUtil.class) .addAsManifestResource(new StringAsset("<beans></beans>"), "beans.xml") // grant necessary permissions for -Dsecurity.manager .addAsResource(createPermissionsXmlAsset( new PropertyPermission("ts.timeout.factor", "read")), "META-INF/jboss-permissions.xml"); return jar; } @Before public void startUp() throws NamingException { checker.resetAll(); } /** * Calling BTM method where transaction timeout is not modified. * Call is expected to be processed. */ @Test public void noTimeout() throws Exception { StatelessBmtBean bean = RemoteLookups.lookupModule(initCtx, StatelessBmtBean.class); bean.testTransaction(1, 0); } /** * Calling BTM method where 3 transactions are started and one of them timeouts. * Each transaction contains 2 XA Resources. * <br> * The assertion checks that 2 transactions were committed and one rolled-back. */ @Test public void timeout() throws Exception { StatelessBmtBean bean = RemoteLookups.lookupModule(initCtx, StatelessBmtBean.class); bean.testTransaction(3, 1); Assert.assertEquals("Two times two XA resources - for each commit happened", 4, checker.getCommitted()); Assert.assertEquals("One time two XA resources - for each rollback happened", 2, checker.getRolledback()); } /** * Calling BTM method where 4 transactions are started and 3 of them timeouts. * Each transaction contains 2 XA Resources. * <br> * The assertion checks that 1 transaction was committed and 3 rolled-back. */ @Test public void timeoutMultiple() throws Exception { StatelessBmtBean bean = RemoteLookups.lookupModule(initCtx, StatelessBmtBean.class); bean.testTransaction(4, 3); Assert.assertEquals("One time two XA resources - for each commit happened", 2, checker.getCommitted()); Assert.assertEquals("Three times two XA resources - for each rollback happened", 6, checker.getRolledback()); } /** * Calling BTM method where transaction timeout is defined small enough to get transaction timeout happens. * Such transaction is rolled-back. * Then transaction timeout is set to default value and other transaction is started which successfully commits. */ @Test public void resetTimeoutToDefault() throws Exception { StatelessBmtRestartTimeoutBean bean = RemoteLookups.lookupModule(initCtx, StatelessBmtRestartTimeoutBean.class); bean.test(); } @Test public void threadStoringTimeout() throws Exception { StatelessBmtBean bean = RemoteLookups.lookupModule(initCtx, StatelessBmtBean.class); TransactionManager tm = (TransactionManager) new InitialContext().lookup("java:/TransactionManager"); int transactionTimeoutToSet = 42; tm.setTransactionTimeout(transactionTimeoutToSet); Assert.assertEquals("Expecting transaction timeout has to be the same as it was written by setter", transactionTimeoutToSet, getTransactionTimeout(tm)); bean.testTransaction(0, 0); Assert.assertEquals("The transaction timeout has to be the same as before BMT call", transactionTimeoutToSet, getTransactionTimeout(tm)); } private int getTransactionTimeout(TransactionManager tmTimeout) { if (tmTimeout instanceof ContextTransactionManager) { return ((ContextTransactionManager) tmTimeout).getTransactionTimeout(); } throw new IllegalStateException("Cannot get transaction timeout"); } }
6,468
40.735484
120
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/bmt/timeout/StatelessBmtRestartTimeoutBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, 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.ejb.transaction.bmt.timeout; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionManagement; import jakarta.ejb.TransactionManagementType; import jakarta.transaction.RollbackException; import jakarta.transaction.TransactionManager; import org.jboss.as.test.integration.transactions.TxTestUtil; import org.jboss.logging.Logger; import org.junit.Assert; @Stateless @TransactionManagement(TransactionManagementType.BEAN) public class StatelessBmtRestartTimeoutBean { private static Logger log = Logger.getLogger(StatelessBmtRestartTimeoutBean.class); @Resource(name = "java:jboss/TransactionManager") private TransactionManager tm; public void test() throws Exception { String txnAsString = null; tm.setTransactionTimeout(1); try { tm.begin(); txnAsString = tm.getTransaction().toString(); TxTestUtil.waitForTimeout(tm); tm.commit(); } catch (RollbackException e) { try { log.tracef("Rollbacking transaction '%s'", txnAsString); tm.rollback(); Assert.fail("Rollback should throw IllegalStateException: BaseTransaction.rollback - ARJUNA016074: no transaction!" + " as the original transaction should be aborted by transaction manager"); } catch (Exception rollbacke) { // expected transaction as there is no txn to rollback - it was aborted by TM log.debugf(rollbacke, "Got expected transaction: %s'", rollbacke.getClass()); } } finally { // reseting transaction timeout to default one tm.setTransactionTimeout(0); } // after reset additional check if default value is used // value depends on settings under txn subsystem but default is 5 minutes tm.begin(); txnAsString = tm.getTransaction().toString(); TxTestUtil.waitForTimeout(tm); tm.commit(); } }
3,097
39.233766
131
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/bmt/timeout/StatelessBmtBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, 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.ejb.transaction.bmt.timeout; import java.rmi.RemoteException; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionManagement; import jakarta.ejb.TransactionManagementType; import jakarta.inject.Inject; import javax.naming.NamingException; import jakarta.transaction.RollbackException; import jakarta.transaction.SystemException; import jakarta.transaction.TransactionManager; import jakarta.transaction.UserTransaction; import org.jboss.as.test.integration.transactions.TransactionCheckerSingleton; import org.jboss.as.test.integration.transactions.TxTestUtil; import org.jboss.logging.Logger; @Stateless @TransactionManagement(TransactionManagementType.BEAN) public class StatelessBmtBean { private static Logger log = Logger.getLogger(StatelessBmtBean.class); @Resource private UserTransaction txn; @Resource(name = "java:jboss/TransactionManager") private TransactionManager tm; @Inject private TransactionCheckerSingleton checker; public String testTransaction(int transactionCount, int timeoutCount) throws RemoteException, NamingException, SystemException { TxTestUtil.checkTransactionExists(tm, false); for(int i = 1; i <= transactionCount; i++) { boolean isTimeout = (i <= timeoutCount); runTransaction(isTimeout); } return TxTestUtil.getStatusAsString(txn.getStatus()); } private void runTransaction(boolean isTimeout) { String txnToString = null; try { if(isTimeout) { txn.setTransactionTimeout(1); } txn.begin(); TxTestUtil.checkTransactionExists(tm, true); txnToString = txn.toString(); TxTestUtil.enlistTestXAResource(tm.getTransaction(), checker); TxTestUtil.enlistTestXAResource(tm.getTransaction(), checker); if(isTimeout) { TxTestUtil.waitForTimeout(tm); } log.tracef("Commiting transaction '%s'", txnToString); txn.commit(); if(isTimeout) { throw new RuntimeException("Expecting transaction being timeouted but it's in state '" + TxTestUtil.getStatusAsString(txn.getStatus()) + "'"); } } catch (RollbackException e) { log.tracef("Rollbacking transaction '%s'.", txnToString); try { txn.rollback(); } catch (Exception rollbacke) { log.debugf(rollbacke, "Expected transaction as can't rollback non active - TM aborted transaction"); } if(isTimeout) { log.tracef("Transaction '%s' was timeouted as expected", txnToString); } else { throw new RuntimeException("Transaction should not be rollbacked as wasn't timeouted", e); } } catch (Exception e) { // Heuristic exceptions handled here throw new RuntimeException("Not expected exception which fails the test", e); } finally { try { txn.setTransactionTimeout(0); } catch (SystemException se) { throw new RuntimeException("Can't reset transaction timeout", se); } } } }
4,388
36.512821
116
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/bmt/lazyenlist/ATMBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2008, 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.ejb.transaction.bmt.lazyenlist; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionManagement; import jakarta.ejb.TransactionManagementType; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import javax.sql.DataSource; import jakarta.transaction.NotSupportedException; import jakarta.transaction.Status; import jakarta.transaction.SystemException; import jakarta.transaction.UserTransaction; import org.jboss.logging.Logger; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @Stateless @TransactionManagement(TransactionManagementType.BEAN) public class ATMBean implements ATM { private static final Logger log = Logger.getLogger(ATMBean.class); @PersistenceContext private EntityManager em; @Resource private UserTransaction ut; @Resource(mappedName = "java:jboss/datasources/ExampleDS") private DataSource ds; private void beginTx() { try { ut.begin(); } catch (NotSupportedException e) { throw new RuntimeException(e); } catch (SystemException e) { throw new RuntimeException(e); } } private void commitTx() { try { ut.commit(); } catch (RuntimeException e) { throw e; } // RollbackException, HeuristicMixedException, HeuristicRollbackException, SystemException catch (Exception e) { throw new RuntimeException(e); } } public long createAccount(double balance) { beginTx(); try { Account a = new Account(); a.setBalance(balance); em.persist(a); commitTx(); return a.getId(); } finally { rollbackTxIfNeeded(); } } public double getBalance(long id) { Account a = em.find(Account.class, id); return a.getBalance(); } private void rollbackTx() { try { ut.rollback(); } catch (RuntimeException e) { throw e; } // SecurityException, SystemException catch (Exception e) { throw new RuntimeException(e); } } private void rollbackTxIfNeeded() { try { switch (ut.getStatus()) { case Status.STATUS_COMMITTED: case Status.STATUS_NO_TRANSACTION: log.infov("Transaction {} is not active thus won't be rollbacked", ut); break; default: log.infov("Transaction {} is active and going to be rollbacked", ut); ut.rollback(); } } catch (RuntimeException e) { throw e; } // SecurityException, SystemException catch (Exception e) { throw new RuntimeException(e); } } public double depositTwice(long id, double a1, double a2) { Account a; beginTx(); try { a = em.find(Account.class, id); double balanceBefore = a.getBalance(); log.infov("Depositing '{}' to account id '{}' with start balance '{}'", a1, a.getId(), balanceBefore); // unsafe (nolock) a.setBalance(balanceBefore + a1); em.flush(); commitTx(); } finally { rollbackTxIfNeeded(); } beginTx(); try { a = em.find(Account.class, id); double balanceBefore = a.getBalance(); log.infov("Depositing '{}' to account id '{}' with start balance '{}'", a2, a.getId(), balanceBefore); // unsafe (nolock) a.setBalance(balanceBefore + a2); em.flush(); commitTx(); } finally { rollbackTxIfNeeded(); } return a.getBalance(); } public double depositTwiceRawSQL(long id, double a1, double a2) { Connection conn = null; ResultSet rs = null; double balance; try { try { conn = ds.getConnection(); PreparedStatement psSelect = conn.prepareStatement("SELECT balance FROM account WHERE id = ?"); psSelect.setLong(1, id); rs = psSelect.executeQuery(); if (!rs.next()) throw new IllegalArgumentException("can't find account " + id); balance = rs.getDouble(1); } finally { if(rs != null) { rs.close(); } } PreparedStatement ps = conn.prepareStatement("UPDATE account SET balance = ? WHERE id = ?"); beginTx(); try { balance += a1; ps.setDouble(1, balance); ps.setLong(2, id); int rows = ps.executeUpdate(); if (rows != 1) throw new IllegalStateException("first update failed"); commitTx(); } finally { ps.close(); rollbackTxIfNeeded(); } ps = conn.prepareStatement("UPDATE account SET balance = ? WHERE id = ?"); beginTx(); try { balance += a2; ps.setDouble(1, balance); ps.setLong(2, id); int rows = ps.executeUpdate(); if (rows != 1) throw new IllegalStateException("second update failed"); commitTx(); } finally { ps.close(); rollbackTxIfNeeded(); } return balance; } catch (SQLException sqle) { throw new RuntimeException(sqle); } finally { try { if(conn != null) { conn.close(); } } catch (Exception e) { log.errorv("Final closing of connection {} was unsuccesful", conn, e); } } } public double depositTwiceWithRollback(long id, double a1, double a2) { Account a; beginTx(); try { a = em.find(Account.class, id); // unsafe (nolock) a.setBalance(a.getBalance() + a1); em.flush(); commitTx(); } finally { rollbackTxIfNeeded(); } beginTx(); try { // unsafe a.setBalance(a.getBalance() + a2); em.flush(); } finally { rollbackTx(); } return a.getBalance(); } /** * Do the same, but then raw sql. * * @param id * @param a1 * @param a2 */ public double withdrawTwiceWithRollback(long id, double a1, double a2) { try { Connection conn = ds.getConnection(); PreparedStatement psSelect = conn.prepareStatement("SELECT balance FROM account WHERE id = ?"); double balance; try { psSelect.setLong(1, id); ResultSet rs = psSelect.executeQuery(); if (!rs.next()) throw new IllegalArgumentException("can't find account " + id); balance = rs.getDouble(1); rs.close(); psSelect.close(); PreparedStatement ps = conn.prepareStatement("UPDATE account SET balance = ? WHERE id = ?"); try { beginTx(); try { balance -= a1; ps.setDouble(1, balance); ps.setLong(2, id); int rows = ps.executeUpdate(); if (rows != 1) throw new IllegalStateException("first update failed"); ps.close(); conn.close(); commitTx(); } finally { rollbackTxIfNeeded(); } conn = ds.getConnection(); ps = conn.prepareStatement("UPDATE account SET balance = ? WHERE id = ?"); beginTx(); try { balance -= a2; ps.setDouble(1, balance); ps.setLong(2, id); int rows = ps.executeUpdate(); if (rows != 1) throw new IllegalStateException("second update failed"); } finally { rollbackTx(); } } finally { ps.close(); } return balance; } finally { conn.close(); } } catch (SQLException e) { throw new RuntimeException(e); } } }
10,211
30.616099
111
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/bmt/lazyenlist/ATM.java
/* * JBoss, Home of Professional Open Source. * Copyright 2008, 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.ejb.transaction.bmt.lazyenlist; import jakarta.ejb.Remote; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @Remote public interface ATM { long createAccount(double balance); double getBalance(long id); double depositTwice(long id, double a1, double a2); double depositTwiceRawSQL(long id, double a1, double a2); double depositTwiceWithRollback(long id, double a1, double a2); double withdrawTwiceWithRollback(long id, double a1, double a2); }
1,569
35.511628
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/bmt/lazyenlist/Account.java
/* * JBoss, Home of Professional Open Source. * Copyright 2008, 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.ejb.transaction.bmt.lazyenlist; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @Entity public class Account { private long id; private double balance; // don't look, not financially save public double getBalance() { return balance; } @Id @GeneratedValue public long getId() { return id; } public void setBalance(double balance) { this.balance = balance; } public void setId(long id) { this.id = id; } }
1,694
30.388889
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/bmt/lazyenlist/LazyTransactionEnlistmentUnitTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2008, 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.ejb.transaction.bmt.lazyenlist; import java.text.MessageFormat; 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.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; /** * Lazy transaction enlistment. Migration test from EJB Testsuite (ejbthree-1028) to AS7 [JIRA JBQA-5483]. * * @author Carlo de Wolf, Ondrej Chaloupka */ @RunWith(Arquillian.class) @RunAsClient public class LazyTransactionEnlistmentUnitTestCase { @ArquillianResource InitialContext ctx; @Deployment public static Archive<?> deployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "tx-lazy-enlist.jar").addPackage( LazyTransactionEnlistmentUnitTestCase.class.getPackage()); jar.addAsManifestResource(LazyTransactionEnlistmentUnitTestCase.class.getPackage(), "persistence.xml", "persistence.xml"); return jar; } @Test public void testDepositTwice() throws Exception { ATM atm = getAtm(); double deposit = 64, increase1 = 128, increase2 = 256; long id = atm.createAccount(deposit); double baseBalance = atm.getBalance(id); Assert.assertEquals("Account should be created with input deposit", deposit, baseBalance, Double.NaN); double balanceOnDeposit = atm.depositTwice(id, increase1, increase2); Assert.assertEquals("Deposit should be increased twice by " + increase1 + " and " + increase2, deposit + increase1 + increase2, balanceOnDeposit, Double.NaN); double balanceAfterDeposit = atm.getBalance(id); Assert.assertEquals("Balance got from ATM should be equal to base deposit plus two increased deposit amounts", deposit + increase1 + increase2, balanceAfterDeposit, Double.NaN); } @Test public void testDepositTwiceRawSQL() throws Exception { ATM atm = getAtm(); double deposit = 64, increase1 = 128, increase2 = 256; long id = atm.createAccount(deposit); double baseBalance = atm.getBalance(id); Assert.assertEquals("Account should be created with input deposit", deposit, baseBalance, Double.NaN); double balanceOnDeposit = atm.depositTwiceRawSQL(id, increase1, increase2); Assert.assertEquals("Deposit should be increased twice by " + increase1 + " and " + increase2, deposit + increase1 + increase2, balanceOnDeposit, Double.NaN); double balanceAfterDeposit = atm.getBalance(id); Assert.assertEquals("Balance got from ATM should be equal to base deposit plus two increased deposit amounts", deposit + increase1 + increase2, balanceAfterDeposit, Double.NaN); } @Test public void testDepositeTwiceWithRollback() throws Exception { ATM atm = getAtm(); // if only long id = atm.createAccount(1000000); double balance = atm.getBalance(id); Assert.assertEquals(1000000, balance, Double.NaN); balance = atm.depositTwiceWithRollback(id, 125000, 250000); // the entity state itself won't be rolled back Assert.assertEquals(1375000, balance, Double.NaN); balance = atm.getBalance(id); Assert.assertEquals(1125000, balance, Double.NaN); } @Test public void testRawSQL() throws Exception { ATM atm = getAtm(); // if only long id = atm.createAccount(1000000); double balance = atm.getBalance(id); Assert.assertEquals(1000000, balance, Double.NaN); balance = atm.withdrawTwiceWithRollback(id, 125000, 250000); balance = atm.getBalance(id); Assert.assertEquals(875000, balance, Double.NaN); } private ATM getAtm() throws NamingException { return (ATM) ctx.lookup(MessageFormat.format("ejb:/tx-lazy-enlist/{0}!{1}", ATMBean.class.getSimpleName(), ATM.class.getName())); } }
5,372
41.642857
137
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/exception/TxExceptionBaseTestCase.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.ejb.transaction.exception; import static org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.EjbType.EJB2; import static org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.EjbType.EJB3; import static org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxContext.RUN_IN_TX_STARTED_BY_CALLER; import static org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxContext.START_BEAN_MANAGED_TX; import static org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxContext.START_CONTAINER_MANAGED_TX; import static org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxManagerException.HEURISTIC_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION; import static org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxManagerException.HEURISTIC_CAUSED_BY_XA_EXCEPTION; import static org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxManagerException.NONE; import static org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxManagerException.ROLLBACK_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION; import static org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxManagerException.ROLLBACK_CAUSED_BY_XA_EXCEPTION; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.rmi.RemoteException; import java.security.AllPermission; import jakarta.transaction.Status; import jakarta.transaction.UserTransaction; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxManagerException; import org.jboss.as.test.integration.transactions.TestXAResource; 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; /** * Base class for testing whether client gets exceptions according to the * specification. * * @author [email protected] */ public abstract class TxExceptionBaseTestCase { private static Logger LOG = Logger.getLogger(TxExceptionBaseTestCase.class); protected static final String APP_NAME = "tx-exception-test"; protected static final String MODULE_NAME = "ejb"; @Deployment public static Archive<?> createDeployment() { final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear"); final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar"); jar.addPackages(true, TxExceptionBaseTestCase.class.getPackage()); jar.addPackage(TestXAResource.class.getPackage()); jar.addPackages(true, "javassist"); // this test needs to create a new public class thru javassist so AllPermission is needed here ear.addAsManifestResource(createPermissionsXmlAsset(new AllPermission()), "permissions.xml"); ear.addAsModule(jar); return ear; } @Test public void exceptionThrownFromEjb2WhichRunsInTxStartedByCaller() throws Exception { runTest(new TestConfig(EJB2, RUN_IN_TX_STARTED_BY_CALLER, tmEx -> throwExceptionFromCmtEjb2())); } @Test public void exceptionThrownFromEjb3WhichRunsInTxStartedByCaller() throws Exception { runTest(new TestConfig(EJB3, RUN_IN_TX_STARTED_BY_CALLER, tmEx -> throwExceptionFromCmtEjb3())); } @Test public void exceptionThrownFromEjb2WhichStartsContainerManagedTx() throws Exception { runTest(new TestConfig(EJB2, START_CONTAINER_MANAGED_TX, tmEx -> throwExceptionFromCmtEjb2())); } @Test public void exceptionThrownFromEjb3WhichStartsContainerManagedTx() throws Exception { runTest(new TestConfig(EJB3, START_CONTAINER_MANAGED_TX, tmEx -> throwExceptionFromCmtEjb3())); } @Test public void exceptionThrownFromEjb2WhichStartsBeanManagedTx() throws Exception { runTest(new TestConfig(EJB2, START_BEAN_MANAGED_TX, tmEx -> throwExceptionFromBmtEjb2())); } @Test public void exceptionThrownFromEjb3WhichStartsBeanManagedTx() throws Exception { runTest(new TestConfig(EJB3, START_BEAN_MANAGED_TX, tmEx -> throwExceptionFromBmtEjb3())); } @Test public void heuristicExceptionThrownFromTmInCallerTx() throws Exception { runTest(new TestConfig(EJB3, RUN_IN_TX_STARTED_BY_CALLER, tmEx -> throwExceptionFromTm(tmEx), HEURISTIC_CAUSED_BY_XA_EXCEPTION)); } @Test public void heuristicExceptionWithSpecificCauseThrownFromTmInCallerTx() throws Exception { runTest(new TestConfig(EJB3, RUN_IN_TX_STARTED_BY_CALLER, tmEx -> throwExceptionFromTm(tmEx), HEURISTIC_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION)); } @Test public void heuristicExceptionThrownFromTm() throws Exception { runTest(new TestConfig(EJB3, START_CONTAINER_MANAGED_TX, tmEx -> throwExceptionFromTm(tmEx), HEURISTIC_CAUSED_BY_XA_EXCEPTION)); } @Test public void heuristicExceptionWithSpecificCauseThrownFromTm() throws Exception { runTest(new TestConfig(EJB3, START_CONTAINER_MANAGED_TX, tmEx -> throwExceptionFromTm(tmEx), HEURISTIC_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION)); } @Test public void rollbackExceptionThrownFromTm() throws Exception { runTest(new TestConfig(EJB3, START_CONTAINER_MANAGED_TX, tmEx -> throwExceptionFromTm(tmEx), ROLLBACK_CAUSED_BY_XA_EXCEPTION)); } @Test public void rollbackExceptionWithSpecificCauseThrownFromTm() throws Exception { runTest(new TestConfig(EJB3, START_CONTAINER_MANAGED_TX, tmEx -> throwExceptionFromTm(tmEx), ROLLBACK_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION)); } @Test public void rollbackExceptionThrownFromTmInCallerTx() throws Exception { runTest(new TestConfig(EJB3, RUN_IN_TX_STARTED_BY_CALLER, tmEx -> throwExceptionFromTm(tmEx), ROLLBACK_CAUSED_BY_XA_EXCEPTION)); } @Test public void rollbackExceptionWithSpecificCauseThrownFromTmInCallerTx() throws Exception { runTest(new TestConfig(EJB3, RUN_IN_TX_STARTED_BY_CALLER, tmEx -> throwExceptionFromTm(tmEx), ROLLBACK_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION)); } private void runTest(TestConfig testType) throws Exception { final UserTransaction userTransaction = getUserTransaction(); try { if (testType.getTxContext() == RUN_IN_TX_STARTED_BY_CALLER) { // clean up possible tx from previous tests rollbackIfExists(userTransaction); userTransaction.begin(); } testType.getEjbMethod().invoke(testType.getTxManagerException()); if (testType.getTxContext() == RUN_IN_TX_STARTED_BY_CALLER && testType.getTxManagerException() != NONE) { userTransaction.commit(); } Assert.fail("An exception was expected."); } catch (Exception e) { LOG.debugf(e, "Received exception: %s. Test type %s", e.getClass(), testType); checkReceivedException(testType, e); } finally { if (testType.getTxContext() == RUN_IN_TX_STARTED_BY_CALLER && testType.getTxManagerException() == NONE) { userTransaction.rollback(); } } } private void rollbackIfExists(UserTransaction userTransaction) throws Exception { LOG.debugf("UserTransaction status is %s.", userTransaction.getStatus()); if (userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION) { userTransaction.rollback(); } } protected abstract UserTransaction getUserTransaction(); protected abstract void throwExceptionFromCmtEjb2() throws RemoteException; protected abstract void throwExceptionFromCmtEjb3(); protected abstract void throwExceptionFromBmtEjb2() throws RemoteException; protected abstract void throwExceptionFromBmtEjb3(); protected abstract void throwExceptionFromTm(TxManagerException txManagerException) throws Exception; protected abstract void checkReceivedException(TestConfig testType, Exception receivedException); }
9,241
45.676768
149
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/exception/TxExceptionEjbClientTestCase.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.ejb.transaction.exception; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import java.rmi.RemoteException; import jakarta.transaction.UserTransaction; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.ejb.remote.common.EJBManagementUtil; import org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxManagerException; import org.jboss.as.test.integration.ejb.transaction.exception.bean.TestBean; import org.jboss.as.test.integration.ejb.transaction.exception.bean.ejb2.BmtEjb2; import org.jboss.as.test.integration.ejb.transaction.exception.bean.ejb2.CmtEjb2; import org.jboss.as.test.integration.ejb.transaction.exception.bean.ejb2.TestBean2Remote; import org.jboss.as.test.integration.ejb.transaction.exception.bean.ejb3.BmtEjb3; import org.jboss.as.test.integration.ejb.transaction.exception.bean.ejb3.CmtEjb3; import org.jboss.ejb.client.EJBClient; import org.jboss.ejb.client.StatelessEJBLocator; import org.junit.BeforeClass; import org.junit.runner.RunWith; /** * Tests that EJB client propagates appropriate exceptions. * * @author [email protected] */ @RunAsClient @RunWith(Arquillian.class) public class TxExceptionEjbClientTestCase extends TxExceptionBaseTestCase { private static String nodeName; @BeforeClass public static void beforeClass() throws Exception { nodeName = EJBManagementUtil.getNodeName(); } @Override protected void checkReceivedException(TestConfig testCnf, Exception receivedEx) { switch (testCnf.getTxContext()) { case RUN_IN_TX_STARTED_BY_CALLER: switch (testCnf.getTxManagerException()) { case NONE: switch (testCnf.getEjbType()) { case EJB2: assertThat(receivedEx.getClass(), equalTo(jakarta.transaction.TransactionRolledbackException.class)); break; case EJB3: assertThat(receivedEx.getClass(), equalTo(jakarta.ejb.EJBTransactionRolledbackException.class)); break; } break; case HEURISTIC_CAUSED_BY_XA_EXCEPTION: case HEURISTIC_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION: assertThat(receivedEx.getClass(), equalTo(jakarta.transaction.HeuristicMixedException.class)); break; case ROLLBACK_CAUSED_BY_XA_EXCEPTION: case ROLLBACK_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION: assertThat(receivedEx.getClass(), equalTo(jakarta.transaction.RollbackException.class)); break; } break; case START_CONTAINER_MANAGED_TX: case START_BEAN_MANAGED_TX: switch (testCnf.getTxManagerException()) { case NONE: switch (testCnf.getEjbType()) { case EJB2: assertThat(receivedEx.getClass(), equalTo(java.rmi.RemoteException.class)); break; case EJB3: assertThat(receivedEx.getClass(), equalTo(jakarta.ejb.EJBException.class)); break; } break; case HEURISTIC_CAUSED_BY_XA_EXCEPTION: assertThat(receivedEx.getClass(), equalTo(jakarta.ejb.EJBException.class)); assertThat(receivedEx.getCause().getClass(), equalTo(jakarta.transaction.HeuristicMixedException.class)); break; case HEURISTIC_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION: assertThat(receivedEx.getClass(), equalTo(jakarta.ejb.EJBException.class)); // FIXME WFLY-8794 // assertThat("HeuristicMixedException should be cause.", receivedEx.getCause().getClass(), equalTo(jakarta.transaction.HeuristicMixedException.class)); assertThat(receivedEx.getCause().getClass(), equalTo(java.lang.ClassNotFoundException.class)); break; case ROLLBACK_CAUSED_BY_XA_EXCEPTION: assertThat(receivedEx.getClass(), equalTo(jakarta.ejb.EJBTransactionRolledbackException.class)); assertThat(receivedEx.getCause().getClass(), equalTo(jakarta.transaction.RollbackException.class)); break; case ROLLBACK_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION: // FIXME should be EJBTransactionRolledbackException assertThat(receivedEx.getClass(), equalTo(jakarta.ejb.EJBException.class)); // FIXME WFLY-8794 // assertThat("HeuristicMixedException should be cause.", receivedEx.getCause().getClass(), equalTo(jakarta.transaction.HeuristicMixedException.class)); assertThat(receivedEx.getCause().getClass(), equalTo(java.lang.ClassNotFoundException.class)); break; } } } @Override protected UserTransaction getUserTransaction() { return EJBClient.getUserTransaction(nodeName); } @Override protected void throwExceptionFromCmtEjb2() throws RemoteException { getBean(TestBean2Remote.class, CmtEjb2.class.getSimpleName()).throwRuntimeException(); } @Override protected void throwExceptionFromCmtEjb3() { getBean(TestBean.class, CmtEjb3.class.getSimpleName()).throwRuntimeException(); } @Override protected void throwExceptionFromBmtEjb2() throws RemoteException { getBean(TestBean2Remote.class, BmtEjb2.class.getSimpleName()).throwRuntimeException(); } @Override protected void throwExceptionFromBmtEjb3() { getBean(TestBean.class, BmtEjb3.class.getSimpleName()).throwRuntimeException(); } @Override protected void throwExceptionFromTm(TxManagerException txManagerException) throws Exception { getBean(TestBean.class, CmtEjb3.class.getSimpleName()).throwExceptionFromTm(txManagerException); } private <T> T getBean(Class<T> viewType, String beanName) { final StatelessEJBLocator<T> remoteBeanLocator = new StatelessEJBLocator<T>(viewType, APP_NAME, MODULE_NAME, beanName, ""); return EJBClient.createProxy(remoteBeanLocator); } }
7,325
44.222222
168
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/exception/TimeoutTestXAResource.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2016, 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.ejb.transaction.exception; import java.lang.reflect.Constructor; import javax.transaction.xa.XAException; import javax.transaction.xa.Xid; import org.jboss.as.test.integration.transactions.TestXAResource; import org.jboss.logging.Logger; import javassist.ClassPool; import javassist.CtClass; /** * Implementation of XAResource for use in tests. * * @author [email protected] */ public class TimeoutTestXAResource extends TestXAResource { private static final Logger log = Logger.getLogger(TimeoutTestXAResource.class); private static XAException RM_SPECIFIC_EXCEPTION = createDriverSpecificXAException(XAException.XAER_RMERR); public TimeoutTestXAResource(TestAction testAction) { super(testAction); } @Override public void commit(Xid xid, boolean onePhase) throws XAException { if(super.testAction == TestXAResource.TestAction.COMMIT_THROW_UNKNOWN_XA_EXCEPTION) throw RM_SPECIFIC_EXCEPTION; else super.commit(xid, onePhase); } @Override public int prepare(Xid xid) throws XAException { if(super.testAction == TestXAResource.TestAction.PREPARE_THROW_UNKNOWN_XA_EXCEPTION) throw RM_SPECIFIC_EXCEPTION; else return super.prepare(xid); } /** * Creates instance of dynamically created XAException class. */ private static XAException createDriverSpecificXAException(int xaErrorCode) { try { return createInstanceOfDriverSpecificXAException(xaErrorCode, createXATestExceptionClass()); } catch (Exception e) { log.errorf(e, "Can't create dynamic instance of XAException class", xaErrorCode); throw new RuntimeException(e); } } /** * Creates new instance of given class. */ private static XAException createInstanceOfDriverSpecificXAException(int xaErrorCode, Class<?> clazz) throws Exception { Constructor<?> constructor = clazz.getDeclaredConstructor(int.class); constructor.setAccessible(true); return (XAException) constructor.newInstance(xaErrorCode); } /** * Creates new public class named org.jboss.as.test.XATestException. */ private static Class<?> createXATestExceptionClass() throws Exception { ClassPool pool = ClassPool.getDefault(); CtClass evalClass = pool.makeClass("org.jboss.as.test.XATestException", pool.get("javax.transaction.xa.XAException")); return evalClass.toClass(); } }
3,574
36.631579
126
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/exception/TxExceptionTestCase.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.ejb.transaction.exception; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import jakarta.inject.Inject; import javax.naming.InitialContext; import javax.naming.NamingException; import jakarta.transaction.UserTransaction; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxManagerException; import org.jboss.as.test.integration.ejb.transaction.exception.bean.TestBean; import org.jboss.as.test.integration.ejb.transaction.exception.bean.ejb2.BmtEjb2; import org.jboss.as.test.integration.ejb.transaction.exception.bean.ejb2.CmtEjb2; import org.jboss.as.test.integration.ejb.transaction.exception.bean.ejb2.TestBean2Local; import org.jboss.as.test.integration.ejb.transaction.exception.bean.ejb3.BmtEjb3; import org.jboss.as.test.integration.ejb.transaction.exception.bean.ejb3.CmtEjb3; import org.junit.runner.RunWith; /** * Tests that container behaves according to the specification when exception is * thrown. * * @author [email protected] */ @RunWith(Arquillian.class) public class TxExceptionTestCase extends TxExceptionBaseTestCase { @ArquillianResource protected InitialContext iniCtx; @Inject private UserTransaction userTransaction; @Override protected void checkReceivedException(TestConfig testCnf, Exception receivedEx) { switch (testCnf.getTxContext()) { case RUN_IN_TX_STARTED_BY_CALLER: switch (testCnf.getTxManagerException()) { case NONE: switch (testCnf.getEjbType()) { case EJB2: assertThat(receivedEx.getClass(), equalTo(jakarta.ejb.TransactionRolledbackLocalException.class)); break; case EJB3: assertThat(receivedEx.getClass(), equalTo(jakarta.ejb.EJBTransactionRolledbackException.class)); break; } break; case HEURISTIC_CAUSED_BY_XA_EXCEPTION: case HEURISTIC_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION: assertThat(receivedEx.getClass(), equalTo(jakarta.transaction.HeuristicMixedException.class)); break; case ROLLBACK_CAUSED_BY_XA_EXCEPTION: case ROLLBACK_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION: assertThat(receivedEx.getClass(), equalTo(jakarta.transaction.RollbackException.class)); break; } break; case START_CONTAINER_MANAGED_TX: case START_BEAN_MANAGED_TX: switch (testCnf.getTxManagerException()) { case NONE: assertThat(receivedEx.getClass(), equalTo(jakarta.ejb.EJBException.class)); break; case HEURISTIC_CAUSED_BY_XA_EXCEPTION: case HEURISTIC_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION: assertThat(receivedEx.getClass(), equalTo(jakarta.ejb.EJBException.class)); assertThat(receivedEx.getCause().getClass(), equalTo(jakarta.transaction.HeuristicMixedException.class)); break; case ROLLBACK_CAUSED_BY_XA_EXCEPTION: case ROLLBACK_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION: assertThat(receivedEx.getClass(), equalTo(jakarta.ejb.EJBTransactionRolledbackException.class)); assertThat(receivedEx.getCause().getClass(), equalTo(jakarta.transaction.RollbackException.class)); } } } @Override protected UserTransaction getUserTransaction() { return userTransaction; } @Override protected void throwExceptionFromCmtEjb2() { getBean(TestBean2Local.class, CmtEjb2.class.getSimpleName()).throwRuntimeException(); } @Override protected void throwExceptionFromCmtEjb3() { getBean(TestBean.class, CmtEjb3.class.getSimpleName()).throwRuntimeException(); } @Override protected void throwExceptionFromBmtEjb2() { getBean(TestBean2Local.class, BmtEjb2.class.getSimpleName()).throwRuntimeException(); } @Override protected void throwExceptionFromBmtEjb3() { getBean(TestBean.class, BmtEjb3.class.getSimpleName()).throwRuntimeException(); } @Override protected void throwExceptionFromTm(TxManagerException txManagerException) throws Exception { getBean(TestBean.class, CmtEjb3.class.getSimpleName()).throwExceptionFromTm(txManagerException); } private <T> T getBean(Class<T> viewType, String beanName) { try { return viewType.cast(iniCtx.lookup("java:global/" + APP_NAME + "/" + MODULE_NAME + "/" + beanName + "!" + viewType.getName())); } catch (NamingException e) { throw new RuntimeException(e); } } }
5,915
40.661972
139
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/exception/TestConfig.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2016, 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.ejb.transaction.exception; /** * Represents configuration for one particular test method. * * @author [email protected] */ public class TestConfig { @FunctionalInterface public interface EjbMethod { void invoke(TxManagerException txManagerException) throws Exception; } public static enum EjbType { EJB2, EJB3 } public static enum TxContext { RUN_IN_TX_STARTED_BY_CALLER, START_CONTAINER_MANAGED_TX, START_BEAN_MANAGED_TX } public static enum TxManagerException { NONE, HEURISTIC_CAUSED_BY_XA_EXCEPTION, HEURISTIC_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION, ROLLBACK_CAUSED_BY_XA_EXCEPTION, ROLLBACK_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION } private final EjbType ejbType; private final TxContext txContext; private final EjbMethod action; private final TxManagerException tmException; public TestConfig(EjbType ejbType, TxContext txContext, EjbMethod action) { this(ejbType, txContext, action, TxManagerException.NONE); } public TestConfig(EjbType ejbType, TxContext txContext, EjbMethod action, TxManagerException txManagerException) { this.ejbType = ejbType; this.txContext = txContext; this.action = action; this.tmException = txManagerException; } public EjbType getEjbType() { return ejbType; } public TxContext getTxContext() { return txContext; } public EjbMethod getEjbMethod() { return action; } public TxManagerException getTxManagerException() { return tmException; } @Override public String toString() { return "TestConfig [ejbType=" + ejbType + ", txContext=" + txContext + ", action=" + action + ", tmException=" + tmException + "]"; } }
2,848
31.747126
170
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/exception/bean/TestBean.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.ejb.transaction.exception.bean; import org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxManagerException; public interface TestBean { void throwRuntimeException(); void throwExceptionFromTm(TxManagerException txManagerException) throws Exception; }
1,343
39.727273
93
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/exception/bean/ejb3/BmtEjb3.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.ejb.transaction.exception.bean.ejb3; import jakarta.annotation.Resource; import jakarta.ejb.LocalBean; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionManagement; import jakarta.ejb.TransactionManagementType; import jakarta.transaction.NotSupportedException; import jakarta.transaction.SystemException; import jakarta.transaction.UserTransaction; import org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxManagerException; import org.jboss.as.test.integration.ejb.transaction.exception.bean.TestBean; @LocalBean @Remote @Stateless @TransactionManagement(TransactionManagementType.BEAN) public class BmtEjb3 implements TestBean { @Resource private UserTransaction utx; @Override public void throwRuntimeException() { try { utx.begin(); throw new RuntimeException(); } catch (NotSupportedException | SystemException e) { throw new IllegalStateException("Can't begin transaction!", e); } } @Override public void throwExceptionFromTm(TxManagerException txManagerException) throws Exception { throw new UnsupportedOperationException(); } }
2,261
34.904762
94
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/exception/bean/ejb3/CmtEjb3.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.ejb.transaction.exception.bean.ejb3; import jakarta.annotation.Resource; import jakarta.ejb.LocalBean; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; import jakarta.transaction.Transaction; import jakarta.transaction.TransactionManager; import org.jboss.as.test.integration.ejb.transaction.exception.TestConfig.TxManagerException; import org.jboss.as.test.integration.ejb.transaction.exception.TimeoutTestXAResource; import org.jboss.as.test.integration.ejb.transaction.exception.bean.TestBean; import org.jboss.as.test.integration.transactions.TestXAResource.TestAction; @LocalBean @Remote @Stateless public class CmtEjb3 implements TestBean { @Resource(name = "java:jboss/TransactionManager") private TransactionManager tm; @Override public void throwRuntimeException() { throw new RuntimeException(); } @Override public void throwExceptionFromTm(TxManagerException txManagerException) throws Exception { Transaction txn = tm.getTransaction(); switch (txManagerException) { case HEURISTIC_CAUSED_BY_XA_EXCEPTION: txn.enlistResource(new TimeoutTestXAResource(TestAction.NONE)); txn.enlistResource(new TimeoutTestXAResource(TestAction.COMMIT_THROW_XAER_RMERR)); break; case HEURISTIC_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION: txn.enlistResource(new TimeoutTestXAResource(TestAction.NONE)); txn.enlistResource(new TimeoutTestXAResource(TestAction.COMMIT_THROW_UNKNOWN_XA_EXCEPTION)); break; case ROLLBACK_CAUSED_BY_XA_EXCEPTION: txn.enlistResource(new TimeoutTestXAResource(TestAction.NONE)); txn.enlistResource(new TimeoutTestXAResource(TestAction.PREPARE_THROW_XAER_RMERR)); break; case ROLLBACK_CAUSED_BY_RM_SPECIFIC_XA_EXCEPTION: txn.enlistResource(new TimeoutTestXAResource(TestAction.NONE)); txn.enlistResource(new TimeoutTestXAResource(TestAction.PREPARE_THROW_UNKNOWN_XA_EXCEPTION)); break; default: throw new IllegalArgumentException("Unknown type " + txManagerException); } } }
3,221
40.844156
105
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/exception/bean/ejb2/BmtEjb2.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.ejb.transaction.exception.bean.ejb2; import jakarta.annotation.Resource; import jakarta.ejb.Local; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionManagement; import jakarta.ejb.TransactionManagementType; import jakarta.transaction.NotSupportedException; import jakarta.transaction.SystemException; import jakarta.transaction.UserTransaction; @Local(TestBean2Local.class) @Remote(TestBean2Remote.class) @Stateless @TransactionManagement(TransactionManagementType.BEAN) public class BmtEjb2 { @Resource private UserTransaction utx; public void throwRuntimeException() { try { utx.begin(); throw new RuntimeException(); } catch (NotSupportedException | SystemException e) { throw new IllegalStateException("Can't begin transaction!", e); } } }
1,924
34.648148
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/exception/bean/ejb2/TestBean2Remote.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.ejb.transaction.exception.bean.ejb2; import java.rmi.RemoteException; import jakarta.ejb.EJBObject; public interface TestBean2Remote extends EJBObject { void throwRuntimeException() throws RemoteException; }
1,278
37.757576
74
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/exception/bean/ejb2/CmtEjb2.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.ejb.transaction.exception.bean.ejb2; import jakarta.annotation.Resource; import jakarta.ejb.Local; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; import jakarta.transaction.TransactionManager; @Local(TestBean2Local.class) @Remote(TestBean2Remote.class) @Stateless public class CmtEjb2 { @Resource(name = "java:jboss/TransactionManager") private TransactionManager tm; public void throwRuntimeException() { throw new RuntimeException(); } }
1,541
34.045455
74
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/exception/bean/ejb2/TestBean2Local.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.ejb.transaction.exception.bean.ejb2; import jakarta.ejb.EJBLocalObject; public interface TestBean2Local extends EJBLocalObject { void throwRuntimeException(); }
1,230
38.709677
74
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/methodparams/LocalHome.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.ejb.transaction.methodparams; import jakarta.ejb.EJBLocalHome; public interface LocalHome extends EJBLocalHome { Local create(); }
1,201
36.5625
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/methodparams/Local.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.ejb.transaction.methodparams; import jakarta.ejb.EJBLocalObject; public interface Local extends EJBLocalObject { boolean test(String[] s); boolean test(String s); boolean test(int x); }
1,266
34.194444
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/methodparams/SecondBean.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.ejb.transaction.methodparams; import jakarta.ejb.EJBException; import jakarta.ejb.SessionBean; import jakarta.ejb.SessionContext; public class SecondBean implements SessionBean { public void ejbCreate() { } public void ejbPassivate() { } public void ejbActivate() { } public void ejbRemove() { } public boolean test(String[] s) { return true; } public boolean test(String s) { return true; } public boolean test(int x) { return true; } public void setSessionContext(SessionContext arg0) throws EJBException { } }
1,677
26.064516
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/methodparams/TxMethodParamsTest.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.ejb.transaction.methodparams; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; 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.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class TxMethodParamsTest { @Deployment public static EnterpriseArchive deploy() { return ShrinkWrap.create(EnterpriseArchive.class) .addAsModule( ShrinkWrap.create(JavaArchive.class, "ejbs.jar") .addPackage("org.jboss.as.test.integration.ejb.transaction.methodparams") .addAsManifestResource(TxMethodParamsTest.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml") ); } @Test public void shouldNotThrowNeverNeverContainerTransactionWithoutMethodParams() throws Exception { LocalHome localHome = (LocalHome) new InitialContext().lookup("java:app/ejbs/FirstWithoutParams!org.jboss.as.test.integration.ejb.transaction.methodparams.LocalHome"); assertThat(localHome.create().test(42), is(true)); assertThat(localHome.create().test("Hello World"), is(true)); assertThat(localHome.create().test(new String[0]), is(true)); } @Test public void shouldNotThrowNeverNeverContainerTransactionWithMethodParams() throws Exception { LocalHome localHome = (LocalHome) new InitialContext().lookup("java:app/ejbs/FirstWithParams!org.jboss.as.test.integration.ejb.transaction.methodparams.LocalHome"); assertThat(localHome.create().test(42), is(true)); assertThat(localHome.create().test("Hello World"), is(true)); assertThat(localHome.create().test(new String[0]), is(true)); } }
3,062
45.409091
175
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/methodparams/FirstBean.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.ejb.transaction.methodparams; import jakarta.ejb.EJBException; import jakarta.ejb.SessionBean; import jakarta.ejb.SessionContext; import javax.naming.InitialContext; import javax.naming.NamingException; public class FirstBean implements SessionBean { public void ejbCreate() { } public void ejbPassivate() { } public void ejbActivate() { } public void ejbRemove() { } public boolean test(String[] s) { try { LocalHome localHome = (LocalHome) new InitialContext().lookup("java:comp/env/ejb/Second"); return localHome.create().test(s); } catch (NamingException e) { e.printStackTrace(); return false; } } public boolean test(String s) { try { LocalHome localHome = (LocalHome) new InitialContext().lookup("java:comp/env/ejb/Second"); return localHome.create().test(s); } catch (NamingException e) { e.printStackTrace(); return false; } } public boolean test(int x) { try { LocalHome localHome = (LocalHome) new InitialContext().lookup("java:comp/env/ejb/Second"); return localHome.create().test(x); } catch (NamingException e) { e.printStackTrace(); return false; } } public void setSessionContext(SessionContext arg0) throws EJBException { } }
2,499
29.487805
102
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/descriptor/TransactionRemote.java
package org.jboss.as.test.integration.ejb.transaction.descriptor; import jakarta.ejb.Remote; /** * @author Stuart Douglas */ @Remote public interface TransactionRemote { int transactionStatus(); int transactionStatus2(); }
237
14.866667
65
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/descriptor/DescriptorBean.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.ejb.transaction.descriptor; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import jakarta.transaction.SystemException; import jakarta.transaction.TransactionManager; /** * @author Stuart Douglas */ @Stateless public class DescriptorBean implements TransactionLocal, TransactionRemote { @Resource(lookup="java:jboss/TransactionManager") private TransactionManager transactionManager; @Override public int transactionStatus() { try { return transactionManager.getStatus(); } catch (SystemException e) { throw new RuntimeException(e); } } @Override public int transactionStatus2() { try { return transactionManager.getStatus(); } catch (SystemException e) { throw new RuntimeException(e); } } }
1,900
32.946429
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/descriptor/EjbTransactionTypeOverrideTestCase.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.ejb.transaction.descriptor; import javax.naming.InitialContext; import javax.naming.NamingException; import jakarta.transaction.NotSupportedException; import jakarta.transaction.Status; import jakarta.transaction.SystemException; 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; /** * Tests for override transaction type for method through ejb-jar.xml. * Bugzilla 1180556 https://bugzilla.redhat.com/show_bug.cgi?id=1180556 * @author Hynek Svabek * */ @RunWith(Arquillian.class) public class EjbTransactionTypeOverrideTestCase { @ArquillianResource private InitialContext initialContext; @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test-tx-override-descriptor.jar"); jar.addPackage(EjbTransactionDescriptorTestCase.class.getPackage()); jar.addAsManifestResource(EjbTransactionDescriptorTestCase.class.getPackage(), "ejb-jar-override.xml", "ejb-jar.xml"); return jar; } @Test public void testOverrideSupportToRequiredThroughtEjbJarXml() throws SystemException, NotSupportedException, NamingException { final TransactionLocal bean = (TransactionLocal) initialContext.lookup("java:module/" + DescriptorBean.class.getSimpleName() + "!" + TransactionLocal.class.getName()); Assert.assertEquals(Status.STATUS_NO_TRANSACTION, bean.transactionStatus()); Assert.assertEquals(Status.STATUS_ACTIVE, bean.transactionStatus2()); } }
2,863
41.117647
175
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/descriptor/EjbTransactionDescriptorTestCase.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.ejb.transaction.descriptor; import jakarta.ejb.EJBException; import jakarta.ejb.EJBTransactionRequiredException; import javax.naming.InitialContext; import javax.naming.NamingException; import jakarta.transaction.NotSupportedException; import jakarta.transaction.Status; import jakarta.transaction.SystemException; import jakarta.transaction.UserTransaction; 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; /** * Tests that is is possible to set a different transaction type from local and remote interfaces * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class EjbTransactionDescriptorTestCase { @ArquillianResource private InitialContext initialContext; @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test-tx-descriptor.jar"); jar.addPackage(EjbTransactionDescriptorTestCase.class.getPackage()); jar.addAsManifestResource(EjbTransactionDescriptorTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml"); return jar; } @Test public void testLocalMethodHasNever() throws SystemException, NotSupportedException, NamingException { final UserTransaction userTransaction = (UserTransaction)new InitialContext().lookup("java:jboss/UserTransaction"); final TransactionLocal bean = (TransactionLocal) initialContext.lookup("java:module/" + DescriptorBean.class.getSimpleName() + "!" + TransactionLocal.class.getName()); Assert.assertEquals(Status.STATUS_NO_TRANSACTION, bean.transactionStatus()); try { userTransaction.begin(); bean.transactionStatus(); throw new RuntimeException("Expected an exception"); } catch (EJBException e) { //ignore } finally { userTransaction.rollback(); } } @Test public void testRemoteMethodHasMandatory() throws SystemException, NotSupportedException, NamingException { final UserTransaction userTransaction = (UserTransaction)new InitialContext().lookup("java:jboss/UserTransaction"); final TransactionRemote bean = (TransactionRemote) initialContext.lookup("java:module/" + DescriptorBean.class.getSimpleName() + "!" + TransactionRemote.class.getName()); userTransaction.begin(); try { Assert.assertEquals(Status.STATUS_ACTIVE, bean.transactionStatus()); } finally { userTransaction.rollback(); } try { bean.transactionStatus(); throw new RuntimeException("Expected an exception"); } catch (EJBTransactionRequiredException e) { //ignore } } @Test public void testRemoteMethodHasMandatoryNoMethodIntf() throws SystemException, NotSupportedException, NamingException { final UserTransaction userTransaction = (UserTransaction)new InitialContext().lookup("java:jboss/UserTransaction"); final TransactionRemote bean = (TransactionRemote) initialContext.lookup("java:module/" + DescriptorBean.class.getSimpleName() + "!" + TransactionRemote.class.getName()); userTransaction.begin(); try { Assert.assertEquals(Status.STATUS_ACTIVE, bean.transactionStatus2()); } finally { userTransaction.rollback(); } try { bean.transactionStatus2(); throw new RuntimeException("Expected an exception"); } catch (EJBTransactionRequiredException e) { //ignore } } }
4,911
41.344828
178
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/descriptor/TransactionLocal.java
package org.jboss.as.test.integration.ejb.transaction.descriptor; import jakarta.ejb.Local; /** * @author Stuart Douglas */ @Local public interface TransactionLocal { int transactionStatus(); int transactionStatus2(); }
236
12.941176
65
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/never/NeverSFSB.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.ejb.transaction.cmt.never; import jakarta.ejb.Stateful; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; /** * @author Stuart Douglas */ @Stateful public class NeverSFSB { @TransactionAttribute(TransactionAttributeType.NEVER) public Long[] doStuff(String[] stuff, String value, long anotherValue) { return null; } }
1,433
34.85
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/never/NeverTransactionTestCase.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.ejb.transaction.cmt.never; 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.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; import jakarta.ejb.EJBException; import jakarta.inject.Inject; import jakarta.transaction.NotSupportedException; import jakarta.transaction.SystemException; import jakarta.transaction.UserTransaction; /** * Test that makes sure a SFSB is not discarded if the transaction * interceptor throws an exception. * * This test also verifies that Jandex handles methods with arrays in their signature correctly (see AS7-1697) * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class NeverTransactionTestCase { @Inject private UserTransaction userTransaction; @Inject private NeverSFSB sfsb; @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, "test-never.war"); war.addPackage(NeverTransactionTestCase.class.getPackage()); war.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); return war; } @Test public void testExceptionThrown() throws SystemException, NotSupportedException { sfsb.doStuff(new String[0],"",0); userTransaction.begin(); try { sfsb.doStuff(new String[0],"",0); throw new RuntimeException("Expected exception when calling NEVER method with an active transaction"); } catch (EJBException e) { } userTransaction.rollback(); } }
2,779
34.641026
114
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/inheritance/TransactionAttributeTestCase.java
/* Copyright 2017 Red Hat, Inc. 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.ejb.transaction.cmt.inheritance; import jakarta.annotation.Resource; import jakarta.ejb.EJB; import jakarta.ejb.EJBException; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; import jakarta.transaction.Transaction; import jakarta.transaction.TransactionManager; 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.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * <p> * Test checking behavior of {@link TransactionAttribute} when inherited * by child classes. * <p> * <b>8.3.7.1</b> Specification of Transaction Attributes with Metadata Annotations<br> * If the bean class has superclasses, the following additional rules apply. * <ul> * <li>A transaction attribute specified on a superclass S applies to the business methods defined by * S. If a class-level transaction attribute is not specified on S, it is equivalent to specification of * TransactionAttribute(REQUIRED) on S.</li> * <li>A transaction attribute may be specified on a business method M defined by class S to override * for method M the transaction attribute value explicitly or implicitly specified on the class S.</li> * <li>If a method M of class S overrides a business method defined by a superclass of S, the transaction * attribute of M is determined by the above rules as applied to class S.</li> * </ul> * * @author Ondrej Chaloupka <[email protected]> */ @RunWith(Arquillian.class) public class TransactionAttributeTestCase { @Resource(lookup = "java:/TransactionManager") private TransactionManager tm; @EJB private SuperSLSB superClass; @EJB private ChildSLSB childClass; @EJB private ChildWithClassAnnotationSLSB childWithClassAnnotation; @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, "transaction-attribute-inheritance.war"); war.addPackage(TransactionAttributeTestCase.class.getPackage()); war.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); return war; } @Test public void superClassCheck() throws Exception { tm.begin(); try { // active transaction superClass.aMethod(); superClass.bMethod(); superClass.cMethod(); } finally { tm.rollback(); } tm.begin(); try { // active transaction superClass.neverMethod(); Assert.fail("TransactionAttribute.NEVER expects failure when running" + " within a transactional context of txn: '" + tm.getTransaction() + "'"); } catch (EJBException ignoreAsExpected) { } finally { tm.rollback(); } // no active transaction superClass.aMethod(); superClass.bMethod(); superClass.cMethod(); superClass.neverMethod(); } /** * Tests expects behavior of {@link TransactionAttributeType#REQUIRED} */ @Test public void defaultBeanAttributeOverridesParentClassDeclaration() throws Exception { tm.begin(); Transaction testTxn = tm.getTransaction(); try { // active transaction Transaction beanTxn = childClass.aMethod(); Assert.assertNotNull("There has to be started a transaction in the bean", beanTxn); Assert.assertEquals("Child method default REQUIRED TransactionAttribute" + " has to override the settings of SUPPORTS from super class", testTxn, beanTxn); } finally { tm.rollback(); } // no active transaction Transaction beanTxn = childClass.aMethod(); Assert.assertNotNull("There has to be started transaction in bean as TransactionAttribute" + " should be REQUIRED", beanTxn); } /** * Tests expects behavior of {@link TransactionAttributeType#SUPPORTS} */ @Test public void inheritsWhenMethodCalledFromParent() throws Exception { tm.begin(); try { // active transaction childClass.bMethod(); } finally { tm.rollback(); } // no active transaction Assert.assertNull("There can't be active transaction here", tm.getTransaction()); childClass.bMethod(); } /** * Tests expects behavior of {@link TransactionAttributeType#MANDATORY} */ @Test public void explicitMethodAttributeOverrides() throws Exception { tm.begin(); try { // active transaction childClass.cMethod(); } finally { tm.rollback(); } try { // no active transaction Assert.assertNull("There can't be active transaction here", tm.getTransaction()); childClass.cMethod(); Assert.fail("Method called with no active transaction but MANDATORY requires it"); } catch (EJBException ignoreAsExpected) { } } /** * Tests expects behavior of {@link TransactionAttributeType#REQUIRED} */ @Test public void defaultBeanAttributeOverridesParentMethodDeclaration() throws Exception { tm.begin(); Transaction testTxn = tm.getTransaction(); try { // active transaction Transaction beanTxn = childClass.neverMethod(); Assert.assertNotNull("There has to be started a transaction in the bean", beanTxn); Assert.assertEquals("Child method default REQUIRED TransactionAttribute" + " has to override the settings of SUPPORTS from super class", testTxn, beanTxn); } finally { tm.rollback(); } // no active transaction Assert.assertNull("There can't be active transaction here", tm.getTransaction()); Transaction beanTxn = childClass.neverMethod(); Assert.assertNotNull("There has to be started a transaction in the bean " + "as TransactionAttribute is REQUIRED", beanTxn); } /** * Tests expects behavior of {@link TransactionAttributeType#NEVER} */ @Test public void classAnnotationOverridesParentDeclaration() throws Exception { tm.begin(); try { // active transaction childWithClassAnnotation.aMethod(); Assert.fail("TransactionAttribute.NEVER expects failure when running" + " within a transactional context of txn: '" + tm.getTransaction() + "'"); } catch (EJBException ignoreAsExpected) { } finally { tm.rollback(); } // no active transaction Assert.assertNull("There can't be active transaction here", tm.getTransaction()); childWithClassAnnotation.aMethod(); } /** * Tests expects behavior of {@link TransactionAttributeType#SUPPORTS} */ @Test public void inheritsWhenMethodCalledFromParentWithChildClassLevelAnnotation() throws Exception { tm.begin(); try { // active transaction childClass.bMethod(); } finally { tm.rollback(); } // no active transaction Assert.assertNull("There can't be active transaction here", tm.getTransaction()); childClass.bMethod(); } }
8,188
33.995726
107
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/inheritance/ChildWithClassAnnotationSLSB.java
/* Copyright 2017 Red Hat, Inc. 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.ejb.transaction.cmt.inheritance; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; import jakarta.transaction.Transaction; import org.jboss.logging.Logger; /** * Child class defining {@link TransactionAttribute} at level * of class. * * @author Ondrej Chaloupka <[email protected]> */ @Stateless @TransactionAttribute(TransactionAttributeType.NEVER) public class ChildWithClassAnnotationSLSB extends SuperSLSB { private static final Logger log = Logger.getLogger(ChildWithClassAnnotationSLSB.class); /** * {@link TransactionAttribute} of the method should be NEVER. */ @Override public Transaction aMethod() { log.trace(this.getClass().getName() + ".aMethod called "); return getTransaction(); } /** * {@link TransactionAttribute} of the method inherited from super class * should be SUPPORTS. */ // bMethod() call }
1,560
29.607843
91
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/inheritance/ChildSLSB.java
/* Copyright 2017 Red Hat, Inc. 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.ejb.transaction.cmt.inheritance; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; import jakarta.transaction.Transaction; import org.jboss.logging.Logger; /** * Bean which shape is based on ejb spec <code>class ABean</code> * from chapter <pre>8.3.7.1Specification of Transaction Attributes * with Metadata Annotations</pre> * * @author Ondrej Chaloupka <[email protected]> */ @Stateless public class ChildSLSB extends SuperSLSB { private static final Logger log = Logger.getLogger(ChildSLSB.class); /** * {@link TransactionAttribute} of the method should be REQUIRED. */ @Override public Transaction aMethod() { log.trace(this.getClass().getName() + ".aMethod called "); return getTransaction(); } /** * {@link TransactionAttribute} of the method inherited from super class * should be SUPPORTS. */ // bMethod() call /** * {@link TransactionAttribute} of the method should be MANDATORY. */ @TransactionAttribute(TransactionAttributeType.MANDATORY) @Override public Transaction cMethod() { log.trace(this.getClass().getName() + ".cMethod called "); return getTransaction(); } /** * {@link TransactionAttribute} of the method should be REQUIRED. */ @Override public Transaction neverMethod() { log.trace(this.getClass().getName() + ".neverMethod called "); return getTransaction(); } }
2,121
28.887324
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/inheritance/SuperSLSB.java
/* Copyright 2017 Red Hat, Inc. 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.ejb.transaction.cmt.inheritance; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; import jakarta.transaction.SystemException; import jakarta.transaction.Transaction; import jakarta.transaction.TransactionManager; import org.jboss.logging.Logger; /** * Parent bean which shape is based on ejb spec <code>class SomeClass</code> * from chapter <pre>8.3.7.1Specification of Transaction Attributes * with Metadata Annotations</pre> * * @author Ondrej Chaloupka <[email protected]> */ @Stateless @TransactionAttribute(TransactionAttributeType.SUPPORTS) public class SuperSLSB { private static final Logger log = Logger.getLogger(SuperSLSB.class); @Resource(lookup = "java:/TransactionManager") protected TransactionManager tm; public Transaction aMethod() { log.trace(this.getClass().getName() + ".aMethod called "); return getTransaction(); } public Transaction bMethod() { log.trace(this.getClass().getName() + ".bMethod called "); return getTransaction(); } public Transaction cMethod() { log.trace(this.getClass().getName() + ".cMethod called "); return getTransaction(); } @TransactionAttribute(TransactionAttributeType.NEVER) public Transaction neverMethod() { log.trace(this.getClass().getName() + ".neverMethod called "); return getTransaction(); } protected Transaction getTransaction() { try { return tm.getTransaction(); } catch (SystemException se) { throw new IllegalStateException("Can't get transaction from tm '" + tm + "'"); } } }
2,343
30.675676
77
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/mandatory/SFSBMandatoryTransactionTestCase.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.ejb.transaction.cmt.mandatory; import jakarta.ejb.EJBTransactionRequiredException; import jakarta.inject.Inject; import jakarta.transaction.NotSupportedException; import jakarta.transaction.SystemException; import jakarta.transaction.UserTransaction; 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.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Test that makes sure a SFSB is not discarded if the transaction * interceptor throws an exception. * @author Stuart Douglas */ @RunWith(Arquillian.class) public class SFSBMandatoryTransactionTestCase { @Inject private UserTransaction userTransaction; @Inject private MandatorySFSB sfsb; @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, "test-mandatory.war"); war.addPackage(SFSBMandatoryTransactionTestCase.class.getPackage()); war.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); return war; } @Test public void testSFSBNotDestroyed() throws SystemException, NotSupportedException { try { sfsb.doStuff(); throw new RuntimeException("Expected an EJBTransactionRequiredException"); } catch (EJBTransactionRequiredException e) { //ignore } userTransaction.begin(); sfsb.doStuff(); userTransaction.rollback(); } }
2,685
34.813333
86
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/mandatory/MandatorySFSB.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.ejb.transaction.cmt.mandatory; import jakarta.ejb.Stateful; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; /** * @author Stuart Douglas */ @Stateful @TransactionAttribute(TransactionAttributeType.MANDATORY) public class MandatorySFSB { public void doStuff() { } }
1,372
33.325
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/timeout/DefaultTransactionTimeoutTestCase.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.ejb.transaction.cmt.timeout; 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; import static org.junit.Assert.assertEquals; /** */ @RunWith(Arquillian.class) public class DefaultTransactionTimeoutTestCase { @Deployment public static Archive<?> createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test-ejb-cmt-timeout.jar"); jar.addClass(BeanWithTimeoutValue.class); jar.addClass(TimeoutRemoteView.class); jar.addClass(TimeoutLocalView.class); jar.addAsManifestResource(DefaultTransactionTimeoutTestCase.class.getPackage(), "jboss-ejb3-default-timeout.xml", "jboss-ejb3.xml"); return jar; } @Test public void testDescriptor() throws Exception { final TimeoutLocalView localView = (TimeoutLocalView) new InitialContext().lookup("java:module/DDBeanWithTimeoutValue!" + TimeoutLocalView.class.getName()); assertEquals(10, localView.getLocalViewTimeout()); } }
2,328
40.589286
164
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/timeout/TimeoutLocalView.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.ejb.transaction.cmt.timeout; import jakarta.ejb.Local; @Local public interface TimeoutLocalView { int getLocalViewTimeout(); }
1,199
37.709677
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/timeout/TimeoutRemoteView.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.ejb.transaction.cmt.timeout; import jakarta.ejb.Remote; @Remote public interface TimeoutRemoteView { int getBeanTimeout(); int getBeanMethodTimeout(); int getRemoteMethodTimeout(); }
1,265
35.171429
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/timeout/TransactionTimeoutTestCase.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.ejb.transaction.cmt.timeout; import static org.junit.Assert.assertEquals; import javax.naming.InitialContext; import jakarta.transaction.TransactionManager; 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; import org.wildfly.transaction.client.ContextTransactionManager; /** */ @RunWith(Arquillian.class) public class TransactionTimeoutTestCase { @Deployment public static Archive<?> createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test-ejb-cmt-timeout.jar"); jar.addClass(BeanWithTimeoutValue.class); jar.addClass(TimeoutRemoteView.class); jar.addClass(TimeoutLocalView.class); jar.addAsManifestResource(TransactionTimeoutTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml"); jar.addAsManifestResource(TransactionTimeoutTestCase.class.getPackage(), "jboss.properties", "jboss.properties"); return jar; } /** */ @Test public void testBeanTimeouts() throws Exception { TimeoutRemoteView remoteView = (TimeoutRemoteView) (new InitialContext() .lookup("java:module/BeanWithTimeoutValue!org.jboss.as.test.integration.ejb.transaction.cmt.timeout.TimeoutRemoteView")); TimeoutLocalView localView = (TimeoutLocalView) (new InitialContext() .lookup("java:module/BeanWithTimeoutValue!org.jboss.as.test.integration.ejb.transaction.cmt.timeout.TimeoutLocalView")); long timeoutValue = -1; timeoutValue = (long) remoteView.getBeanTimeout(); Assert.assertEquals("Bean-level timeout failed", 5L, timeoutValue); timeoutValue = (long) remoteView.getBeanMethodTimeout(); Assert.assertEquals("Bean-method timeout failed", 6L, timeoutValue); timeoutValue = (long) remoteView.getRemoteMethodTimeout(); Assert.assertEquals("Remote-method timeout failed", 7L, timeoutValue); timeoutValue = (long) localView.getLocalViewTimeout(); Assert.assertEquals("Local-view timeout failed", 5L, timeoutValue); } @Test public void testDescriptor() throws Exception { final TimeoutLocalView localView = (TimeoutLocalView) new InitialContext() .lookup("java:module/DDBeanWithTimeoutValue!" + TimeoutLocalView.class.getName()); assertEquals(10, localView.getLocalViewTimeout()); } @Test public void testDescriptorWithNestedExpressions() throws Exception { final TimeoutLocalView localView = (TimeoutLocalView) new InitialContext() .lookup("java:module/DDBeanWithTimeoutValueUsingNestedExpression!" + TimeoutLocalView.class .getName()); assertEquals(90, localView.getLocalViewTimeout()); } @Test public void threadStoringTimeout() throws Exception { TimeoutLocalView localView = (TimeoutLocalView) (new InitialContext() .lookup("java:module/BeanWithTimeoutValue!org.jboss.as.test.integration.ejb.transaction.cmt.timeout.TimeoutLocalView")); TransactionManager tm = (TransactionManager) new InitialContext().lookup("java:/TransactionManager"); int transactionTimeoutToSet = 42; tm.setTransactionTimeout(transactionTimeoutToSet); Assert.assertEquals("Expecting transaction timeout has to be the same as it was written by setter", transactionTimeoutToSet, getTransactionTimeout(tm)); localView.getLocalViewTimeout(); Assert.assertEquals("The transaction timeout has to be the same as before CMT call", transactionTimeoutToSet, getTransactionTimeout(tm)); } private int getTransactionTimeout(TransactionManager tmTimeout) { if (tmTimeout instanceof ContextTransactionManager) { return ((ContextTransactionManager) tmTimeout).getTransactionTimeout(); } throw new IllegalStateException("Cannot get transaction timeout"); } }
5,284
44.560345
137
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/timeout/BeanWithTimeoutValue.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.ejb.transaction.cmt.timeout; import java.util.concurrent.TimeUnit; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import jakarta.transaction.TransactionManager; import org.jboss.ejb3.annotation.TransactionTimeout; import org.wildfly.transaction.client.LocalTransaction; @Stateless @TransactionTimeout(value=5, unit=TimeUnit.SECONDS) public class BeanWithTimeoutValue implements TimeoutRemoteView, TimeoutLocalView { @Resource(lookup="java:jboss/TransactionManager") private TransactionManager transactionManager; protected int getTimeout() { try { return ((LocalTransaction) transactionManager.getTransaction()).getTransactionTimeout(); } catch (Exception e) { return -1; } } /** * This method should inherit transaction timeout specified on bean-level */ public int getBeanTimeout() { return getTimeout(); } /** * This method has explicity transaction timeout in bean-class */ @TransactionTimeout(value=6, unit=TimeUnit.SECONDS) public int getBeanMethodTimeout() { return getTimeout(); } /** * This method has method-level timeout specified on remote-view */ @TransactionTimeout(value=7, unit=TimeUnit.SECONDS) public int getRemoteMethodTimeout() { return getTimeout(); } /** * This method has timeout specified on entire local view */ public int getLocalViewTimeout() { return getTimeout(); } }
2,591
31.810127
100
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/beforecompletion/BeforeCompletionSFSB.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.ejb.transaction.cmt.beforecompletion; import jakarta.ejb.BeforeCompletion; import jakarta.ejb.Stateful; /** * * @author Stuart Douglas */ @Stateful public class BeforeCompletionSFSB { @BeforeCompletion public void beforeCompletion() { throw new RuntimeException("failed @BeforeCompletion"); } public void enlist() { } }
1,411
31.090909
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/beforecompletion/BeforeCompletionExceptionDestroysBeanTestCase.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.ejb.transaction.cmt.beforecompletion; import jakarta.ejb.NoSuchEJBException; import javax.naming.InitialContext; import javax.naming.NamingException; import jakarta.transaction.HeuristicMixedException; import jakarta.transaction.HeuristicRollbackException; import jakarta.transaction.NotSupportedException; import jakarta.transaction.RollbackException; import jakarta.transaction.SystemException; import jakarta.transaction.UserTransaction; 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.Test; import org.junit.runner.RunWith; /** * Test that ensures that a SFSB is destroyed if an exception is thrown by it's @BeforeCompletion method * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class BeforeCompletionExceptionDestroysBeanTestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, "test-beforecompletion.war"); war.addPackage(BeforeCompletionExceptionDestroysBeanTestCase.class.getPackage()); return war; } @Test public void testExceptionInBeforeCompletionDestroysBean() throws NamingException, SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException { final UserTransaction userTransaction = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction"); final BeforeCompletionSFSB bean = (BeforeCompletionSFSB) new InitialContext().lookup("java:module/" + BeforeCompletionSFSB.class.getSimpleName()); //begin a transaction userTransaction.begin(); bean.enlist(); //commit, this should destroy the bean, as it's @BeforeCompletion method will throw an exception try { userTransaction.commit(); } catch (RollbackException expected ) { } try { userTransaction.begin(); bean.enlist(); throw new RuntimeException("Expected SFSB to be destroyed"); } catch (NoSuchEJBException expected) { } finally { userTransaction.rollback(); } } }
3,340
39.253012
180
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/fail/TransactionFirstPhaseErrorTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018 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.ejb.transaction.cmt.fail; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.util.PropertyPermission; import jakarta.ejb.EJBException; import jakarta.inject.Inject; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.transaction.xa.XAResource; 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.test.integration.transactions.TransactionCheckerSingleton; import org.jboss.as.test.integration.transactions.RemoteLookups; import org.jboss.as.test.integration.transactions.TxTestUtil; import org.jboss.as.test.integration.transactions.spi.TestLastResource; 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.JavaArchive; import org.jboss.tm.LastResource; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; /** * Test of behavior when one phase commit is used. */ @RunWith(Arquillian.class) public class TransactionFirstPhaseErrorTestCase { @ArquillianResource private InitialContext initCtx; @Inject private TransactionCheckerSingleton checker; @Deployment public static Archive<?> createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test-txn-one-phase.jar") .addPackage(TxTestUtil.class.getPackage()) .addClass(TestLastResource.class) .addClasses(InnerBean.class, OuterBean.class) .addAsManifestResource(new StringAsset("Dependencies: org.jboss.jboss-transaction-spi \n"), "MANIFEST.MF") // grant necessary permissions for -Dsecurity.manager .addAsResource(createPermissionsXmlAsset( new PropertyPermission("ts.timeout.factor", "read")), "META-INF/jboss-permissions.xml"); return jar; } @Before public void startUp() throws NamingException { checker.resetAll(); } /** * Using {@link XAResource} which fails with <code>XAResource.XAER_RMFAIL</code> * during commit.<br> * Expecting the error will be propagated to the caller. */ @Test public void xaOnePhaseCommitFail() throws Exception { OuterBean bean = RemoteLookups.lookupModule(initCtx, OuterBean.class); try { bean.outerMethodXA(); Assert.fail("Expecting the one phase commit failed and exception was propagated to the caller."); } catch (EJBException expected) { Assert.assertTrue("Expecting on RMFAIL to get unknown state of the transaction outcome - ie. HeuristicMixedException", expected.getCause() != null && expected.getCause().getClass().equals(jakarta.transaction.HeuristicMixedException.class)); } } /** * Using two {@link XAResource}s where the first one fails with <code>XAResource.XAER_RMFAIL</code> * during commit.<br> * Expecting the no error will be thrown as 2PC prepare phase finished and rmfail says * that recovery manager should retry the commit later. */ @Test public void xaTwoPhaseCommitFail() throws Exception { OuterBean bean = RemoteLookups.lookupModule(initCtx, OuterBean.class); bean.outerMethod2pcXA(); } /** * Using {@link XAResource} where optimization for {@link LastResource} is used. * The commit call fails with <code>XAResource.XAER_RMFAIL</code><br> * Expecting the error will be propagated to the caller. */ @Test public void localOnePhaseCommitFail() throws Exception { OuterBean bean = RemoteLookups.lookupModule(initCtx, OuterBean.class); try { bean.outerMethodLocal(); Assert.fail("Expecting the one phase commit failed and exception was propagated to the caller."); } catch (EJBException expected) { Assert.assertTrue("Expecting on RMFAIL to get unknown state of the transaction outcome - ie. HeuristicMixedException", expected.getCause() != null && expected.getCause().getClass().equals(jakarta.transaction.HeuristicMixedException.class)); } } }
5,388
41.101563
141
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/fail/InnerBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018 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.ejb.transaction.cmt.fail; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; import jakarta.inject.Inject; import jakarta.transaction.SystemException; import jakarta.transaction.TransactionManager; import org.jboss.as.test.integration.transactions.spi.TestLastResource; import org.jboss.as.test.integration.transactions.TestXAResource; import org.jboss.as.test.integration.transactions.TransactionCheckerSingleton; import org.jboss.as.test.integration.transactions.TxTestUtil; @Stateless @TransactionAttribute(TransactionAttributeType.REQUIRED) public class InnerBean { @Inject private TransactionCheckerSingleton checker; @Resource(name = "java:jboss/TransactionManager") private TransactionManager tm; public void innerMethodXA() { try { TestXAResource xaResource = new TestXAResource(TestXAResource.TestAction.COMMIT_THROW_XAER_RMFAIL, checker); TxTestUtil.enlistTestXAResource(tm.getTransaction(), xaResource); } catch (SystemException se) { throw new IllegalStateException("Can't get transaction from transaction manager: " + tm); } } public void innerMethod2pcXA() { try { TestXAResource xaResource1 = new TestXAResource(TestXAResource.TestAction.COMMIT_THROW_XAER_RMFAIL, checker); TestXAResource xaResource2 = new TestXAResource(checker); TxTestUtil.enlistTestXAResource(tm.getTransaction(), xaResource1); TxTestUtil.enlistTestXAResource(tm.getTransaction(), xaResource2); } catch (SystemException se) { throw new IllegalStateException("Can't get transaction from transaction manager: " + tm); } } public void innerMethodLocal() { try { TestXAResource xaResource = new TestLastResource(TestXAResource.TestAction.COMMIT_THROW_XAER_RMFAIL, checker); TxTestUtil.enlistTestXAResource(tm.getTransaction(), xaResource); } catch (SystemException se) { throw new IllegalStateException("Can't get transaction from transaction manager: " + tm); } } }
3,265
40.341772
122
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/fail/OuterBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018 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.ejb.transaction.cmt.fail; import jakarta.ejb.EJB; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; @Stateless @TransactionAttribute(TransactionAttributeType.NEVER) public class OuterBean { @EJB InnerBean innerBean; public void outerMethodXA() { innerBean.innerMethodXA(); } public void outerMethod2pcXA() { innerBean.innerMethod2pcXA(); } public void outerMethodLocal() { innerBean.innerMethodLocal(); } }
1,592
32.1875
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/lifecycle/StatefulRequiresNewLifecycleBean.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 * 2110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.transaction.cmt.lifecycle; import jakarta.annotation.PostConstruct; import jakarta.ejb.Stateful; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; @Stateful public class StatefulRequiresNewLifecycleBean extends LifecycleSuperClass { @PostConstruct @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) private void postConstruct() { saveTxState(); } }
1,488
36.225
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/lifecycle/StatelessRequired2LifecycleBean.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.ejb.transaction.cmt.lifecycle; import jakarta.annotation.PostConstruct; import jakarta.ejb.Stateless; @Stateless public class StatelessRequired2LifecycleBean extends LifecycleSuperClass { @PostConstruct public void postConstruct() { saveTxState(); } }
1,338
35.189189
74
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/lifecycle/StatelessRequiredLifecycleBean.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.ejb.transaction.cmt.lifecycle; import jakarta.annotation.PostConstruct; import jakarta.ejb.Stateless; @Stateless public class StatelessRequiredLifecycleBean extends LifecycleSuperClass { @PostConstruct public void postConstruct() { saveTxState(); } }
1,337
35.162162
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/lifecycle/LifecycleSuperClass.java
package org.jboss.as.test.integration.ejb.transaction.cmt.lifecycle; import jakarta.annotation.Resource; import jakarta.transaction.TransactionSynchronizationRegistry; /** * @author Stuart Douglas */ public class LifecycleSuperClass { @Resource protected TransactionSynchronizationRegistry trs; int state; Object key; protected void saveTxState() { state = trs.getTransactionStatus(); key = trs.getTransactionKey(); } public int getState() { return state; } public Object getKey() { return key; } }
580
18.366667
68
java