@Deployment
public static Archive<?> deployment() {
return ShrinkWrap.create(JavaArchive.class, "test.jar")
.addClass(AccountSessionBean.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
cd javaee7-samples/ejb/stateless/Now we are ready to start testing. You can run all the tests in this sample by executing:
mvn test
Or you can run individual tests by executing one of the following:mvn test -Dtest=AccountSessionStatelessnessTestmvn test -Dtest=AccountSessionBeanWithInterfaceTestmvn test -Dtest=AccountSessionBeanTest
@Deployment
public static Archive<?> deployment() {
return ShrinkWrap.create(JavaArchive.class, "test.jar")
.addClass(AccountSessionBean.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
JSR 318: Enterprise JavaBeans, Version 3.1 3.4.7.2 Session Object Identity / Stateless Session Beans
All business object references of the same interface type for the same stateless session bean have the same object identity, which is assigned by the container. All references to the no-interface view of the same stateless session bean have the same object identity.
@Test
public void should_be_identical_beans() {
assertThat("Expect same instances", account1, is(account2));
}
Arquillian specific method for creating a file which can be deployed while executing the test.
@Deployment
public static Archive<?> deployment() {
return ShrinkWrap.create(JavaArchive.class)
.addClass(AccountSessionBeanWithInterface.class)
.addClass(Account.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
Test of withdraw method, of class AccountSessionBean.
@Test
public void shouldWithdrawGivenAmount() {
// given
final float amount = 5.0F;
// when
final String actual = sut.withdraw(amount);
// then
assertThat(actual, is(equalTo("Withdrawn: " + amount)));
}
Test of deposit method, of class AccountSessionBean.
@Test
public void shouldDepositGivenAmount() {
// given
final float amount = 10.0F;
// when
final String actual = sut.deposit(amount);
// then
assertThat(actual, is(equalTo("Deposited: " + amount)));
}
Arquillian specific method for creating a file which can be deployed while executing the test.
@Deployment
public static Archive<?> deployment() {
return ShrinkWrap.create(JavaArchive.class)
.addClass(AccountSessionBean.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
Test of withdraw method, of class AccountSessionBean.
@Test
public void shouldWithdrawGivenAmount() {
// given
final float amount = 5.0F;
// when
final String actual = sut.withdraw(amount);
// then
assertThat(actual, is(equalTo("Withdrawn: " + amount)));
}
Test of deposit method, of class AccountSessionBean.
@Test
public void shouldDepositGivenAmount() {
// given
final float amount = 10.0F;
// when
final String actual = sut.deposit(amount);
// then
assertThat(actual, is(equalTo("Deposited: " + amount)));
}
There's a lot more about JavaEE to cover. If you're ready to learn more, check out the other available samples.
git clone git://github.com/javaee-samples/javaee7-samples.git
cd javaee7-samples/ejb/stateless/
Do the changes as you see fit and send a pull request!
Good Luck!