Merge pull request #1880 from pritambanerjee999/master
EJB Session Beans
This commit is contained in:
commit
3bf80a1f2b
|
@ -0,0 +1,106 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.baeldung.ejb</groupId>
|
||||
<artifactId>ejb</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>ejb-session-beans</artifactId>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<arquillian-bom.version>1.1.12.Final</arquillian-bom.version>
|
||||
<shrinkwrap-resolver-impl-maven.version>2.2.6</shrinkwrap-resolver-impl-maven.version>
|
||||
<arquillian-junit-container.version>1.1.12.Final</arquillian-junit-container.version>
|
||||
<arquillian-glassfish-embedded-3.1.version>1.0.0.Final</arquillian-glassfish-embedded-3.1.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<javaee-api.version>7.0</javaee-api.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jboss.arquillian</groupId>
|
||||
<artifactId>arquillian-bom</artifactId>
|
||||
<version>1.1.13.Final</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<version>${javaee-api.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.arquillian.junit</groupId>
|
||||
<artifactId>arquillian-junit-container</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>arquillian-glassfish-embedded</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jboss.arquillian.container</groupId>
|
||||
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
|
||||
<version>1.0.0.CR4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.main.extras</groupId>
|
||||
<artifactId>glassfish-embedded-all</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.17</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.ejb.stateful;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
|
||||
public class EJBClient1 {
|
||||
|
||||
@EJB
|
||||
public StatefulEJB statefulEJB;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.ejb.stateful;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
|
||||
public class EJBClient2 {
|
||||
|
||||
@EJB
|
||||
public StatefulEJB statefulEJB;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.ejb.stateful;
|
||||
|
||||
import javax.ejb.Stateful;
|
||||
|
||||
@Stateful
|
||||
public class StatefulEJB {
|
||||
|
||||
public String name;
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.ejb.stateless;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
|
||||
public class EJBClient1 {
|
||||
|
||||
@EJB
|
||||
public StatelessEJB statelessEJB;
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.ejb.stateless;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
|
||||
public class EJBClient2 {
|
||||
|
||||
@EJB
|
||||
public StatelessEJB statelessEJB;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.ejb.stateless;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
|
||||
|
||||
@Stateless
|
||||
public class StatelessEJB {
|
||||
|
||||
public String name;
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.baeldung.ejb.test.stateful;
|
||||
|
||||
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.EmptyAsset;
|
||||
import org.jboss.shrinkwrap.api.spec.JavaArchive;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.baeldung.ejb.stateful.EJBClient1;
|
||||
import com.baeldung.ejb.stateful.EJBClient2;
|
||||
import com.baeldung.ejb.stateful.StatefulEJB;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
||||
@RunWith(Arquillian.class)
|
||||
public class StatefulEJBTest {
|
||||
|
||||
@Inject
|
||||
private EJBClient1 ejbClient1;
|
||||
|
||||
@Inject
|
||||
private EJBClient2 ejbClient2;
|
||||
|
||||
@Test
|
||||
public void givenOneStatefulBean_whenTwoClientsSetValueOnBean_thenClientStateIsMaintained() {
|
||||
|
||||
// act
|
||||
ejbClient1.statefulEJB.name = "Client 1";
|
||||
ejbClient2.statefulEJB.name = "Client 2";
|
||||
|
||||
// assert
|
||||
Assert.assertNotEquals(ejbClient1.statefulEJB.name, ejbClient2.statefulEJB.name);
|
||||
Assert.assertEquals("Client 1", ejbClient1.statefulEJB.name);
|
||||
Assert.assertEquals("Client 2", ejbClient2.statefulEJB.name);
|
||||
|
||||
}
|
||||
|
||||
@Deployment
|
||||
public static JavaArchive createDeployment() {
|
||||
return ShrinkWrap.create(JavaArchive.class)
|
||||
.addClass(StatefulEJB.class)
|
||||
.addClass(EJBClient1.class)
|
||||
.addClass(EJBClient2.class)
|
||||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.baeldung.ejb.test.stateless;
|
||||
|
||||
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.EmptyAsset;
|
||||
import org.jboss.shrinkwrap.api.spec.JavaArchive;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.baeldung.ejb.stateless.EJBClient1;
|
||||
import com.baeldung.ejb.stateless.EJBClient2;
|
||||
import com.baeldung.ejb.stateless.StatelessEJB;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
||||
@RunWith(Arquillian.class)
|
||||
public class StatelessEJBTest {
|
||||
|
||||
@Inject
|
||||
private EJBClient1 ejbClient1;
|
||||
|
||||
@Inject
|
||||
private EJBClient2 ejbClient2;
|
||||
|
||||
@Test
|
||||
public void givenOneStatelessBean_whenStateIsSetInOneBean_secondBeanShouldHaveSameState() {
|
||||
|
||||
// act
|
||||
ejbClient1.statelessEJB.name = "Client 1";
|
||||
|
||||
// assert
|
||||
Assert.assertEquals("Client 1", ejbClient1.statelessEJB.name);
|
||||
Assert.assertEquals("Client 1", ejbClient2.statelessEJB.name);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenOneStatelessBean_whenStateIsSetInBothBeans_secondBeanShouldHaveSecondBeanState() {
|
||||
|
||||
// act
|
||||
ejbClient1.statelessEJB.name = "Client 1";
|
||||
ejbClient2.statelessEJB.name = "Client 2";
|
||||
|
||||
// assert
|
||||
Assert.assertEquals("Client 2", ejbClient2.statelessEJB.name);
|
||||
|
||||
}
|
||||
|
||||
@Deployment
|
||||
public static JavaArchive createDeployment() {
|
||||
return ShrinkWrap.create(JavaArchive.class)
|
||||
.addClass(StatelessEJB.class)
|
||||
.addClass(EJBClient1.class)
|
||||
.addClass(EJBClient2.class)
|
||||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
|
||||
}
|
||||
|
||||
}
|
|
@ -40,7 +40,12 @@
|
|||
<version>1.0-SNAPSHOT</version>
|
||||
<type>ejb</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baeldung.ejb</groupId>
|
||||
<artifactId>ejb-session-beans</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<type>ejb</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
|
@ -75,5 +80,7 @@
|
|||
<modules>
|
||||
<module>ejb-remote</module>
|
||||
<module>ejb-client</module>
|
||||
<module>ejb-session-beans</module>
|
||||
<module>ejb-session-beans-client</module>
|
||||
</modules>
|
||||
</project>
|
Loading…
Reference in New Issue