Stateless

Run
How to run the sample
The source code for this sample can be found in the javaee7-samples GitHub repository. The first thing we need to do is to get the source by downloading the repository and then go into the samples folder:
git clone git://github.com/javaee-samples/javaee7-samples.git
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

AccountSessionStatelessnessTest

Missing a description for the story. Add some javadoc to the TestClass. Show me how!
Missing a description for the deployment. Add some javadoc to the @Deployment method. Show me how!
@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));
}

AccountSessionBeanWithInterfaceTest

Missing a description for the story. Add some javadoc to the TestClass. Show me how!

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)));
}

AccountSessionBeanTest

Missing a description for the story. Add some javadoc to the TestClass. Show me how!

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)));
}

Share the Knowledge

Find this sample useful? Share on

There's a lot more about JavaEE to cover. If you're ready to learn more, check out the other available samples.

Help Improve

Find a bug in the sample? Something missing? You can fix it by editing the source, making the correction and sending a pull request. Or report the problem to the issue tracker

Recent Changelog

  • Jul 15, 2014: Removed header license. the licensing is now referenced in the license file in the root of the project by Roberto Cortez
  • Mar 26, 2014: Fixing #205. removing spec not compliant assertions by kubamarchwicki
  • Mar 25, 2014: Suggestion howto fix #205 by Alexander Heusingfeld
  • Dec 09, 2013: Favouring injection over initialcontext for #75 ejb stateless and statefull tests by kubamarchwicki
  • Dec 08, 2013: Test same stateless bean on every ctx lookup by kubamarchwicki
  • Dec 08, 2013: Removing obsolete servlets and index.jsp files by kubamarchwicki
  • Dec 02, 2013: Tests for ejb/stateless & ejb/stateful by Rafał Roppel
  • Nov 08, 2013: Cocommenting the test for now until ejb injection is identified by Arun Gupta
  • Nov 08, 2013: Cocommenting the test for now until ejb injection is identified by Arun Gupta
  • Nov 07, 2013: Commenting arquillian dependencies till it is sorted out by Arun Gupta
How to help improve this sample
The source code for this sample can be found in the javaee7-samples GitHub repository. The first thing you need to do is to get the source by downloading the repository and then go into the samples folder:
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!