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/transaction/cmt/lifecycle/LifecycleMethodTransactionManagementTestCase.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 javax.naming.InitialContext; import javax.naming.NamingException; import jakarta.transaction.NotSupportedException; import jakarta.transaction.Status; import jakarta.transaction.SystemException; import jakarta.transaction.TransactionSynchronizationRegistry; import jakarta.transaction.UserTransaction; import org.junit.Assert; 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; /** * tests the transactional behaviour of EJB lifecycle methods */ @RunWith(Arquillian.class) public class LifecycleMethodTransactionManagementTestCase { @Deployment public static Archive<?> createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejbLifecycleAnnotations.jar"); jar.addPackage(LifecycleMethodTransactionManagementTestCase.class.getPackage()); return jar; } @Test public void testDefaultRequired() throws NamingException { StatelessRequired2LifecycleBean required = (StatelessRequired2LifecycleBean)new InitialContext().lookup("java:module/StatelessRequired2LifecycleBean"); Assert.assertEquals(Status.STATUS_ACTIVE, required.getState()); } @Test public void testStatelessRequiredAsRequiresNew() throws SystemException, NotSupportedException, NamingException { UserTransaction userTransaction = (UserTransaction) new InitialContext().lookup("java:jboss/UserTransaction"); TransactionSynchronizationRegistry tsr = (TransactionSynchronizationRegistry) new InitialContext().lookup("java:jboss/TransactionSynchronizationRegistry"); userTransaction.begin(); StatelessRequiredLifecycleBean required = (StatelessRequiredLifecycleBean)new InitialContext().lookup("java:module/StatelessRequiredLifecycleBean"); try { Object key = tsr.getTransactionKey(); Assert.assertNotSame(key, required.getKey()); Assert.assertEquals(Status.STATUS_ACTIVE, required.getState()); } finally { userTransaction.rollback(); } } @Test public void testNeverRequired() throws SystemException, NotSupportedException, NamingException { UserTransaction userTransaction = (UserTransaction) new InitialContext().lookup("java:jboss/UserTransaction"); userTransaction.begin(); StatelessNeverLifecycleBean never = (StatelessNeverLifecycleBean)new InitialContext().lookup("java:module/StatelessNeverLifecycleBean"); try { Assert.assertEquals(Status.STATUS_NO_TRANSACTION, never.getState()); } finally { userTransaction.rollback(); } } @Test public void testStatefulRequiresNew() throws SystemException, NotSupportedException, NamingException { UserTransaction userTransaction = (UserTransaction) new InitialContext().lookup("java:jboss/UserTransaction"); TransactionSynchronizationRegistry tsr = (TransactionSynchronizationRegistry) new InitialContext().lookup("java:jboss/TransactionSynchronizationRegistry"); userTransaction.begin(); StatefulRequiresNewLifecycleBean required = (StatefulRequiresNewLifecycleBean)new InitialContext().lookup("java:module/StatefulRequiresNewLifecycleBean"); try { Object key = tsr.getTransactionKey(); Assert.assertNotSame(key, required.getKey()); Assert.assertEquals(Status.STATUS_ACTIVE, required.getState()); } finally { userTransaction.rollback(); } } }
4,808
45.240385
163
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/cmt/lifecycle/StatelessNeverLifecycleBean.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; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; @Stateless public class StatelessNeverLifecycleBean extends LifecycleSuperClass { @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) @PostConstruct public void postConstruct() { saveTxState(); } }
1,486
36.175
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/mdb/timeout/AnnotationTimeoutMDB.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.mdb.timeout; import java.util.concurrent.TimeUnit; import jakarta.annotation.Resource; import jakarta.ejb.ActivationConfigProperty; import jakarta.ejb.MessageDriven; import jakarta.ejb.TransactionAttribute; import jakarta.inject.Inject; import jakarta.jms.ConnectionFactory; import jakarta.jms.Destination; import jakarta.jms.JMSContext; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.jms.TextMessage; import jakarta.transaction.TransactionManager; import org.jboss.ejb3.annotation.TransactionTimeout; import org.jboss.logging.Logger; import org.jboss.as.test.integration.transactions.TransactionCheckerSingleton; import org.jboss.as.test.integration.transactions.TxTestUtil; /** * <p> * It's expected that {@link TransactionTimeout} annotation does not work for MDB * with {@link TransactionAttribute} set as REQUIRED because transaction is already started * at time of calling onMessage method and as such timeout can't be changed at that time * (can't change timeout of already started txn). * <p> * In other words, using {@link TransactionTimeout} does not change transaction timeout * for this bean. */ @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destination", propertyValue = TransactionTimeoutQueueSetupTask.ANNOTATION_TIMEOUT_JNDI_NAME) }) @TransactionTimeout(value = 1, unit = TimeUnit.SECONDS) public class AnnotationTimeoutMDB implements MessageListener { private static final Logger log = Logger.getLogger(AnnotationTimeoutMDB.class); public static final String REPLY_PREFIX = "replying "; @Resource(lookup = "java:/JmsXA") private ConnectionFactory factory; @Resource(name = "java:jboss/TransactionManager") private TransactionManager tm; @Inject private TransactionCheckerSingleton checker; @Override public void onMessage(Message message) { try { log.tracef("onMessage received message: %s '%s'", message, ((TextMessage) message).getText()); final Destination replyTo = message.getJMSReplyTo(); if (replyTo == null) { throw new RuntimeException("ReplyTo info in message was not specified" + " and bean does not know where to reply to"); } TxTestUtil.enlistTestXAResource(tm.getTransaction(), checker); try ( JMSContext context = factory.createContext() ) { context.createProducer() .setJMSCorrelationID(message.getJMSMessageID()) .send(replyTo, REPLY_PREFIX + ((TextMessage) message).getText()); } // would timeout txn when TransactionTimeout be cared TxTestUtil.waitForTimeout(tm); } catch (Exception e) { throw new RuntimeException("onMessage method execution failed", e); } } }
3,980
39.212121
142
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/mdb/timeout/DefaultTimeoutMDB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2017, 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.mdb.timeout; import jakarta.annotation.Resource; import jakarta.ejb.ActivationConfigProperty; import jakarta.ejb.MessageDriven; import jakarta.inject.Inject; import jakarta.jms.ConnectionFactory; import jakarta.jms.Destination; import jakarta.jms.JMSContext; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.jms.TextMessage; import jakarta.transaction.TransactionManager; import jakarta.transaction.TransactionSynchronizationRegistry; import org.jboss.as.test.integration.transactions.TransactionCheckerSingleton; import org.jboss.as.test.integration.transactions.TxTestUtil; import org.jboss.logging.Logger; /** * Message driven bean that receiving from queue * {@link TransactionTimeoutQueueSetupTask#DEFAULT_TIMEOUT_JNDI_NAME}. * * @author Ondrej Chaloupka <[email protected]> */ @MessageDriven(activationConfig = { @ActivationConfigProperty( propertyName = "destination", propertyValue = TransactionTimeoutQueueSetupTask.DEFAULT_TIMEOUT_JNDI_NAME) }) public class DefaultTimeoutMDB implements MessageListener { private static final Logger log = Logger.getLogger(DefaultTimeoutMDB.class); public static final String REPLY_PREFIX = "replying "; @Resource(lookup = "java:/JmsXA") private ConnectionFactory factory; @Resource(name = "java:jboss/TransactionManager") private TransactionManager tm; @Inject private TransactionCheckerSingleton checker; @Resource private TransactionSynchronizationRegistry synchroRegistry; @Override public void onMessage(Message message) { try { log.tracef("onMessage received message: %s '%s'", message, ((TextMessage) message).getText()); final Destination replyTo = message.getJMSReplyTo(); if (replyTo == null) { throw new RuntimeException("ReplyTo info in message was not specified" + " and bean does not know where to reply to"); } // should timeout txn - this timeout waiting has to be greater than 1 s // (see transaction timeout default setup task) TxTestUtil.waitForTimeout(tm); TxTestUtil.enlistTestXAResource(tm.getTransaction(), checker); try (JMSContext context = factory.createContext()) { context.createProducer() .setJMSCorrelationID(message.getJMSMessageID()) .send(replyTo, REPLY_PREFIX + ((TextMessage) message).getText()); } } catch (Exception e) { throw new RuntimeException("onMessage method execution failed", e); } } }
3,727
37.43299
106
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/mdb/timeout/MessageDrivenTimeoutTestCase.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.mdb.timeout; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.util.PropertyPermission; import jakarta.inject.Inject; import jakarta.jms.Destination; import jakarta.jms.Message; import jakarta.jms.MessageProducer; import jakarta.jms.Queue; import jakarta.jms.QueueConnection; import jakarta.jms.QueueConnectionFactory; import jakarta.jms.QueueReceiver; import jakarta.jms.QueueSession; import jakarta.jms.Session; import jakarta.jms.TextMessage; 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.arquillian.api.ServerSetup; 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.spec.JavaArchive; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; /** * Test of timeout of global transaction where MDB receiving message * and mock {@link XAResource} is added to the mix to get 2PC processing. */ @RunWith(Arquillian.class) @ServerSetup(TransactionTimeoutQueueSetupTask.class) public class MessageDrivenTimeoutTestCase { @ArquillianResource private InitialContext initCtx; @Inject private TransactionCheckerSingleton checker; @Deployment public static Archive<?> deployment() { final Archive<?> deployment = ShrinkWrap.create(JavaArchive.class, "mdb-timeout.jar") .addPackage(MessageDrivenTimeoutTestCase.class.getPackage()) .addPackage(TxTestUtil.class.getPackage()) .addClass(TimeoutUtil.class) // grant necessary permissions for -Dsecurity.manager because of usage TimeoutUtil .addAsResource(createPermissionsXmlAsset( new PropertyPermission("ts.timeout.factor", "read")), "META-INF/jboss-permissions.xml"); return deployment; } @Before public void startUp() throws NamingException { checker.resetAll(); } /** * MDB receives a message where <code>onMessage</code> method using an {@link XAResource} and adding transaction * synchronization. The processing should be finished with sucessful 2PC commit. */ @Test public void noTimeout() throws Exception { String text = "no timeout"; Queue q = sendMessage(text, TransactionTimeoutQueueSetupTask.NO_TIMEOUT_JNDI_NAME, initCtx); Assert.assertEquals("Sent and received message does not match at expected way", NoTimeoutMDB.REPLY_PREFIX + text, receiveMessage(q, initCtx, true)); Assert.assertEquals("Synchronization before completion has to be called", 1, checker.countSynchronizedBefore()); Assert.assertEquals("Synchronization after completion has to be called", 1, checker.countSynchronizedAfter()); Assert.assertEquals("Expecting one test XA resources being commmitted", 1, checker.getCommitted()); Assert.assertEquals("Expecting no rollback happened", 0, checker.getRolledback()); } /** * MDB receives a message when annotated to have transaction timeout defined. * MDB using {@link XAResource} but processing takes longer than and timeout time is exceeded. * As transaction annotation does not affects MDB processing the commit should happen. */ @Test public void transactionTimeoutAnnotation() throws Exception { String text = "annotation timeout"; Queue q = sendMessage(text, TransactionTimeoutQueueSetupTask.ANNOTATION_TIMEOUT_JNDI_NAME, initCtx); Assert.assertEquals("Sent and received message does not match at expected way", AnnotationTimeoutMDB.REPLY_PREFIX + text, receiveMessage(q, initCtx, true)); Assert.assertEquals("Expecting one test XA resources being commmitted", 1, checker.getCommitted()); Assert.assertEquals("Expecting no rollback happened", 0, checker.getRolledback()); } /** * MDB receives a message MDB activation property is used to have transaction timeout defined. * MDB using {@link XAResource} but processing takes longer than and timeout time is exceeded. * As activation property instruct the RA to set transaction timeout then the transaction * should be rolled-back. */ @Test public void transactionTimeoutActivationProperty() throws Exception { String text = "activation property timeout"; Queue q = sendMessage(text, TransactionTimeoutQueueSetupTask.PROPERTY_TIMEOUT_JNDI_NAME, initCtx); Assert.assertNull("No message should be received as mdb timeouted", receiveMessage(q, initCtx, false)); Assert.assertEquals("Expecting no commmit happened", 0, checker.getCommitted()); } static Queue sendMessage(String text, String queueJndi, InitialContext initCtx) throws Exception { QueueConnection connection = getConnection(initCtx); connection.start(); Queue replyDestination = null; try { final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); final Message message = session.createTextMessage(text); replyDestination = (Queue) initCtx.lookup(TransactionTimeoutQueueSetupTask.REPLY_QUEUE_JNDI_NAME); message.setJMSReplyTo(replyDestination); final Destination destination = (Destination) initCtx.lookup(queueJndi); final MessageProducer producer = session.createProducer(destination); producer.send(message); producer.close(); } finally { connection.close(); } return replyDestination; } static String receiveMessage(Queue replyQueue, InitialContext initCtx, boolean isCommitExpected) throws Exception { QueueConnection connection = getConnection(initCtx); connection.start(); try { final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); final QueueReceiver receiver = session.createReceiver(replyQueue); // when expecting commit (message should be in queue): wait a bit longer before failing // when expecting rollback (message should not be in queue): fail faster only till timeout elapses final Message reply = receiver.receive(TimeoutUtil.adjust(isCommitExpected ? 5000 : TxTestUtil.timeoutWaitTime_ms)); Thread.sleep(TimeoutUtil.adjust(500)); // waiting for synchro could be finished before checking if(reply == null) return null; return ((TextMessage) reply).getText(); } finally { connection.close(); } } static QueueConnection getConnection(InitialContext initCtx) throws Exception { final QueueConnectionFactory factory = (QueueConnectionFactory) initCtx.lookup("java:/JmsXA"); return factory.createQueueConnection(); } }
8,376
44.775956
128
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/mdb/timeout/TransactionTimeoutQueueSetupTask.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.mdb.timeout; import java.io.IOException; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.client.helpers.ClientConstants; import org.jboss.as.test.integration.common.jms.JMSOperations; import org.jboss.as.test.integration.common.jms.JMSOperationsProvider; import org.jboss.dmr.ModelNode; public class TransactionTimeoutQueueSetupTask implements ServerSetupTask { public static final String NO_TIMEOUT_QUEUE_NAME = "noTimeoutQueue"; public static final String NO_TIMEOUT_JNDI_NAME = "queue/" + NO_TIMEOUT_QUEUE_NAME; public static final String DEFAULT_TIMEOUT_QUEUE_NAME = "defaultTimeoutQueue"; public static final String DEFAULT_TIMEOUT_JNDI_NAME = "queue/" + DEFAULT_TIMEOUT_QUEUE_NAME; public static final String ANNOTATION_TIMEOUT_QUEUE_NAME = "annotationTimeoutQueue"; public static final String ANNOTATION_TIMEOUT_JNDI_NAME = "queue/" + ANNOTATION_TIMEOUT_QUEUE_NAME; public static final String PROPERTY_TIMEOUT_QUEUE_NAME = "propertyTimeoutQueue"; public static final String PROPERTY_TIMEOUT_JNDI_NAME = "queue/" + PROPERTY_TIMEOUT_QUEUE_NAME; public static final String REPLY_QUEUE_NAME = "replyQueue"; public static final String REPLY_QUEUE_JNDI_NAME = "queue/" + REPLY_QUEUE_NAME; private ModelNode amqServerDefaultAdress = new ModelNode().add(ClientConstants.SUBSYSTEM, "messaging-activemq") .add("server", "default"); private JMSOperations adminOperations; @Override public void setup(ManagementClient managementClient, String containerId) throws Exception { adminOperations = JMSOperationsProvider.getInstance(managementClient.getControllerClient()); adminOperations.createJmsQueue(NO_TIMEOUT_QUEUE_NAME, NO_TIMEOUT_JNDI_NAME); adminOperations.createJmsQueue(DEFAULT_TIMEOUT_QUEUE_NAME, DEFAULT_TIMEOUT_JNDI_NAME); adminOperations.createJmsQueue(ANNOTATION_TIMEOUT_QUEUE_NAME, ANNOTATION_TIMEOUT_JNDI_NAME); adminOperations.createJmsQueue(PROPERTY_TIMEOUT_QUEUE_NAME, PROPERTY_TIMEOUT_JNDI_NAME); adminOperations.createJmsQueue(REPLY_QUEUE_NAME, REPLY_QUEUE_JNDI_NAME); setMaxDeliveryAttempts(PROPERTY_TIMEOUT_QUEUE_NAME); setMaxDeliveryAttempts(DEFAULT_TIMEOUT_QUEUE_NAME); } @Override public void tearDown(ManagementClient managementClient, String containerId) throws Exception { if (adminOperations != null) { try { adminOperations.removeJmsQueue(NO_TIMEOUT_QUEUE_NAME); adminOperations.removeJmsQueue(DEFAULT_TIMEOUT_QUEUE_NAME); adminOperations.removeJmsQueue(ANNOTATION_TIMEOUT_QUEUE_NAME); adminOperations.removeJmsQueue(PROPERTY_TIMEOUT_QUEUE_NAME); adminOperations.removeJmsQueue(REPLY_QUEUE_NAME); removeAddressSettings(DEFAULT_TIMEOUT_QUEUE_NAME); removeAddressSettings(PROPERTY_TIMEOUT_QUEUE_NAME); } finally { adminOperations.close(); } } } // /subsystem=messaging-activemq/server=default/address-setting=jms.queue.propertyTimeoutQueue:add(max-delivery-attempts=1) private void setMaxDeliveryAttempts(String queueName) throws IOException { ModelNode address = amqServerDefaultAdress.clone().add("address-setting", "jms.queue." + queueName); ModelNode operation = new ModelNode(); operation.get(ClientConstants.OP).set(ClientConstants.ADD); operation.get(ClientConstants.OP_ADDR).set(address); operation.get("max-delivery-attempts").set(1); adminOperations.getControllerClient().execute(operation); } private void removeAddressSettings(String queueName) throws IOException { ModelNode address = amqServerDefaultAdress.clone().add("address-setting", "jms.queue." + queueName); ModelNode operation = new ModelNode(); operation.get(ClientConstants.OP).set(ClientConstants.REMOVE_OPERATION); operation.get(ClientConstants.OP_ADDR).set(address); adminOperations.getControllerClient().execute(operation); } }
5,254
49.528846
127
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/mdb/timeout/TransactionDefaultTimeoutSetupTask.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2017, 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.mdb.timeout; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.client.helpers.ClientConstants; import org.jboss.dmr.ModelNode; /** * Setup task to set default transaction timeout for 1 second. * * @author Ondrej Chaloupka <[email protected]> */ public class TransactionDefaultTimeoutSetupTask implements ServerSetupTask { private static final String DEFAULT_TIMEOUT_PARAM_NAME = "default-timeout"; private static ModelNode address = new ModelNode().add(ClientConstants.SUBSYSTEM, "transactions"); private static ModelNode operation = new ModelNode(); static { operation.get(ClientConstants.OP_ADDR).set(address); } public void setup(ManagementClient managementClient, String containerId) throws Exception { operation.get(ClientConstants.OP).set(ClientConstants.WRITE_ATTRIBUTE_OPERATION); operation.get(ClientConstants.NAME).set(DEFAULT_TIMEOUT_PARAM_NAME); operation.get(ClientConstants.VALUE).set(1); // 1 second managementClient.getControllerClient().execute(operation); } @Override public void tearDown(ManagementClient managementClient, String containerId) throws Exception { operation.get(ClientConstants.OP).set(ClientConstants.UNDEFINE_ATTRIBUTE_OPERATION); operation.get(ClientConstants.NAME).set(DEFAULT_TIMEOUT_PARAM_NAME); managementClient.getControllerClient().execute(operation); } }
2,590
41.47541
102
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/mdb/timeout/MessageDrivenDefaultTimeoutTestCase.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.mdb.timeout; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.util.PropertyPermission; import jakarta.inject.Inject; import jakarta.jms.Queue; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.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.spec.JavaArchive; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; /** * <p> * Test of timeouting a global transaction on MDB because of default transaction * timeout is redefined to be small enough to timeout being hit. * <p> * Default transaction timeout is defined under {@link TransactionDefaultTimeoutSetupTask} * and the timeout time in MDB is specified by {@link TxTestUtil#waitForTimeout(jakarta.transaction.TransactionManager)}. */ @RunWith(Arquillian.class) @ServerSetup({TransactionTimeoutQueueSetupTask.class, TransactionDefaultTimeoutSetupTask.class}) public class MessageDrivenDefaultTimeoutTestCase { @ArquillianResource private InitialContext initCtx; @Inject private TransactionCheckerSingleton checker; @Deployment public static Archive<?> deployment() { final Archive<?> deployment = ShrinkWrap.create(JavaArchive.class, "mdb-default-timeout.jar") .addPackage(MessageDrivenDefaultTimeoutTestCase.class.getPackage()) .addPackage(TxTestUtil.class.getPackage()) .addClass(TimeoutUtil.class) // grant necessary permissions for -Dsecurity.manager because of usage TimeoutUtil .addAsResource(createPermissionsXmlAsset( new PropertyPermission("ts.timeout.factor", "read")), "META-INF/jboss-permissions.xml"); return deployment; } @Before public void startUp() throws NamingException { checker.resetAll(); } /** * MDB receives a message with default transaction timeout redefined. * The bean waits till timeout occurs and the transaction should be rolled-back. */ @Test public void defaultTimeout() throws Exception { String text = "default timeout"; Queue q = MessageDrivenTimeoutTestCase.sendMessage(text, TransactionTimeoutQueueSetupTask.DEFAULT_TIMEOUT_JNDI_NAME, initCtx); Assert.assertNull("No message should be received as mdb timeouted", MessageDrivenTimeoutTestCase.receiveMessage(q, initCtx, false)); Assert.assertEquals("Expecting no commmit happened as default timeout was hit", 0, checker.getCommitted()); } }
4,092
41.635417
140
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/mdb/timeout/ActivationPropertyTimeoutMDB.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.mdb.timeout; import jakarta.annotation.Resource; import jakarta.ejb.ActivationConfigProperty; import jakarta.ejb.MessageDriven; import jakarta.inject.Inject; import jakarta.jms.ConnectionFactory; import jakarta.jms.Destination; import jakarta.jms.JMSContext; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.jms.TextMessage; import jakarta.transaction.TransactionManager; import org.jboss.logging.Logger; import org.jboss.as.test.integration.transactions.TransactionCheckerSingleton; import org.jboss.as.test.integration.transactions.TxTestUtil; @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destination", propertyValue = TransactionTimeoutQueueSetupTask.PROPERTY_TIMEOUT_JNDI_NAME), @ActivationConfigProperty(propertyName = "transactionTimeout", propertyValue = "1") }) public class ActivationPropertyTimeoutMDB implements MessageListener { private static final Logger log = Logger.getLogger(ActivationPropertyTimeoutMDB.class); public static final String REPLY_PREFIX = "replying "; @Resource(lookup = "java:/JmsXA") private ConnectionFactory factory; @Resource(name = "java:jboss/TransactionManager") private TransactionManager tm; @Inject private TransactionCheckerSingleton checker; @Override public void onMessage(Message message) { try { log.tracef("onMessage received message: %s '%s'", message, ((TextMessage) message).getText()); // this should mean that second attempt for calling onMessage comes to play if(checker.getRolledback() > 0) { log.tracef("Discarding message '%s' as onMessage called for second time", message); return; } final Destination replyTo = message.getJMSReplyTo(); if (replyTo == null) { throw new RuntimeException("ReplyTo info in message was not specified" + " and bean does not know where to reply to"); } // should timeout txn - this timeout waiting has to be greater than 1 s // (see transactionTimeout activation config property) TxTestUtil.waitForTimeout(tm); TxTestUtil.enlistTestXAResource(tm.getTransaction(), checker); try ( JMSContext context = factory.createContext() ) { context.createProducer() .setJMSCorrelationID(message.getJMSMessageID()) .send(replyTo, REPLY_PREFIX + ((TextMessage) message).getText()); } } catch (Exception e) { throw new RuntimeException("onMessage method execution failed", e); } } }
3,810
39.115789
137
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/mdb/timeout/NoTimeoutMDB.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.mdb.timeout; import jakarta.annotation.Resource; import jakarta.ejb.ActivationConfigProperty; import jakarta.ejb.MessageDriven; import jakarta.inject.Inject; import jakarta.jms.ConnectionFactory; import jakarta.jms.Destination; import jakarta.jms.JMSContext; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.jms.TextMessage; import jakarta.transaction.TransactionManager; import jakarta.transaction.TransactionSynchronizationRegistry; import org.jboss.as.test.integration.transactions.TransactionCheckerSingleton; import org.jboss.as.test.integration.transactions.TxTestUtil; import org.jboss.logging.Logger; @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destination", propertyValue = TransactionTimeoutQueueSetupTask.NO_TIMEOUT_JNDI_NAME) }) public class NoTimeoutMDB implements MessageListener { private static final Logger log = Logger.getLogger(NoTimeoutMDB.class); public static final String REPLY_PREFIX = "replying "; @Resource(lookup = "java:/JmsXA") private ConnectionFactory factory; @Resource(name = "java:jboss/TransactionManager") private TransactionManager tm; @Inject private TransactionCheckerSingleton checker; @Resource private TransactionSynchronizationRegistry synchroRegistry; @Override public void onMessage(Message message) { try { log.tracef("onMessage received message: %s '%s'", message, ((TextMessage) message).getText()); final Destination replyTo = message.getJMSReplyTo(); if (replyTo == null) { throw new RuntimeException("ReplyTo info in message was not specified" + " and bean does not know where to reply to"); } TxTestUtil.enlistTestXAResource(tm.getTransaction(), checker); TxTestUtil.addSynchronization(tm.getTransaction(), checker); try ( JMSContext context = factory.createContext() ) { context.createProducer() .setJMSCorrelationID(message.getJMSMessageID()) .send(replyTo, REPLY_PREFIX + ((TextMessage) message).getText()); } } catch (Exception e) { throw new RuntimeException("onMessage method execution failed", e); } } }
3,433
38.022727
134
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/usertransaction/CMTSLSB.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.transaction.usertransaction; import org.jboss.logging.Logger; import jakarta.annotation.PostConstruct; import jakarta.annotation.Resource; import jakarta.ejb.EJB; import jakarta.ejb.EJBContext; import jakarta.ejb.Stateless; import javax.naming.InitialContext; import javax.naming.NamingException; /** * @author Jaikiran Pai * @author Eduardo Martins */ @Stateless public class CMTSLSB { private static final Logger logger = Logger.getLogger(CMTSLSB.class); @Resource private EJBContext ejbContext; @EJB private BMTSLSB bmtSlsb; @PostConstruct void onConstruct() { this.checkUserTransactionAccess(); } public void checkUserTransactionAccessDenial() { // check access to UserTransaction this.checkUserTransactionAccess(); // now invoke a BMT SLSB and we expect that, that bean has access to the UserTransaction during the invocation this.bmtSlsb.checkUserTransactionAvailability(); // now check UserTransaction access for ourselves (again) after the call to the BMT bean has completed this.checkUserTransactionAccess(); } private void checkUserTransactionAccess() { // (JBoss specific) java:jboss/UserTransaction lookup string try { final String utJndiName = "java:jboss/UserTransaction"; InitialContext.doLookup(utJndiName); throw new RuntimeException("UserTransaction lookup at " + utJndiName + " was expected to fail in a CMT bean"); } catch (NamingException e) { // expected since it's in CMT logger.trace("Got the expected exception while looking up UserTransaction in CMT bean", e); } // (spec mandated) java:comp/UserTransaction lookup string try { final String utJavaCompJndiName = "java:comp/UserTransaction"; InitialContext.doLookup(utJavaCompJndiName); throw new RuntimeException("UserTransaction lookup at " + utJavaCompJndiName + " was expected to fail in a CMT bean"); } catch (NamingException e) { // expected since it's in CMT logger.trace("Got the expected exception while looking up UserTransaction in CMT bean", e); } // try invoking EJBContext.getUserTransaction() try { ejbContext.getUserTransaction(); throw new RuntimeException("EJBContext.getUserTransaction() was expected to throw an exception when invoked from a CMT bean, but it didn't!"); } catch (IllegalStateException ise) { // expected since it's in CMT logger.trace("Got the expected exception while looking up EJBContext.getUserTransaction() in CMT bean", ise); } } }
3,796
39.393617
154
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/usertransaction/BMTSLSB.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.transaction.usertransaction; import jakarta.annotation.PostConstruct; import jakarta.annotation.Resource; import jakarta.ejb.EJBContext; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionManagement; import jakarta.ejb.TransactionManagementType; import javax.naming.InitialContext; import javax.naming.NamingException; import jakarta.transaction.UserTransaction; /** * @author Jaikiran Pai * @author Eduardo Martins */ @Stateless @TransactionManagement(value = TransactionManagementType.BEAN) public class BMTSLSB { @Resource private EJBContext ejbContext; @Resource private UserTransaction userTransaction; @PostConstruct void onConstruct() { try { this.checkUserTransactionAccess(); } catch (NamingException e) { throw new RuntimeException(e); } } public void checkUserTransactionAvailability() { try { this.checkUserTransactionAccess(); } catch (NamingException e) { throw new RuntimeException(e); } } private void checkUserTransactionAccess() throws NamingException { if (userTransaction == null) { throw new RuntimeException("UserTransaction injection in a BMT bean was expected to happen successfully, but it didn't!"); } // (JBoss specific) java:jboss/UserTransaction lookup string final String utJndiName = "java:jboss/UserTransaction"; final UserTransaction userTxInJBossNamespace = InitialContext.doLookup(utJndiName); if (userTxInJBossNamespace == null) { throw new RuntimeException("UserTransaction lookup at " + utJndiName + " returned null in a BMT bean"); } // (spec mandated) java:comp/UserTransaction lookup string final String utJavaCompJndiName = "java:comp/UserTransaction"; final UserTransaction userTxInJavaCompNamespace = InitialContext.doLookup(utJavaCompJndiName); if (userTxInJavaCompNamespace == null) { throw new RuntimeException("UserTransaction lookup at " + utJavaCompJndiName + " returned null in a BMT bean"); } // try invoking EJBContext.getUserTransaction() final UserTransaction ut = ejbContext.getUserTransaction(); if (ut == null) { throw new RuntimeException("EJBContext.getUserTransaction() returned null in a BMT bean"); } } }
3,470
37.566667
134
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/usertransaction/UserTransactionAccessTestCase.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.transaction.usertransaction; 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.Test; import org.junit.runner.RunWith; import javax.naming.InitialContext; /** * @author Jaikiran Pai * @author Eduardo Martins */ @RunWith(Arquillian.class) public class UserTransactionAccessTestCase { private static final String MODULE_NAME = "user-transaction-access-test"; @Deployment public static JavaArchive createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar"); jar.addPackage(UserTransactionAccessTestCase.class.getPackage()); return jar; } @Test public void testUserTransactionLookupInBMT() throws Exception { final CMTSLSB cmtSlsb = InitialContext.doLookup("java:module/" + CMTSLSB.class.getSimpleName() + "!" + CMTSLSB.class.getName()); cmtSlsb.checkUserTransactionAccessDenial(); // test with a BMT bean now final BMTSLSB bmtSlsb = InitialContext.doLookup("java:module/" + BMTSLSB.class.getSimpleName() + "!" + BMTSLSB.class.getName()); bmtSlsb.checkUserTransactionAvailability(); } }
2,361
38.366667
136
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/annotation/AnnotatedTx.java
package org.jboss.as.test.integration.ejb.transaction.annotation; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; public interface AnnotatedTx { @TransactionAttribute(TransactionAttributeType.NEVER) int getActiveTransaction(); @TransactionAttribute(TransactionAttributeType.MANDATORY) int getNonActiveTransaction(); }
375
27.923077
65
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/annotation/AnnotatedTxBean.java
package org.jboss.as.test.integration.ejb.transaction.annotation; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; import jakarta.transaction.SystemException; import jakarta.transaction.TransactionManager; @Stateless public class AnnotatedTxBean implements AnnotatedTx { @Resource(lookup = "java:jboss/TransactionManager") private TransactionManager transactionManager; @TransactionAttribute(TransactionAttributeType.REQUIRED) public int getActiveTransaction() { return getTransactionStatus(); } @TransactionAttribute(TransactionAttributeType.NEVER) public int getNonActiveTransaction() { return getTransactionStatus(); } private int getTransactionStatus() { try { return transactionManager.getStatus(); } catch (SystemException e) { throw new RuntimeException(e); } } }
984
27.970588
65
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/annotation/BeanWithoutTransactionManagementValue.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.annotation; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionManagement; /** * User: jpai */ @TransactionManagement // don't specify an explicit value @Stateless public class BeanWithoutTransactionManagementValue { public void doNothing() { } }
1,348
33.589744
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/annotation/AnnotatedTransactionTestCase.java
package org.jboss.as.test.integration.ejb.transaction.annotation; import jakarta.ejb.EJBException; 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; @RunWith(Arquillian.class) public class AnnotatedTransactionTestCase { @ArquillianResource private InitialContext initialContext; @Deployment public static Archive createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "bz-1466909.jar"); jar.addPackage(AnnotatedTransactionTestCase.class.getPackage()); return jar; } @Test public void testMethodHasTransaction() throws SystemException, NotSupportedException, NamingException { final UserTransaction userTransaction = (UserTransaction) new InitialContext().lookup("java:jboss/UserTransaction"); final AnnotatedTx bean = (AnnotatedTx) initialContext.lookup("java:module/" + AnnotatedTxBean.class.getSimpleName() + "!" + AnnotatedTx.class.getName()); userTransaction.begin(); try { Assert.assertEquals(Status.STATUS_ACTIVE, bean.getActiveTransaction()); } finally { userTransaction.rollback(); } } @Test public void testMethodHasNoTransaction() throws SystemException, NotSupportedException, NamingException { final UserTransaction userTransaction = (UserTransaction) new InitialContext().lookup("java:jboss/UserTransaction"); final AnnotatedTx bean = (AnnotatedTx) initialContext.lookup("java:module/" + AnnotatedTxBean.class.getSimpleName() + "!" + AnnotatedTx.class.getName()); bean.getNonActiveTransaction(); Assert.assertEquals(Status.STATUS_NO_TRANSACTION, bean.getNonActiveTransaction()); try { userTransaction.begin(); bean.getNonActiveTransaction(); Assert.fail(); } catch (EJBException e) { Assert.assertTrue(true); } finally { userTransaction.rollback(); } } }
2,543
37.545455
161
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/transaction/annotation/NoExplicitTransactionManagementValueTestCase.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.annotation; 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 jakarta.ejb.EJB; /** * Test that a bean which uses {@link jakarta.ejb.TransactionManagement} annotation * without any explicit value, doesn't cause a deployment failure. * * @see https://issues.jboss.org/browse/AS7-1506 * <p/> * User: Jaikiran Pai */ @RunWith(Arquillian.class) public class NoExplicitTransactionManagementValueTestCase { @EJB(mappedName = "java:module/BeanWithoutTransactionManagementValue") private BeanWithoutTransactionManagementValue bean; @Deployment public static Archive<?> createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "as7-1506.jar"); jar.addClass(BeanWithoutTransactionManagementValue.class); return jar; } /** * Test that the deployment of the bean was successful and invocation on the bean * works */ @Test public void testSuccessfulDeployment() { this.bean.doNothing(); } }
2,340
34.469697
85
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/RebindTestCase.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.naming; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_RESOURCE_OPERATION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.BINDING; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.BINDING_TYPE; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.LOOKUP; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.OBJECT_FACTORY; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.REBIND; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.SIMPLE; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.TYPE; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.VALUE; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.io.FilePermission; import java.net.URL; import jakarta.ejb.EJB; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.naming.NamingContext; import org.jboss.as.naming.subsystem.NamingExtension; import org.jboss.dmr.ModelNode; import org.jboss.remoting3.security.RemotingPermission; 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.Test; import org.junit.runner.RunWith; /** * Test case for changing JBDI bound values in the naming subsystem without forcing a reload/restart (see WFLY-3239). * Uses AS controller to do the bind/rebind, lookup is through an EJB. * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class RebindTestCase { @ArquillianResource private ManagementClient managementClient; @EJB(mappedName = "java:global/RebindTestCase/BindingLookupBean") private BindingLookupBean bean; @Deployment public static Archive<?> deploy() { String tmpdir = System.getProperty("jboss.home"); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "RebindTestCase.jar"); jar.addClasses(RebindTestCase.class, BindingLookupBean.class); jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller, " + "org.jboss.remoting\n" ), "MANIFEST.MF"); jar.addAsManifestResource(createPermissionsXmlAsset( new RemotingPermission("connect"), new RemotingPermission("createEndpoint"), new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read") ), "permissions.xml"); return jar; } @Test public void testRebinding() throws Exception { final String name = "java:global/rebind"; final String lookup = "java:global/lookup"; Exception error = null; try { ModelNode operation = prepareAddBindingOperation(name, SIMPLE); operation.get(VALUE).set("http://localhost"); operation.get(TYPE).set(URL.class.getName()); ModelNode operationResult = managementClient.getControllerClient().execute(operation); verifyBinding(operationResult, name, "http://localhost"); operation = prepareRebindOperation(name, SIMPLE); operation.get(VALUE).set("http://localhost2"); operation.get(TYPE).set(URL.class.getName()); operationResult = managementClient.getControllerClient().execute(operation); verifyBinding(operationResult, name, "http://localhost2"); operation = prepareRebindOperation(name, SIMPLE); operation.get(VALUE).set("2"); operation.get(TYPE).set(Integer.class.getName()); operationResult = managementClient.getControllerClient().execute(operation); verifyBinding(operationResult, name, "2"); operation = prepareAddBindingOperation(lookup, SIMPLE); operation.get(VALUE).set("looked up"); operation.get(TYPE).set(String.class.getName()); operationResult = managementClient.getControllerClient().execute(operation); verifyBinding(operationResult, lookup, "looked up"); operation = prepareRebindOperation(name, LOOKUP); operation.get(LOOKUP).set(lookup); operationResult = managementClient.getControllerClient().execute(operation); verifyBinding(operationResult, name, "looked up"); operation = prepareReadResourceOperation(name); operationResult = managementClient.getControllerClient().execute(operation); Assert.assertFalse(operationResult.get(FAILURE_DESCRIPTION).toString(), operationResult.get(FAILURE_DESCRIPTION).isDefined()); Assert.assertEquals("java:global/lookup", operationResult.get(RESULT).get(LOOKUP).asString()); } catch (Exception e) { error = e; throw e; } finally { removeBinding(name, error); removeBinding(lookup, error); } } @Test public void testRebindingObjectFactory() throws Exception { final String bindingName = "java:global/bind"; Exception error = null; try { ModelNode operation = prepareAddBindingOperation(bindingName, SIMPLE); operation.get(VALUE).set("2"); operation.get(TYPE).set(Integer.class.getName()); ModelNode operationResult = managementClient.getControllerClient().execute(operation); verifyBindingClass(operationResult, bindingName, Integer.class.getName()); operation = prepareRebindOperation(bindingName, OBJECT_FACTORY); operation.get("module").set("org.jboss.as.naming"); operation.get("class").set("org.jboss.as.naming.interfaces.java.javaURLContextFactory"); operationResult = managementClient.getControllerClient().execute(operation); verifyBindingClass(operationResult, bindingName, NamingContext.class.getName()); } catch (Exception e) { error = e; throw e; } finally { removeBinding(bindingName, error); } } @Test public void testRebindingLookup() throws Exception { final String simpleBindingName1 = "java:global/simple1"; final String simpleBindingName2 = "java:global/simple2"; final String lookupBindingName = "java:global/lookup"; Exception error = null; try { ModelNode operation = prepareAddBindingOperation(simpleBindingName1, SIMPLE); operation.get(VALUE).set("simple1"); operation.get(TYPE).set(String.class.getName()); ModelNode operationResult = managementClient.getControllerClient().execute(operation); verifyBinding(operationResult, simpleBindingName1, "simple1"); operation = prepareAddBindingOperation(simpleBindingName2, SIMPLE); operation.get(VALUE).set("simple2"); operation.get(TYPE).set(String.class.getName()); operationResult = managementClient.getControllerClient().execute(operation); verifyBinding(operationResult, simpleBindingName2, "simple2"); operation = prepareAddBindingOperation(lookupBindingName, LOOKUP); operation.get(LOOKUP).set(simpleBindingName1); operationResult = managementClient.getControllerClient().execute(operation); verifyBinding(operationResult, lookupBindingName, "simple1"); operation = prepareRebindOperation(lookupBindingName, LOOKUP); operation.get(LOOKUP).set(simpleBindingName2); operationResult = managementClient.getControllerClient().execute(operation); verifyBinding(operationResult, lookupBindingName, "simple2"); } catch (Exception e) { error = e; throw e; } finally { removeBinding(simpleBindingName1, error); removeBinding(simpleBindingName2, error); removeBinding(lookupBindingName, error); } } private void verifyBinding(ModelNode result, String bindingName, String bindingValue) throws Exception { Assert.assertFalse(result.get(FAILURE_DESCRIPTION).toString(), result.get(FAILURE_DESCRIPTION).isDefined()); Assert.assertEquals(bindingValue, bean.lookupBind(bindingName).toString()); } private void verifyBindingClass(ModelNode result, String bindingName, String bindingClassName) throws Exception { Class bindingClass = Class.forName(bindingClassName); Assert.assertFalse(result.get(FAILURE_DESCRIPTION).toString(), result.get(FAILURE_DESCRIPTION).isDefined()); Assert.assertTrue(bindingClass.isInstance(bean.lookupBind(bindingName))); } private ModelNode prepareAddBindingOperation(String bindingName, String bindingType) { ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); operation.get(OP_ADDR).set(getBindingAddress(bindingName)); operation.get(BINDING_TYPE).set(bindingType); return operation; } private ModelNode prepareRebindOperation(String bindingName, String bindingType) { ModelNode operation = new ModelNode(); operation.get(OP).set(REBIND); operation.get(OP_ADDR).set(getBindingAddress(bindingName)); operation.get(BINDING_TYPE).set(bindingType); return operation; } private ModelNode prepareReadResourceOperation(String bindingName) { ModelNode operation = new ModelNode(); operation.get(OP).set(READ_RESOURCE_OPERATION); operation.get(OP_ADDR).set(getBindingAddress(bindingName)); return operation; } private ModelNode getBindingAddress(String bindingName) { ModelNode bindingAddress = new ModelNode(); bindingAddress.add(SUBSYSTEM, NamingExtension.SUBSYSTEM_NAME); bindingAddress.add(BINDING, bindingName); return bindingAddress; } private void removeBinding (String bindingName, Exception testException) throws Exception { ModelNode removeOperation = new ModelNode(); removeOperation.get(OP).set(REMOVE); removeOperation.get(OP_ADDR).set(getBindingAddress(bindingName)); removeOperation.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true); ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation); if (testException == null) { //Only error here if the test was successful Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION) .isDefined()); } else { if (removeResult.get(FAILURE_DESCRIPTION).isDefined()) { throw new Exception(removeResult.get(FAILURE_DESCRIPTION) + " - there was an exisiting exception in the test, it is added as the cause", testException); } } } }
13,054
46.645985
138
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/URLBindingTestCase.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.naming; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.BINDING; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.BINDING_TYPE; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.SIMPLE; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.TYPE; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.VALUE; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.io.FilePermission; import java.net.URL; import jakarta.ejb.EJB; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.naming.subsystem.NamingExtension; import org.jboss.as.test.shared.TestSuiteEnvironment; import org.jboss.dmr.ModelNode; import org.jboss.remoting3.security.RemotingPermission; 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.Test; import org.junit.runner.RunWith; /** * Test case for binding of {@link URL} (see AS7-5140). Uses AS controller to do the bind, lookup is through an EJB. * * @author Eduardo Martins */ @RunWith(Arquillian.class) public class URLBindingTestCase { @ArquillianResource private ManagementClient managementClient; @EJB(mappedName = "java:global/URLBindingTestCaseBean/BindingLookupBean") private BindingLookupBean bean; @Deployment public static Archive<?> deploy() { final String tempDir = TestSuiteEnvironment.getTmpDir(); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "URLBindingTestCaseBean.jar"); jar.addClasses(URLBindingTestCase.class, BindingLookupBean.class); jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller, org.jboss.remoting\n"), "MANIFEST.MF"); jar.addAsManifestResource(createPermissionsXmlAsset( new RemotingPermission("createEndpoint"), new RemotingPermission("connect"), new FilePermission(tempDir+"/-", "read") ), "jboss-permissions.xml"); return jar; } @Test public void testURLBinding() throws Exception { final String name = "java:global/as75140"; final ModelNode address = new ModelNode(); address.add(SUBSYSTEM, NamingExtension.SUBSYSTEM_NAME); address.add(BINDING, name); // bind a URL final ModelNode bindingAdd = new ModelNode(); bindingAdd.get(OP).set(ADD); bindingAdd.get(OP_ADDR).set(address); bindingAdd.get(BINDING_TYPE).set(SIMPLE); bindingAdd.get(VALUE).set("http://localhost"); bindingAdd.get(TYPE).set(URL.class.getName()); try { final ModelNode addResult = managementClient.getControllerClient().execute(bindingAdd); Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined()); Assert.assertEquals("http://localhost", bean.lookupBind(name).toString()); } finally { // unbind it final ModelNode bindingRemove = new ModelNode(); bindingRemove.get(OP).set(REMOVE); bindingRemove.get(OP_ADDR).set(address); bindingRemove.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true); final ModelNode removeResult = managementClient.getControllerClient().execute(bindingRemove); Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION) .isDefined()); } } }
5,645
45.661157
129
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/LookupEjb.java
package org.jboss.as.test.integration.naming; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import javax.naming.ldap.LdapContext; /** * @author Stuart Douglas */ @Stateless public class LookupEjb { @Resource(lookup = "java:global/ldap/dc=jboss,dc=org") private LdapContext ldapCtx; public LdapContext getLdapCtx() { return ldapCtx; } }
386
18.35
58
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/BindingLookupBean.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.naming; import jakarta.ejb.Stateless; import javax.naming.InitialContext; import javax.naming.NamingException; /** * @author Eduardo Martins */ @Stateless public class BindingLookupBean { public Object lookupBind(String name) throws NamingException { return new InitialContext().lookup(name); } }
1,380
34.410256
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/ObjectFactoryWithEnvironmentBindingTestCase.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.naming; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.BINDING; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.BINDING_TYPE; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.CLASS; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.ENVIRONMENT; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.MODULE; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.OBJECT_FACTORY; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.nio.file.Files; import java.util.Collections; import java.util.HashMap; import java.util.Hashtable; import java.util.Map; import javax.naming.InitialContext; import javax.naming.spi.ObjectFactory; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.naming.subsystem.NamingExtension; import org.jboss.dmr.ModelNode; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.xnio.IoUtils; /** * Test case for binding of {@link ObjectFactory} with environment properties (see AS7-4575). The test case deploys a module, * containing the object factory class, and then uses the {@link ManagementClient} to bind it. The factory, when invoked to * retrieve an instance, verifies that the env properties are the ones used in the binding management operation. * * @author Eduardo Martins */ @RunWith(Arquillian.class) @ServerSetup(ObjectFactoryWithEnvironmentBindingTestCase.ObjectFactoryWithEnvironmentBindingTestCaseServerSetup.class) public class ObjectFactoryWithEnvironmentBindingTestCase { private static Logger LOGGER = Logger.getLogger(ObjectFactoryWithEnvironmentBindingTestCase.class); // caution, must match module.xml private static final String MODULE_NAME = "objectFactoryWithEnvironmentBindingModule"; private static final String MODULE_JAR_NAME = "objectFactoryWithEnvironmentBinding.jar"; // the environment properties used in the binding operation private static final Map<String, String> ENVIRONMENT_PROPERTIES = getEnvironmentProperties(); private static Map<String, String> getEnvironmentProperties() { final Map<String, String> map = new HashMap<String, String>(); map.put("p1", "v1"); map.put("p2", "v2"); return Collections.unmodifiableMap(map); } public static void validateEnvironmentProperties(Hashtable<?, ?> environment) throws IllegalArgumentException { for (Map.Entry<String, String> property : ENVIRONMENT_PROPERTIES.entrySet()) { String value = (String) environment.get(property.getKey()); if (value == null || !value.equals(property.getValue())) { throw new IllegalArgumentException("Unexpected value for environment property named " + property.getKey() + ": " + value); } } } static class ObjectFactoryWithEnvironmentBindingTestCaseServerSetup implements ServerSetupTask { @Override public void setup(final ManagementClient managementClient, final String containerId) throws Exception { deployModule(); // bind the object factory final ModelNode address = createAddress(); final ModelNode bindingAdd = new ModelNode(); bindingAdd.get(OP).set(ADD); bindingAdd.get(OP_ADDR).set(address); bindingAdd.get(BINDING_TYPE).set(OBJECT_FACTORY); bindingAdd.get(MODULE).set(MODULE_NAME); bindingAdd.get(CLASS).set(ObjectFactoryWithEnvironmentBinding.class.getName()); final ModelNode environment = new ModelNode(); for (Map.Entry<String, String> property : ENVIRONMENT_PROPERTIES.entrySet()) { environment.add(property.getKey(), property.getValue()); } bindingAdd.get(ENVIRONMENT).set(environment); final ModelNode addResult = managementClient.getControllerClient().execute(bindingAdd); Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined()); LOGGER.trace("Object factory bound."); } private ModelNode createAddress() { final ModelNode address = new ModelNode(); address.add(SUBSYSTEM, NamingExtension.SUBSYSTEM_NAME); address.add(BINDING, "java:global/b"); return address; } @Override public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception { try { // unbind the object factory final ModelNode bindingRemove = new ModelNode(); bindingRemove.get(OP).set(REMOVE); bindingRemove.get(OP_ADDR).set(createAddress()); bindingRemove.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true); final ModelNode removeResult = managementClient.getControllerClient().execute(bindingRemove); Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION) .isDefined()); LOGGER.trace("Object factory unbound."); } finally { undeployModule(); LOGGER.trace("Module undeployed."); } } } @Deployment public static JavaArchive deploy() { return ShrinkWrap.create(JavaArchive.class, "ObjectFactoryWithEnvironmentBindingTestCase.jar") .addClass(ObjectFactoryWithEnvironmentBindingTestCase.class); } @Test public void testBindingWithEnvironment() throws Exception { InitialContext context = new InitialContext(); Assert.assertEquals("v1", context.lookup("java:global/b")); } private static void deployModule() throws IOException { File testModuleRoot = new File(getModulesHome(), MODULE_NAME); if (testModuleRoot.exists()) { throw new IllegalArgumentException(testModuleRoot + " already exists"); } File testModuleMainDir = new File(testModuleRoot, "main"); if (!testModuleMainDir.mkdirs()) { throw new IllegalArgumentException("Could not create " + testModuleMainDir); } Archive<?> moduleJar = ShrinkWrap.create(JavaArchive.class, MODULE_JAR_NAME) .addClass(ObjectFactoryWithEnvironmentBinding.class) .addClass(ObjectFactoryWithEnvironmentBindingTestCase.class); final InputStream moduleJarInputStream = moduleJar.as(ZipExporter.class).exportAsInputStream(); try { copyFile(new File(testModuleMainDir, MODULE_JAR_NAME), moduleJarInputStream); } finally { IoUtils.safeClose(moduleJarInputStream); } URL moduleXmlURL = ObjectFactoryWithEnvironmentBindingTestCase.class.getResource( ObjectFactoryWithEnvironmentBindingTestCase.class.getSimpleName() + "-module.xml"); if (moduleXmlURL == null) { throw new IllegalStateException("Could not find module.xml"); } copyFile(new File(testModuleMainDir, "module.xml"), moduleXmlURL.openStream()); } private static void undeployModule() { File testModuleRoot = new File(getModulesHome(), MODULE_NAME); deleteRecursively(testModuleRoot); } private static File getModulesHome() { String modulePath = System.getProperty("module.path", null); if (modulePath == null) { String jbossHome = System.getProperty("jboss.home", null); if (jbossHome == null) { throw new IllegalStateException("Neither -Dmodule.path nor -Djboss.home were set"); } modulePath = jbossHome + File.separatorChar + "modules"; } else { modulePath = modulePath.split(File.pathSeparator)[0]; } File moduleDir = new File(modulePath); if (!moduleDir.exists()) { throw new IllegalStateException("Determined module path does not exist"); } if (!moduleDir.isDirectory()) { throw new IllegalStateException("Determined module path is not a dir"); } return moduleDir; } private static void copyFile(File target, InputStream src) throws IOException { Files.copy(src, target.toPath()); } private static void deleteRecursively(File file) { if (file.exists()) { if (file.isDirectory()) { for (String name : file.list()) { deleteRecursively(new File(file, name)); } } file.delete(); } } }
10,963
44.874477
126
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/ExternalContextBindingTestCase.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.naming; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.BINDING; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.BINDING_TYPE; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.CACHE; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.CLASS; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.ENVIRONMENT; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.EXTERNAL_CONTEXT; import static org.jboss.as.naming.subsystem.NamingSubsystemModel.MODULE; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.security.Security; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.directory.Attributes; import javax.naming.directory.InitialDirContext; import javax.naming.ldap.LdapContext; import org.apache.directory.api.ldap.model.entry.DefaultEntry; import org.apache.directory.api.ldap.model.ldif.LdifEntry; import org.apache.directory.api.ldap.model.ldif.LdifReader; import org.apache.directory.api.ldap.model.schema.SchemaManager; import org.apache.directory.server.annotations.CreateLdapServer; import org.apache.directory.server.annotations.CreateTransport; import org.apache.directory.server.core.annotations.AnnotationUtils; import org.apache.directory.server.core.annotations.ContextEntry; import org.apache.directory.server.core.annotations.CreateDS; import org.apache.directory.server.core.annotations.CreatePartition; import org.apache.directory.server.core.api.DirectoryService; import org.apache.directory.server.core.factory.DSAnnotationProcessor; import org.apache.directory.server.factory.ServerAnnotationProcessor; import org.apache.directory.server.ldap.LdapServer; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.naming.subsystem.NamingExtension; import org.jboss.as.test.integration.security.common.ManagedCreateLdapServer; import org.jboss.as.test.integration.security.common.ManagedCreateTransport; import org.jboss.as.test.shared.util.AssumeTestGroupUtil; import org.jboss.dmr.ModelNode; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.naming.java.permission.JndiPermission; /** * Test for external context binding. There are tests which use a usual InitialContext and treat it * as an external context and tests which connect to an actual external LDAP server. * @author Stuart Douglas, Jan Martiska */ @RunWith(Arquillian.class) @ServerSetup({ExternalContextBindingTestCase.ObjectFactoryWithEnvironmentBindingTestCaseServerSetup.class, ExternalContextBindingTestCase.PrepareExternalLDAPServerSetup.class}) public class ExternalContextBindingTestCase { @BeforeClass public static void beforeClass() { // https://issues.redhat.com/browse/WFLY-17383 AssumeTestGroupUtil.assumeJDKVersionBefore(20); } private static Logger LOGGER = Logger.getLogger(ExternalContextBindingTestCase.class); private static final String MODULE_NAME = "org.jboss.as.naming"; public static final int LDAP_PORT = 10389; static class ObjectFactoryWithEnvironmentBindingTestCaseServerSetup implements ServerSetupTask { @Override public void setup(final ManagementClient managementClient, final String containerId) throws Exception { // bind the object factory ModelNode address = createAddress("nocache"); ModelNode bindingAdd = new ModelNode(); bindingAdd.get(OP).set(ADD); bindingAdd.get(OP_ADDR).set(address); bindingAdd.get(BINDING_TYPE).set(EXTERNAL_CONTEXT); bindingAdd.get(MODULE).set(MODULE_NAME); bindingAdd.get(CLASS).set(InitialContext.class.getName()); ModelNode addResult = managementClient.getControllerClient().execute(bindingAdd); Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined()); LOGGER.trace("Object factory bound."); address = createAddress("cache"); bindingAdd = new ModelNode(); bindingAdd.get(OP).set(ADD); bindingAdd.get(OP_ADDR).set(address); bindingAdd.get(BINDING_TYPE).set(EXTERNAL_CONTEXT); bindingAdd.get(MODULE).set(MODULE_NAME); bindingAdd.get(CACHE).set(true); bindingAdd.get(CLASS).set(InitialContext.class.getName()); addResult = managementClient.getControllerClient().execute(bindingAdd); Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined()); LOGGER.trace("Object factory bound."); address = createAddress("ldap"); bindingAdd = new ModelNode(); bindingAdd.get(OP).set(ADD); bindingAdd.get(OP_ADDR).set(address); bindingAdd.get(BINDING_TYPE).set(EXTERNAL_CONTEXT); bindingAdd.get(MODULE).set(MODULE_NAME); bindingAdd.get(CLASS).set(InitialDirContext.class.getName()); bindingAdd.get(ENVIRONMENT).add("java.naming.provider.url", "ldap://"+managementClient.getMgmtAddress()+":"+ ExternalContextBindingTestCase.LDAP_PORT); bindingAdd.get(ENVIRONMENT).add("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory"); bindingAdd.get(ENVIRONMENT).add(Context.SECURITY_AUTHENTICATION, "simple"); bindingAdd.get(ENVIRONMENT) .add(Context.SECURITY_PRINCIPAL, "uid=jduke,ou=People,dc=jboss,dc=org"); bindingAdd.get(ENVIRONMENT).add(Context.SECURITY_CREDENTIALS, "theduke"); addResult = managementClient.getControllerClient().execute(bindingAdd); Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined()); address = createAddress("ldap-cache"); bindingAdd = new ModelNode(); bindingAdd.get(OP).set(ADD); bindingAdd.get(OP_ADDR).set(address); bindingAdd.get(BINDING_TYPE).set(EXTERNAL_CONTEXT); bindingAdd.get(MODULE).set(MODULE_NAME); bindingAdd.get(CLASS).set(InitialDirContext.class.getName()); bindingAdd.get(CACHE).set(true); bindingAdd.get(ENVIRONMENT).add("java.naming.provider.url", "ldap://"+managementClient.getMgmtAddress()+":"+ ExternalContextBindingTestCase.LDAP_PORT); bindingAdd.get(ENVIRONMENT).add("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory"); bindingAdd.get(ENVIRONMENT).add(Context.SECURITY_AUTHENTICATION, "simple"); bindingAdd.get(ENVIRONMENT) .add(Context.SECURITY_PRINCIPAL, "uid=jduke,ou=People,dc=jboss,dc=org"); bindingAdd.get(ENVIRONMENT).add(Context.SECURITY_CREDENTIALS, "theduke"); addResult = managementClient.getControllerClient().execute(bindingAdd); Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined()); } private ModelNode createAddress(String part) { final ModelNode address = new ModelNode(); address.add(SUBSYSTEM, NamingExtension.SUBSYSTEM_NAME); address.add(BINDING, "java:global/" + part); return address; } @Override public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception { // unbind the object factorys ModelNode bindingRemove = new ModelNode(); bindingRemove.get(OP).set(REMOVE); bindingRemove.get(OP_ADDR).set(createAddress("nocache")); bindingRemove.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true); ModelNode removeResult = managementClient.getControllerClient().execute(bindingRemove); Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION) .isDefined()); LOGGER.trace("Object factory with uncached InitialContext unbound."); bindingRemove = new ModelNode(); bindingRemove.get(OP).set(REMOVE); bindingRemove.get(OP_ADDR).set(createAddress("cache")); bindingRemove.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true); removeResult = managementClient.getControllerClient().execute(bindingRemove); Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION) .isDefined()); LOGGER.trace("Object factory with cached InitialContext unbound."); bindingRemove = new ModelNode(); bindingRemove.get(OP).set(REMOVE); bindingRemove.get(OP_ADDR).set(createAddress("ldap")); bindingRemove.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true); removeResult = managementClient.getControllerClient().execute(bindingRemove); Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION) .isDefined()); LOGGER.trace("Object factory with uncached InitialDirContext unbound."); bindingRemove = new ModelNode(); bindingRemove.get(OP).set(REMOVE); bindingRemove.get(OP_ADDR).set(createAddress("ldap-cache")); bindingRemove.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true); removeResult = managementClient.getControllerClient().execute(bindingRemove); Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION) .isDefined()); LOGGER.trace("Object factory with cached InitialDirContext unbound."); } } //@formatter:off @CreateDS( name = "JBossDS-ExternalContextBindingTestCase", factory = org.jboss.as.test.integration.ldap.InMemoryDirectoryServiceFactory.class, partitions = { @CreatePartition( name = "jboss", suffix = "dc=jboss,dc=org", contextEntry = @ContextEntry( entryLdif = "dn: dc=jboss,dc=org\n" + "dc: jboss\n" + "objectClass: top\n" + "objectClass: domain\n\n")) }) @CreateLdapServer( transports = { @CreateTransport(protocol = "LDAP", port = ExternalContextBindingTestCase.LDAP_PORT) }) //@formatter:on static class PrepareExternalLDAPServerSetup implements ServerSetupTask { private DirectoryService directoryService; private LdapServer ldapServer; private boolean removeBouncyCastle = false; public void fixTransportAddress(ManagedCreateLdapServer createLdapServer, String address) { final CreateTransport[] createTransports = createLdapServer.transports(); for (int i = 0; i < createTransports.length; i++) { final ManagedCreateTransport mgCreateTransport = new ManagedCreateTransport( createTransports[i]); mgCreateTransport.setAddress(address); createTransports[i] = mgCreateTransport; } } @Override public void setup(ManagementClient managementClient, String containerId) throws Exception { try { if(Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { Security.addProvider(new BouncyCastleProvider()); removeBouncyCastle = true; } } catch(SecurityException ex) { LOGGER.warn("Cannot register BouncyCastleProvider", ex); } directoryService = DSAnnotationProcessor.getDirectoryService(); final SchemaManager schemaManager = directoryService.getSchemaManager(); try { for (LdifEntry ldifEntry : new LdifReader( ExternalContextBindingTestCase.class .getResourceAsStream(ExternalContextBindingTestCase.class.getSimpleName() + ".ldif"))) { directoryService.getAdminSession() .add(new DefaultEntry(schemaManager, ldifEntry.getEntry())); } } catch (Exception e) { e.printStackTrace(); throw e; } final ManagedCreateLdapServer createLdapServer = new ManagedCreateLdapServer( (CreateLdapServer)AnnotationUtils.getInstance(CreateLdapServer.class)); fixTransportAddress(createLdapServer, managementClient.getMgmtAddress()); ldapServer = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService); ldapServer.start(); } @Override public void tearDown(ManagementClient managementClient, String containerId) throws Exception { ldapServer.stop(); directoryService.shutdown(); if(removeBouncyCastle) { try { Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME); } catch(SecurityException ex) { LOGGER.warn("Cannot deregister BouncyCastleProvider", ex); } } } } @Deployment public static JavaArchive deploy() { return ShrinkWrap.create(JavaArchive.class, "externalContextBindingTest.jar") .addClasses(ExternalContextBindingTestCase.class, LookupEjb.class) .addAsManifestResource(createPermissionsXmlAsset( new JndiPermission("*", "lookup"), new RuntimePermission("accessClassInPackage.com.sun.jndi.ldap") ), "jboss-permissions.xml"); } @Test public void testBasicWithoutCache() throws Exception { InitialContext context = new InitialContext(); InitialContext lookupContext = (InitialContext) context.lookup("java:global/nocache"); Assert.assertNotNull(lookupContext); LookupEjb ejb = (LookupEjb) lookupContext.lookup("java:module/LookupEjb"); Assert.assertNotNull(ejb); InitialContext newLookupContext = (InitialContext) context.lookup("java:global/nocache"); Assert.assertNotSame(lookupContext, newLookupContext); Assert.assertEquals(InitialContext.class, lookupContext.getClass()); } @Test public void testBasicWithCache() throws Exception { InitialContext context = new InitialContext(); InitialContext lookupContext = (InitialContext) context.lookup("java:global/cache"); Assert.assertNotNull(lookupContext); LookupEjb ejb = (LookupEjb) lookupContext.lookup("java:module/LookupEjb"); Assert.assertNotNull(ejb); InitialContext newLookupContext = (InitialContext) context.lookup("java:global/cache"); Assert.assertSame(lookupContext, newLookupContext); //close should have no effect lookupContext.close(); ejb = (LookupEjb) lookupContext.lookup("java:module/LookupEjb"); Assert.assertNotNull(ejb); Assert.assertNotSame(InitialContext.class, lookupContext.getClass()); } @Test public void testWithActualLDAPContextWithoutCache() throws Exception { testWithActualLDAPContext(false); } @Test public void testWithActualLDAPContextWithCache() throws Exception { testWithActualLDAPContext(true); } private void testWithActualLDAPContext(boolean withCache) throws Exception { InitialContext ctx = null; InitialDirContext ldapContext1 = null; InitialDirContext ldapContext2 = null; try { ctx = new InitialContext(); String initialDirContext = withCache ? "java:global/ldap-cache" : "java:global/ldap"; LOGGER.debug("looking up "+initialDirContext+" ...."); ldapContext1 = (InitialDirContext)ctx.lookup(initialDirContext); ldapContext2 = (InitialDirContext)ctx.lookup(initialDirContext); Assert.assertNotNull(ldapContext1); Assert.assertNotNull(ldapContext2); if(withCache) { Assert.assertSame(ldapContext1, ldapContext2); } else { Assert.assertNotSame(ldapContext1, ldapContext2); } LOGGER.debug("acquired external LDAP context: " + ldapContext1.toString()); LdapContext c = (LdapContext)ldapContext1.lookup("dc=jboss,dc=org"); c = (LdapContext)c.lookup("ou=People"); Attributes attributes = c.getAttributes("uid=jduke"); Assert.assertTrue(attributes.get("description").contains("awesome")); // resource injection LookupEjb ejb = (LookupEjb) ctx.lookup("java:module/LookupEjb"); Assert.assertNotNull(ejb); c = ejb.getLdapCtx(); Assert.assertNotNull(c); c = (LdapContext)c.lookup("ou=People"); attributes = c.getAttributes("uid=jduke"); Assert.assertTrue(attributes.get("description").contains("awesome")); } finally { if (ctx != null) { ctx.close(); } if(ldapContext1 != null) { ldapContext1.close(); } if(ldapContext2 != null) { ldapContext2.close(); } } } }
20,602
49.25122
120
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/ObjectFactoryWithEnvironmentBinding.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.naming; import java.util.Hashtable; import javax.naming.Context; import javax.naming.Name; import javax.naming.spi.ObjectFactory; /** * An {@link ObjectFactory} which verifies the environment received on * {@link ObjectFactory#getObjectInstance(Object, Name, Context, Hashtable)}, is the same that a test case used in the factory's * binding operation. * * @author Eduardo Martins * @author Stuart Douglas * */ public class ObjectFactoryWithEnvironmentBinding implements ObjectFactory { @Override public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable<?, ?> environment) throws Exception { ObjectFactoryWithEnvironmentBindingTestCase.validateEnvironmentProperties(environment); return environment.get("p1"); } }
1,864
38.680851
147
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/rmi/RmiContextLookupBean.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.naming.rmi; import jakarta.ejb.Stateless; import javax.naming.Context; import javax.naming.InitialContext; /** * * @author Eduardo Martins */ @Stateless public class RmiContextLookupBean { public void testRmiContextLookup(String serverAddress, int serverPort) throws Exception { final Context rmiContext = InitialContext.doLookup("rmi://" + serverAddress + ":" + serverPort); rmiContext.close(); } }
1,492
35.414634
104
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/rmi/RmiContextLookupTestCase.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.naming.rmi; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; import javax.naming.InitialContext; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; /** * * Test which ensures RMI Context is available in JNDI. * @author Eduardo Martins * */ @RunWith(Arquillian.class) public class RmiContextLookupTestCase { @ArquillianResource private ManagementClient managementClient; @Deployment public static WebArchive getDeployment() { return ShrinkWrap.create(WebArchive.class, RmiContextLookupTestCase.class.getSimpleName() + ".war") .addClasses(RmiContextLookupTestCase.class, RmiContextLookupBean.class) .addAsManifestResource(new StringAsset("Dependencies: jdk.naming.rmi\n"), "MANIFEST.MF") .addAsManifestResource(createPermissionsXmlAsset(new RuntimePermission("accessClassInPackage.com.sun.jndi.url.rmi")), "permissions.xml"); } @Test public void testTaskSubmit() throws Exception { final RmiContextLookupBean bean = InitialContext.doLookup("java:module/" + RmiContextLookupBean.class.getSimpleName()); bean.testRmiContextLookup(managementClient.getMgmtAddress(), 11090); } }
2,668
40.061538
149
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/ldap/LdapUrlInSearchBaseTestCase.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.naming.ldap; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.assertEquals; import java.net.SocketPermission; import java.net.URL; import java.net.URLEncoder; import java.security.Security; import org.apache.commons.io.FileUtils; import org.apache.directory.server.annotations.CreateLdapServer; import org.apache.directory.server.annotations.CreateTransport; import org.apache.directory.server.core.annotations.AnnotationUtils; import org.apache.directory.server.core.annotations.ContextEntry; import org.apache.directory.server.core.annotations.CreateDS; import org.apache.directory.server.core.annotations.CreateIndex; import org.apache.directory.server.core.annotations.CreatePartition; import org.apache.directory.server.core.api.DirectoryService; import org.apache.directory.server.core.factory.DSAnnotationProcessor; import org.apache.directory.server.factory.ServerAnnotationProcessor; import org.apache.directory.server.ldap.LdapServer; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.security.common.ManagedCreateLdapServer; import org.jboss.as.test.integration.security.common.Utils; import org.jboss.as.test.shared.util.AssumeTestGroupUtil; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; /** * Regression test for LDAP related issues. * * @author Josef Cacek */ @RunWith(Arquillian.class) @ServerSetup({ LdapUrlInSearchBaseTestCase.LDAPServerSetupTask.class }) @RunAsClient public class LdapUrlInSearchBaseTestCase { @BeforeClass public static void beforeClass() { // https://issues.redhat.com/browse/WFLY-17383 AssumeTestGroupUtil.assumeJDKVersionBefore(20); } private static Logger LOGGER = Logger.getLogger(LdapUrlInSearchBaseTestCase.class); @ArquillianResource ManagementClient mgmtClient; @ArquillianResource URL webAppURL; // Public methods -------------------------------------------------------- /** * Creates {@link WebArchive} with the {@link LdapUrlTestServlet}. * * @return */ @Deployment public static WebArchive deployment() { final WebArchive war = ShrinkWrap.create(WebArchive.class, "ldap-test.war"); war.addClasses(LdapUrlTestServlet.class); war.addAsManifestResource(createPermissionsXmlAsset( new SocketPermission("*:10389", "connect,resolve"), new RuntimePermission("accessClassInPackage.com.sun.jndi.ldap"), new RuntimePermission("accessClassInPackage.com.sun.jndi.url.ldap") ), "permissions.xml"); return war; } /** * Tests if it's possible to have searchBase prefixed with LDAP URL, InitialDirContext is used. * * @throws Exception */ @Test public void testDir() throws Exception { final URL servletURL = new URL(webAppURL.toExternalForm() + "?" + LdapUrlTestServlet.PARAM_HOST + "=" + URLEncoder.encode(Utils.getSecondaryTestAddress(mgmtClient), "UTF-8")); assertEquals("cn=Java Duke", Utils.makeCallWithBasicAuthn(servletURL, null, null, 200)); } /** * Tests if it's possible to have searchBase prefixed with LDAP URL, InitialLdapContext is used. * * @throws Exception */ @Test public void testLdap() throws Exception { final URL servletURL = new URL(webAppURL.toExternalForm() + "?" + LdapUrlTestServlet.PARAM_HOST + "=" + URLEncoder.encode(Utils.getSecondaryTestAddress(mgmtClient), "UTF-8") + "&" + LdapUrlTestServlet.PARAM_LDAP + "="); assertEquals("cn=Java Duke", Utils.makeCallWithBasicAuthn(servletURL, null, null, 200)); } /** * To test the behavior outside of the AS (i.e. org.jboss.as.naming.InitialContext is not used). * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { LDAPServerSetupTask ldapSetup = new LDAPServerSetupTask(); ldapSetup.setup(null, null); ldapSetup.tearDown(null, null); } // Embedded classes ------------------------------------------------------ /** * A server setup task which configures and starts LDAP server. */ //@formatter:off @CreateDS( name = "JBossDS-LdapUrlInSearchBaseTestCase", factory = org.jboss.as.test.integration.ldap.InMemoryDirectoryServiceFactory.class, partitions = { @CreatePartition( name = "jboss", suffix = "dc=jboss,dc=org", contextEntry = @ContextEntry( entryLdif = "dn: dc=jboss,dc=org\n" + "dc: jboss\n" + "objectClass: top\n" + "objectClass: domain\n\n" ), indexes = { @CreateIndex( attribute = "objectClass" ), @CreateIndex( attribute = "dc" ), @CreateIndex( attribute = "ou" ) }) }) @CreateLdapServer ( transports = { @CreateTransport( protocol = "LDAP", port = 10389, address = "0.0.0.0" ), }) //@formatter:on static class LDAPServerSetupTask implements ServerSetupTask { private DirectoryService directoryService; private LdapServer ldapServer; private boolean removeBouncyCastle = false; /** * Creates directory services and starts LDAP server * * @param managementClient * @param containerId * @throws Exception * @see org.jboss.as.arquillian.api.ServerSetupTask#setup(org.jboss.as.arquillian.container.ManagementClient, * java.lang.String) */ public void setup(ManagementClient managementClient, String containerId) throws Exception { try { if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { Security.addProvider(new BouncyCastleProvider()); removeBouncyCastle = true; } } catch (SecurityException ex) { LOGGER.warn("Cannot register BouncyCastleProvider", ex); } directoryService = DSAnnotationProcessor.getDirectoryService(); DSAnnotationProcessor.injectEntries(directoryService, "dn: uid=jduke,dc=jboss,dc=org\n" // + "objectclass: top\n" // + "objectclass: uidObject\n" // + "objectclass: person\n" // + "uid: jduke\n" // + "cn: Java Duke\n" // + "sn: Duke\n" // + "userPassword: theduke\n"); final ManagedCreateLdapServer createLdapServer = new ManagedCreateLdapServer( (CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class)); Utils.fixApacheDSTransportAddress(createLdapServer, Utils.getSecondaryTestAddress(managementClient, false)); ldapServer = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService); ldapServer.start(); } /** * Stops LDAP server and shuts down the directory service. * * @param managementClient * @param containerId * @throws Exception * @see org.jboss.as.arquillian.api.ServerSetupTask#tearDown(org.jboss.as.arquillian.container.ManagementClient, * java.lang.String) */ public void tearDown(ManagementClient managementClient, String containerId) throws Exception { ldapServer.stop(); directoryService.shutdown(); FileUtils.deleteDirectory(directoryService.getInstanceLayout().getInstanceDirectory()); if (removeBouncyCastle) { try { Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME); } catch (SecurityException ex) { LOGGER.warn("Cannot deregister BouncyCastleProvider", ex); } } } } }
9,833
39.975
125
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/ldap/LdapUrlTestServlet.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.naming.ldap; import java.io.IOException; import java.io.PrintWriter; import java.util.Hashtable; import javax.naming.Context; import javax.naming.NamingEnumeration; import javax.naming.directory.Attributes; import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext; import javax.naming.directory.SearchControls; import javax.naming.directory.SearchResult; import javax.naming.ldap.InitialLdapContext; import javax.naming.ldap.LdapContext; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * A servlet which tries to do a search in LDAP server. Default call use InitialDirContext. You can add parameter * {@link #PARAM_LDAP} to your request and then InitialLdapContext is used. * * @author Josef Cacek */ @WebServlet(urlPatterns = { LdapUrlTestServlet.SERVLET_PATH }) public class LdapUrlTestServlet extends HttpServlet { private static final long serialVersionUID = 1L; public static final String SERVLET_PATH = "/*"; public static final String PARAM_HOST = "host"; public static final String PARAM_LDAP = "ldapctx"; /** * Writes simple text response. * * @param req * @param resp * @throws ServletException * @throws IOException * @see jakarta.servlet.http.HttpServlet#doGet(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse) */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/plain"); final PrintWriter writer = resp.getWriter(); try { String host = req.getParameter(PARAM_HOST); writer.write(runSearch(host, req.getParameter(PARAM_LDAP) != null)); } catch (Exception e) { throw new ServletException(e); } writer.close(); } /** * Try to search in LDAP with search base containing URL. Also try to retrieve RequestControls from LdapContext. * * @param hostname * @return * @throws Exception */ public static String runSearch(final String hostname, boolean testLdapCtx) throws Exception { final StringBuilder result = new StringBuilder(); final String ldapUrl = "ldap://" + (hostname == null ? "localhost" : hostname) + ":10389"; final Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.PROVIDER_URL, ldapUrl); env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system"); env.put(Context.SECURITY_CREDENTIALS, "secret"); final SearchControls ctl = new SearchControls(); ctl.setReturningAttributes(new String[] { "cn" }); DirContext dirCtx = null; if (testLdapCtx) { // LdapContext must also work LdapContext ldapCtx = new InitialLdapContext(env, null); // next line tests if the LdapContext works ldapCtx.getRequestControls(); dirCtx = ldapCtx; } else { dirCtx = new InitialDirContext(env); } final NamingEnumeration<SearchResult> nenum = dirCtx.search(ldapUrl + "/dc=jboss,dc=org", "(uid=jduke)", ctl); while (nenum.hasMore()) { SearchResult sr = nenum.next(); Attributes attrs = sr.getAttributes(); result.append("cn=").append(attrs.get("cn").get()); } dirCtx.close(); return result.toString(); } }
4,837
38.333333
133
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/shared/SharedBindingTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.naming.shared; import org.jboss.arquillian.container.test.api.Deployer; 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; import org.wildfly.naming.java.permission.JndiPermission; import javax.naming.InitialContext; import javax.naming.NamingException; import java.util.concurrent.TimeUnit; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; /** * A test case which verifies proper release of shared binds, i.e., automated unbind only after every deployment that shares the bind is undeployed. * @author Eduardo Martins */ @RunWith(Arquillian.class) public class SharedBindingTestCase { private static final String BEAN_ONE_JAR_NAME = "BEAN_ONE"; private static final String BEAN_TWO_JAR_NAME = "BEAN_TWO"; private static final String TEST_RESULTS_BEAN_JAR_NAME = "TEST_RESULTS_BEAN_JAR_NAME"; @ArquillianResource public Deployer deployer; @Deployment(name = BEAN_ONE_JAR_NAME, managed = false) public static Archive<?> deployOne() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, BEAN_ONE_JAR_NAME +".jar"); jar.addClasses(BeanOne.class, TestResults.class); jar.addAsManifestResource(SharedBindingTestCase.class.getPackage(), "ejb-jar-one.xml", "ejb-jar.xml"); jar.addAsManifestResource(createPermissionsXmlAsset( new JndiPermission("global/sharedbinds/two", "rebind")), "permissions.xml"); return jar; } @Deployment(name = BEAN_TWO_JAR_NAME, managed = false) public static Archive<?> deployTwo() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, BEAN_TWO_JAR_NAME +".jar"); jar.addClasses(BeanTwo.class, TestResults.class); jar.addAsManifestResource(SharedBindingTestCase.class.getPackage(), "ejb-jar-two.xml", "ejb-jar.xml"); jar.addAsManifestResource(createPermissionsXmlAsset( new JndiPermission("global/sharedbinds/two", "rebind")), "permissions.xml"); return jar; } @Deployment public static Archive<?> deployThree() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, TEST_RESULTS_BEAN_JAR_NAME +".jar"); jar.addClasses(TestResultsBean.class, TestResults.class); return jar; } @ArquillianResource private InitialContext initialContext; @Test public void test() throws NamingException, InterruptedException { // deploy bean one and two deployer.deploy(BEAN_ONE_JAR_NAME); boolean undeployedBeanOne = false; try { try { deployer.deploy(BEAN_TWO_JAR_NAME); // undeploy bean one first deployer.undeploy(BEAN_ONE_JAR_NAME); undeployedBeanOne = true; } finally { deployer.undeploy(BEAN_TWO_JAR_NAME); } } finally { if(!undeployedBeanOne) { deployer.undeploy(BEAN_ONE_JAR_NAME); } } // lookup bean three and assert test results final TestResults testResults = (TestResults) initialContext.lookup("java:global/"+ TEST_RESULTS_BEAN_JAR_NAME +"/"+TestResultsBean.class.getSimpleName()+"!"+TestResults.class.getName()); testResults.await(5, TimeUnit.SECONDS); Assert.assertTrue(testResults.isPostContructOne()); Assert.assertTrue(testResults.isPostContructTwo()); Assert.assertTrue(testResults.isPreDestroyOne()); Assert.assertTrue(testResults.isPreDestroyTwo()); } }
4,967
41.461538
195
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/shared/BeanOne.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.naming.shared; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import jakarta.ejb.EJB; import jakarta.ejb.Singleton; import jakarta.ejb.Startup; import javax.naming.InitialContext; /** * @author Eduardo Martins */ @Startup @Singleton public class BeanOne { @EJB(lookup = "java:global/TEST_RESULTS_BEAN_JAR_NAME/TestResultsBean!org.jboss.as.test.integration.naming.shared.TestResults") private TestResults testResults; @PostConstruct public void postConstruct() { try { new InitialContext().lookup(TestResults.SHARED_BINDING_NAME_ONE); new InitialContext().rebind(TestResults.SHARED_BINDING_NAME_TWO,""); testResults.setPostContructOne(true); } catch (Throwable e) { e.printStackTrace(); testResults.setPostContructOne(false); } } @PreDestroy public void preDestroy() { try { new InitialContext().lookup(TestResults.SHARED_BINDING_NAME_ONE); new InitialContext().lookup(TestResults.SHARED_BINDING_NAME_TWO); testResults.setPreDestroyOne(true); } catch (Throwable e) { e.printStackTrace(); testResults.setPreDestroyOne(false); } } }
2,332
33.820896
131
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/shared/BeanTwo.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.naming.shared; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import jakarta.ejb.EJB; import jakarta.ejb.Singleton; import jakarta.ejb.Startup; import javax.naming.InitialContext; /** * @author Eduardo Martins */ @Startup @Singleton public class BeanTwo { @EJB(lookup = "java:global/TEST_RESULTS_BEAN_JAR_NAME/TestResultsBean!org.jboss.as.test.integration.naming.shared.TestResults") private TestResults testResults; @PostConstruct public void postConstruct() { try { new InitialContext().lookup(TestResults.SHARED_BINDING_NAME_ONE); new InitialContext().rebind(TestResults.SHARED_BINDING_NAME_TWO,""); testResults.setPostContructTwo(true); } catch (Throwable e) { e.printStackTrace(); testResults.setPostContructTwo(false); } } @PreDestroy public void preDestroy() { try { new InitialContext().lookup(TestResults.SHARED_BINDING_NAME_ONE); new InitialContext().lookup(TestResults.SHARED_BINDING_NAME_TWO); testResults.setPreDestroyTwo(true); } catch (Throwable e) { e.printStackTrace(); testResults.setPreDestroyTwo(false); } } }
2,331
34.333333
131
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/shared/TestResults.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.naming.shared; import jakarta.ejb.Remote; import java.util.concurrent.TimeUnit; /** * @author Eduardo Martins */ @Remote public interface TestResults { String SHARED_BINDING_NAME_ONE = "java:global/sharedbinds/one"; String SHARED_BINDING_NAME_TWO = "java:global/sharedbinds/two"; boolean isPostContructOne(); void setPostContructOne(boolean postContructOne); boolean isPostContructTwo(); void setPostContructTwo(boolean postContructTwo); boolean isPreDestroyOne(); void setPreDestroyOne(boolean preDestroyOne); boolean isPreDestroyTwo(); void setPreDestroyTwo(boolean preDestroyTwo); void await(long timeout, TimeUnit timeUnit) throws InterruptedException; }
1,779
31.363636
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/shared/TestResultsBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.naming.shared; import jakarta.ejb.Singleton; import jakarta.ejb.Startup; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; /** * @author Eduardo Martins */ @Startup @Singleton public class TestResultsBean implements TestResults { private final CountDownLatch latch = new CountDownLatch(4); private boolean postContructOne; private boolean postContructTwo; private boolean preDestroyOne; private boolean preDestroyTwo; public boolean isPostContructOne() { return postContructOne; } public void setPostContructOne(boolean postContructOne) { this.postContructOne = postContructOne; latch.countDown(); } public boolean isPostContructTwo() { return postContructTwo; } public void setPostContructTwo(boolean postContructTwo) { this.postContructTwo = postContructTwo; latch.countDown(); } public boolean isPreDestroyOne() { return preDestroyOne; } public void setPreDestroyOne(boolean preDestroyOne) { this.preDestroyOne = preDestroyOne; latch.countDown(); } public boolean isPreDestroyTwo() { return preDestroyTwo; } public void setPreDestroyTwo(boolean preDestroyTwo) { this.preDestroyTwo = preDestroyTwo; latch.countDown(); } public void await(long timeout, TimeUnit timeUnit) throws InterruptedException { latch.await(timeout, timeUnit); } }
2,544
29.297619
84
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/multiple/MyEjbBean.java
package org.jboss.as.test.integration.naming.remote.multiple; import java.util.Properties; import jakarta.ejb.Stateless; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.as.network.NetworkUtils; @Stateless public class MyEjbBean implements MyEjb { protected MyObject lookup() { try { Properties env = new Properties(); String address = System.getProperty("node0", "localhost"); // format possible IPv6 address address = NetworkUtils.formatPossibleIpv6Address(address); env.put(Context.PROVIDER_URL, "http-remoting://" + address + ":8080"); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory"); Context ctx = new InitialContext(env); try { return (MyObject) ctx.lookup("loc/stub"); } finally { ctx.close(); } } catch (NamingException e) { throw new RuntimeException(e); } } public String doIt() { MyObject obj = lookup(); return obj.doIt("Test"); } }
1,191
30.368421
111
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/multiple/BindRmiServlet.java
package org.jboss.as.test.integration.naming.remote.multiple; import javax.naming.InitialContext; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; @WebServlet(name = "BindRmiServlet", urlPatterns = {"/BindRmiServlet"}, loadOnStartup = 1) public class BindRmiServlet extends HttpServlet { public void init() throws ServletException { try { InitialContext ctx = new InitialContext(); ctx.bind("java:jboss/exported/loc/stub", new MyObject()); } catch (Exception e) { throw new ServletException(e); } } }
650
33.263158
90
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/multiple/NestedRemoteContextTestCase.java
package org.jboss.as.test.integration.naming.remote.multiple; import static java.util.concurrent.TimeUnit.SECONDS; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.assertEquals; import java.io.FilePermission; import java.net.URL; import java.util.PropertyPermission; 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.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.naming.java.permission.JndiPermission; /** * Regression test for AS7-5718 * * @author [email protected] */ @RunWith(Arquillian.class) @RunAsClient public class NestedRemoteContextTestCase { @ArquillianResource(CallEjbServlet.class) private URL callEjbUrl; private static final Package thisPackage = NestedRemoteContextTestCase.class.getPackage(); @Deployment public static EnterpriseArchive deploymentTwo() { JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb.jar") .addClasses(MyEjbBean.class, MyEjb.class, MyObject.class); WebArchive war = ShrinkWrap.create(WebArchive.class, "web.war") .addClasses(CallEjbServlet.class, MyObject.class) .setWebXML(thisPackage, "web.xml"); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "ejb.ear") .addAsModule(ejbJar) .addAsModule(war) .addAsManifestResource(thisPackage, "ear-jboss-deployment-structure.xml", "jboss-deployment-structure.xml") .addAsManifestResource(createPermissionsXmlAsset( // CallEjbServlet reads node0 system property new PropertyPermission("node0", "read"), new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read")), "permissions.xml"); return ear; } @Deployment(name = "binder") public static WebArchive deploymentThree() { return ShrinkWrap.create(WebArchive.class, "binder.war") .addClasses(BindRmiServlet.class, MyObject.class) .setWebXML(MultipleClientRemoteJndiTestCase.class.getPackage(), "web.xml") // BindRmiServlet binds java:jboss/exported/loc/stub .addAsManifestResource(createPermissionsXmlAsset(new JndiPermission("java:jboss/exported/loc/stub", "bind")), "permissions.xml"); } @Test public void testLifeCycle() throws Exception { String result = HttpRequest.get(callEjbUrl.toExternalForm() + "CallEjbServlet", 1000, SECONDS); assertEquals("TestHello", result); } }
3,127
41.27027
125
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/multiple/MyEjb.java
package org.jboss.as.test.integration.naming.remote.multiple; import jakarta.ejb.Remote; @Remote public interface MyEjb { String doIt(); }
145
15.222222
61
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/multiple/RunRmiServlet.java
package org.jboss.as.test.integration.naming.remote.multiple; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.jboss.as.network.NetworkUtils; @WebServlet(name = "RunRmiServlet", urlPatterns = {"/RunRmiServlet"}) public class RunRmiServlet extends HttpServlet { private List<Context> contexts = new ArrayList<Context>(); protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { MyObject stub = lookup(); PrintWriter writer = resp.getWriter(); try { writer.print(stub.doIt("Test")); } finally { writer.close(); } } protected MyObject lookup() throws ServletException { try { Properties env = new Properties(); String address = System.getProperty("node0", "localhost"); // format possible IPv6 address address = NetworkUtils.formatPossibleIpv6Address(address); env.put(Context.PROVIDER_URL, "remote+http://" + address + ":8080"); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory"); Context ctx = new InitialContext(env); try { return (MyObject) ctx.lookup("loc/stub"); } finally { //ctx.close(); contexts.add(ctx); } } catch (NamingException e) { throw new ServletException(e); } } public void destroy() { for (Context c : contexts) { try { c.close(); } catch (NamingException e) { throw new RuntimeException(e); } } contexts.clear(); } }
2,157
32.2
113
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/multiple/MyObject.java
package org.jboss.as.test.integration.naming.remote.multiple; import java.io.Serializable; public class MyObject implements Serializable { public String doIt(String s) { return s; } }
202
19.3
61
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/multiple/CallEjbServlet.java
package org.jboss.as.test.integration.naming.remote.multiple; import java.io.IOException; import java.io.Writer; import java.util.Properties; import jakarta.ejb.EJB; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.jboss.as.network.NetworkUtils; @WebServlet(name = "CallEjbServlet", urlPatterns = {"/CallEjbServlet"}) public class CallEjbServlet extends HttpServlet { @EJB MyEjb ejb; protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Context ctx = null; try { Properties env = new Properties(); String address = System.getProperty("node0", "localhost"); // format possible IPv6 address address = NetworkUtils.formatPossibleIpv6Address(address); env.put(Context.PROVIDER_URL, "remote+http://" + address + ":8080"); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory"); ctx = new InitialContext(env); // ensure it's actually connected to the server MyObject obj = (MyObject) ctx.lookup("loc/stub"); // call the EJB which also does remote lookup Writer writer = resp.getWriter(); writer.write(ejb.doIt()); writer.write(obj.doIt("Hello")); writer.flush(); } catch (NamingException e) { throw new RuntimeException(e); } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { throw new RuntimeException(e); } } } } }
1,984
34.446429
113
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/multiple/MultipleClientRemoteJndiTestCase.java
package org.jboss.as.test.integration.naming.remote.multiple; import java.io.FilePermission; import java.net.SocketPermission; import java.net.URL; import java.util.PropertyPermission; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.wildfly.naming.java.permission.JndiPermission; import org.jboss.as.test.integration.common.HttpRequest; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; import static java.util.concurrent.TimeUnit.SECONDS; import org.jboss.as.test.integration.security.common.Utils; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import org.jboss.remoting3.security.RemotingPermission; import static org.junit.Assert.assertEquals; /** * Regression test for AS7-5718 * @author [email protected] */ @RunWith(Arquillian.class) @RunAsClient public class MultipleClientRemoteJndiTestCase { @ArquillianResource(RunRmiServlet.class) @OperateOnDeployment("one") private URL urlOne; @ArquillianResource(RunRmiServlet.class) @OperateOnDeployment("two") private URL urlTwo; private static final Package thisPackage = MultipleClientRemoteJndiTestCase.class.getPackage(); @Deployment(name="one") public static WebArchive deploymentOne() { return ShrinkWrap.create(WebArchive.class, "one.war") .addClasses(RunRmiServlet.class, MyObject.class) .setWebXML(thisPackage, "web.xml") .addAsManifestResource(thisPackage, "war-jboss-deployment-structure.xml", "jboss-deployment-structure.xml") .addAsManifestResource(createPermissionsXmlAsset( // RunRmiServlet reads node0 system property new PropertyPermission("node0", "read"), // RunRmiServlet looks up for MyObject using connection through http-remoting Endpoint new RemotingPermission("connect"), new SocketPermission(Utils.getDefaultHost(true), "accept,connect,listen,resolve"), new RuntimePermission("getClassLoader"), new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read")), "permissions.xml"); } @Deployment(name="two") public static WebArchive deploymentTwo() { return ShrinkWrap.create(WebArchive.class, "two.war") .addClasses(RunRmiServlet.class, MyObject.class) .setWebXML(thisPackage, "web.xml") .addAsManifestResource(thisPackage, "war-jboss-deployment-structure.xml", "jboss-deployment-structure.xml") .addAsManifestResource(createPermissionsXmlAsset( // RunRmiServlet reads node0 system property new PropertyPermission("node0", "read"), // RunRmiServlet looks up for MyObject using connection through http-remoting Endpoint new RemotingPermission("connect"), new SocketPermission(Utils.getDefaultHost(true), "accept,connect,listen,resolve"), new RuntimePermission("getClassLoader")), "permissions.xml"); } @Deployment(name="binder") public static WebArchive deploymentThree() { return ShrinkWrap.create(WebArchive.class, "binder.war") .addClasses(BindRmiServlet.class, MyObject.class) .setWebXML(MultipleClientRemoteJndiTestCase.class.getPackage(), "web.xml") // BindRmiServlet binds java:jboss/exported/loc/stub .addAsManifestResource(createPermissionsXmlAsset(new JndiPermission("java:jboss/exported/loc/stub", "bind")), "permissions.xml"); } @Test public void testLifeCycle() throws Exception { String result1 = HttpRequest.get(urlOne.toExternalForm() + "RunRmiServlet", 1000, SECONDS); assertEquals("Test", result1); String result2 = HttpRequest.get(urlTwo.toExternalForm() + "RunRmiServlet", 1000, SECONDS); assertEquals("Test", result2); } }
4,478
46.648936
125
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/simple/BindingEjb.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.naming.remote.simple; import jakarta.annotation.PostConstruct; import jakarta.ejb.Singleton; import jakarta.ejb.Startup; import javax.naming.InitialContext; /** * @author John Bailey */ @Singleton @Startup public class BindingEjb { @PostConstruct public void bind() throws Exception { new InitialContext().bind("java:jboss/exported/test", "TestValue"); new InitialContext().bind("java:jboss/exported/context/test", "TestValue"); } }
1,530
33.022222
83
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/simple/RemoteNamingHTTPTestCase.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.naming.remote.simple; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.assertEquals; import java.net.URI; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.naming.client.WildFlyInitialContextFactory; import org.wildfly.naming.java.permission.JndiPermission; import org.wildfly.security.auth.client.AuthenticationConfiguration; import org.wildfly.security.auth.client.AuthenticationContext; import org.wildfly.security.auth.client.MatchRule; /** * @author Stuart Douglas */ @RunWith(Arquillian.class) @RunAsClient public class RemoteNamingHTTPTestCase { @ContainerResource private ManagementClient managementClient; @Deployment public static Archive<?> deploy() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test.jar") .addClasses(BindingEjb.class) // BindingEjb binds java:jboss/exported/test and java:jboss/exported/context/test .addAsManifestResource(createPermissionsXmlAsset( new JndiPermission("java:jboss/exported/test", "bind"), new JndiPermission("java:jboss/exported/context/test", "bind")), "permissions.xml"); return jar; } public Context getRemoteHTTPContext() throws Exception { final Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName()); URI webUri = managementClient.getWebUri(); URI namingUri = new URI("http", webUri.getUserInfo(), webUri.getHost(), webUri.getPort(), "/wildfly-services", "" ,""); env.put(Context.PROVIDER_URL, namingUri.toString()); env.put(Context.SECURITY_PRINCIPAL, System.getProperty("jboss.application.username", "guest")); env.put(Context.SECURITY_CREDENTIALS, System.getProperty("jboss.application.username", "guest")); return new InitialContext(env); } private static AuthenticationContext old; @BeforeClass public static void setup() { AuthenticationConfiguration config = AuthenticationConfiguration.empty().useName("user1").usePassword("password1"); AuthenticationContext context = AuthenticationContext.empty().with(MatchRule.ALL, config); old = AuthenticationContext.captureCurrent(); AuthenticationContext.getContextManager().setGlobalDefault(context); } @AfterClass public static void after() { AuthenticationContext.getContextManager().setGlobalDefault(old); } @Test public void testHTTPRemoteLookup() throws Exception { Context context = null; try { context = getRemoteHTTPContext(); assertEquals("TestValue", context.lookup("test")); } finally { if (context != null) context.close(); } } @Test public void testHTTPRemoteContextLookup() throws Exception { Context context = null; try { context = getRemoteHTTPContext(); assertEquals("TestValue", ((Context) context.lookup("")).lookup("test")); } finally { if (context != null) context.close(); } } @Test public void testHTTPNestedLookup() throws Exception { Context context = null; try { context = getRemoteHTTPContext(); assertEquals("TestValue", ((Context) context.lookup("context")).lookup("test")); } finally { if (context != null) context.close(); } } }
5,290
38.192593
127
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/simple/RemoteNamingTestCase.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.naming.remote.simple; import java.net.URI; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.common.DefaultConfiguration; import org.wildfly.naming.java.permission.JndiPermission; 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 static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.assertEquals; /** * @author John Bailey */ @RunWith(Arquillian.class) @RunAsClient public class RemoteNamingTestCase { @ContainerResource private ManagementClient managementClient; @Deployment public static Archive<?> deploy() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test.jar") .addClasses(BindingEjb.class) // BindingEjb binds java:jboss/exported/test and java:jboss/exported/context/test .addAsManifestResource(createPermissionsXmlAsset( new JndiPermission("java:jboss/exported/test", "bind"), new JndiPermission("java:jboss/exported/context/test", "bind")), "permissions.xml"); return jar; } public Context getRemoteContext() throws Exception { final Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, org.wildfly.naming.client.WildFlyInitialContextFactory.class.getName()); URI webUri = managementClient.getWebUri(); //TODO replace with remote+http once the New WildFly Naming Client is merged URI namingUri = new URI("http-remoting", webUri.getUserInfo(), webUri.getHost(), webUri.getPort(), "", "" ,""); env.put(Context.PROVIDER_URL, namingUri.toString()); env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); return new InitialContext(DefaultConfiguration.addSecurityProperties(env)); } @Test public void testRemoteLookup() throws Exception { Context context = null; try { context = getRemoteContext(); assertEquals("TestValue", context.lookup("test")); } finally { if (context != null) context.close(); } } @Test public void testRemoteContextLookup() throws Exception { Context context = null; try { context = getRemoteContext(); assertEquals("TestValue", ((Context) context.lookup("")).lookup("test")); } finally { if (context != null) context.close(); } } @Test public void testNestedLookup() throws Exception { Context context = null; try { context = getRemoteContext(); assertEquals("TestValue", ((Context) context.lookup("context")).lookup("test")); } finally { if (context != null) context.close(); } } }
4,474
37.247863
121
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/ejb/Singleton.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.naming.remote.ejb; import jakarta.ejb.Stateless; import javax.naming.InitialContext; import javax.naming.NamingException; /** * @author John Bailey */ @Stateless public class Singleton implements BinderRemote { public String echo(String value) { return "Echo: " + value; } private final String JNDI_NAME = "java:jboss/exported/some/entry"; // methods to do JNDI binding for remote access public void bind() { try { InitialContext ic = new InitialContext(); ic.bind(JNDI_NAME, "Test"); } catch (NamingException e) { throw new RuntimeException(e); } } public void rebind() { try { InitialContext ic = new InitialContext(); ic.rebind(JNDI_NAME, "Test2"); } catch (NamingException e) { throw new RuntimeException(e); } } public void unbind() { try { InitialContext ic = new InitialContext(); ic.unbind(JNDI_NAME); } catch (NamingException e) { throw new RuntimeException(e); } } }
2,175
31
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/ejb/StatefulBean.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.naming.remote.ejb; import jakarta.ejb.Stateful; /** * @author John Bailey, Ondrej Chaloupka */ @Stateful public class StatefulBean implements Remote { public String echo(String value) { return "Echo: " + value; } }
1,297
35.055556
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/ejb/Bean.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.naming.remote.ejb; import jakarta.ejb.Singleton; /** * @author John Bailey, Ondrej Chaloupka */ @Singleton public class Bean implements Remote { public String echo(String value) { return "Echo: " + value; } }
1,291
34.888889
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/ejb/Remote.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.naming.remote.ejb; /** * @author John Bailey */ @jakarta.ejb.Remote public interface Remote { String echo(String value); }
1,192
36.28125
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/ejb/BinderRemote.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.naming.remote.ejb; /** * @author James Livingston */ @jakarta.ejb.Remote public interface BinderRemote extends Remote { void bind(); void rebind(); void unbind(); }
1,242
35.558824
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/remote/ejb/RemoteNamingEjbTestCase.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.naming.remote.ejb; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.net.URL; import java.util.HashSet; import java.util.Properties; import java.util.Set; import javax.naming.Binding; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NameClassPair; import javax.naming.NameNotFoundException; import javax.naming.NamingEnumeration; 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.as.arquillian.container.ManagementClient; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.test.integration.common.DefaultConfiguration; import org.wildfly.naming.java.permission.JndiPermission; import org.jboss.dmr.ModelNode; 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.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.operations.common.Util; /** * @author John Bailey, Ondrej Chaloupka */ @RunWith(Arquillian.class) @RunAsClient public class RemoteNamingEjbTestCase { private static final String ARCHIVE_NAME = "test"; @ArquillianResource private URL baseUrl; @ArquillianResource private ManagementClient managementClient; @Deployment public static Archive<?> deploy() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar"); jar.addClasses(Remote.class, BinderRemote.class, Bean.class, Singleton.class, StatefulBean.class); jar.addAsResource(createPermissionsXmlAsset(new JndiPermission("java:jboss/exported/-", "all")), "META-INF/jboss-permissions.xml"); return jar; } public InitialContext getRemoteContext() throws Exception { final Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, org.wildfly.naming.client.WildFlyInitialContextFactory.class.getName()); env.put(Context.PROVIDER_URL, managementClient.getRemoteEjbURL().toString()); env.put("jboss.naming.client.ejb.context", true); env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); return new InitialContext(DefaultConfiguration.addSecurityProperties(env)); } @Test public void testIt() throws Exception { final InitialContext ctx = getRemoteContext(); final ClassLoader current = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(Remote.class.getClassLoader()); Remote remote = (Remote) ctx.lookup(ARCHIVE_NAME + "/" + Bean.class.getSimpleName() + "!" + Remote.class.getName()); assertNotNull(remote); assertEquals("Echo: test", remote.echo("test")); remote = (Remote) ctx.lookup(ARCHIVE_NAME + "/" + Singleton.class.getSimpleName() + "!" + BinderRemote.class.getName()); assertNotNull(remote); assertEquals("Echo: test", remote.echo("test")); remote = (Remote) ctx.lookup(ARCHIVE_NAME + "/" + StatefulBean.class.getSimpleName() + "!" + Remote.class.getName()); assertNotNull(remote); assertEquals("Echo: test", remote.echo("test")); final Set<String> expected = new HashSet<String>(); expected.add(Bean.class.getSimpleName() + "!" + Remote.class.getName()); expected.add(Singleton.class.getSimpleName() + "!" + BinderRemote.class.getName()); expected.add(StatefulBean.class.getSimpleName() + "!" + Remote.class.getName()); NamingEnumeration<NameClassPair> e = ctx.list("test"); while (e.hasMore()) { NameClassPair binding = e.next(); if (!expected.remove(binding.getName())) { Assert.fail("unknown binding " + binding.getName()); } } if (!expected.isEmpty()) { Assert.fail("bindings not found " + expected); } } finally { ctx.close(); Thread.currentThread().setContextClassLoader(current); } } @Test public void testDeploymentBinding() throws Exception { final InitialContext ctx = getRemoteContext(); BinderRemote binder = null; try { try { ctx.lookup("some/entry"); fail("expected exception"); } catch (NameNotFoundException e) { // expected } // test binding binder = (BinderRemote) ctx.lookup(ARCHIVE_NAME + "/" + Singleton.class.getSimpleName() + "!" + BinderRemote.class.getName()); assertNotNull(binder); binder.bind(); assertEquals("Test", ctx.lookup("some/entry")); NamingEnumeration<Binding> bindings = ctx.listBindings("some"); assertTrue(bindings.hasMore()); assertEquals("Test", bindings.next().getObject()); assertFalse(bindings.hasMore()); // test rebinding binder.rebind(); assertEquals("Test2", ctx.lookup("some/entry")); bindings = ctx.listBindings("some"); assertTrue(bindings.hasMore()); assertEquals("Test2", bindings.next().getObject()); assertFalse(bindings.hasMore()); // test unbinding binder.unbind(); try { ctx.lookup("some/entry"); fail("expected exception"); } catch (NameNotFoundException e) { // expected } // test rebinding when it doesn't already exist binder.rebind(); assertEquals("Test2", ctx.lookup("some/entry")); bindings = ctx.listBindings("some"); assertTrue(bindings.hasMore()); assertEquals("Test2", bindings.next().getObject()); assertFalse(bindings.hasMore()); } finally { // clean up in case any JNDI bindings were left around try { if (binder != null) binder.unbind(); } catch (Exception e) { // expected } ctx.close(); } } @Test public void testRemoteNamingGracefulShutdown() throws Exception { ModelNode op = new ModelNode(); op.get(ModelDescriptionConstants.OP).set("suspend"); managementClient.getControllerClient().execute(op); Thread.currentThread().setContextClassLoader(Remote.class.getClassLoader()); final InitialContext ctx = getRemoteContext(); final ClassLoader current = Thread.currentThread().getContextClassLoader(); try { try { Remote remote = (Remote) ctx.lookup(ARCHIVE_NAME + "/" + Bean.class.getSimpleName() + "!" + Remote.class.getName()); Assert.fail(); } catch (NamingException expected) { } try { Remote remote = (Remote) ctx.lookup(ARCHIVE_NAME + "/" + Singleton.class.getSimpleName() + "!" + BinderRemote.class.getName()); Assert.fail(); } catch (NamingException expected) { } try { Remote remote = (Remote) ctx.lookup(ARCHIVE_NAME + "/" + StatefulBean.class.getSimpleName() + "!" + Remote.class.getName()); Assert.fail(); } catch (NamingException expected) { } } finally { op = new ModelNode(); op.get(ModelDescriptionConstants.OP).set("resume"); managementClient.getControllerClient().execute(op); ctx.close(); Thread.currentThread().setContextClassLoader(current); } } @Test public void testSystemPropertyConfig() throws Exception { System.setProperty("java.naming.factory.initial","org.wildfly.naming.client.WildFlyInitialContextFactory"); final Properties env = new Properties(); env.put(Context.PROVIDER_URL, managementClient.getRemoteEjbURL().toString()); env.put("jboss.naming.client.ejb.context", true); env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); final InitialContext ctx = new InitialContext(env); final ClassLoader current = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(Remote.class.getClassLoader()); Remote remote = (Remote) ctx.lookup(ARCHIVE_NAME + "/" + Bean.class.getSimpleName() + "!" + Remote.class.getName()); assertNotNull(remote); assertEquals("Echo: test", remote.echo("test")); } finally { ctx.close(); Thread.currentThread().setContextClassLoader(current); } } @Test public void testValue() throws Exception { ModelNode operation = Util.createEmptyOperation("jndi-view", PathAddress.pathAddress("subsystem", "naming")); ModelNode res = ManagementOperations.executeOperation(managementClient.getControllerClient(), operation); ModelNode node = res.get("java: contexts", "java:jboss/exported", "test", "children", "Bean!org.jboss.as.test.integration.naming.remote.ejb.Remote", "class-name"); Assert.assertEquals("org.jboss.as.test.integration.naming.remote.ejb.Remote", node.asString()); } }
11,176
38.217544
143
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/injection/Binder.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.naming.injection; import jakarta.ejb.Remote; import javax.naming.NamingException; /** * @author Eduardo Martins */ @Remote public interface Binder { String LINK_NAME = "java:global/z"; void bindAndLink(Object value) throws NamingException; }
1,319
32.846154
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/injection/BinderBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.naming.injection; import jakarta.ejb.Stateless; import javax.naming.InitialContext; import javax.naming.LinkRef; import javax.naming.NamingException; /** * @author Eduardo Martins */ @Stateless public class BinderBean implements Binder { private static final String SRC_NAME = "java:global/a"; public void bindAndLink(Object value) throws NamingException { InitialContext initialContext = new InitialContext(); initialContext.bind(SRC_NAME, value); initialContext.bind(Binder.LINK_NAME, new LinkRef(SRC_NAME)); } }
1,620
35.022222
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/injection/LinkRefResourceInjectionTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.naming.injection; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.arquillian.container.test.api.Deployer; 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; import org.wildfly.naming.java.permission.JndiPermission; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; /** * A test which enforces that * @author Eduardo Martins */ @RunWith(Arquillian.class) public class LinkRefResourceInjectionTestCase { private static final String BINDER_JAR_NAME = "binder"; private static final String INJECTED_JAR_NAME = "injected"; @ArquillianResource public Deployer deployer; @Deployment public static Archive<?> deployBinder() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, BINDER_JAR_NAME+".jar"); jar.addClasses(BinderBean.class, Binder.class, Injected.class); jar.addAsManifestResource(createPermissionsXmlAsset( new JndiPermission("global/a", "bind"), new JndiPermission("global/b", "bind"), new JndiPermission("global/z", "bind") ), "jboss-permissions.xml"); return jar; } @Deployment(name = INJECTED_JAR_NAME, managed = false) public static Archive<?> deployInjected() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, INJECTED_JAR_NAME+".jar"); jar.addClasses(InjectedBean.class, Injected.class, Binder.class); return jar; } @ArquillianResource private InitialContext initialContext; @Test public void test() throws NamingException { String bindValue = "az"; // lookup binder ejb final Binder binder = (Binder) initialContext.lookup("java:global/"+BINDER_JAR_NAME+"/"+BinderBean.class.getSimpleName()+"!"+Binder.class.getName()); // bind the value, which will be accessible at Binder.LINK_NAME binder.bindAndLink(bindValue); // deploy the injected bean, which has a field resource injection pointing to Binder.LINK_NAME deployer.deploy(INJECTED_JAR_NAME); try { final Injected injected = (Injected) initialContext.lookup("java:global/"+INJECTED_JAR_NAME+"/InjectedBean!"+Injected.class.getName()); // this assertion implies that the link was followed corrected into the src binding Assert.assertEquals(injected.getInjectedResource(),bindValue); } finally { deployer.undeploy(INJECTED_JAR_NAME); } } }
3,928
39.927083
157
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/injection/InjectedBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.naming.injection; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; /** * @author Eduardo Martins */ @Stateless public class InjectedBean implements Injected { @Resource(lookup=Binder.LINK_NAME) private String resource; public String getInjectedResource() { return resource; } }
1,388
32.071429
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/injection/Injected.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.naming.injection; import jakarta.ejb.Remote; /** * @author Eduardo Martins */ @Remote public interface Injected { String getInjectedResource(); }
1,218
32.861111
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/local/simple/ServletWithBind.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.naming.local.simple; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet(name = "ServletWithBind", urlPatterns = {"/simple"}) public class ServletWithBind extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String msg = req.getParameter("op"); if ("bind".equals(msg)) { try { final Context context = new InitialContext(); context.bind("java:jboss/web-test", "Test"); context.bind("java:/web-test", "Test"); } catch (NamingException e) { throw new ServletException(e); } } } }
2,080
40.62
113
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/local/simple/BeanWithBind.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.naming.local.simple; import jakarta.ejb.Stateless; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; /** * @author John Bailey */ @Stateless public class BeanWithBind { public void doBind() { try { final Context context = new InitialContext(); context.bind("java:jboss/test", "Test"); context.bind("java:/test", "Test"); } catch (NamingException e) { throw new RuntimeException(e); } } }
1,586
34.266667
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/local/simple/DeploymentWithBindTestCase.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.naming.local.simple; import static java.util.concurrent.TimeUnit.SECONDS; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.assertNotNull; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.junit.InSequence; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.common.HttpRequest; import org.jboss.as.test.shared.TestSuiteEnvironment; 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; import org.wildfly.naming.java.permission.JndiPermission; import java.net.SocketPermission; /** * @author John Bailey */ @RunWith(Arquillian.class) public class DeploymentWithBindTestCase { @Deployment public static Archive<?> deploy() { final WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war"); war.addClasses(HttpRequest.class, BeanWithBind.class, ServletWithBind.class); war.addAsManifestResource(createPermissionsXmlAsset( new JndiPermission("global", "listBindings"), new JndiPermission("jboss", "listBindings"), new JndiPermission("jboss/exported", "listBindings"), new JndiPermission("/test", "bind"), new JndiPermission("/web-test", "bind"), new JndiPermission("jboss/test", "bind"), new JndiPermission("jboss/web-test", "bind"), // org.jboss.as.test.integration.common.HttpRequest needs the following permissions new RuntimePermission("modifyThread"), new SocketPermission(TestSuiteEnvironment.getHttpAddress() + ":" + TestSuiteEnvironment.getHttpPort(), "connect,resolve")), "permissions.xml"); return war; } @ArquillianResource private InitialContext iniCtx; @ArquillianResource private ManagementClient managementClient; protected <T> T lookup(Class<T> beanType) throws NamingException { return beanType.cast(iniCtx.lookup("java:global/test/" + beanType.getSimpleName() + "!" + beanType.getName())); } @Test @InSequence(1) public void testEjb() throws Exception { final BeanWithBind bean = lookup(BeanWithBind.class); bean.doBind(); assertNotNull(iniCtx.lookup("java:jboss/test")); assertNotNull(iniCtx.lookup("java:/test")); } private String performCall(String urlPattern, String op) throws Exception { return HttpRequest.get(managementClient.getWebUri() + "/test/" + urlPattern + "?op=" + op, 10, SECONDS); } @Test @InSequence(2) public void testServlet() throws Exception { performCall("simple", "bind"); assertNotNull(iniCtx.lookup("java:jboss/test")); assertNotNull(iniCtx.lookup("java:/test")); } @Test @InSequence(3) public void testBasicsNamespaces() throws Exception { iniCtx.lookup("java:global"); iniCtx.listBindings("java:global"); iniCtx.lookup("java:jboss"); iniCtx.listBindings("java:jboss"); iniCtx.lookup("java:jboss/exported"); iniCtx.listBindings("java:jboss/exported"); } }
4,588
37.889831
139
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/connector/JMXConnectorTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2009, Red Hat Middleware LLC, and individual contributors * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * 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.naming.connector; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import javax.management.MBeanServer; import javax.management.remote.JMXConnectorServer; import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXServiceURL; import javax.naming.Context; import java.lang.management.ManagementFactory; import java.net.SocketPermission; import java.rmi.registry.LocateRegistry; import java.util.Properties; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; /** * Tests that JMX Connector work properly from container. * * @author baranowb * @author Eduardo Martins * */ @RunWith(Arquillian.class) @RunAsClient public class JMXConnectorTestCase { // NOTE: this test may fail on Ubuntu, since it has definition of localhost as 127.0.1.1 private static final Logger log = Logger.getLogger(JMXConnectorTestCase.class.getName()); private static final String CB_DEPLOYMENT_NAME = "naming-connector-bean"; // module private JMXConnectorServer connectorServer; private final int port = 11090; private JMXServiceURL jmxServiceURL; private String rmiServerJndiName; @ArquillianResource private ManagementClient managementClient; @Before public void beforeTest() throws Exception { LocateRegistry.createRegistry(port); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final String address = managementClient.getMgmtAddress(); rmiServerJndiName = "rmi://" + address + ":" + port + "/jmxrmi"; jmxServiceURL = new JMXServiceURL("service:jmx:rmi:///jndi/"+rmiServerJndiName); connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(jmxServiceURL, null, mbs); connectorServer.start(); } @After public void afterTest() throws Exception { if (connectorServer != null) { connectorServer.stop(); } } @Deployment public static JavaArchive createTestArchive() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, CB_DEPLOYMENT_NAME); archive.addClass(ConnectedBean.class); archive.addClass(ConnectedBeanInterface.class); archive.addAsManifestResource(new StringAsset("Dependencies: jdk.naming.rmi\n"), "MANIFEST.MF"); archive.addAsManifestResource(createPermissionsXmlAsset( new RuntimePermission("accessClassInPackage.com.sun.jndi.url.rmi"), new SocketPermission("*:*", "connect,resolve") ), "permissions.xml"); return archive; } @Test public void testMBeanCount() throws Exception { final Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, org.wildfly.naming.client.WildFlyInitialContextFactory.class.getName()); env.put(Context.PROVIDER_URL, managementClient.getRemoteEjbURL().toString()); env.put("jboss.naming.client.ejb.context", true); env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); final javax.naming.InitialContext initialContext = new javax.naming.InitialContext(env); try { ConnectedBeanInterface connectedBean = (ConnectedBeanInterface) initialContext.lookup(CB_DEPLOYMENT_NAME + "/" + ConnectedBean.class.getSimpleName() + "!" + ConnectedBeanInterface.class.getName()); int mBeanCountFromJNDI = connectedBean.getMBeanCountFromJNDI(rmiServerJndiName); log.trace("MBean server count from jndi: " + mBeanCountFromJNDI); int mBeanCountFromConnector = connectedBean.getMBeanCountFromConnector(jmxServiceURL); log.trace("MBean server count from connector: " + mBeanCountFromConnector); Assert.assertEquals(mBeanCountFromConnector, mBeanCountFromJNDI); } finally { initialContext.close(); } } }
5,266
42.528926
209
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/connector/ConnectedBeanInterface.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.naming.connector; import jakarta.ejb.Remote; import javax.management.remote.JMXServiceURL; /** * @author baranowb * @author Eduardo Martins * */ @Remote public interface ConnectedBeanInterface { int getMBeanCountFromConnector(JMXServiceURL jmxServiceURL) throws Exception; int getMBeanCountFromJNDI(String rmiServerJndiName) throws Exception; }
1,424
33.756098
81
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/naming/connector/ConnectedBean.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.naming.connector; import jakarta.ejb.Stateless; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import javax.management.remote.rmi.RMIConnection; import javax.management.remote.rmi.RMIServer; import javax.naming.InitialContext; /** * Simple bean to check access MBean server count through JMXConnector and JNDI. * * @author baranowb * @author Eduardo Martins */ @Stateless public class ConnectedBean implements ConnectedBeanInterface { public int getMBeanCountFromConnector(JMXServiceURL jmxServiceURL) throws Exception { final JMXConnector connector = JMXConnectorFactory.connect(jmxServiceURL, null); try { return connector.getMBeanServerConnection().getMBeanCount(); } finally { if (connector != null) { connector.close(); } } } public int getMBeanCountFromJNDI(String rmiServerJndiName) throws Exception { final RMIServer rmiServer = InitialContext.doLookup(rmiServerJndiName); final RMIConnection rmiConnection = rmiServer.newClient(null); try { return rmiConnection.getMBeanCount(null); } finally { if (rmiConnection != null) { rmiConnection.close(); } } } }
2,423
36.292308
89
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/SarWithinEarServiceMBean.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.sar; /** * User: jpai */ public interface SarWithinEarServiceMBean { int add(int x, int y); }
1,164
35.40625
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/JNDIBindingService.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.sar; import java.util.concurrent.atomic.AtomicInteger; import javax.naming.InitialContext; import org.jboss.logging.Logger; /** * An MBean that binds to JNDI in its start method and unbinds from JNDI in its stop method * * @author Jaikiran Pai * */ public class JNDIBindingService implements JNDIBindingServiceMBean { private static final Logger logger = Logger.getLogger(JNDIBindingService.class); private static final String NAME = "java:global/env/foo/legacy"; private static final String VALUE = "BAR"; private static final AtomicInteger count = new AtomicInteger(1); private String jndiName; public void create() throws Exception { logger.trace("create()"); this.jndiName = NAME + count.getAndIncrement(); } public void start() throws Exception { logger.trace("start()"); new InitialContext().bind(jndiName, VALUE); logger.trace("Bound to JNDI " + jndiName); } public void stop() throws Exception { logger.trace("stop()"); new InitialContext().unbind(jndiName); logger.trace("Unbound from jndi " + jndiName); } public void destroy() throws Exception { logger.trace("destroy()"); } @Override public void sayHello() { logger.trace("Hello from " + this); } }
2,384
32.125
91
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/JNDIBindingMBeanTestCase.java
package org.jboss.as.test.integration.sar; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; 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.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.common.DefaultConfiguration; 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.naming.java.permission.JndiPermission; /** * Tests that MBean(s) binding to JNDI in their <code>start</code> lifecycle method do not hang up the deployment. * * @see https://developer.jboss.org/thread/251092 * @author Jaikiran Pai */ @RunWith(Arquillian.class) @RunAsClient public class JNDIBindingMBeanTestCase { @ContainerResource private ManagementClient managementClient; @Deployment public static JavaArchive createDeployment() { final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, "multiple-jndi-binding-mbeans.sar"); sar.addClasses(JNDIBindingService.class, JNDIBindingMBeanTestCase.class, JNDIBindingServiceMBean.class); sar.addAsManifestResource(JNDIBindingMBeanTestCase.class.getPackage(), "multiple-jndi-binding-mbeans-jboss-service.xml", "jboss-service.xml"); sar.addAsManifestResource(createPermissionsXmlAsset(new JndiPermission("global/env/foo/-", "bind,unbind")), "permissions.xml"); return sar; } /** * Makes sure that the MBeans that are expected to be up and running are accessible. * * @throws Exception * @see https://developer.jboss.org/thread/251092 */ @Test public void testMBeanStartup() throws Exception { // get mbean server final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials()); try { final MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection(); // check the deployed MBeans for (int i = 1; i <= 9; i++) { final String mbeanName = "jboss:name=mbean-startup-jndi-bind-" + i; final Object instance = mBeanServerConnection.getObjectInstance(new ObjectName(mbeanName)); Assert.assertNotNull("No instance returned for MBean: " + mbeanName, instance); } } finally { connector.close(); } } }
2,858
40.434783
150
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/JNDIBindingServiceMBean.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.sar; public interface JNDIBindingServiceMBean { void sayHello(); }
1,134
39.535714
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/SarWithinEarTestCase.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.sar; import java.io.IOException; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.common.DefaultConfiguration; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.After; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.xnio.IoUtils; /** * Test that a service configured in a .sar within a .ear deployment works fine, both when the .ear contains a application.xml * and when it doesn't. * <p/> * User: Jaikiran Pai */ @RunWith(Arquillian.class) @RunAsClient public class SarWithinEarTestCase { private static final String EAR_WITHOUT_APPLICATION_XML = "sar-within-ear-without-application-xml.ear"; private static final String EAR_WITH_APPLICATION_XML = "sar-within-ear-with-application-xml.ear"; @ContainerResource private ManagementClient managementClient; private JMXConnector connector; @After public void closeConnector() { IoUtils.safeClose(connector); } /** * Create a .ear, without an application.xml, with a nested .sar deployment * * @return */ @Deployment(name = "ear-without-application-xml", testable = false) public static EnterpriseArchive getEarWithoutApplicationDotXml() { final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, "simple-sar.sar"); sar.addClasses(SarWithinEarServiceMBean.class, SarWithinEarService.class); sar.addAsManifestResource(SarWithinEarTestCase.class.getPackage(), "jboss-service-without-application-xml.xml", "jboss-service.xml"); final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, EAR_WITHOUT_APPLICATION_XML); ear.addAsModule(sar); return ear; } /** * Create a .ear with an application.xml and a nested .sar deployment * * @return */ @Deployment(name = "ear-with-application-xml", testable = false) public static EnterpriseArchive getEarWithApplicationDotXml() { final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, "simple-sar.sar"); sar.addClasses(SarWithinEarServiceMBean.class, SarWithinEarService.class); sar.addAsManifestResource(SarWithinEarTestCase.class.getPackage(), "jboss-service-with-application-xml.xml", "jboss-service.xml"); final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, EAR_WITH_APPLICATION_XML); ear.addAsModule(sar); ear.addAsManifestResource(SarWithinEarTestCase.class.getPackage(), "application.xml", "application.xml"); return ear; } /** * Tests that invocation on a service deployed within a .sar, inside a .ear without an application.xml, is successful. * * @throws Exception */ @OperateOnDeployment("ear-without-application-xml") @Test public void testSarWithinEarWithoutApplicationXml() throws Exception { this.testSarWithinEar("jboss:name=service-in-sar-within-a-ear-without-application-xml"); } /** * Tests that invocation on a service deployed within a .sar, inside a .ear with an application.xml, is successful. * * @throws Exception */ @OperateOnDeployment("ear-with-application-xml") @Test public void testSarWithinEarWithApplicationXml() throws Exception { this.testSarWithinEar("jboss:name=service-in-sar-within-a-ear-with-application-xml"); } private void testSarWithinEar(final String serviceName) throws Exception { final MBeanServerConnection mBeanServerConnection = this.getMBeanServerConnection(); final ObjectName mbeanObjectName = new ObjectName(serviceName); final int num1 = 3; final int num2 = 4; // invoke the operation on MBean Integer sum = (Integer) mBeanServerConnection.invoke(mbeanObjectName, "add", new Object[]{num1, num2}, new String[]{Integer.TYPE.getName(), Integer.TYPE.getName()}); Assert.assertEquals("Unexpected return value from MBean: " + mbeanObjectName, num1 + num2, (int) sum); } private MBeanServerConnection getMBeanServerConnection() throws IOException { connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials()); return connector.getMBeanServerConnection(); } }
5,944
41.769784
173
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/SarWithinEarService.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.sar; /** * User: jpai */ public class SarWithinEarService implements SarWithinEarServiceMBean { public SarWithinEarService() { } @Override public int add(int x, int y) { return x + y; } }
1,285
31.15
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/order/LifecycleEmitterMBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.test.integration.sar.order; import javax.management.ObjectName; public interface LifecycleEmitterMBean { String getId(); void setId(String id); ObjectName getLifecycleListener(); void setLifecycleListener(ObjectName lifecycleListener); }
989
29
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/order/ServiceMBeanSupportOrderingTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, 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.sar.order; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.io.IOException; import java.util.Arrays; import java.util.List; import javax.management.AttributeNotFoundException; import javax.management.InstanceNotFoundException; import javax.management.MBeanException; import javax.management.MBeanPermission; import javax.management.MBeanServerConnection; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import javax.management.ReflectionException; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.common.DefaultConfiguration; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.system.ServiceMBeanSupport; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Test that MBeans which extend {@link ServiceMBeanSupport} and depend on other such mbeans have their create/start/stop/destroyService methods called in correct dependency order. * * @author Brian Stansberry */ @RunWith(Arquillian.class) @RunAsClient public class ServiceMBeanSupportOrderingTestCase { private static final String UNMANAGED_SAR_DEPLOYMENT_NAME = "service-mbean-order-test"; private static final List<String> FORWARD_ORDER = Arrays.asList("A", "B", "C"); private static final List<String> REVERSE_ORDER = Arrays.asList("C", "B", "A"); @ContainerResource private ManagementClient managementClient; @ArquillianResource private Deployer deployer; @Deployment(name = ServiceMBeanSupportOrderingTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME, managed = false) public static JavaArchive geTestMBeanSar() { final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, "service-mbean-order-test.sar"); sar.addClasses(LifecycleEmitterMBean.class, LifecycleEmitter.class); sar.addAsManifestResource(ServiceMBeanSupportOrderingTestCase.class.getPackage(), "jboss-service.xml", "jboss-service.xml"); sar.addAsManifestResource(createPermissionsXmlAsset( new MBeanPermission(ServiceMBeanSupportOrderingTestCase.class.getPackage().getName() + ".*", "*")), "permissions.xml"); return sar; } @Deployment public static JavaArchive getTestResultMBeanSar() { final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, "service-mbean-order-test-result.sar"); sar.addClasses(LifecycleListenerMBean.class, LifecycleListener.class); sar.addAsManifestResource(ServiceMBeanSupportOrderingTestCase.class.getPackage(), "result-jboss-service.xml", "jboss-service.xml"); return sar; } /** * Tests that invocation on a service deployed within a .sar, inside a .ear without an application.xml, is successful. * * @throws Exception */ @Test public void testServiceMBeanSupportLifecycleOrder() throws Exception { // get mbean server final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials()); final MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection(); // deploy the unmanaged sar deployer.deploy(ServiceMBeanSupportOrderingTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME); // undeploy it deployer.undeploy(ServiceMBeanSupportOrderingTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME); // Check the order of lifecycle events checkOrder(mBeanServerConnection, "Starts", FORWARD_ORDER); checkOrder(mBeanServerConnection, "Stops", REVERSE_ORDER); checkOrder(mBeanServerConnection, "Creates", FORWARD_ORDER); checkOrder(mBeanServerConnection, "Destroys", REVERSE_ORDER); } private static void checkOrder(MBeanServerConnection mBeanServerConnection, String lifecycleStage, List<String> expected) throws MalformedObjectNameException, ReflectionException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, IOException { List<?> order = (List<?>) mBeanServerConnection.getAttribute(new ObjectName("jboss:name=OrderListener"), lifecycleStage); Assert.assertEquals("Unexpected order for " + lifecycleStage, expected, order); } }
5,861
45.896
268
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/order/LifecycleListener.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.test.integration.sar.order; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.jboss.system.ServiceMBeanSupport; public class LifecycleListener extends ServiceMBeanSupport implements LifecycleListenerMBean { private final List<String> creates = Collections.synchronizedList(new ArrayList<>()); private final List<String> starts = Collections.synchronizedList(new ArrayList<>()); private final List<String> stops = Collections.synchronizedList(new ArrayList<>()); private final List<String> destroys = Collections.synchronizedList(new ArrayList<>()); @Override public void mbeanCreated(String id) { creates.add(id); } @Override public synchronized void mbeanStarted(String id) { starts.add(id); } @Override public synchronized void mbeanStopped(String id) { stops.add(id); } @Override public void mbeanDestroyed(String id) { destroys.add(id); } @Override public List<String> getCreates() { return creates; } @Override public List<String> getStarts() { return starts; } @Override public List<String> getStops() { return stops; } @Override public List<String> getDestroys() { return destroys; } }
2,052
26.743243
94
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/order/LifecycleEmitter.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.test.integration.sar.order; import javax.management.InstanceNotFoundException; import javax.management.MBeanException; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import javax.management.ReflectionException; import org.jboss.system.ServiceMBeanSupport; public class LifecycleEmitter extends ServiceMBeanSupport implements LifecycleEmitterMBean { private static final String[] LISTENER_SIG = { "java.lang.String" }; private static volatile ObjectName LISTENER; private volatile String id; private volatile ObjectName listener; @Override public String getId() { return id; } @Override public void setId(String id) { this.id = id; } @Override public ObjectName getLifecycleListener() { return listener; } @Override public void setLifecycleListener(ObjectName listener) { this.listener = listener; } @Override protected void createService() throws Exception { invokeListener("mbeanCreated"); } @Override protected void startService() throws Exception { invokeListener("mbeanStarted"); } @Override protected void stopService() throws Exception { invokeListener("mbeanStopped"); } @Override protected void destroyService() throws Exception { invokeListener("mbeanDestroyed"); } private void invokeListener(String methodName) throws MalformedObjectNameException, ReflectionException, InstanceNotFoundException, MBeanException { if ("A".equals(id)) { // Add a delay to give the other mbeans a chance to (incorrectly) move ahead try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } getServer().invoke(getListenerObjectName(), methodName, new Object[]{ id }, LISTENER_SIG); } private static ObjectName getListenerObjectName() throws MalformedObjectNameException { if (LISTENER == null) { LISTENER = ObjectName.getInstance("jboss:name=OrderListener"); } return LISTENER; } }
2,933
29.5625
152
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/order/LifecycleListenerMBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021 Red Hat, Inc., and individual contributors * as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.test.integration.sar.order; import java.util.List; public interface LifecycleListenerMBean { void mbeanCreated(String id); void mbeanStarted(String id); void mbeanStopped(String id); void mbeanDestroyed(String id); List<String> getCreates(); List<String> getStarts(); List<String> getStops(); List<String> getDestroys(); }
1,095
25.095238
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/SarInjectionTestCase.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.sar.injection; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; 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.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.sar.injection.pojos.A; 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.xnio.IoUtils; /** * [AS7-2574] setter declared in a superclass prevents SAR deployments from being deployed * * @author <a href="mailto:[email protected]">Richard Opalka</a> */ @RunWith(Arquillian.class) @RunAsClient public final class SarInjectionTestCase { @ContainerResource private ManagementClient managementClient; @Deployment public static JavaArchive createDeployment() throws Exception { final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, "injection.sar"); sar.addPackage(A.class.getPackage()); sar.addAsManifestResource(SarInjectionTestCase.class.getPackage(), "jboss-service.xml", "jboss-service.xml"); return sar; } @Test public void testMBean() throws Exception { final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL()); try { final MBeanServerConnection mbeanServer = connector.getMBeanServerConnection(); final ObjectName objectName = new ObjectName("jboss:name=POJOService"); Assert.assertTrue(2 == (Integer) mbeanServer.getAttribute(objectName, "Count")); Assert.assertTrue(2 == (Integer) mbeanServer.getAttribute(objectName, "InjectedCount")); Assert.assertTrue((Boolean) mbeanServer.getAttribute(objectName, "CreateCalled")); Assert.assertTrue((Boolean) mbeanServer.getAttribute(objectName, "StartCalled")); Assert.assertFalse((Boolean) mbeanServer.getAttribute(objectName, "StopCalled")); Assert.assertFalse((Boolean) mbeanServer.getAttribute(objectName, "DestroyCalled")); } finally { IoUtils.safeClose(connector); } } }
3,495
41.634146
117
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/valuefactory/SourceBean.java
/* Copyright 2016 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.sar.injection.valuefactory; public class SourceBean implements SourceBeanMBean { private int count; @Override public int getCount() { return count; } public void setCount(int count) { this.count = count; } @Override public int getCount(String count) { return Integer.parseInt(count); } }
950
25.416667
72
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/valuefactory/TargetBeanMBean.java
/* Copyright 2016 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.sar.injection.valuefactory; public interface TargetBeanMBean { int getSourceCount(); int getCountWithArgument(); }
723
29.166667
72
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/valuefactory/SourceBeanMBean.java
/* Copyright 2016 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.sar.injection.valuefactory; public interface SourceBeanMBean { int getCount(); int getCount(String count); }
716
30.173913
72
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/valuefactory/TargetBean.java
/* Copyright 2016 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.sar.injection.valuefactory; public class TargetBean implements TargetBeanMBean { private int sourceCount; private int countWithArgument; @Override public int getSourceCount() { return sourceCount; } public void setSourceCount(int sourceCount) { this.sourceCount = sourceCount; } @Override public int getCountWithArgument() { return countWithArgument; } public void setCountWithArgument(int countWithArgument) { this.countWithArgument = countWithArgument; } }
1,142
26.878049
72
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/valuefactory/SarValueFactoryInjectionTestCase.java
/* Copyright 2016 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.sar.injection.valuefactory; 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.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.container.ManagementClient; 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.xnio.IoUtils; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; @RunWith(Arquillian.class) @RunAsClient public final class SarValueFactoryInjectionTestCase { @ContainerResource private ManagementClient managementClient; @Deployment public static JavaArchive createDeployment() throws Exception { final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, "injection.sar"); sar.addPackage(SourceBean.class.getPackage()); sar.addAsManifestResource(SarValueFactoryInjectionTestCase.class.getPackage(), "jboss-service.xml", "jboss-service.xml"); return sar; } @Test public void testMBean() throws Exception { final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL()); try { final MBeanServerConnection mbeanServer = connector.getMBeanServerConnection(); final ObjectName objectName = new ObjectName("jboss:name=TargetBean"); Assert.assertEquals("Injection using value-factory without method arguments failed", 2, ((Integer) mbeanServer.getAttribute(objectName, "SourceCount")).intValue()); Assert.assertEquals("Injection using value-factory with method argument failed", 4, ((Integer) mbeanServer.getAttribute(objectName, "CountWithArgument")).intValue()); } finally { IoUtils.safeClose(connector); } } }
2,623
39.369231
178
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/pojos/POJOServiceMBean.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.sar.injection.pojos; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public interface POJOServiceMBean { boolean getStartCalled(); boolean getStopCalled(); boolean getCreateCalled(); boolean getDestroyCalled(); int getCount(); int getInjectedCount(); }
1,379
31.093023
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/pojos/AbstractSetterMethodsA.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.sar.injection.pojos; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public abstract class AbstractSetterMethodsA extends AbstractLifycycleMethodsA { private int count; public final void setCount(final int count) { this.count = count; } public final int getCount() { return this.count; } }
1,425
33.780488
80
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/pojos/POJOService.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.sar.injection.pojos; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public final class POJOService extends AbstractService implements POJOServiceMBean {}
1,250
42.137931
85
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/pojos/AbstractService.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.sar.injection.pojos; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> */ abstract class AbstractService { private A a; private int injectedCount; public final void setA(final A a) { this.a = a; } public final int getCount() { return a.getCount(); } public final int getInjectedCount() { return injectedCount; } public void setInjectedCount(int injectedCount) { this.injectedCount = injectedCount; } public final boolean getStartCalled() { return a.getStartCalled(); } public final boolean getStopCalled() { return a.getStopCalled(); } public final boolean getCreateCalled() { return a.getCreateCalled(); } public final boolean getDestroyCalled() { return a.getDestroyCalled(); } }
1,918
28.075758
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/pojos/AMBean.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.sar.injection.pojos; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public interface AMBean { int getCount(); boolean getStartCalled(); boolean getCreateCalled(); }
1,277
33.540541
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/pojos/A.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.sar.injection.pojos; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> */ public final class A extends AbstractSetterMethodsA implements AMBean {}
1,237
41.689655
72
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/pojos/AbstractLifycycleMethodsA.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.sar.injection.pojos; /** * @author <a href="mailto:[email protected]">Richard Opalka</a> */ abstract class AbstractLifycycleMethodsA { private boolean startCalled; private boolean stopCalled; private boolean createCalled; private boolean destroyCalled; public final void start() { startCalled = true; } public final void stop() { stopCalled = true; } public final void create() { createCalled = true; } public final void destroy() { destroyCalled = true; } public final boolean getStartCalled() { return startCalled; } public final boolean getStopCalled() { return stopCalled; } public final boolean getCreateCalled() { return createCalled; } public final boolean getDestroyCalled() { return destroyCalled; } }
1,937
27.5
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/depends/B.java
package org.jboss.as.test.integration.sar.injection.depends; import java.util.List; import javax.management.ObjectName; public class B implements BMBean { private List<ObjectName> names; @Override public List<ObjectName> getObjectNames() { return names; } @Override public void setObjectNames(List<ObjectName> names) { this.names = names; } }
392
18.65
60
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/depends/AMBean.java
package org.jboss.as.test.integration.sar.injection.depends; import javax.management.ObjectName; public interface AMBean { ObjectName getObjectName(); void setObjectName(ObjectName text); }
201
19.2
60
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/depends/A.java
package org.jboss.as.test.integration.sar.injection.depends; import javax.management.ObjectName; public class A implements AMBean { ObjectName name; public ObjectName getObjectName() { return name; } public void setObjectName(ObjectName name) { this.name = name; } }
307
18.25
60
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/depends/BMBean.java
package org.jboss.as.test.integration.sar.injection.depends; import java.util.List; import javax.management.ObjectName; public interface BMBean { List<ObjectName> getObjectNames(); void setObjectNames(List<ObjectName> names); }
247
21.545455
60
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/depends/DependsTestCase.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.sar.injection.depends; import java.util.List; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnectorFactory; 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.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.common.DefaultConfiguration; 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 Tomasz Adamski */ @RunWith(Arquillian.class) @RunAsClient public final class DependsTestCase { @ContainerResource private ManagementClient managementClient; @Deployment public static JavaArchive createDeployment() throws Exception { final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, "injection.sar"); sar.addPackage(A.class.getPackage()); sar.addAsManifestResource(DependsTestCase.class.getPackage(), "jboss-service.xml", "jboss-service.xml"); return sar; } @Test @SuppressWarnings("unchecked") public void testMBean() throws Exception { final MBeanServerConnection mbeanServer = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials()).getMBeanServerConnection(); final ObjectName a1ObjectName = new ObjectName("test:service=A1"); final ObjectName aObjectName = (ObjectName) mbeanServer.getAttribute(a1ObjectName, "ObjectName"); Assert.assertTrue(aObjectName.equals(new ObjectName("test:service=A"))); final ObjectName bObjectName = new ObjectName("test:service=B"); final List<ObjectName> objectNames = (List<ObjectName>) mbeanServer.getAttribute(bObjectName, "ObjectNames"); Assert.assertTrue(objectNames.contains(new ObjectName("test:service=A"))); Assert.assertTrue(objectNames.contains(new ObjectName("test:service=A1"))); } }
3,211
40.714286
177
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/resource/X.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.sar.injection.resource; import jakarta.annotation.Resource; import javax.naming.Context; import jakarta.transaction.TransactionManager; /** * * @author Eduardo Martins * */ public class X implements XMBean { private TransactionManager transactionManager; @Resource(lookup = "java:jboss/mail") private Context context; @Resource(lookup = "java:/TransactionManager") public void setTransactionManager(TransactionManager transactionManager) { this.transactionManager = transactionManager; } @Override public boolean resourcesInjected() { return transactionManager != null && context != null; } }
1,718
32.057692
78
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/resource/XMBean.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.sar.injection.resource; /** * * @author Eduardo Martins * */ public interface XMBean { /** * * @return */ boolean resourcesInjected(); }
1,229
30.538462
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/injection/resource/SarResourceInjectionTestCase.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.sar.injection.resource; import jakarta.annotation.Resource; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; 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.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.common.DefaultConfiguration; 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.xnio.IoUtils; /** * [AS7-1699] Tests {@link Resource} injection on MBeans * * @author Eduardo Martins */ @RunWith(Arquillian.class) @RunAsClient public final class SarResourceInjectionTestCase { @ContainerResource private ManagementClient managementClient; @Deployment public static JavaArchive createDeployment() throws Exception { return ShrinkWrap.create(JavaArchive.class, "as7-1699.sar") .addClasses(XMBean.class, X.class) .addAsManifestResource(SarResourceInjectionTestCase.class.getPackage(), "jboss-service.xml", "jboss-service.xml"); } @Test public void testMBean() throws Exception { final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials()); try { final MBeanServerConnection mbeanServer = connector.getMBeanServerConnection(); final ObjectName objectName = new ObjectName("jboss:name=X"); Assert.assertTrue((Boolean) mbeanServer.invoke(objectName, "resourcesInjected", null, null)); } finally { IoUtils.safeClose(connector); } } }
3,011
38.631579
139
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/context/classloader/MBeanTCCLTestCase.java
package org.jboss.as.test.integration.sar.context.classloader; import java.io.IOException; import javax.management.MBeanServerConnection; import javax.management.MBeanTrustPermission; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; 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.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.common.DefaultConfiguration; import org.jboss.as.test.integration.sar.context.classloader.mbean.MBeanInAModuleService; import org.jboss.as.test.integration.sar.context.classloader.mbean.MBeanInAModuleServiceMBean; 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.After; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.xnio.IoUtils; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; /** * Tests that the MBean instance lifecycle has the correct TCCL set. The TCCL is expected to be the classloader of the deployment through which the MBean was deployed. * * @author: Jaikiran Pai * @see https://issues.jboss.org/browse/WFLY-822 */ @RunWith(Arquillian.class) @RunAsClient public class MBeanTCCLTestCase { private static final String EAR_NAME = "tccl-mbean-test-app"; private static final String SAR_NAME = "tccl-mbean-test-sar"; @ContainerResource private ManagementClient managementClient; private JMXConnector connector; /** * .ear * | * |---- META-INF/jboss-deployment-structure.xml * | * |---- .sar * | | * | |--- META-INF/jboss-service.xml (deploys the MBean whose class resides in a separate JBoss module) * | | * | |--- ClassA, ClassB, ClassC, ClassD (all of which will be attempted to be loaded from the MBean class which resides in a different JBoss module than this deployment) * | * | * |---- .jar (configured as a JBoss Module in jboss-deployment-structure.xml of the .ear) * | | * | |---- MBean class (which relies on TCCL to load the classes present in the .sar deployment) * * @return */ @Deployment public static Archive createDeployment() { // create a .sar which will contain a jboss-service.xml. The actual MBean class will reside in a module which will be added as a dependency on the .sar final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, SAR_NAME + ".sar"); // add the jboss-service.xml to the META-INF of the .sar sar.addAsManifestResource(MBeanInAModuleService.class.getPackage(), "tccl-test-service.xml", "jboss-service.xml"); // add some (dummy) classes to the .sar. These classes will then be attempted to be loaded from the MBean class (which resides in a module) sar.addClasses(ClassAInSarDeployment.class, ClassBInSarDeployment.class, ClassCInSarDeployment.class, ClassDInSarDeployment.class); // now create a plain .jar containing the MBean class. This jar will be configured as a JBoss Module, in the jboss-deployment-structure.xml of the .ear to which this // .jar will be added final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "jar-containing-mbean-class.jar"); jar.addClasses(MBeanInAModuleService.class, MBeanInAModuleServiceMBean.class); // create the .ear with the .sar and the .jar and the jboss-deployment-structure.xml final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, EAR_NAME + ".ear"); ear.addAsModule(sar); ear.addAsModule(jar); ear.addAsManifestResource(MBeanTCCLTestCase.class.getPackage(), "jboss-deployment-structure.xml", "jboss-deployment-structure.xml"); ear.addAsManifestResource(createPermissionsXmlAsset( // mbean [wildfly:name=tccl-test-mbean] needs the following permission new MBeanTrustPermission("register"), // MBeanInAModuleService#testClassLoadByTCCL() needs the following permission new RuntimePermission("getClassLoader")), "permissions.xml"); return ear; } @After public void closeConnector() { IoUtils.safeClose(connector); } /** * Tests the MBean was deployed successfully and can be invoked. The fact that the MBean deployed successfully is a sign that the TCCL access from within the MBean code, worked fine * * @throws Exception */ @Test public void testTCCLInMBeanInvocation() throws Exception { final MBeanServerConnection mBeanServerConnection = this.getMBeanServerConnection(); final ObjectName mbeanObjectName = new ObjectName("wildfly:name=tccl-test-mbean"); final int num1 = 3; final int num2 = 4; // invoke the operation on MBean final Integer sum = (Integer) mBeanServerConnection.invoke(mbeanObjectName, "add", new Object[]{num1, num2}, new String[]{Integer.TYPE.getName(), Integer.TYPE.getName()}); Assert.assertEquals("Unexpected return value from MBean: " + mbeanObjectName, num1 + num2, (int) sum); } private MBeanServerConnection getMBeanServerConnection() throws IOException { connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials()); return connector.getMBeanServerConnection(); } }
5,785
46.42623
185
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/context/classloader/ClassDInSarDeployment.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.sar.context.classloader; /** * @author: Jaikiran Pai */ public class ClassDInSarDeployment { }
1,160
37.7
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/context/classloader/ClassCInSarDeployment.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.sar.context.classloader; /** * @author: Jaikiran Pai */ public class ClassCInSarDeployment { }
1,160
37.7
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/context/classloader/ClassBInSarDeployment.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.sar.context.classloader; /** * @author: Jaikiran Pai */ public class ClassBInSarDeployment { }
1,160
37.7
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/context/classloader/ClassAInSarDeployment.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.sar.context.classloader; /** * @author: Jaikiran Pai */ public class ClassAInSarDeployment { }
1,160
37.7
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/sar/context/classloader/mbean/MBeanInAModuleServiceMBean.java
package org.jboss.as.test.integration.sar.context.classloader.mbean; /** * @author: Jaikiran Pai */ public interface MBeanInAModuleServiceMBean { int add(int a, int b); }
179
17
68
java