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/ejb2/reference/annotation/StatefulSession30.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.ejb2.reference.annotation;
import jakarta.ejb.EJBObject;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
public interface StatefulSession30 extends EJBObject, StatefulSession30RemoteBusiness {
}
| 1,294 | 39.46875 | 87 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/ejb2/reference/annotation/LocalStatefulSession30.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.ejb2.reference.annotation;
import jakarta.ejb.EJBLocalObject;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
public interface LocalStatefulSession30 extends EJBLocalObject {
String getLocalValue();
void setLocalValue(String value);
}
| 1,343 | 37.4 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/ejb2/reference/annotation/ReferenceAnnotationDescriptorTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.ejb2.reference.annotation;
import java.rmi.NoSuchObjectException;
import jakarta.ejb.EJBHome;
import jakarta.ejb.EJBMetaData;
import jakarta.ejb.EJBObject;
import jakarta.ejb.Handle;
import jakarta.ejb.HomeHandle;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.test.integration.ejb.ejb2.reference.global.Session21;
import org.jboss.as.test.integration.ejb.ejb2.reference.global.Session21Bean;
import org.jboss.as.test.integration.ejb.ejb2.reference.global.Session21Home;
import org.jboss.as.test.integration.ejb.ejb2.reference.global.Session30;
import org.jboss.as.test.integration.ejb.ejb2.reference.global.Session30RemoteBusiness;
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;
/**
* Test for EJB3.0/EJB2.1 references.
* Part of migration from EJB Testsuite (reference21_30) to AS7 [JIRA JBQA-5483].
*
* @author William DeCoste, Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
public class ReferenceAnnotationDescriptorTestCase {
@Deployment
public static Archive<?> deployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "reference-ejb2-ejb3.jar")
.addClasses(
HomedStatefulSession30Bean.class,
LocalSession30.class,
LocalSession30Business.class,
LocalStatefulSession30.class,
LocalStatefulSession30Business.class,
ReferenceAnnotationDescriptorTestCase.class,
Session30Home.class,
Session30LocalHome.class,
Session30Bean.class,
StatefulSession30.class,
StatefulSession30Bean.class,
StatefulSession30Home.class,
StatefulSession30LocalHome.class,
StatefulSession30RemoteBusiness.class
)
.addClasses(
Session30.class,
Session30RemoteBusiness.class,
Session21.class,
Session21Home.class,
Session21Bean.class);
jar.addAsManifestResource(ReferenceAnnotationDescriptorTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
jar.addAsManifestResource(ReferenceAnnotationDescriptorTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
return jar;
}
@Test
public void testSession21() throws Exception {
InitialContext jndiContext = new InitialContext();
Session21Home home = (Session21Home) jndiContext.lookup("java:module/Session21!" + Session21Home.class.getName());
Session21 session = home.create();
String access = session.access();
Assert.assertEquals("Session21", access);
access = session.access30();
Assert.assertEquals("Session30", access);
}
@Test
public void testSession30() throws Exception {
InitialContext jndiContext = new InitialContext();
Session30Home sessionHome = (Session30Home) jndiContext.lookup("java:module/Session30!" + Session30Home.class.getName());
Session30 session = sessionHome.create();
String access = session.access();
Assert.assertEquals("Session30", access);
access = session.access21();
Assert.assertEquals("Session21", access);
}
@Test
public void testSessionHome30() throws Exception {
InitialContext jndiContext = new InitialContext();
Session30RemoteBusiness session = (Session30RemoteBusiness) jndiContext.lookup("java:module/Session30!" + Session30RemoteBusiness.class.getName());
Assert.assertNotNull(session);
String access = session.access();
Assert.assertEquals("Session30", access);
Session30Home home = (Session30Home) jndiContext.lookup("java:module/Session30!" + Session30Home.class.getName());
Assert.assertNotNull(home);
Session30 sessionRemote = home.create();
Assert.assertNotNull(sessionRemote);
access = sessionRemote.access();
Assert.assertEquals("Session30", access);
}
@Test
public void testStatefulRemove() throws Exception {
InitialContext jndiContext = new InitialContext();
StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("java:module/StatefulSession30!" + StatefulSession30Home.class.getName());
Assert.assertNotNull(home);
StatefulSession30 session = home.create();
Assert.assertNotNull(session);
session.setValue("123");
String value = session.getValue();
Assert.assertEquals("123", value);
EJBObject ejbObject = session;
Handle handle = session.getHandle();
Assert.assertNotNull(handle);
home.remove(handle);
try {
session.getValue();
Assert.assertTrue(false);
} catch (NoSuchObjectException nsoe) {
// OK: EJB3.1 7.5.3
}
session = home.create();
Assert.assertNotNull(session);
session.setValue("123");
value = session.getValue();
Assert.assertEquals("123", value);
session.remove();
try {
session.getValue();
Assert.assertTrue(false);
} catch (NoSuchObjectException nsoe) {
// OK: EJB3.1 7.5.3
}
}
@Test
public void testStatefulSessionHome30() throws Exception {
InitialContext jndiContext = new InitialContext();
StatefulSession30RemoteBusiness session = (StatefulSession30RemoteBusiness) jndiContext.lookup("java:module/StatefulSession30!" + StatefulSession30RemoteBusiness.class.getName());
Assert.assertNotNull(session);
session.setValue("testing");
String value = session.getValue();
Assert.assertEquals("testing", value);
StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("java:module/StatefulSession30!" + StatefulSession30Home.class.getName());
Assert.assertNotNull(home);
session = home.create();
Assert.assertNotNull(session);
session.setValue("123");
value = session.getValue();
Assert.assertEquals("123", value);
session = home.create("456");
Assert.assertNotNull(session);
value = session.getValue();
Assert.assertEquals("456", value);
session = home.create("combined", new Integer("789"));
Assert.assertNotNull(session);
value = session.getValue();
Assert.assertEquals("combined789", value);
}
@Test
public void testRemoteHomeAnnotation() throws Exception {
InitialContext jndiContext = new InitialContext();
StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("java:module/HomedStatefulSession30!" + StatefulSession30Home.class.getName());
Assert.assertNotNull(home);
StatefulSession30 session = home.create();
Assert.assertNotNull(session);
session.setValue("123");
String value = session.getValue();
Assert.assertEquals("123", value);
session = home.create("456");
Assert.assertNotNull(session);
value = session.getValue();
Assert.assertEquals("456", value);
session = home.create("combined", new Integer("789"));
Assert.assertNotNull(session);
value = session.getValue();
Assert.assertEquals("combined789", value);
}
@Test
public void testLocalHomeAnnotation() throws Exception {
InitialContext jndiContext = new InitialContext();
StatefulSession30RemoteBusiness session = (StatefulSession30RemoteBusiness) jndiContext.lookup("java:module/StatefulSession30!" + StatefulSession30RemoteBusiness.class.getName());
String access = session.accessLocalHome();
Assert.assertEquals("LocalHome", access);
}
@Test
public void testLocalHome() throws Exception {
InitialContext jndiContext = new InitialContext();
StatefulSession30RemoteBusiness statefulSession = (StatefulSession30RemoteBusiness) jndiContext.lookup("java:module/StatefulSession30!" + StatefulSession30RemoteBusiness.class.getName());
Assert.assertNotNull(statefulSession);
String access = statefulSession.accessLocalStateless();
Assert.assertEquals("Session30", access);
Session30RemoteBusiness session = (Session30RemoteBusiness) jndiContext.lookup("java:module/Session30!" + Session30RemoteBusiness.class.getName());
Assert.assertNotNull(session);
access = session.accessLocalStateful();
Assert.assertEquals("default", access);
access = session.accessLocalStateful("testing");
Assert.assertEquals("testing", access);
access = session.accessLocalStateful("testing", new Integer(123));
Assert.assertEquals("testing123", access);
}
@Test
public void testStatefulState() throws Exception {
InitialContext jndiContext = new InitialContext();
StatefulSession30RemoteBusiness session1 = (StatefulSession30RemoteBusiness) jndiContext.lookup("java:module/StatefulSession30!" + StatefulSession30RemoteBusiness.class.getName());
Assert.assertNotNull(session1);
session1.setValue("testing");
Assert.assertEquals("testing", session1.getValue());
StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("java:module/StatefulSession30!" + StatefulSession30Home.class.getName());
Assert.assertNotNull(home);
StatefulSession30 session3 = home.create();
Assert.assertNotNull(session3);
session3.setValue("123");
Assert.assertEquals("123", session3.getValue());
StatefulSession30 session4 = home.create();
Assert.assertNotNull(session4);
Assert.assertEquals("default", session4.getValue());
Assert.assertEquals("default", session4.getValue());
StatefulSession30 session5 = home.create("init");
Assert.assertNotNull(session5);
Assert.assertEquals("init", session5.getValue());
StatefulSession30 session6 = home.create("init", new Integer(123));
Assert.assertNotNull(session6);
Assert.assertEquals("init123", session6.getValue());
StatefulSession30 session7 = home.create("secondinit");
Assert.assertNotNull(session7);
Assert.assertEquals("secondinit", session7.getValue());
Assert.assertEquals("testing", session1.getValue());
Assert.assertEquals("123", session3.getValue());
Assert.assertEquals("default", session4.getValue());
Assert.assertEquals("init", session5.getValue());
Assert.assertEquals("init123", session6.getValue());
Assert.assertEquals("secondinit", session7.getValue());
}
@Test
public void testStateful21Interfaces() throws Exception {
InitialContext jndiContext = new InitialContext();
StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("java:module/StatefulSession30!" + StatefulSession30Home.class.getName());
Assert.assertNotNull(home);
EJBMetaData metadata = home.getEJBMetaData();
Assert.assertNotNull(metadata);
Assert.assertEquals(StatefulSession30.class, metadata.getRemoteInterfaceClass());
HomeHandle homeHandle = home.getHomeHandle();
Assert.assertNotNull(homeHandle);
EJBHome ejbHome = homeHandle.getEJBHome();
Assert.assertNotNull(ejbHome);
metadata = ejbHome.getEJBMetaData();
Assert.assertNotNull(metadata);
Assert.assertEquals(StatefulSession30.class, metadata.getRemoteInterfaceClass());
StatefulSession30 session = home.create();
Assert.assertNotNull(session);
ejbHome = session.getEJBHome();
Assert.assertNotNull(ejbHome);
Handle handle = session.getHandle();
Assert.assertNotNull(handle);
EJBObject ejbObject = handle.getEJBObject();
Assert.assertNotNull(ejbObject);
ejbHome = ejbObject.getEJBHome();
Assert.assertNotNull(ejbHome);
Handle handle1 = ejbObject.getHandle();
Assert.assertNotNull(handle1);
StatefulSession30 session1 = home.create();
Assert.assertFalse(session.isIdentical(session1));
Assert.assertTrue(session.isIdentical(session));
}
@Test
public void testStateless21Interfaces() throws Exception {
InitialContext jndiContext = new InitialContext();
Session30Home home = (Session30Home) jndiContext.lookup("java:module/Session30!" + Session30Home.class.getName());
Assert.assertNotNull(home);
EJBMetaData metadata = home.getEJBMetaData();
Assert.assertNotNull(metadata);
Assert.assertEquals(Session30.class.getName(), metadata.getRemoteInterfaceClass().getName());
HomeHandle homeHandle = home.getHomeHandle();
Assert.assertNotNull(homeHandle);
EJBHome ejbHome = homeHandle.getEJBHome();
Assert.assertNotNull(ejbHome);
metadata = ejbHome.getEJBMetaData();
Assert.assertNotNull(metadata);
Assert.assertEquals(Session30.class.getName(), metadata.getRemoteInterfaceClass().getName());
Session30 session = home.create();
Assert.assertNotNull(session);
ejbHome = session.getEJBHome();
Assert.assertNotNull(ejbHome);
Handle handle = session.getHandle();
Assert.assertNotNull(handle);
EJBObject ejbObject = handle.getEJBObject();
Assert.assertNotNull(ejbObject);
ejbHome = ejbObject.getEJBHome();
Assert.assertNotNull(ejbHome);
Handle handle1 = ejbObject.getHandle();
Assert.assertNotNull(handle1);
Session30 session1 = home.create();
Assert.assertTrue(session.isIdentical(session1));
}
}
| 15,276 | 39.630319 | 195 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/ejb2/reference/annotation/StatefulSession30Bean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.ejb2.reference.annotation;
import jakarta.annotation.PreDestroy;
import jakarta.ejb.Init;
import jakarta.ejb.Local;
import jakarta.ejb.LocalHome;
import jakarta.ejb.Remote;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.Stateful;
import javax.naming.InitialContext;
import org.jboss.logging.Logger;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
@Stateful(name = "StatefulSession30")
@Local(LocalStatefulSession30Business.class)
@Remote(StatefulSession30RemoteBusiness.class)
@RemoteHome(StatefulSession30Home.class)
@LocalHome(StatefulSession30LocalHome.class)
public class StatefulSession30Bean implements java.io.Serializable, StatefulSession30RemoteBusiness {
private static final long serialVersionUID = -8986168637251530390L;
private static final Logger log = Logger.getLogger(StatefulSession30Bean.class);
private String value = null;
public void setValue(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public void setLocalValue(String value) {
this.value = value;
}
public String getLocalValue() {
return value;
}
public String accessLocalStateless() {
try {
InitialContext jndiContext = new InitialContext();
Session30LocalHome localHome = (Session30LocalHome) jndiContext.lookup("java:module/Session30!" + Session30LocalHome.class.getName());
LocalSession30 localSession = localHome.create();
return localSession.access();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public String accessLocalHome() {
try {
InitialContext jndiContext = new InitialContext();
StatefulSession30LocalHome home = (StatefulSession30LocalHome) jndiContext.lookup("java:module/HomedStatefulSession30!" + StatefulSession30LocalHome.class.getName());
LocalStatefulSession30 session = home.create();
session.setLocalValue("LocalHome");
return session.getLocalValue();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Init
public void ejbCreate() {
value = "default";
}
@Init
public void ejbCreate(String value) {
this.value = value;
}
@Init
public void ejbCreate(String value, Integer suffix) {
this.value = value + suffix;
}
@PreDestroy
public void preDestroy() {
log.trace("Invoking PreDestroy");
}
}
| 3,615 | 31.576577 | 178 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/ejb2/reference/annotation/StatefulSession30RemoteBusiness.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.ejb2.reference.annotation;
import java.rmi.RemoteException;
/**
* StatefulSession30RemoteBusiness
*
* @author <a href="mailto:[email protected]">ALR</a>
*/
public interface StatefulSession30RemoteBusiness {
void setValue(String value) throws RemoteException;
String getValue() throws RemoteException;
String accessLocalStateless() throws RemoteException;
String accessLocalHome() throws RemoteException;
}
| 1,509 | 35.829268 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/EJBServletHelper.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.servlet;
import javax.naming.InitialContext;
/**
* Implements processRequest method.
*/
public class EJBServletHelper {
protected void processRequest(String lookupString, InitialContext ctx) throws Exception {
Session30BusinessRemote remote = (Session30BusinessRemote) ctx.lookup(lookupString + Session30BusinessRemote.class.getName());
remote.hello();
remote.goodbye();
TestObject o = new TestObject();
remote.access(o);
o = remote.createTestObject();
Session30BusinessLocal local = (Session30BusinessLocal) ctx.lookup(lookupString + Session30BusinessLocal.class.getName());
o = new TestObject();
local.access(o);
o = local.createTestObject();
local.getWarTestObject();
Session30Home home = (Session30Home) ctx.lookup(lookupString + Session30Home.class.getName());
Session30Remote remote21 = home.create();
remote21.access(o);
Session30LocalHome localHome = (Session30LocalHome) ctx.lookup(lookupString + Session30LocalHome.class.getName());
Session30Local local21 = localHome.create();
local21.access(o);
home = (Session30Home) ctx.lookup("java:comp/env/ejb/remote/Session30");
remote21 = home.create();
remote21.access(o);
localHome = (Session30LocalHome) ctx.lookup("java:comp/env/ejb/local/Session30");
local21 = localHome.create();
local21.access(o);
}
}
| 2,532 | 37.378788 | 134 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/Session30Home.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.servlet;
import java.rmi.RemoteException;
import jakarta.ejb.EJBHome;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
public interface Session30Home extends EJBHome {
Session30Remote create() throws jakarta.ejb.CreateException, RemoteException;
}
| 1,347 | 38.647059 | 82 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/StatefulLocal.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.servlet;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
public interface StatefulLocal {
String access(TestObject o);
}
| 1,219 | 38.354839 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/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.ejb.servlet;
import jakarta.ejb.Local;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateful;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
@Stateful(name = "Stateful")
@Remote(StatefulRemote.class)
@Local(StatefulLocal.class)
@SecurityDomain("other")
public class StatefulBean implements StatefulRemote, StatefulLocal {
public String access(TestObject o) {
return "Session30";
}
}
| 1,542 | 34.883721 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/StatefulRemote.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.servlet;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
public interface StatefulRemote {
String access(TestObject o);
}
| 1,220 | 38.387097 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/EJBServletEar.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.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.concurrent.Callable;
import jakarta.ejb.EJB;
import javax.naming.InitialContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jboss.as.test.shared.integration.ejb.security.Util;
import org.jboss.logging.Logger;
/**
* A servlet that accesses an EJB and tests whether the call argument is serialized.
*
* @author [email protected]
*/
public class EJBServletEar extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(EJBServletEar.class);
@EJB(lookup = "java:app/ejb3-ear-servlet-ejbs/Session30!org.jboss.as.test.integration.ejb.servlet.Session30BusinessRemote")
Session30BusinessRemote injectedSession;
@EJB(lookup = "java:app/ejb3-ear-servlet-ejbs/StatelessBean!org.jboss.as.test.integration.ejb.servlet.StatelessLocal")
StatelessLocal injectedStateless;
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final Callable<Void> callable = () -> {
InitialContext ctx = new InitialContext();
injectedSession.hello();
injectedSession.goodbye();
injectedStateless.hello();
injectedStateless.goodbye();
String lookupString = "java:app/ejb3-ear-servlet-ejbs/Session30!";
EJBServletHelper test = new EJBServletHelper();
test.processRequest(lookupString, ctx);
return null;
};
try {
Util.switchIdentitySCF("user1", "password1", callable);
} catch (Exception e) {
log.error(e);
throw new ServletException("Failed to call EJBs/Session30 through remote and local interfaces", e);
}
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.print("EJBServlet OK");
out.close();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
}
| 3,540 | 38.786517 | 130 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/Session30.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.servlet;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
public interface Session30 {
void hello();
void goodbye();
String access(TestObject o);
TestObject createTestObject();
boolean checkEqPointer(TestObject to);
WarTestObject getWarTestObject();
}
| 1,374 | 32.536585 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/Session30Local.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.servlet;
import jakarta.ejb.EJBLocalObject;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
public interface Session30Local extends EJBLocalObject, Session30 {
}
| 1,258 | 38.34375 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/TestObject.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.servlet;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
public class TestObject implements java.io.Serializable {
private static final long serialVersionUID = 1L;
public TestObject() {
}
}
| 1,299 | 35.111111 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/Session30BusinessRemote.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.servlet;
import jakarta.ejb.Remote;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@Remote
public interface Session30BusinessRemote extends Session30 {
}
| 1,249 | 36.878788 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/Session30LocalHome.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.servlet;
import jakarta.ejb.EJBLocalHome;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
public interface Session30LocalHome extends EJBLocalHome {
Session30Local create() throws jakarta.ejb.CreateException;
}
| 1,310 | 38.727273 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/StatelessBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.servlet;
import jakarta.ejb.Local;
import jakarta.ejb.Stateful;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
@Stateful
@Local(StatelessLocal.class)
public class StatelessBean implements StatelessLocal {
public void hello() {
}
public void goodbye() {
}
}
| 1,370 | 33.275 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/Session30Bean.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.servlet;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.EJB;
import jakarta.ejb.Local;
import jakarta.ejb.LocalHome;
import jakarta.ejb.Remote;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.Stateless;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
@Stateless(name = "Session30")
@Remote(Session30BusinessRemote.class)
@Local(Session30BusinessLocal.class)
@RemoteHome(Session30Home.class)
@LocalHome(Session30LocalHome.class)
@SecurityDomain("other")
public class Session30Bean implements Session30 {
@EJB
private StatefulRemote stateful;
private TestObject testObject;
@RolesAllowed({ "Role1" })
public void hello() {
}
@RolesAllowed({ "Role1" })
public void goodbye() {
}
public String access(TestObject o) {
return stateful.access(o);
}
public TestObject createTestObject() {
testObject = new TestObject();
return testObject;
}
public boolean checkEqPointer(TestObject to) {
return to == testObject;
}
public WarTestObject getWarTestObject() {
return new WarTestObject();
}
}
| 2,266 | 28.441558 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/Session30BusinessLocal.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.servlet;
import jakarta.ejb.Local;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@Local
public interface Session30BusinessLocal extends Session30 {
}
| 1,245 | 36.757576 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/StatelessLocal.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.servlet;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
public interface StatelessLocal {
void hello();
void goodbye();
}
| 1,226 | 36.181818 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/Session30Remote.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.servlet;
import jakarta.ejb.EJBObject;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
public interface Session30Remote extends EJBObject, Session30 {
}
| 1,248 | 38.03125 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/ServletUnitTestCase.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.servlet;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.test.integration.common.HttpRequest;
import org.jboss.as.test.shared.integration.ejb.security.Util;
import org.jboss.logging.Logger;
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.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.security.permission.ElytronPermission;
/**
* A servlet that accesses an EJB and tests whether the call argument is serialized.
* Part of migration AS5 testsuite to AS7 [JIRA JBQA-5275].
*
* @author William DeCoste, Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
@RunAsClient
public class ServletUnitTestCase {
private static final Logger log = Logger.getLogger(ServletUnitTestCase.class.getName());
@Deployment(name = "ejb", order = 2)
public static Archive<?> deployEjbs() {
JavaArchive jar = getEjbs("ejb3-servlet-ejbs.jar");
jar.addAsManifestResource(new StringAsset("Dependencies: deployment.ejb3-servlet-client.jar \n"), "MANIFEST.MF");
return jar;
}
@Deployment(name = "client", order = 1)
public static Archive<?> deployClient() {
JavaArchive jar = getClient("ejb3-servlet-client.jar");
return jar;
}
@ArquillianResource
@OperateOnDeployment("servlet")
private URL ejbServletUrl;
@Deployment(name = "servlet", order = 3)
public static Archive<?> deployServlet() {
WebArchive war = getServlet("ejb3-servlet.war");
war.addClass(EJBServlet.class);
war.addClass(Util.class);
war.addAsWebInfResource(ServletUnitTestCase.class.getPackage(), "jboss-web.xml", "jboss-web.xml");
war.addAsWebInfResource(ServletUnitTestCase.class.getPackage(), "web.xml", "web.xml");
war.addAsManifestResource(new StringAsset("Dependencies: deployment.ejb3-servlet-ejbs.jar \n"), "MANIFEST.MF");
war.addAsManifestResource(createPermissionsXmlAsset(new ElytronPermission("getSecurityDomain"),
new ElytronPermission("authenticate")), "permissions.xml");
return war;
}
@ArquillianResource
@OperateOnDeployment("ear")
private URL servletUrl;
@Deployment(name = "ear", order = 4)
public static Archive<?> deployEar() {
EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "ejb3-ear-servlet.ear");
ear.addAsModule(getClient("ejb3-ear-servlet-client.jar"));
ear.addAsModule(getEjbs("ejb3-ear-servlet-ejbs.jar"));
WebArchive war = getServlet("ejb3-ear-servlet.war");
war.addAsWebInfResource(ServletUnitTestCase.class.getPackage(), "jboss-web-ear.xml", "jboss-web.xml");
war.addAsWebInfResource(ServletUnitTestCase.class.getPackage(), "web-ear.xml", "web.xml");
war.addClass(EJBServletEar.class);
war.addClass(Util.class);
ear.addAsManifestResource(createPermissionsXmlAsset(new ElytronPermission("getSecurityDomain"),
new ElytronPermission("authenticate")), "permissions.xml");
ear.addAsModule(war);
ear.addAsManifestResource(ServletUnitTestCase.class.getPackage(), "application.xml", "application.xml");
return ear;
}
private static JavaArchive getEjbs(String archiveName) {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, archiveName);
jar.addClasses(
Session30.class,
Session30Bean.class,
Session30BusinessLocal.class,
Session30BusinessRemote.class,
Session30Home.class,
Session30Local.class,
Session30LocalHome.class,
Session30Remote.class,
StatefulBean.class,
StatefulLocal.class,
StatefulRemote.class,
StatelessBean.class,
StatelessLocal.class,
TestObject.class);
jar.addAsManifestResource(ServletUnitTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
return jar;
}
private static JavaArchive getClient(String archiveName) {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, archiveName);
jar.addClasses(WarTestObject.class);
return jar;
}
private static WebArchive getServlet(String archiveName) {
WebArchive war = ShrinkWrap.create(WebArchive.class, archiveName);
war.addClasses(EJBServletHelper.class);
return war;
}
@Test
public void testEJBServletEar() throws Exception {
String res = HttpRequest.get( servletUrl.toExternalForm() + "EJBServlet", 4, TimeUnit.SECONDS);
Assert.assertEquals("EJBServlet OK", res);
}
@Test
public void testEJBServlet() throws Exception {
String res = HttpRequest.get( ejbServletUrl.toExternalForm() + "EJBServlet", 4, TimeUnit.SECONDS);
Assert.assertEquals("EJBServlet OK", res);
}
}
| 6,715 | 41.238994 | 121 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/WarTestObject.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.servlet;
/**
* @author <a href="mailto:[email protected]">William DeCoste</a>
*/
public class WarTestObject implements java.io.Serializable {
private static final long serialVersionUID = 1L;
public WarTestObject() {
}
}
| 1,305 | 35.277778 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/servlet/EJBServlet.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.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.concurrent.Callable;
import jakarta.ejb.EJB;
import javax.naming.InitialContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jboss.as.test.shared.integration.ejb.security.Util;
import org.jboss.logging.Logger;
/**
* A servlet that accesses an EJB and tests whether the call argument is serialized.
*
* @author [email protected]
*/
public class EJBServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(EJBServlet.class);
@EJB(lookup = "java:global/ejb3-servlet-ejbs/Session30!org.jboss.as.test.integration.ejb.servlet.Session30BusinessRemote")
Session30BusinessRemote injectedSession;
@EJB(lookup = "java:global/ejb3-servlet-ejbs/StatelessBean!org.jboss.as.test.integration.ejb.servlet.StatelessLocal")
StatelessLocal injectedStateless;
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final Callable<Void> callable = () -> {
InitialContext ctx = new InitialContext();
injectedSession.hello();
injectedSession.goodbye();
injectedStateless.hello();
injectedStateless.goodbye();
String lookupString = "java:global/ejb3-servlet-ejbs/Session30!";
EJBServletHelper test = new EJBServletHelper();
test.processRequest(lookupString, ctx);
return null;
};
try {
Util.switchIdentitySCF("user1", "password1", callable);
} catch (Exception e) {
log.error(e);
throw new ServletException("Failed to call EJBs/Session30 through remote and local interfaces", e);
}
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.print("EJBServlet OK");
out.close();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
}
| 3,531 | 38.685393 | 130 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/bridgemethods/CDIInterceptor.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.bridgemethods;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;
import org.jboss.classfilewriter.AccessFlag;
/**
* @author Stuart Douglas
*/
@Interceptor
@BridgeIntercepted
public class CDIInterceptor {
@AroundInvoke
public Object invoke(final InvocationContext ic) throws Exception {
if((AccessFlag.BRIDGE & ic.getMethod().getModifiers()) != 0) {
throw new RuntimeException("Bridge method passed through invocation context");
}
ic.setParameters(new Object[]{true});
return ic.proceed();
}
}
| 1,699 | 34.416667 | 90 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/bridgemethods/BridgeIntercepted.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.bridgemethods;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import jakarta.interceptor.InterceptorBinding;
/**
* @author Stuart Douglas
*/
@Retention(RetentionPolicy.RUNTIME)
@InterceptorBinding
public @interface BridgeIntercepted {
}
| 1,336 | 37.2 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/bridgemethods/EjbBridgeMethodsTestCase.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.bridgemethods;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that bridge methods are correctly intercepted, and the correct method object is used in the invocation context
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class EjbBridgeMethodsTestCase {
@Deployment
public static JavaArchive depoy() {
return ShrinkWrap.create(JavaArchive.class, "testBridgeMethods.jar")
.addPackage(EjbBridgeMethodsTestCase.class.getPackage())
.addAsManifestResource(new StringAsset("<beans><interceptors><class>" + CDIInterceptor.class.getName() + "</class></interceptors></beans>"), "beans.xml");
}
@Test
public void testInterceptedBridgeMethod() throws NamingException {
ConcreteInterface ejb = (ConcreteInterface)new InitialContext().lookup("java:module/" + BridgeMethodEjb.class.getSimpleName() + "!" + ConcreteInterface.class.getName());
Assert.assertEquals(1, (int) ejb.method(false));
Assert.assertEquals(1, ((GenericInterface)ejb).method(false));
}
@Test
public void testCdiInterceptedBridgeMethod() throws NamingException {
ConcreteInterface ejb = (ConcreteInterface)new InitialContext().lookup("java:module/" + BridgeMethodEjb.class.getSimpleName() + "!" + ConcreteInterface.class.getName());
Assert.assertEquals(1, (int)ejb.cdiMethod(false));
Assert.assertEquals(1, ((GenericInterface) ejb).cdiMethod(false));
}
}
| 2,897 | 41.617647 | 177 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/bridgemethods/EjbInterceptor.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.bridgemethods;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
import org.jboss.classfilewriter.AccessFlag;
/**
* @author Stuart Douglas
*/
public class EjbInterceptor {
@AroundInvoke
public Object invoke(final InvocationContext ic) throws Exception {
if((AccessFlag.BRIDGE & ic.getMethod().getModifiers()) != 0) {
throw new RuntimeException("Bridge method passed through invocation context");
}
ic.setParameters(new Object[]{true});
return ic.proceed();
}
}
| 1,627 | 35.177778 | 90 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/bridgemethods/BridgeMethodEjb.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.bridgemethods;
import jakarta.ejb.Local;
import jakarta.ejb.Stateless;
import jakarta.interceptor.Interceptors;
/**
* @author Stuart Douglas
*/
@Stateless
@Local(ConcreteInterface.class)
public class BridgeMethodEjb implements ConcreteInterface {
@Override
@Interceptors(EjbInterceptor.class)
public Integer method(final boolean intercepted) {
return intercepted ? 1 : 0;
}
@Override
@BridgeIntercepted
public Integer cdiMethod(final boolean intercepted) {
return intercepted ? 1 : 0;
}
}
| 1,609 | 32.541667 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/bridgemethods/ConcreteInterface.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.bridgemethods;
/**
* @author Stuart Douglas
*/
public interface ConcreteInterface extends GenericInterface {
Integer method(boolean intercepted);
Integer cdiMethod(boolean intercepted);
}
| 1,266 | 37.393939 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/bridgemethods/GenericInterface.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.bridgemethods;
/**
* @author Stuart Douglas
*/
public interface GenericInterface {
Object method(boolean intercepted);
Object cdiMethod(boolean intercepted);
}
| 1,239 | 35.470588 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/persistence/SimpleEntity.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.persistence;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
/**
* User: jpai
*/
@Entity
public class SimpleEntity {
@Id
private int id;
private String name;
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setId(int id) {
this.id = id;
}
}
| 1,504 | 26.363636 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/persistence/PersistenceUnitTestCase.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.persistence;
import jakarta.ejb.EJB;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* User: jpai
*/
@RunWith(Arquillian.class)
public class PersistenceUnitTestCase {
private static final String persistence_xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?> " +
"<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\" version=\"1.0\">" +
" <persistence-unit name=\"ejb3-persistence-test-pu\">" +
" <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>" +
"<properties> <property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/>" +
"</properties>" +
" </persistence-unit>" +
"</persistence>";
@EJB (mappedName = "java:module/SingletonBean")
private SingletonBean singletonBean;
@Deployment
public static Archive<?> getDeployment() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb3-persistence-test.jar");
jar.addClasses(SingletonBean.class, SimpleEntity.class);
jar.addAsResource(new StringAsset(persistence_xml), "META-INF/persistence.xml");
return jar;
}
@Test
public void testSingletonBeanDestroy() {
this.singletonBean.doNothing();
}
}
| 2,631 | 36.070423 | 94 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/persistence/SingletonBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.persistence;
import jakarta.annotation.PreDestroy;
import jakarta.ejb.Singleton;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceContext;
import org.jboss.logging.Logger;
/**
* User: jpai
*/
@Singleton
public class SingletonBean {
private static final Logger logger = Logger.getLogger(SingletonBean.class);
@PersistenceContext(unitName = "ejb3-persistence-test-pu")
private EntityManager entityManager;
public void doNothing() {
}
@PreDestroy
private void sleepAndDestroy() throws Exception {
logger.trace("Sleeping for 3 seconds while destroying singleton bean " + this);
// sleep for a while just to reproduce a race condition with EntityManagerFactory being closed before
// the singleton bean can finish its pre-destroy
Thread.sleep(3000);
logger.trace("Woke up after 3 seconds while destroying singleton bean " + this);
final EntityManagerFactory entityManagerFactory = this.entityManager.getEntityManagerFactory();
boolean emFactoryOpen = entityManagerFactory.isOpen();
if (!emFactoryOpen) {
throw new RuntimeException("Entitymanager factory: " + entityManagerFactory + " has been closed " +
"even before singleton bean " + this + " could complete its @PreDestroy");
}
}
}
| 2,472 | 38.253968 | 111 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/log/StatefulBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.log;
import jakarta.ejb.CreateException;
import jakarta.ejb.SessionBean;
import jakarta.ejb.SessionContext;
import org.jboss.logging.Logger;
public class StatefulBean implements SessionBean, StatefulInterface {
protected SessionContext context;
protected Logger log = Logger.getLogger( this.getClass() );
public void ejbCreate() throws CreateException {
log.info("ejbCreate();");
}
public void ejbRemove() {
log.info("ejbRemove();");
}
public void ejbActivate() {
log.info("ejbActivate();");
}
public void ejbPassivate() {
log.info("ejbPassivate();");
}
public void setSessionContext(SessionContext context) {
this.context = context;
}
}
| 1,793 | 31.618182 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/log/StatefulInterface.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.log;
public interface StatefulInterface {
}
| 1,103 | 41.461538 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/log/InvalidTransactionAttributeTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.log;
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 java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
/**
* Tests if the WARN message was logged when default transaction attribute was used on SFSB lifecyle method
* Test for [ WFLY-9509 ].
*
* @author Daniel Cihak
*/
@RunWith(Arquillian.class)
public class InvalidTransactionAttributeTestCase {
private static final String ARCHIVE_NAME = "InvalidTransactionAttribute";
@ArquillianResource
Deployer deployer;
@Deployment(name = "invalidtransactionattribute", testable = false, managed = false)
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar");
jar.addClasses(InvalidTransactionAttributeTestCase.class, StatefulBean.class, StatefulInterface.class);
jar.addAsManifestResource(InvalidTransactionAttributeTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
return jar;
}
@Test
public void testInvalidTransactionAttributeWarnLogged() {
PrintStream oldOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
System.setOut(new PrintStream(baos));
deployer.deploy("invalidtransactionattribute");
try {
System.setOut(oldOut);
String output = new String(baos.toByteArray(), StandardCharsets.UTF_8);
Assert.assertFalse(output, output.contains("WFLYEJB0463"));
Assert.assertFalse(output, output.contains("ERROR"));
} finally {
deployer.undeploy("invalidtransactionattribute");
}
} finally {
System.setOut(oldOut);
}
}
}
| 3,233 | 38.439024 | 120 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/systemexception/SystemExceptionSLSB.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.stateless.systemexception;
import jakarta.ejb.Stateless;
/**
* stateful session bean
*
*/
@Stateless
public class SystemExceptionSLSB {
public static final String MESSAGE = "Expected Exception";
private boolean used = false;
/**
* Throw a system exception, but only if an exception has not been thrown before from this bean
*
* This should throw an exception every time, as the bean should not be re-used after the system exception
*
*/
public void systemException() {
if(used) {
return;
}
used = true;
throw new RuntimeException(MESSAGE);
}
}
| 1,707 | 31.846154 | 110 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/systemexception/SystemExceptionTestCase.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.stateless.systemexception;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Tests that SLSB's are not re-used after a system exception
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class SystemExceptionTestCase {
private static final String ARCHIVE_NAME = "SystemExceptionTestCase";
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar");
jar.addPackage(SystemExceptionTestCase.class.getPackage());
return jar;
}
@ArquillianResource
private InitialContext iniCtx;
protected <T> T lookup(Class<T> beanType) throws NamingException {
return beanType.cast(iniCtx.lookup("java:global/" + ARCHIVE_NAME + "/" + beanType.getSimpleName() + "!" + beanType.getName()));
}
/**
* Ensure that a system exception destroys the bean.
*
* @throws Exception
*/
@Test
public void testSystemExceptionDestroysBean() throws Exception {
SystemExceptionSLSB slsb = lookup(SystemExceptionSLSB.class);
for (int i = 1; i < 50; ++i) {
boolean fail = false;
try {
slsb.systemException();
fail = true;
} catch (RuntimeException e) {
}
if(fail) {
Assert.fail("No system exception was thrown, which means bean has been re-used after a system exception");
}
}
}
}
| 2,952 | 33.337209 | 135 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/pooling/ejb2/CountedSessionBean3.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.stateless.pooling.ejb2;
import java.rmi.RemoteException;
import org.jboss.logging.Logger;
/**
* @author <a href="mailto:[email protected]">Dimitris Andreadis</a>
*/
public class CountedSessionBean3 extends CountedSessionBean1 {
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(CountedSessionBean3.class);
public CountedSessionBean3() {
log.trace("CTOR3");
}
public void ejbCreate() throws RemoteException {
log.trace("ejbCreate[3]: " + CounterSingleton.createCounter3.incrementAndGet());
}
public void ejbRemove() {
try {
log.trace("ejbRemove[3]: " + CounterSingleton.removeCounter3.incrementAndGet());
} catch (Exception e) {
log.error("Ignored exception", e);
}
}
}
| 1,896 | 36.196078 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/pooling/ejb2/CountedSessionHome.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.stateless.pooling.ejb2;
import java.rmi.RemoteException;
import jakarta.ejb.CreateException;
import jakarta.ejb.EJBHome;
/**
* @author <a href="mailto:[email protected]">Dimitris Andreadis</a>
*/
public interface CountedSessionHome extends EJBHome {
CountedSession create() throws RemoteException, CreateException;
}
| 1,400 | 37.916667 | 74 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/pooling/ejb2/CountedSessionBean2.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.stateless.pooling.ejb2;
import java.rmi.RemoteException;
import org.jboss.logging.Logger;
/**
* @author <a href="mailto:[email protected]">Dimitris Andreadis</a>
*/
public class CountedSessionBean2 extends CountedSessionBean1 {
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(CountedSessionBean2.class);
public CountedSessionBean2() {
log.trace("CTOR2");
}
public void ejbCreate() throws RemoteException {
log.trace("ejbCreate[2]: " + CounterSingleton.createCounter2.incrementAndGet());
}
public void ejbRemove() {
try {
log.trace("ejbRemove[2]: " + CounterSingleton.removeCounter2.incrementAndGet());
} catch (Exception e) {
log.error("Ignored exception", e);
}
}
}
| 1,896 | 36.196078 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/pooling/ejb2/CountedSessionBean1.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.stateless.pooling.ejb2;
import java.rmi.RemoteException;
import jakarta.ejb.EJBException;
import jakarta.ejb.SessionBean;
import jakarta.ejb.SessionContext;
import org.jboss.logging.Logger;
/**
* @author <a href="mailto:[email protected]">Dimitris Andreadis</a>
*/
public class CountedSessionBean1 implements SessionBean {
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(CountedSessionBean1.class);
protected SessionContext ctx;
public CountedSessionBean1() {
log.trace("CTOR1");
}
// Business Methods ----------------------------------------------
public void doSomething(long delay) {
log.trace("doSomething(" + delay + ")");
if (delay > 0) {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
public void doSomethingSync(long delay) {
try {
doSomething(delay);
} finally {
EjbRemoveUnitTestCase.CDL.countDown();
}
}
// Container callbacks -------------------------------------------
public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException {
this.ctx = ctx;
log.trace("setSessionContext");
}
public void ejbCreate() throws RemoteException {
log.trace("ejbCreate[1]: " + CounterSingleton.createCounter1.incrementAndGet());
}
public void ejbRemove() {
try {
log.trace("ejbRemove[1]: " + CounterSingleton.removeCounter1.incrementAndGet());
} catch (Exception e) {
log.error("Ignored exception", e);
}
}
public void ejbActivate() {
log.trace("ejbActivate");
}
public void ejbPassivate() {
log.trace("ejbPassivate");
}
}
| 2,962 | 31.922222 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/pooling/ejb2/CountedSession.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.stateless.pooling.ejb2;
import java.rmi.RemoteException;
import jakarta.ejb.EJBObject;
/**
* @author <a href="mailto:[email protected]">Dimitris Andreadis</a>
*/
public interface CountedSession extends EJBObject {
void doSomething(long delay) throws RemoteException;
void doSomethingSync(long delay) throws RemoteException;
}
| 1,412 | 39.371429 | 74 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/pooling/ejb2/EjbRemoveUnitTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2012, Red Hat Middleware LLC, and individual contributors
* as indicated by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.stateless.pooling.ejb2;
import java.rmi.RemoteException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.jboss.logging.Logger;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.wildfly.test.api.Authentication;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.ejb.remote.common.EJBManagementUtil;
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 that bean is pooled and ejbRemove is correctly called.
* Part of the migration of tests from EJB3 testsuite to AS7 testsuite [JBQA-5483].
*
* Dimitris Andreadis, Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
@ServerSetup(EjbRemoveUnitTestCase.EjbRemoveUnitTestCaseSetup.class)
public class EjbRemoveUnitTestCase {
private static final Logger log = Logger.getLogger(EjbRemoveUnitTestCase.class.getName());
private static final String POOL_NAME2 = "CustomConfig2";
private static final String POOL_NAME3 = "CustomConfig3";
private static final String DEFAULT_POOL_ATTR = "default-slsb-instance-pool";
public static final CountDownLatch CDL = new CountDownLatch(10);
static class EjbRemoveUnitTestCaseSetup implements ServerSetupTask {
@Override
public void setup(final ManagementClient managementClient, final String containerId) throws Exception {
EJBManagementUtil.createStrictMaxPool(managementClient.getControllerClient(), POOL_NAME2, 5, 10 * 1000, TimeUnit.MILLISECONDS);
EJBManagementUtil.createStrictMaxPool(managementClient.getControllerClient(), POOL_NAME3, 5, 10 * 1000, TimeUnit.MILLISECONDS);
}
@Override
public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception {
EJBManagementUtil.removeStrictMaxPool(managementClient.getControllerClient(), POOL_NAME2);
EJBManagementUtil.removeStrictMaxPool(managementClient.getControllerClient(), POOL_NAME3);
}
}
@ArquillianResource
private InitialContext ctx;
@ArquillianResource
private ManagementClient managementClient;
@Deployment(managed=true, testable = false, name = "single", order = 0)
public static Archive<?> deploymentSingleton() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "single.jar")
.addClasses(CounterSingleton.class);
return jar;
}
@Deployment(managed=true, testable = true, name = "beans", order = 1)
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test-session-remove.jar");
jar.addClasses(
CountedSessionHome.class, CountedSession.class,
CountedSessionBean1.class, CountedSessionBean2.class, CountedSessionBean3.class,
Authentication.class);
jar.addAsManifestResource(EjbRemoveUnitTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
jar.addAsManifestResource(EjbRemoveUnitTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
jar.addAsManifestResource(EjbRemoveUnitTestCase.class.getPackage(), "jboss-all.xml", "jboss-all.xml");
jar.addAsManifestResource(new StringAsset("Dependencies: deployment.single.jar, org.jboss.as.controller-client, org.jboss.dmr \n"), "MANIFEST.MF");
return jar;
}
/**
* In this test, pooling is enabled (Maximum==5) so after the initial create() call, the same instance should be used from
* the pool, and only removed when the app gets undeployed
*/
@Test
@OperateOnDeployment("beans")
public void testEjbRemoveNotCalledForEveryCall() throws Exception {
CountedSessionHome countedHome = (CountedSessionHome) ctx.lookup("java:module/CountedSession2!"
+ CountedSessionHome.class.getName());
CountedSession counted = countedHome.create();
counted.doSomething(2);
Assert.assertEquals("createCounter", 1, CounterSingleton.createCounter2.get());
Assert.assertEquals("removeCounter", 0, CounterSingleton.removeCounter2.get());
counted.remove();
Assert.assertEquals("createCounter", 1, CounterSingleton.createCounter2.get());
Assert.assertEquals("removeCounter", 0, CounterSingleton.removeCounter2.get());
}
@Test
@OperateOnDeployment("beans")
public void testEjbRemoveMultiThread() throws Exception {
CountedSessionHome countedHome = (CountedSessionHome) ctx.lookup("java:module/CountedSession3!"
+ CountedSessionHome.class.getName());
final CountedSession counted = countedHome.create();
Runnable runnable = new Runnable() {
public void run() {
try {
// introduce 250ms delay
counted.doSomethingSync(233);
} catch (RemoteException e) {
// ignore
}
}
};
for (int i = 0; i < 10; i++) {
new Thread(runnable).start();
}
// wait for all 10 threads to finish
CDL.await(5, TimeUnit.SECONDS);
Assert.assertTrue("createCounter has to be == 5 but was " + CounterSingleton.createCounter3.get(), CounterSingleton.createCounter3.get() == 5);
}
}
| 6,916 | 42.503145 | 155 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/pooling/ejb2/CounterSingleton.java
|
package org.jboss.as.test.integration.ejb.stateless.pooling.ejb2;
import java.util.concurrent.atomic.AtomicInteger;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
@Singleton
@Startup
public class CounterSingleton {
public static AtomicInteger createCounter1 = new AtomicInteger(0);
public static AtomicInteger createCounter2 = new AtomicInteger(0);
public static AtomicInteger createCounter3 = new AtomicInteger(0);
public static AtomicInteger removeCounter1 = new AtomicInteger(0);
public static AtomicInteger removeCounter2 = new AtomicInteger(0);
public static AtomicInteger removeCounter3 = new AtomicInteger(0);
}
| 656 | 37.647059 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/callerprincipal/Ejb2GetCallerPrincipalTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, 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.stateless.callerprincipal;
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.ServerSetup;
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.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Hashtable;
import static org.junit.Assert.assertTrue;
/**
* Tests if EJB2 application shows the correct user when getCallerPrincipal method is used inside the EJB.
* Test for [ WFLY-12301 ].
*
* @author Daniel Cihak
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup(Ejb2GetCallerPrincipalServerSetupTask.class)
public class Ejb2GetCallerPrincipalTestCase {
private static final String DEPLOYMENT = "DEPLOYMENT";
private static final String ROLE1 = "Users";
@Deployment
public static Archive<?> deploy() {
EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, DEPLOYMENT + ".ear");
JavaArchive ejb2 = ShrinkWrap.create(JavaArchive.class, "ejb2.jar");
ejb2.addClasses(TestEJB2.class, TestEJB2Bean.class, TestEJB2Int.class, TestEJB2Home.class);
ejb2.addAsManifestResource(Ejb2GetCallerPrincipalTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
ear.addAsModule(ejb2);
JavaArchive ejb3 = ShrinkWrap.create(JavaArchive.class, "ejb3.jar");
ejb3.addClasses(TestEJB3Remote.class, TestEJB3.class);
ear.addAsModule(ejb3);
return ear;
}
@Test
public void testEjb2GetCallerPrincipal() throws Exception {
Context ctx = getInitialContext();
TestEJB3Remote ejb3 = (TestEJB3Remote) ctx.lookup("ejb:DEPLOYMENT/ejb3/TestEJB3!org.jboss.as.test.integration.ejb.stateless.callerprincipal.TestEJB3Remote");
assertTrue("Caller must be user1 and must be in the role Users.", ejb3.isCallerInRole(ROLE1));
TestEJB2 ejb2X = (TestEJB2) ctx.lookup("ejb:DEPLOYMENT/ejb2/TestEJB2Bean!org.jboss.as.test.integration.ejb.stateless.callerprincipal.TestEJB2");
assertTrue("Caller must be user1 and must be in the role Users.", ejb2X.isCallerInRole(ROLE1));
TestEJB2Home ejb2Home = (TestEJB2Home) ctx.lookup("ejb:DEPLOYMENT/ejb2/TestEJB2Bean!org.jboss.as.test.integration.ejb.stateless.callerprincipal.TestEJB2Home");
TestEJB2 ejb2 = ejb2Home.create();
assertTrue("Caller must be user1 and must be in the role Users.", ejb2.isCallerInRole(ROLE1));
}
private InitialContext getInitialContext() throws NamingException {
final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
jndiProperties.put(Context.SECURITY_PRINCIPAL, "user1");
jndiProperties.put(Context.SECURITY_CREDENTIALS, "password1");
jndiProperties.put(Context.PROVIDER_URL, "remote+http://" + TestSuiteEnvironment.getServerAddress() + ":" + TestSuiteEnvironment.getHttpPort());
return new InitialContext(jndiProperties);
}
}
| 4,469 | 45.082474 | 167 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/callerprincipal/TestEJB3Remote.java
|
package org.jboss.as.test.integration.ejb.stateless.callerprincipal;
public interface TestEJB3Remote {
boolean isCallerInRole(String role) throws Exception;
}
| 164 | 22.571429 | 68 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/callerprincipal/TestEJB2Bean.java
|
package org.jboss.as.test.integration.ejb.stateless.callerprincipal;
import jakarta.ejb.CreateException;
import jakarta.ejb.SessionBean;
import jakarta.ejb.SessionContext;
import java.rmi.RemoteException;
import java.util.logging.Logger;
public class TestEJB2Bean implements SessionBean, TestEJB2Int {
private static final Logger log = Logger.getLogger(TestEJB2Bean.class.getName());
private static final String USER = "user1";
public boolean isCallerInRole(String role) throws Exception {
String caller = ctx.getCallerPrincipal().getName();
if (!USER.equals(caller)) {
throw new Exception("Caller name is not " + USER + ", but " + caller);
}
return ctx.isCallerInRole(role);
}
private SessionContext ctx;
public void setSessionContext(SessionContext pCtx) {
ctx = pCtx;
}
public void ejbCreate() throws RemoteException, CreateException {
}
public void ejbRemove() throws RemoteException {
}
public void ejbActivate() throws RemoteException {
}
public void ejbPassivate() throws RemoteException {
}
}
| 1,125 | 25.809524 | 85 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/callerprincipal/TestEJB2Int.java
|
package org.jboss.as.test.integration.ejb.stateless.callerprincipal;
public interface TestEJB2Int {
boolean isCallerInRole(String role) throws Exception;
}
| 164 | 17.333333 | 68 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/callerprincipal/TestEJB3.java
|
package org.jboss.as.test.integration.ejb.stateless.callerprincipal;
import jakarta.annotation.Resource;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.Remote;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import java.util.logging.Logger;
@Stateless
@Remote(TestEJB3Remote.class)
@RolesAllowed({ "Users" })
public class TestEJB3 implements TestEJB3Remote {
private static final Logger log = Logger.getLogger(TestEJB3.class.getName());
private static final String USER = "user1";
@Resource
private SessionContext ctx;
public boolean isCallerInRole(String role) throws Exception {
String caller = ctx.getCallerPrincipal().getName();
if (!USER.equals(caller)) {
throw new Exception("Caller name is not " + USER + ", but " + caller);
}
return ctx.isCallerInRole(role);
}
}
| 885 | 26.6875 | 82 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/callerprincipal/TestEJB2.java
|
package org.jboss.as.test.integration.ejb.stateless.callerprincipal;
import jakarta.ejb.EJBObject;
public interface TestEJB2 extends EJBObject, TestEJB2Int {
}
| 163 | 19.5 | 68 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/callerprincipal/Ejb2GetCallerPrincipalServerSetupTask.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, 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.stateless.callerprincipal;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.client.helpers.ClientConstants;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.test.integration.security.common.CoreUtils;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.as.test.shared.SnapshotRestoreSetupTask;
import org.jboss.dmr.ModelNode;
import java.util.List;
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.OPERATION_HEADERS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ROLLBACK_ON_RUNTIME_FAILURE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION;
import static org.jboss.as.test.integration.management.util.ModelUtil.createOpNode;
/**
*
* Server setup task for test Ejb2GetCallerPrincipalTestCase.
* Configures security domain and http connector in EJB3 and remoting subsystems.
*
* @author Daniel Cihak
*/
public class Ejb2GetCallerPrincipalServerSetupTask extends SnapshotRestoreSetupTask {
@Override
public void doSetup(ManagementClient managementClient, String containerId) throws Exception {
// /subsystem=ejb3/application-security-domain=other:add(security-domain=ApplicationDomain)
ModelNode addEjbDomain = createOpNode("subsystem=ejb3/application-security-domain=other", ADD);
addEjbDomain.get("security-domain").set("ApplicationDomain");
// /subsystem=remoting/http-connector=http-remoting-connector:write-attribute(name=sasl-authentication-factory, value=application-sasl-authentication)
ModelNode updateRemotingConnector = createOpNode("subsystem=remoting/http-connector=http-remoting-connector", WRITE_ATTRIBUTE_OPERATION);
updateRemotingConnector.get(ClientConstants.NAME).set("sasl-authentication-factory");
updateRemotingConnector.get(ClientConstants.VALUE).set("application-sasl-authentication");
ModelNode updateOp = Util.createCompositeOperation(List.of(addEjbDomain, updateRemotingConnector));
updateOp.get(OPERATION_HEADERS, ROLLBACK_ON_RUNTIME_FAILURE).set(false);
updateOp.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
CoreUtils.applyUpdate(updateOp, managementClient.getControllerClient());
ServerReload.reloadIfRequired(managementClient);
}
}
| 3,651 | 51.927536 | 158 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateless/callerprincipal/TestEJB2Home.java
|
package org.jboss.as.test.integration.ejb.stateless.callerprincipal;
import jakarta.ejb.CreateException;
import jakarta.ejb.EJBHome;
import java.rmi.RemoteException;
public interface TestEJB2Home extends EJBHome {
TestEJB2 create() throws RemoteException, CreateException;
}
| 282 | 22.583333 | 68 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/AccountManagerBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton;
import jakarta.ejb.EJB;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Remote;
import jakarta.ejb.Singleton;
/**
* AccountManagerBean
*
* @author Jaikiran Pai
*/
@Singleton
@LocalBean
@Remote(AccountManager.class)
public class AccountManagerBean implements AccountManager {
/**
* Inject the no-interface view of the Calculator
*/
@EJB
private Calculator simpleCalculator;
private int balance;
/**
* @see org.jboss.ejb3.nointerface.integration.test.common.AccountManager#credit(int)
*/
public void credit(int amount) {
this.balance = this.simpleCalculator.add(this.balance, amount);
}
/**
* @see org.jboss.ejb3.nointerface.integration.test.common.AccountManager#debit(int)
*/
public void debit(int amount) {
this.balance = this.simpleCalculator.subtract(this.balance, amount);
}
public int balance() {
return this.balance;
}
public void throwException() {
throw new IllegalArgumentException();
}
}
| 2,107 | 28.690141 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/SingletonUnitTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton;
import org.jboss.logging.Logger;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* SingletonUnitTestCase
* <p>
* Part of the migration AS6->AS7 testsuite [JBQA-5275] - ejb3/singleton.
*
* @author Jaikiran Pai, Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
public class SingletonUnitTestCase {
private static final Logger log = Logger.getLogger(SingletonUnitTestCase.class.getName());
@ArquillianResource
InitialContext ctx;
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb31singleton.jar");
jar.addPackage(SingletonUnitTestCase.class.getPackage());
return jar;
}
@Test
public void testSingletonBeanAccess() throws Exception {
AccountManagerBean accountManagerLocal = (AccountManagerBean) ctx.lookup("java:module/"
+ AccountManagerBean.class.getSimpleName() + "!" + AccountManagerBean.class.getName());
AccountManager accountManagerRemote = (AccountManager) ctx.lookup("java:module/"
+ AccountManagerBean.class.getSimpleName() + "!" + AccountManager.class.getName());
int initialBalance = accountManagerRemote.balance();
Assert.assertEquals("Unexpected initial balance", 0, initialBalance);
// credit
accountManagerRemote.credit(100);
AccountManager anotherAccountManagerRemoteInstance = (AccountManager) ctx.lookup("java:module/"
+ AccountManagerBean.class.getSimpleName() + "!" + AccountManager.class.getName());
int balanceAfterCredit = anotherAccountManagerRemoteInstance.balance();
Assert.assertEquals("Unexpected balance after credit", 100, balanceAfterCredit);
// debit
anotherAccountManagerRemoteInstance.debit(50);
// checking whether singleton works after throwing exception in a business method
// EJB3.1 4.8.4
try {
accountManagerLocal.throwException();
} catch (Exception e) {
// it's supposed - OK
}
int balanceAfterDebit = accountManagerRemote.balance();
Assert.assertEquals("Unexpected balance after debit", 50, balanceAfterDebit);
// testing singleton identity - EJB3.1 3.4.7.3
Assert.assertFalse(accountManagerRemote.equals(accountManagerLocal));
Assert.assertTrue(accountManagerRemote.equals(anotherAccountManagerRemoteInstance));
}
}
| 3,878 | 39.831579 | 103 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/Calculator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton;
import jakarta.ejb.Singleton;
/**
* Calculator
*
* @author Jaikiran Pai
*/
@Singleton
public class Calculator {
public int subtract(int a, int b) {
return a - b;
}
public int add(int a, int b) {
return a + b;
}
}
| 1,329 | 30.666667 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/AccountManager.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton;
/**
* AccountManager
*
* @author Jaikiran Pai
*/
public interface AccountManager {
/**
* Credits the amount to the account
*
* @param amount Amount to be credited
* @return
*/
void credit(int amount);
/**
* Debits the amount from the account
*
* @param amount Amount to be debited
* @return
*/
void debit(int amount);
int balance();
}
| 1,490 | 28.82 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/sessionbean/SingletonImplementingSessionBeanTestCase.java
|
package org.jboss.as.test.integration.ejb.singleton.sessionbean;
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.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.dmr.ModelNode;
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;
import java.io.IOException;
import java.util.stream.Collectors;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
@RunWith(Arquillian.class)
public class SingletonImplementingSessionBeanTestCase {
private static final PathAddress LOG_FILE_ADDRESS = PathAddress.pathAddress()
.append(SUBSYSTEM, "logging")
.append("log-file", "server.log");
@ArquillianResource
private ManagementClient managementClient;
@Deployment
public static JavaArchive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "singleton-session-bean.jar");
jar.addPackage(SingletonImplementingSessionBeanTestCase.class.getPackage());
jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller\n"), "MANIFEST.MF");
return jar;
}
@Test
@RunAsClient()
public void testWarningDuringDeployment() throws IOException {
Assert.assertTrue("Log should contain warning that singleton bean can't implement SessionBean interface",
retrieveServerLog().contains("WFLYEJB0515"));
}
private String retrieveServerLog() throws IOException {
ModelNode op = Util.createEmptyOperation("read-log-file", LOG_FILE_ADDRESS);
op.get("lines").set(30);
ModelNode result = managementClient.getControllerClient().execute(op);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
return result.get(RESULT).asList().stream().map(ModelNode::toString).collect(Collectors.joining("\n"));
}
}
| 2,559 | 42.389831 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/sessionbean/SingletonSessionBean.java
|
package org.jboss.as.test.integration.ejb.singleton.sessionbean;
import jakarta.ejb.EJBException;
import jakarta.ejb.SessionBean;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
import java.rmi.RemoteException;
@Singleton
@Startup
public class SingletonSessionBean implements SessionBean {
@Override
public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException {
}
@Override
public void ejbRemove() throws EJBException, RemoteException {
}
@Override
public void ejbActivate() throws EJBException, RemoteException {
}
@Override
public void ejbPassivate() throws EJBException, RemoteException {
}
}
| 721 | 23.896552 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/deployment/HelloRemote.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2018, 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.as.test.integration.ejb.singleton.deployment;
import jakarta.ejb.Remote;
/**
* @author Bartosz Spyrko-Smietanko
*/
@Remote
public interface HelloRemote {
String hello();
}
| 996 | 34.607143 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/deployment/HelloBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2018, 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.as.test.integration.ejb.singleton.deployment;
import jakarta.ejb.Stateless;
/**
* @author Bartosz Spyrko-Smietanko
*/
@Stateless
public class HelloBean implements HelloRemote {
public String hello() {
return "hello";
}
}
| 1,058 | 33.16129 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/deployment/StartupSingletonFailureTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2018, 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.as.test.integration.ejb.singleton.deployment;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
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.management.base.AbstractCliTestBase;
import org.jboss.as.test.integration.management.cli.DeployURLTestCase;
import org.jboss.as.test.shared.TestSuiteEnvironment;
import org.jboss.ejb.client.EJBClient;
import org.jboss.ejb.client.StatelessEJBLocator;
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.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.impl.base.exporter.zip.ZipExporterImpl;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import jakarta.ejb.NoSuchEJBException;
import java.io.File;
import java.net.URL;
/**
* @author Bartosz Spyrko-Smietanko
*/
@RunWith(Arquillian.class)
@RunAsClient
public class StartupSingletonFailureTestCase extends AbstractCliTestBase {
public static EnterpriseArchive deployment(boolean includeInOrder) {
EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "TestEar.ear");
JavaArchive ejb1 = ShrinkWrap.create(JavaArchive.class, "ejb1.jar");
ejb1.addClass(SingletonOne.class);
JavaArchive ejb2 = ShrinkWrap.create(JavaArchive.class, "ejb2.jar");
ejb2.addClass(HelloBean.class);
ejb2.addClass(HelloRemote.class);
WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war");
war.addAsWebResource(new StringAsset("Hello"), "index.html");
war.addAsWebInfResource(new StringAsset("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<web-app xmlns=\"http://java.sun.com/xml/ns/javaee\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\" " +
"version=\"3.0\"></web-app>"), "web.xml");
ear.addAsModule(ejb1);
ear.addAsModule(ejb2);
ear.addAsModule(war);
if (includeInOrder) {
ear.setApplicationXML(new StringAsset("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<application>" +
"<initialize-in-order>true</initialize-in-order>" +
"<module><web><web-uri>test.war</web-uri><context-root>test</context-root></web></module>" +
"<module><ejb>ejb1.jar</ejb></module>" +
"<module><ejb>ejb2.jar</ejb></module>" +
"</application>"));
}
return ear;
}
// dummy deployment to keep Arquillian happy - not used in test
@Deployment
public static Archive<?> getDeployment() {
JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "dummy.jar");
ja.addClass(DeployURLTestCase.class);
return ja;
}
private static File unorderedEarFile;
private static File inOrderEarFile;
@BeforeClass
public static void before() throws Exception {
unorderedEarFile = exportEar(false, "TestEar.ear");
inOrderEarFile = exportEar(true, "TestEarInOrder.ear");
AbstractCliTestBase.initCLI();
}
private static File exportEar(boolean inOrder, String name) {
EnterpriseArchive ear = deployment(inOrder);
String tempDir = TestSuiteEnvironment.getTmpDir();
File earFile = new File(tempDir + File.separator + name);
new ZipExporterImpl(ear).exportTo(earFile, true);
return earFile;
}
@AfterClass
public static void after() throws Exception {
unorderedEarFile.delete();
inOrderEarFile.delete();
AbstractCliTestBase.closeCLI();
}
@Test
@SuppressWarnings({"unchecked"})
public void testEjbInAnotherModuleShouldFail() throws Exception {
testEjbInAnotherModuleShouldFail(unorderedEarFile);
}
@Test
@SuppressWarnings({"unchecked"})
public void testInOrderDeploymentEjbInAnotherModuleShouldFail() throws Exception {
testEjbInAnotherModuleShouldFail(inOrderEarFile);
}
private void testEjbInAnotherModuleShouldFail(File earFile) throws Exception {
try {
cli.sendLine("deploy --url=" + earFile.toURI().toURL().toExternalForm() + " --name=" + earFile.getName() + " --headers={rollback-on-runtime-failure=false}");
final StatelessEJBLocator<HelloRemote> locator = new StatelessEJBLocator(HelloRemote.class, "TestEar", "ejb2", HelloBean.class.getSimpleName(), "");
final HelloRemote proxy = EJBClient.createProxy(locator);
Assert.assertNotNull("Received a null proxy", proxy);
try {
proxy.hello();
Assert.fail("Call should have failed");
} catch (NoSuchEJBException e) {
Assert.assertTrue(e.getMessage(), e.getMessage().startsWith("EJBCLIENT000079"));
}
} finally {
cli.sendLine("undeploy " + earFile.getName());
}
}
@Test
public void testWebModuleShouldFail(@ArquillianResource URL url) throws Exception {
testWebModuleShouldFail(url, unorderedEarFile);
}
@Test
public void testInOrderDeploymentWebModuleShouldFail(@ArquillianResource URL url) throws Exception {
testWebModuleShouldFail(url, inOrderEarFile);
}
private void testWebModuleShouldFail(URL url, File earFile) throws Exception {
try {
cli.sendLine("deploy --url=" + earFile.toURI().toURL().toExternalForm() + " --name=" + earFile.getName() + " --headers={rollback-on-runtime-failure=false}");
try(CloseableHttpClient client = HttpClientBuilder.create().build()) {
final HttpGet get = new HttpGet(url.toExternalForm() + "/test/index.html");
Assert.assertEquals(500, client.execute(get).getStatusLine().getStatusCode());
}
} finally {
cli.sendLine("undeploy " + earFile.getName());
}
}
}
| 7,345 | 41.218391 | 169 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/deployment/SingletonOne.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2018, 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.as.test.integration.ejb.singleton.deployment;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
/**
* @author Bartosz Spyrko-Smietanko
*/
@Singleton
@Startup
public class SingletonOne {
@PostConstruct
public void startUp() {
throw new RuntimeException("Singleton one fails");
}
}
| 1,169 | 33.411765 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/startup/SLSBTwo.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.startup;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.Local;
import jakarta.ejb.Stateless;
import org.jboss.logging.Logger;
/**
* User: jpai
*/
@Stateless
@Local(DoSomethingView.class)
public class SLSBTwo implements DoSomethingView {
private static Logger logger = Logger.getLogger(SLSBTwo.class);
@PostConstruct
public void onConstruct() throws Exception {
this.doSomething();
}
@Override
public void doSomething() {
logger.trace(this.getClass().getName() + "#doSomething()");
}
}
| 1,627 | 30.921569 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/startup/SingletonBeanRemoteView.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.startup;
/**
* User: jpai
*/
public interface SingletonBeanRemoteView {
void doSomething();
String echo(String msg);
}
| 1,208 | 34.558824 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/startup/SLSBOne.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.startup;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.EJB;
import jakarta.ejb.Local;
import jakarta.ejb.Stateless;
import org.jboss.logging.Logger;
/**
* User: jpai
*/
@Stateless
@Local(DoSomethingView.class)
public class SLSBOne implements DoSomethingView {
private static Logger logger = Logger.getLogger(SLSBOne.class);
@EJB(beanName = "SLSBTwo")
private DoSomethingView slsbTwo;
@PostConstruct
public void onConstruct() throws Exception {
this.slsbTwo.doSomething();
}
@Override
public void doSomething() {
logger.trace(this.getClass().getName() + "#doSomething()");
}
}
| 1,728 | 30.436364 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/startup/StartupSingletonA.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.startup;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.EJB;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
import org.jboss.logging.Logger;
/**
* User: jpai
*/
@Startup
@Singleton
public class StartupSingletonA {
private static Logger logger = Logger.getLogger(StartupSingletonA.class);
@EJB(beanName = "SLSBOne")
private DoSomethingView slsbOne;
@PostConstruct
public void onConstruct() throws Exception {
this.slsbOne.doSomething();
}
public void doSomething() {
logger.trace(this.getClass().getName() + "#doSomething()");
}
public String echo(String msg) {
logger.trace("Echo " + msg);
return msg;
}
}
| 1,789 | 29.338983 | 77 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/startup/DoSomethingView.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.startup;
/**
* User: jpai
*/
public interface DoSomethingView {
void doSomething();
}
| 1,170 | 35.59375 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/startup/SingletonB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.startup;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.EJB;
import jakarta.ejb.Remote;
import jakarta.ejb.Singleton;
import org.jboss.logging.Logger;
/**
* User: jpai
*/
@Singleton
@Remote(SingletonBeanRemoteView.class)
public class SingletonB implements SingletonBeanRemoteView {
private static Logger logger = Logger.getLogger(SingletonB.class);
@EJB(beanName = "SLSBTwo")
private DoSomethingView slsbTwo;
@PostConstruct
public void onConstruct() throws Exception {
slsbTwo.doSomething();
}
public void doSomething() {
logger.trace(this.getClass().getName() + "#doSomething()");
}
@Override
public String echo(String msg) {
logger.trace("Echo " + msg);
return msg;
}
}
| 1,847 | 30.322034 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/startup/StartupSingletonDependencyGraphTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.startup;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Singleton startup dependency.
* Part of the migration AS6->AS7 testsuite [JBQA-5275] - ejb3/singleton.
*
* @author Jaikiran Pai, Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
public class StartupSingletonDependencyGraphTestCase {
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb3-singleton-startup.jar");
jar.addPackage(StartupSingletonDependencyGraphTestCase.class.getPackage());
return jar;
}
@Test
public void testStartupSingletonBeanAccess() throws Exception {
final SingletonBeanRemoteView singletonBean = InitialContext.doLookup("java:module/" + SingletonB.class.getSimpleName());
singletonBean.doSomething();
final String message = "Hello world!";
final String reply = singletonBean.echo(message);
Assert.assertEquals("Unexpected reply from singleton bean", message, reply);
}
}
| 2,392 | 38.229508 | 129 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/startup/postconstruct/Client.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.startup.postconstruct;
import org.jboss.logging.Logger;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.EJB;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
/**
* @author Jan Martiska / [email protected]
*/
@Startup
@Singleton
public class Client {
private Logger logger = Logger.getLogger(Client.class.getCanonicalName());
@EJB
private Controller controller;
@PostConstruct
public void postConstruct() {
logger.trace("Client's PostConstruct called.");
}
}
| 1,597 | 31.612245 | 78 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/startup/postconstruct/SinglePostConstructInvocationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.startup.postconstruct;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test for AS7-[3855|2785]: Do not call @PostConstruct multiple times on @Startup @Singleton bean.
*
* @author Jan Martiska / [email protected]
*/
@RunWith(Arquillian.class)
public class SinglePostConstructInvocationTestCase {
@Deployment
public static Archive<?> getDeployment() {
JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "single-postconstruct-invocation-test");
archive.addClasses(Client.class, Controller.class);
return archive;
}
@Test
public void doTest() throws Exception {
InitialContext ctx = new InitialContext();
Controller controller = (Controller) ctx.lookup("java:module/Controller");
Assert.assertEquals(1, controller.getPostConstructInvocationCounter());
ctx.close();
}
}
| 2,256 | 37.254237 | 107 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/startup/postconstruct/Controller.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.startup.postconstruct;
import org.jboss.logging.Logger;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
/**
* @author Jan Martiska / [email protected]
*/
@Startup
@Singleton
public class Controller {
private int postConstructInvocationCounter = 0;
private Logger logger = Logger.getLogger(Controller.class.getCanonicalName());
@PostConstruct
public void postConstruct() {
logger.trace("Controller's PostConstruct called.");
postConstructInvocationCounter++;
}
public int getPostConstructInvocationCounter() {
return postConstructInvocationCounter;
}
}
| 1,740 | 33.82 | 82 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/concurrency/ReadOnlySingletonBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.concurrency;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.AccessTimeout;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Lock;
import jakarta.ejb.LockType;
import jakarta.ejb.Singleton;
/**
* @author Jaikiran Pai
*/
@Singleton
@LocalBean
@Lock(value = LockType.READ)
public class ReadOnlySingletonBean implements ReadOnlySingleton {
@AccessTimeout(value = 1, unit = TimeUnit.SECONDS)
public String twoSecondEcho(String msg) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return msg;
}
}
| 1,699 | 32.333333 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/concurrency/SingletonBeanTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.concurrency;
import static org.jboss.as.controller.client.helpers.ClientConstants.OUTCOME;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.jboss.logging.Logger;
import jakarta.ejb.ConcurrentAccessTimeoutException;
import jakarta.ejb.EJB;
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.controller.client.helpers.ClientConstants;
import org.jboss.dmr.ModelNode;
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;
/**
* Testcase for testing the basic functionality of an EJB3 singleton session bean.
*
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
@ServerSetup(SingletonBeanTestCase.AllowPropertyReplacementSetup.class)
public class SingletonBeanTestCase {
private static final Logger log = Logger.getLogger(SingletonBeanTestCase.class.getName());
@Deployment
public static JavaArchive createDeployment() {
// create the ejb jar
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb3-singleton-bean-example.jar");
jar.addClass(ReadOnlySingletonBean.class);
jar.addClass(LongWritesSingletonBean.class);
jar.addClass(ReadOnlySingleton.class);
jar.addClass(SingletonBeanTestCase.class);
jar.addClass(ReadOnlySingletonBeanDescriptor.class);
jar.addClass(ReadOnlySingletonBeanDescriptorWithExpression.class);
jar.addAsManifestResource(SingletonBeanTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
jar.addAsManifestResource(SingletonBeanTestCase.class.getPackage(), "jboss.properties", "jboss.properties");
return jar;
}
static class AllowPropertyReplacementSetup implements ServerSetupTask {
@Override
public void setup(ManagementClient managementClient, String s) throws Exception {
final ModelNode enableSubstitutionOp = new ModelNode();
enableSubstitutionOp.get(ClientConstants.OP_ADDR).set(ClientConstants.SUBSYSTEM, "ee");
enableSubstitutionOp.get(ClientConstants.OP).set(ClientConstants.WRITE_ATTRIBUTE_OPERATION);
enableSubstitutionOp.get(ClientConstants.NAME).set("spec-descriptor-property-replacement");
enableSubstitutionOp.get(ClientConstants.VALUE).set(true);
try {
applyUpdate(managementClient, enableSubstitutionOp);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public void tearDown(ManagementClient managementClient, String s) throws Exception {
final ModelNode disableSubstitution = new ModelNode();
disableSubstitution.get(ClientConstants.OP_ADDR).set(ClientConstants.SUBSYSTEM, "ee");
disableSubstitution.get(ClientConstants.OP).set(ClientConstants.WRITE_ATTRIBUTE_OPERATION);
disableSubstitution.get(ClientConstants.NAME).set("spec-descriptor-property-replacement");
disableSubstitution.get(ClientConstants.VALUE).set(false);
try {
applyUpdate(managementClient, disableSubstitution);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private void applyUpdate(final ManagementClient managementClient, final ModelNode update)
throws Exception {
ModelNode result = managementClient.getControllerClient().execute(update);
if (result.hasDefined(OUTCOME)
&& ClientConstants.SUCCESS.equals(result.get(OUTCOME).asString())) {
} else if (result.hasDefined(ClientConstants.FAILURE_DESCRIPTION)) {
final String failureDesc = result.get(ClientConstants.FAILURE_DESCRIPTION).toString();
throw new RuntimeException(failureDesc);
} else {
throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome"));
}
}
}
@EJB(mappedName = "java:global/ejb3-singleton-bean-example/ReadOnlySingletonBean!org.jboss.as.test.integration.ejb.singleton.concurrency.ReadOnlySingletonBean")
private ReadOnlySingletonBean readOnlySingletonBean;
@EJB(mappedName = "java:global/ejb3-singleton-bean-example/LongWritesSingletonBean!org.jboss.as.test.integration.ejb.singleton.concurrency.LongWritesSingletonBean")
private LongWritesSingletonBean longWritesSingletonBean;
@EJB(mappedName = "java:global/ejb3-singleton-bean-example/ReadOnlySingletonBeanDescriptor!org.jboss.as.test.integration.ejb.singleton.concurrency.ReadOnlySingletonBeanDescriptor")
private ReadOnlySingletonBeanDescriptor readOnlySingletonBeanDescriptor;
@EJB(mappedName = "java:global/ejb3-singleton-bean-example/ReadOnlySingletonBeanDescriptorWithExpression!org.jboss.as.test.integration.ejb.singleton.concurrency.ReadOnlySingletonBeanDescriptorWithExpression")
private ReadOnlySingletonBeanDescriptorWithExpression readOnlySingletonBeanDescriptorWithExpression;
/**
* Tests that the concurrency on a singleton bean with lock type READ works as expected
*
* @throws Exception
*/
@Test
public void testReadOnlySingletonBean() throws Exception {
testReadOnlySingleton(readOnlySingletonBean);
}
@Test
public void testReadOnlySingletonDescriptor() throws Exception {
testReadOnlySingleton(readOnlySingletonBeanDescriptor);
}
@Test
public void testReadOnlySingletonDescriptorWithExpression() throws Exception {
testReadOnlySingleton(readOnlySingletonBeanDescriptorWithExpression);
}
public void testReadOnlySingleton(ReadOnlySingleton readOnlySingleton) throws Exception {
final int NUM_THREADS = 10;
ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS);
@SuppressWarnings("unchecked")
Future<String>[] results = new Future[NUM_THREADS];
for (int i = 0; i < NUM_THREADS; i++) {
results[i] = executor.submit(new ReadOnlySingletonBeanInvoker(readOnlySingleton, i));
}
for (int i = 0; i < NUM_THREADS; i++) {
String result = results[i].get(10, TimeUnit.SECONDS);
Assert.assertEquals("Unexpected value from singleton bean", String.valueOf(i), result);
}
}
/**
* Tests that invocation on a singleton bean method with write lock results in ConcurrentAccessTimeoutException
* for subsequent invocations, if the previous invocation(s) hasn't yet completed.
*
* @throws Exception
*/
@Test
public void testLongWritesSingleton() throws Exception {
// let's invoke a bean method (with WRITE lock semantics) which takes a long time to complete
final ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
// let's now try and invoke on this bean while the previous operation is in progress.
// we expect a ConcurrentAccessTimeoutException
final int NUM_THREADS = 10;
final ExecutorService nextTenInvocations = Executors.newFixedThreadPool(NUM_THREADS);
Future<?>[] results = new Future[NUM_THREADS];
// let the 10 threads invoke on the bean's method (which has WRITE lock semantics) which has an accesstimeout value
// set on it
for (int i = 0; i < NUM_THREADS; i++) {
results[i] = nextTenInvocations.submit(new LongWritesSingletonBeanInvoker(longWritesSingletonBean));
}
// Now fetch the results.
// all are expected to timeout
// one is expected to complete successfully
// rest all are expected to timeout
final List<Object> passed = new ArrayList<Object>();
final List<Throwable> throwables = new ArrayList<Throwable>();
for (int i = 0; i < NUM_THREADS; i++) {
try {
passed.add(results[i].get(10, TimeUnit.SECONDS));
} catch (ExecutionException ee) {
throwables.add(ee.getCause());
}
}
// only one call succeeded, so count should be 1
Assert.assertEquals("Unexpected count on singleton bean after invocation on method with WRITE lock semantic: ", 1, this.longWritesSingletonBean.getCount());
for (Throwable t : throwables) {
assertTrue(t.toString(), t instanceof ConcurrentAccessTimeoutException);
}
assertEquals(1, passed.size());
assertEquals(NUM_THREADS - 1, throwables.size());
}
private class ReadOnlySingletonBeanInvoker implements Callable<String> {
private ReadOnlySingleton bean;
private int num;
ReadOnlySingletonBeanInvoker(ReadOnlySingleton bean, int num) {
this.bean = bean;
this.num = num;
}
@Override
public String call() throws Exception {
log.trace("Bean: " + bean.toString());
return bean.twoSecondEcho(String.valueOf(this.num));
}
}
private class LongWritesSingletonBeanInvoker implements Callable<Object> {
private LongWritesSingletonBean bean;
LongWritesSingletonBeanInvoker(LongWritesSingletonBean bean) {
this.bean = bean;
}
@Override
public Object call() throws Exception {
bean.fiveSecondWriteOperation();
return null;
}
}
}
| 11,066 | 42.743083 | 212 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/concurrency/ReadOnlySingletonBeanDescriptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.concurrency;
/**
* @author Ondrej Chaloupka
*/
public class ReadOnlySingletonBeanDescriptor implements ReadOnlySingleton {
public String twoSecondEcho(String msg) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return msg;
}
}
| 1,419 | 35.410256 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/concurrency/ReadOnlySingleton.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.concurrency;
/**
* @author Ondrej Chaloupka
*/
public interface ReadOnlySingleton {
String twoSecondEcho(String msg);
}
| 1,203 | 37.83871 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/concurrency/GreeterCommonBusiness.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.concurrency;
/**
* Business interface of an EJB capable of greeting a user
*
* @author <a href="mailto:[email protected]">ALR</a>
*/
public interface GreeterCommonBusiness {
/**
* Prefix that will be used in {@link GreeterCommonBusiness#greet(String)}
*/
String PREFIX = "Hello, ";
/**
* Greets the user by prepending the specified name with the {@link GreeterCommonBusiness#PREFIX}
*
* @param name
* @return
*/
String greet(String name);
}
| 1,584 | 33.456522 | 101 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/concurrency/LongWritesSingletonBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.concurrency;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.AccessTimeout;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Lock;
import jakarta.ejb.LockType;
import jakarta.ejb.Singleton;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
/**
* @author Jaikiran Pai
*/
@Singleton
@LocalBean
@TransactionManagement(value = TransactionManagementType.BEAN)
public class LongWritesSingletonBean {
private int count;
@AccessTimeout(value = 1, unit = TimeUnit.SECONDS)
public void fiveSecondWriteOperation() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
count++;
}
@Lock(value = LockType.READ)
public int getCount() {
return this.count;
}
}
| 1,908 | 31.355932 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/concurrency/ReadOnlySingletonBeanDescriptorWithExpression.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.concurrency;
/**
* @author Ondrej Chaloupka
*/
public class ReadOnlySingletonBeanDescriptorWithExpression implements ReadOnlySingleton {
public String twoSecondEcho(String msg) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return msg;
}
}
| 1,433 | 35.769231 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/concurrency/inheritance/SingletonChildBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.concurrency.inheritance;
import java.util.concurrent.CountDownLatch;
import jakarta.ejb.AccessTimeout;
import jakarta.ejb.ConcurrencyManagement;
import jakarta.ejb.ConcurrencyManagementType;
import jakarta.ejb.Lock;
import jakarta.ejb.LockType;
import jakarta.ejb.Singleton;
/**
* @author Stuart Douglas
*/
@Singleton
@Lock(LockType.READ)
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
public class SingletonChildBean extends SingletonBaseBean {
//this is now a read lock
@AccessTimeout(value = 0)
public void writeLockOverriddenByParent(CountDownLatch cont, CountDownLatch entered) throws InterruptedException {
super.writeLockOverriddenByParent(cont, entered);
}
@Lock(LockType.WRITE)
@AccessTimeout(value = 0)
public void readLockOverriddenByParent(CountDownLatch cont, CountDownLatch entered) throws InterruptedException {
super.readLockOverriddenByParent(cont, entered);
}
}
| 2,017 | 36.37037 | 118 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/concurrency/inheritance/SingletonConcurrencyInheritanceTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.concurrency.inheritance;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import jakarta.ejb.ConcurrentAccessTimeoutException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that methods that are overriden no not used the annotations of the methods that they override
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class SingletonConcurrencyInheritanceTestCase {
private static final String ARCHIVE_NAME = "ConcurrencyTestCase";
@Deployment
public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME + ".war");
war.addPackage(SingletonConcurrencyInheritanceTestCase.class.getPackage());
return war;
}
@ArquillianResource
private InitialContext iniCtx;
protected <T> T lookup(String beanName, Class<T> interfaceType) throws NamingException {
return interfaceType.cast(iniCtx.lookup("java:global/" + ARCHIVE_NAME + "/" + beanName + "!" + interfaceType.getName()));
}
/**
* Test overriden method uses correct lock type
*/
@Test
public void testOverridenMethodNoAnnotation() throws Exception {
final SingletonBaseBean singleton = lookup(SingletonChildBean.class.getSimpleName(), SingletonChildBean.class);
ExecutorService pool = Executors.newSingleThreadExecutor();
final CountDownLatch latch = new CountDownLatch(2);
final CountDownLatch entered = new CountDownLatch(1);
//call a method with a write lock
//this will block till we hit the latch
Future<?> future = pool.submit(new Runnable() {
@Override
public void run() {
try {
singleton.readLockOverriddenByParent(latch, entered);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
entered.await();
try {
singleton.readLockOverriddenByParent(latch, entered);
throw new RuntimeException("Expecting a concurrency access exception");
} catch (ConcurrentAccessTimeoutException e) {
//expected
}
latch.countDown();
future.get();
}
@Test
public void testOverridenMethodWithAnnotation() throws Exception {
final SingletonBaseBean singleton = lookup(SingletonChildBean.class.getSimpleName(), SingletonChildBean.class);
ExecutorService pool = Executors.newSingleThreadExecutor();
final CountDownLatch latch = new CountDownLatch(2);
final CountDownLatch entered = new CountDownLatch(1);
//call a method with a write lock
//this will block till we hit the latch
Future<?> future = pool.submit(new Runnable() {
@Override
public void run() {
try {
singleton.writeLockOverriddenByParent(latch, entered);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
entered.await();
singleton.writeLockOverriddenByParent(latch, entered);
future.get();
}
@Test
public void testWriteLockMethodNotOverridden() throws Exception {
final SingletonBaseBean singleton = lookup(SingletonChildBean.class.getSimpleName(), SingletonChildBean.class);
ExecutorService pool = Executors.newSingleThreadExecutor();
final CountDownLatch latch = new CountDownLatch(2);
final CountDownLatch entered = new CountDownLatch(1);
//call a method with a write lock
//this will block till we hit the latch
Future<?> future = pool.submit(new Runnable() {
@Override
public void run() {
try {
singleton.writeLock(latch, entered);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
entered.await();
try {
singleton.writeLock(latch, entered);
throw new RuntimeException("Expecting a concurrency access exception");
} catch (ConcurrentAccessTimeoutException e) {
//expected
}
latch.countDown();
future.get();
}
@Test
public void testImplicitWriteLockMethodNotOverridden() throws Exception {
final SingletonBaseBean singleton = lookup(SingletonChildBean.class.getSimpleName(), SingletonChildBean.class);
ExecutorService pool = Executors.newSingleThreadExecutor();
final CountDownLatch latch = new CountDownLatch(2);
final CountDownLatch entered = new CountDownLatch(1);
//call a method with a write lock
//this will block till we hit the latch
Future<?> future = pool.submit(new Runnable() {
@Override
public void run() {
try {
singleton.impliedWriteLock(latch, entered);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
entered.await();
try {
singleton.impliedWriteLock(latch, entered);
throw new RuntimeException("Expecting a concurrency access exception");
} catch (ConcurrentAccessTimeoutException e) {
//expected
}
latch.countDown();
future.get();
}
@Test
public void testReadLockNotOverridden() throws Exception {
final SingletonBaseBean singleton = lookup(SingletonChildBean.class.getSimpleName(), SingletonChildBean.class);
ExecutorService pool = Executors.newSingleThreadExecutor();
final CountDownLatch latch = new CountDownLatch(2);
final CountDownLatch entered = new CountDownLatch(1);
//call a method with a write lock
//this will block till we hit the latch
Future<?> future = pool.submit(new Runnable() {
@Override
public void run() {
try {
singleton.readLock(latch, entered);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
entered.await();
singleton.readLock(latch, entered);
future.get();
}
@Test
public void testWritersBlockReader() throws Exception {
final SingletonBaseBean singleton = lookup(SingletonChildBean.class.getSimpleName(), SingletonChildBean.class);
ExecutorService pool = Executors.newSingleThreadExecutor();
final CountDownLatch latch = new CountDownLatch(2);
final CountDownLatch entered = new CountDownLatch(1);
//call a method with a write lock
//this will block till we hit the latch
Future<?> future = pool.submit(new Runnable() {
@Override
public void run() {
try {
singleton.writeLock(latch, entered);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
entered.await();
try {
singleton.readLock(latch, entered);
throw new RuntimeException("Expecting a concurrency access exception");
} catch (ConcurrentAccessTimeoutException e) {
//expected
}
latch.countDown();
future.get();
}
}
| 9,080 | 37.478814 | 129 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/concurrency/inheritance/SingletonBaseBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.concurrency.inheritance;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.AccessTimeout;
import jakarta.ejb.Lock;
import jakarta.ejb.LockType;
public class SingletonBaseBean {
@Lock(LockType.WRITE)
@AccessTimeout(value = 0)
public void writeLockOverriddenByParent(CountDownLatch cont, CountDownLatch entered) throws InterruptedException {
entered.countDown();
cont.countDown();
if (!cont.await(2, TimeUnit.SECONDS)) {
throw new RuntimeException("Could not acquire lock within 2 seconds");
}
}
@Lock(LockType.READ)
@AccessTimeout(value = 0)
public void readLockOverriddenByParent(CountDownLatch cont, CountDownLatch entered) throws InterruptedException {
entered.countDown();
cont.countDown();
if (!cont.await(2, TimeUnit.SECONDS)) {
throw new RuntimeException("Could not acquire lock within 2 seconds");
}
}
@Lock(LockType.WRITE)
@AccessTimeout(value = 0)
public void writeLock(CountDownLatch cont, CountDownLatch entered) throws InterruptedException {
entered.countDown();
cont.countDown();
if (!cont.await(2, TimeUnit.SECONDS)) {
throw new RuntimeException("Could not acquire lock within 2 seconds");
}
}
@Lock(LockType.READ)
@AccessTimeout(value = 0)
public void readLock(CountDownLatch cont, CountDownLatch entered) throws InterruptedException {
entered.countDown();
cont.countDown();
if (!cont.await(2, TimeUnit.SECONDS)) {
throw new RuntimeException("Could not acquire lock within 2 seconds");
}
}
@AccessTimeout(value = 0)
public void impliedWriteLock(CountDownLatch cont, CountDownLatch entered) throws InterruptedException {
entered.countDown();
cont.countDown();
if (!cont.await(2, TimeUnit.SECONDS)) {
throw new RuntimeException("Could not acquire lock within 2 seconds");
}
}
}
| 3,123 | 36.190476 | 118 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/SingletonThree.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.ejb.DependsOn;
import jakarta.ejb.EJB;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
/**
* @author Ondrej Chaloupka
*/
@DependsOn({"SingletonTwo"})
@Singleton
@Startup
public class SingletonThree {
@EJB(lookup = "java:global/callcounter/CallCounterSingleton")
CallCounterSingleton callCounter;
@PostConstruct
public void postConstruct() {
callCounter.addCall(SingletonThree.class.getSimpleName());
}
@PreDestroy
public void preDestroy() {
callCounter.addCall(SingletonThree.class.getSimpleName());
}
}
| 1,749 | 32.653846 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/SingletonTwo.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.ejb.DependsOn;
import jakarta.ejb.EJB;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
/**
* @author Ondrej Chaloupka
*/
@DependsOn("one.jar#SingletonOne")
@Singleton
@Startup
public class SingletonTwo {
@EJB(lookup = "java:global/callcounter/CallCounterSingleton")
CallCounterSingleton callCounter;
@PostConstruct
public void postConstruct() {
callCounter.addCall(SingletonTwo.class.getSimpleName());
}
@PreDestroy
public void preDestroy() {
callCounter.addCall(SingletonTwo.class.getSimpleName());
}
}
| 1,749 | 32.653846 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/CallCounterSingleton.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson;
import java.util.ArrayList;
import java.util.List;
import jakarta.ejb.Singleton;
/**
* Counting ordering of calls.
*
* @author Ondrej Chaloupka
*/
@Singleton
public class CallCounterSingleton {
private List<String> orderLog = new ArrayList<String>();
public void addCall(String call) {
this.orderLog.add(call);
}
public List<String> getCalls() {
return this.orderLog;
}
}
| 1,503 | 31.695652 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/SingletonOne.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.ejb.EJB;
import jakarta.ejb.Singleton;
/**
* @author Ondrej Chaloupka
*/
@Singleton
public class SingletonOne {
@EJB(lookup = "java:global/callcounter/CallCounterSingleton")
CallCounterSingleton callCounter;
@PostConstruct
public void postConstruct() {
callCounter.addCall(SingletonOne.class.getSimpleName());
}
@PreDestroy
public void preDestroy() {
callCounter.addCall(SingletonOne.class.getSimpleName());
}
}
| 1,647 | 33.333333 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/DependsOnSingletonUnitTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson;
import java.util.ArrayList;
import java.util.List;
import org.jboss.logging.Logger;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
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.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @author Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
public class DependsOnSingletonUnitTestCase {
private static final Logger log = Logger.getLogger(DependsOnSingletonUnitTestCase.class.getName());
@ArquillianResource
InitialContext ctx;
@ArquillianResource
Deployer deployer;
@Deployment(name = "callcounter", order = 0, managed = true, testable = true)
public static Archive<?> deployCallcounter() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "callcounter.jar");
jar.addClass(CallCounterSingleton.class);
jar.addClass(DependsOnSingletonUnitTestCase.class);
return jar;
}
@Deployment(name = "ear", order = 1, managed = false, testable = false)
public static Archive<?> deployDependsOn() {
JavaArchive jarOne = ShrinkWrap.create(JavaArchive.class, "one.jar");
jarOne.addClass(SingletonOne.class);
JavaArchive jarTwo = ShrinkWrap.create(JavaArchive.class, "two.jar");
jarTwo.addClass(SingletonTwo.class);
JavaArchive jarThree = ShrinkWrap.create(JavaArchive.class, "three.jar");
jarThree.addClass(SingletonThree.class);
EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "dependson-test.ear");
ear.addAsModule(jarOne);
ear.addAsModule(jarTwo);
ear.addAsModule(jarThree);
ear.addAsManifestResource(DependsOnSingletonUnitTestCase.class.getPackage(), "application.xml", "application.xml");
ear.addAsManifestResource(new StringAsset("Dependencies: deployment.callcounter.jar \n"), "MANIFEST.MF");
return ear;
}
@Test
@OperateOnDeployment("callcounter")
public void testDependsOn() throws Exception {
CallCounterSingleton singleton = (CallCounterSingleton) ctx.lookup("java:module/CallCounterSingleton");
deployer.deploy("ear");
deployer.undeploy("ear");
List<String> expectedOrder = new ArrayList<String>();
expectedOrder.add("SingletonOne");
expectedOrder.add("SingletonTwo");
expectedOrder.add("SingletonThree");
expectedOrder.add("SingletonThree");
expectedOrder.add("SingletonTwo");
expectedOrder.add("SingletonOne");
Assert.assertEquals(expectedOrder, singleton.getCalls());
}
}
| 4,132 | 39.126214 | 123 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/session/SetupModuleServerSetupTask.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson.session;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.ejb.singleton.dependson.mdb.CallCounterInterface;
import org.jboss.as.test.module.util.TestModule;
import org.jboss.as.test.shared.ModuleUtils;
/**
* @author baranowb
*/
public class SetupModuleServerSetupTask implements ServerSetupTask {
private volatile TestModule testModule;
@Override
public void setup(ManagementClient arg0, String arg1) throws Exception {
testModule = ModuleUtils.createTestModuleWithEEDependencies(SessionConstants.TEST_MODULE_NAME);
testModule.addResource("module.jar").addClasses(CallCounterInterface.class, Trigger.class);
testModule.create();
}
@Override
public void tearDown(ManagementClient arg0, String arg1) throws Exception {
if (testModule != null) {
testModule.remove();
}
}
}
| 2,044 | 36.87037 | 103 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/session/Trigger.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson.session;
/**
* @author baranowb
*/
public interface Trigger {
void trigger();
}
| 1,176 | 33.617647 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/session/StatelesBeanWhichDependsOn.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson.session;
import jakarta.ejb.DependsOn;
import jakarta.ejb.Remote;
import jakarta.ejb.Remove;
import jakarta.ejb.Stateless;
/**
* @author baranowb
*/
@Stateless
@Remote(Trigger.class)
@DependsOn("CallCounterProxy")
public class StatelesBeanWhichDependsOn extends BeanBase {
// This is required to trigger purge - circumvents WFLY-817
@Remove
public void trigger() {
super.logger.trace("Session.trigger");
super.counter.setMessage();
}
}
| 1,558 | 34.431818 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/session/SessionConstants.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson.session;
/**
* @author baranowb
*/
public interface SessionConstants {
String DEPLOYMENT_NAME_SESSION = "session";
String DEPLOYMENT_JAR_NAME_SESSION = DEPLOYMENT_NAME_SESSION + ".jar";
String TEST_MODULE_NAME = "Session";
String TEST_MODULE_NAME_FULL = "test." + TEST_MODULE_NAME;
String EJB_STATEFUL = "java:global/session/StatefulBeanWhichDependsOn!org.jboss.as.test.integration.ejb.singleton.dependson.session.Trigger";
String EJB_STATELES = "java:global/session/StatelesBeanWhichDependsOn!org.jboss.as.test.integration.ejb.singleton.dependson.session.Trigger";
}
| 1,683 | 43.315789 | 145 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/session/StatefulBeanWhichDependsOn.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson.session;
import jakarta.ejb.DependsOn;
import jakarta.ejb.Remote;
import jakarta.ejb.Remove;
import jakarta.ejb.Stateful;
/**
* @author baranowb
*/
@Stateful
@Remote(Trigger.class)
@DependsOn("CallCounterProxy")
public class StatefulBeanWhichDependsOn extends BeanBase {
// This is required to trigger purge - circumvents WFLY-817
@Remove
public void trigger() {
super.logger.trace("Session.trigger");
super.counter.setMessage();
}
}
| 1,556 | 34.386364 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/session/StatelesBeanWhichDependsOnTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson.session;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.integration.ejb.singleton.dependson.mdb.CallCounterProxy;
import org.jboss.as.test.integration.ejb.singleton.dependson.mdb.Constants;
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.Test;
import org.junit.runner.RunWith;
/**
* @author baranowb
*/
@ServerSetup({SetupModuleServerSetupTask.class})
@RunWith(Arquillian.class)
public class StatelesBeanWhichDependsOnTestCase extends SessionWhichDependeOnTestCaseBase {
@ArquillianResource
InitialContext ctx;
@Override
protected Trigger getTrigger() throws Exception {
return (Trigger) ctx.lookup(SessionConstants.EJB_STATELES);
}
@Deployment(name = Constants.DEPLOYMENT_NAME_COUNTER, order = 0, managed = true, testable = true)
public static Archive<?> getTestArchive() throws Exception {
JavaArchive jar = getTestArchiveBase();
jar.addClass(StatelesBeanWhichDependsOnTestCase.class);
return jar;
}
@Deployment(name = SessionConstants.DEPLOYMENT_NAME_SESSION, order = 1, managed = false, testable = false)
public static Archive<?> getSessionArchive() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, SessionConstants.DEPLOYMENT_NAME_SESSION);
jar.addClass(Constants.class);
jar.addClass(CallCounterProxy.class);
jar.addClass(SessionConstants.class);
jar.addClass(BeanBase.class);
jar.addClass(StatelesBeanWhichDependsOn.class);
jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr, "
+ SessionConstants.TEST_MODULE_NAME_FULL + "\n"), "MANIFEST.MF");
return jar;
}
@Test
public void test() throws Exception {
super.testSessionBean();
}
}
| 3,255 | 39.7 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/session/StatefulBeanWhichDependsOnTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson.session;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.integration.ejb.singleton.dependson.mdb.CallCounterProxy;
import org.jboss.as.test.integration.ejb.singleton.dependson.mdb.Constants;
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.Test;
import org.junit.runner.RunWith;
/**
* @author baranowb
*/
@ServerSetup({SetupModuleServerSetupTask.class})
@RunWith(Arquillian.class)
public class StatefulBeanWhichDependsOnTestCase extends SessionWhichDependeOnTestCaseBase {
@ArquillianResource
InitialContext ctx;
@Override
protected Trigger getTrigger() throws Exception {
return (Trigger) ctx.lookup(SessionConstants.EJB_STATEFUL);
}
@Deployment(name = Constants.DEPLOYMENT_NAME_COUNTER, order = 0, managed = true, testable = true)
public static Archive<?> getTestArchive() throws Exception {
JavaArchive jar = getTestArchiveBase();
jar.addClass(StatefulBeanWhichDependsOnTestCase.class);
return jar;
}
@Deployment(name = SessionConstants.DEPLOYMENT_NAME_SESSION, order = 1, managed = false, testable = false)
public static Archive<?> getSessionArchive() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, SessionConstants.DEPLOYMENT_NAME_SESSION);
jar.addClass(Constants.class);
jar.addClass(CallCounterProxy.class);
jar.addClass(SessionConstants.class);
jar.addClass(BeanBase.class);
jar.addClass(StatefulBeanWhichDependsOn.class);
jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr, "
+ SessionConstants.TEST_MODULE_NAME_FULL + "\n"), "MANIFEST.MF");
return jar;
}
@Test
public void test() throws Exception {
super.testSessionBean();
}
}
| 3,255 | 39.7 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/session/SessionWhichDependeOnTestCaseBase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson.session;
import jakarta.ejb.EJB;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.test.integration.ejb.singleton.dependson.mdb.CallCounterInterface;
import org.jboss.as.test.integration.ejb.singleton.dependson.mdb.CallCounterSingleton;
import org.jboss.as.test.integration.ejb.singleton.dependson.mdb.Constants;
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.Assert;
/**
* @author baranowb
*/
public abstract class SessionWhichDependeOnTestCaseBase {
protected static final Logger logger = Logger.getLogger(SessionWhichDependeOnTestCaseBase.class);
@ArquillianResource
Deployer deployer;
@EJB
private CallCounterInterface counter;
protected abstract Trigger getTrigger() throws Exception;
protected static JavaArchive getTestArchiveBase() throws Exception {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, Constants.DEPLOYMENT_JAR_NAME_COUNTER);
jar.addClass(CallCounterSingleton.class);
jar.addClass(SessionConstants.class);
jar.addClass(Constants.class);
jar.addClass(SetupModuleServerSetupTask.class);
jar.addClass(SessionWhichDependeOnTestCaseBase.class);
jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr, "
+ SessionConstants.TEST_MODULE_NAME_FULL + "\n"), "MANIFEST.MF");
return jar;
}
public void testSessionBean() throws Exception {
this.deployer.deploy(SessionConstants.DEPLOYMENT_NAME_SESSION);
getTrigger().trigger();
this.deployer.undeploy(SessionConstants.DEPLOYMENT_NAME_SESSION);
Assert.assertTrue("PostConstruct not called!", counter.isPostConstruct());
Assert.assertTrue("Message not called!", counter.isMessage());
Assert.assertTrue("PreDestroy not called!", counter.isPreDestroy());
}
}
| 3,166 | 41.226667 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/session/BeanBase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson.session;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.ejb.EJB;
import org.jboss.as.test.integration.ejb.singleton.dependson.mdb.CallCounterProxy;
import org.jboss.logging.Logger;
/**
* Base for session beans.
*
* @author baranowb
*/
//@DependsOn("CallCounterProxy")
public abstract class BeanBase implements Trigger {
protected final Logger logger = Logger.getLogger(getClass());
@EJB
protected CallCounterProxy counter;
@PostConstruct
public void postConstruct() {
this.logger.trace("Session.postConstruct");
this.counter.setPostConstruct();
}
@PreDestroy
public void preDestroy() {
this.logger.trace("Session.preDestroy");
this.counter.setPreDestroy();
}
}
| 1,871 | 33.036364 | 82 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/mdb/Constants.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson.mdb;
/**
* @author baranowb
*/
public interface Constants {
String TEST_MODULE_NAME = "MDBDepends";
String TEST_MODULE_NAME_FULL = "test." + TEST_MODULE_NAME;
String EJB_JMS_NAME = "java:module/JMSMessagingUtil";
String QUEUE_NAME = "mdbtest/queue";
String QUEUE_JNDI_NAME = "java:jboss/" + QUEUE_NAME;
String QUEUE_REPLY_NAME = "mdbtest/replyQueue";
String QUEUE_REPLY_JNDI_NAME = "java:jboss/" + QUEUE_REPLY_NAME;
String SYS_PROP_KEY = "jboss/" + QUEUE_NAME;
String SYS_PROP_VALUE = "activemq-ra.rar";
String DEPLOYMENT_NAME_COUNTER = "callcounter";
String DEPLOYMENT_JAR_NAME_COUNTER = DEPLOYMENT_NAME_COUNTER + ".jar";
String DEPLOYMENT_NAME_MDB = "mdb";
String DEPLOYMENT_JAR_NAME_MDB = DEPLOYMENT_NAME_MDB + ".jar";
//dont use classes directly. Some are not shared.
String SINGLETON_EJB = "java:global/callcounter/CallCounterSingleton!org.jboss.as.test.integration.ejb.singleton.dependson.mdb.CallCounterInterface";
}
| 2,076 | 42.270833 | 153 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/singleton/dependson/mdb/MDBWhichDependsOnTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.singleton.dependson.mdb;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.jms.Message;
import jakarta.jms.Queue;
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.as.arquillian.api.ServerSetup;
import org.jboss.as.test.integration.common.jms.JMSOperations;
import org.jboss.as.test.integration.ejb.mdb.JMSMessagingUtil;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.logging.Logger;
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;
import java.util.PropertyPermission;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
/**
* WFLY-2732 - test if MDB can access @DependsOn ejbs in @PostConstruct and @PreDestroy annotated methods.
*
* @author baranowb
*/
@RunWith(Arquillian.class)
@ServerSetup({JmsQueueServerSetupTask.class, SetupModuleServerSetupTask.class})
public class MDBWhichDependsOnTestCase {
private static final Logger logger = Logger.getLogger(MDBWhichDependsOnTestCase.class);
@ArquillianResource
Deployer deployer;
@EJB(mappedName = Constants.EJB_JMS_NAME)
private JMSMessagingUtil jmsUtil;
@EJB
private CallCounterInterface counter;
@Resource(mappedName = Constants.QUEUE_JNDI_NAME)
private Queue queue;
@Resource(mappedName = Constants.QUEUE_REPLY_JNDI_NAME)
private Queue replyQueue;
@Deployment(name = Constants.DEPLOYMENT_NAME_COUNTER, order = 0, managed = true, testable = true)
public static Archive<?> getTestArchive() throws Exception {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, Constants.DEPLOYMENT_JAR_NAME_COUNTER);
jar.addClass(CallCounterSingleton.class);
jar.addClass(MDBWhichDependsOnTestCase.class);
jar.addClass(Constants.class);
jar.addClasses(JMSMessagingUtil.class, TimeoutUtil.class);
jar.addClasses(JmsQueueServerSetupTask.class, SetupModuleServerSetupTask.class);
jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr, "
+ Constants.TEST_MODULE_NAME_FULL + "\n"), "MANIFEST.MF");
jar.addAsManifestResource(createPermissionsXmlAsset(
new PropertyPermission(TimeoutUtil.FACTOR_SYS_PROP, "read")), "permissions.xml");
return jar;
}
@Deployment(name = Constants.DEPLOYMENT_NAME_MDB, order = 1, managed = false, testable = false)
public static Archive getMDBArchive() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, Constants.DEPLOYMENT_JAR_NAME_MDB);
jar.addPackage(JMSOperations.class.getPackage());
jar.addClasses(JMSMessagingUtil.class, TimeoutUtil.class);
jar.addClass(MDBWhichDependsOn.class);
jar.addClass(Constants.class);
jar.addClass(CallCounterProxy.class);
jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr, "
+ Constants.TEST_MODULE_NAME_FULL + "\n"), "MANIFEST.MF");
jar.addAsManifestResource(createPermissionsXmlAsset(
new PropertyPermission(TimeoutUtil.FACTOR_SYS_PROP, "read")), "permissions.xml");
return jar;
}
/**
* Test an annotation based MDB with properties substitution
*
* @throws Exception
*/
@Test
public void testAnnoBasedMDB() throws Exception {
this.deployer.deploy(Constants.DEPLOYMENT_NAME_MDB);
this.jmsUtil.sendTextMessage("Say Nihao to new message!", this.queue, this.replyQueue);
final Message reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
Assert.assertNotNull("Reply message was null on reply queue: " + this.replyQueue, reply);
this.deployer.undeploy(Constants.DEPLOYMENT_NAME_MDB);
Assert.assertTrue("PostConstruct not called!", counter.isPostConstruct());
Assert.assertTrue("Message not called!", counter.isMessage());
Assert.assertTrue("PreDestroy not called!", counter.isPreDestroy());
}
}
| 5,466 | 42.736 | 113 |
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.