This repository has been archived by the owner on Oct 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EAT] : Adding an ejb-client testcase with wildfly-config. Other conf…
…ig changes. (JBEAP-10301)
- Loading branch information
Showing
12 changed files
with
610 additions
and
1 deletion.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
...org/jboss/additional/testsuite/jdkall/present/ejb/remote/client/AbstractEJBDirectory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* 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.additional.testsuite.jdkall.present.ejb.remote.client; | ||
|
||
import java.util.Properties; | ||
|
||
import javax.ejb.EJBHome; | ||
import javax.ejb.SessionBean; | ||
import javax.naming.Context; | ||
import javax.naming.InitialContext; | ||
import javax.naming.NamingException; | ||
import javax.transaction.UserTransaction; | ||
import org.jboss.eap.additional.testsuite.annotations.EapAdditionalTestsuite; | ||
|
||
|
||
/** | ||
* @author Paul Ferraro | ||
* | ||
*/ | ||
@EapAdditionalTestsuite({"modules/testcases/jdkAll/Wildfly/ejb/src/main/java","modules/testcases/jdkAll/Eap7/ejb/src/main/java"}) | ||
public abstract class AbstractEJBDirectory implements EJBDirectory { | ||
private final Context context; | ||
private final String txContextName; | ||
|
||
protected enum Type { | ||
STATEFUL, STATELESS, SINGLETON, HOME | ||
} | ||
|
||
protected AbstractEJBDirectory(String txContextName, Properties env) throws NamingException { | ||
this(txContextName, new InitialContext(env)); | ||
} | ||
|
||
protected AbstractEJBDirectory(String txContextName, InitialContext context) { | ||
this.context = context; | ||
this.txContextName = txContextName; | ||
} | ||
|
||
@Override | ||
public void close() throws NamingException { | ||
this.context.close(); | ||
} | ||
|
||
@Override | ||
public <T> T lookupStateful(Class<? extends T> beanClass, Class<T> beanInterface) throws NamingException { | ||
return this.lookupStateful(beanClass.getSimpleName(), beanInterface); | ||
} | ||
|
||
@Override | ||
public <T> T lookupStateful(String beanName, Class<T> beanInterface) throws NamingException { | ||
return this.lookup(beanName, beanInterface, Type.STATEFUL); | ||
} | ||
|
||
@Override | ||
public <T> T lookupStateless(Class<? extends T> beanClass, Class<T> beanInterface) throws NamingException { | ||
return this.lookupStateless(beanClass.getSimpleName(), beanInterface); | ||
} | ||
|
||
@Override | ||
public <T> T lookupStateless(String beanName, Class<T> beanInterface) throws NamingException { | ||
return this.lookup(beanName, beanInterface, Type.STATELESS); | ||
} | ||
|
||
@Override | ||
public <T> T lookupSingleton(Class<? extends T> beanClass, Class<T> beanInterface) throws NamingException { | ||
return this.lookupSingleton(beanClass.getSimpleName(), beanInterface); | ||
} | ||
|
||
@Override | ||
public <T> T lookupSingleton(String beanName, Class<T> beanInterface) throws NamingException { | ||
return this.lookup(beanName, beanInterface, Type.SINGLETON); | ||
} | ||
|
||
@Override | ||
public <T extends EJBHome> T lookupHome(Class<? extends SessionBean> beanClass, Class<T> homeInterface) throws NamingException { | ||
return this.lookupHome(beanClass.getSimpleName(), homeInterface); | ||
} | ||
|
||
@Override | ||
public <T extends EJBHome> T lookupHome(String beanName, Class<T> homeInterface) throws NamingException { | ||
return this.lookup(beanName, homeInterface, Type.HOME); | ||
} | ||
|
||
@Override | ||
public UserTransaction lookupUserTransaction() throws NamingException { | ||
return this.lookup(this.txContextName, UserTransaction.class); | ||
} | ||
|
||
protected <T> T lookup(String beanName, Class<T> beanInterface, Type type) throws NamingException { | ||
return this.lookup(this.createJndiName(beanName, beanInterface, type), beanInterface); | ||
} | ||
|
||
protected abstract <T> String createJndiName(String beanName, Class<T> beanInterface, Type type); | ||
|
||
protected <T> T lookup(String name, Class<T> targetClass) throws NamingException { | ||
return targetClass.cast(this.context.lookup(name)); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...in/java/org/jboss/additional/testsuite/jdkall/present/ejb/remote/client/EJBDirectory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.additional.testsuite.jdkall.present.ejb.remote.client; | ||
|
||
import javax.ejb.EJBHome; | ||
import javax.ejb.SessionBean; | ||
import javax.naming.NamingException; | ||
import javax.transaction.UserTransaction; | ||
import org.jboss.eap.additional.testsuite.annotations.EapAdditionalTestsuite; | ||
|
||
/** | ||
* EJB lookup helper | ||
* | ||
* @author Paul Ferraro | ||
*/ | ||
@EapAdditionalTestsuite({"modules/testcases/jdkAll/Wildfly/ejb/src/main/java","modules/testcases/jdkAll/Eap7/ejb/src/main/java"}) | ||
public interface EJBDirectory extends AutoCloseable { | ||
<T> T lookupStateful(String beanName, Class<T> beanInterface) throws NamingException; | ||
|
||
<T> T lookupStateful(Class<? extends T> beanClass, Class<T> beanInterface) throws NamingException; | ||
|
||
<T> T lookupStateless(String beanName, Class<T> beanInterface) throws NamingException; | ||
|
||
<T> T lookupStateless(Class<? extends T> beanClass, Class<T> beanInterface) throws NamingException; | ||
|
||
<T> T lookupSingleton(String beanName, Class<T> beanInterface) throws NamingException; | ||
|
||
<T> T lookupSingleton(Class<? extends T> beanClass, Class<T> beanInterface) throws NamingException; | ||
|
||
<T extends EJBHome> T lookupHome(String beanName, Class<T> homeInterface) throws NamingException; | ||
|
||
<T extends EJBHome> T lookupHome(Class<? extends SessionBean> beanClass, Class<T> homeInterface) throws NamingException; | ||
|
||
UserTransaction lookupUserTransaction() throws NamingException; | ||
|
||
@Override | ||
void close() throws NamingException; | ||
} |
139 changes: 139 additions & 0 deletions
139
.../jboss/additional/testsuite/jdkall/present/ejb/remote/client/RemoteEJBClientTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2015, Red Hat, Inc. and/or its affiliates, 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.additional.testsuite.jdkall.present.ejb.remote.client; | ||
|
||
import java.io.File; | ||
import org.jboss.additional.testsuite.jdkall.present.ejb.remote.stateful.RemoteCounter; | ||
import org.jboss.additional.testsuite.jdkall.present.ejb.remote.stateless.RemoteCalculator; | ||
|
||
import javax.naming.NamingException; | ||
import org.jboss.additional.testsuite.jdkall.present.ejb.remote.stateful.CounterBean; | ||
import org.jboss.additional.testsuite.jdkall.present.ejb.remote.stateless.CalculatorBean; | ||
|
||
import org.jboss.eap.additional.testsuite.annotations.EapAdditionalTestsuite; | ||
|
||
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.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import static org.junit.Assert.assertTrue; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* A sample program which acts a remote client for a EJB deployed on JBoss EAP server. This program shows how to lookup stateful and | ||
* stateless beans via JNDI and then invoke on them | ||
* | ||
* @author Jaikiran Pai | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
@EapAdditionalTestsuite({"modules/testcases/jdkAll/Wildfly/ejb/src/main/java","modules/testcases/jdkAll/Eap7/ejb/src/main/java"}) | ||
public class RemoteEJBClientTestCase { | ||
|
||
private static final String ARCHIVE_NAME = "test"; | ||
|
||
@Deployment | ||
public static Archive<?> deploy() { | ||
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar"); | ||
jar.addClass(RemoteEJBClientTestCase.class); | ||
jar.addPackage(RemoteCounter.class.getPackage()); | ||
jar.addPackage(RemoteCalculator.class.getPackage()); | ||
jar.addAsResource("META-INF/wildfly-config.xml"); | ||
return jar; | ||
} | ||
|
||
|
||
@Test | ||
public void testVoidAsyncStatelessMethod() throws Exception { | ||
// Invoke a stateless bean | ||
invokeStatelessBean(); | ||
|
||
// Invoke a stateful bean | ||
invokeStatefulBean(); | ||
} | ||
|
||
/** | ||
* Looks up a stateless bean and invokes on it | ||
* | ||
* @throws NamingException | ||
*/ | ||
private static void invokeStatelessBean() throws Exception { | ||
// Let's lookup the remote stateless calculator | ||
final RemoteCalculator statelessRemoteCalculator = lookupRemoteStatelessCalculator(); | ||
// invoke on the remote calculator | ||
int a = 204; | ||
int b = 340; | ||
int sum = statelessRemoteCalculator.add(a, b); | ||
assertTrue("invokeStatelessBean error ...", sum == a + b); | ||
// try one more invocation, this time for subtraction | ||
int num1 = 3434; | ||
int num2 = 2332; | ||
int difference = statelessRemoteCalculator.subtract(num1, num2); | ||
|
||
assertTrue("invokeStatelessBean error ...", difference == num1 - num2); | ||
} | ||
|
||
/** | ||
* Looks up a stateful bean and invokes on it | ||
* | ||
* @throws NamingException | ||
*/ | ||
private static void invokeStatefulBean() throws Exception { | ||
// Let's lookup the remote stateful counter | ||
final RemoteCounter statefulRemoteCounter = lookupRemoteStatefulCounter(); | ||
// invoke on the remote counter bean | ||
final int NUM_TIMES = 5; | ||
for (int i = 0; i < NUM_TIMES; i++) { | ||
statefulRemoteCounter.increment(); | ||
} | ||
assertTrue("invokeStatefulBean error ...", statefulRemoteCounter.getCount() == NUM_TIMES); | ||
// now decrementing | ||
for (int i = NUM_TIMES; i > 0; i--) { | ||
statefulRemoteCounter.decrement(); | ||
} | ||
assertTrue("invokeStatefulBean error ...", statefulRemoteCounter.getCount() == 0); | ||
} | ||
|
||
/** | ||
* Looks up and returns the proxy to remote stateless calculator bean | ||
* | ||
* @return | ||
* @throws NamingException | ||
*/ | ||
private static RemoteCalculator lookupRemoteStatelessCalculator() throws Exception { | ||
EJBDirectory context = new RemoteEJBDirectory(ARCHIVE_NAME); | ||
RemoteCalculator bean = context.lookupStateless(CalculatorBean.class, RemoteCalculator.class); | ||
|
||
return bean; | ||
} | ||
|
||
/** | ||
* Looks up and returns the proxy to remote stateful counter bean | ||
* | ||
* @return | ||
* @throws NamingException | ||
*/ | ||
private static RemoteCounter lookupRemoteStatefulCounter() throws NamingException { | ||
EJBDirectory context = new RemoteEJBDirectory(ARCHIVE_NAME); | ||
RemoteCounter bean = context.lookupStateful(CounterBean.class, RemoteCounter.class); | ||
|
||
return bean; | ||
} | ||
} |
Oops, something went wrong.