BAEL 717 - Singleton Session Bean (#4104)
* BAEL-717: Singleton EJB Bean Files for BAEL-717:Singleton EJB Bean. * BAEL-717: Singleton EJB Bean Corrected Indentation. * BAEL-717: Singleton EJB Bean Corrected Indentation. * BAEL-717: Singleton EJB Bean Corrected Indentation. * BAEL-717: Singleton EJB Bean Corrected Indentation. * BAEL-717: Singleton EJB Bean Changed artifactId value. * BAEL-717: Singleton EJB Bean. Added module for Singleton EJB Bean. * BAEL-717: Singleton EJB Bean. Removed Singleton EJB Bean Module. * BAEL-717: Singleton EJB Bean Changed the JNDI Lookup name. * BAEL-717: Singleton EJB Bean. Added the "singleton-ejb-bean" module. * BAEL-717: Singleton EJB Bean. Corrected Indentation. * BAEL-717: Singleton EJB Bean Corrected Indentation. * BAEL-717: Singleton EJB Bean. Corrected Indentation. * BAEL-717: Singleton EJB Bean. Corrected Indentation. * BAEL-717:Singleton EJB Bean. Corrected Indentation. * BAEL-717:Singleton EJB Bean. Corrected Indentation. * BAEL-717: Singleton Session Bean. Added class for Bean-Managed concurrrency. Changed class name from CountryStateCacheBean to CountryStateContainerManagedBean. * BAEL-717: Singleton Session Bean. Changing the name of the class to CountryStateContainerManagedBean. * BAEL-717: Singleton Session Bean. Added method to test Bean-Managed concurrency. * Get Latest. * deleting CountryStateBeanManagedBean for new file. * deleting CountryStateCacheBean for new file. * deleting CountryStateContainerManagedBean for new file. * BAEL-717: Singleton Session Bean. Adding file for Bean with Bean-Managed concurrency. Changing file name for original file to CountryStateContainerManagedBean with Container-Managed concurrency. * Deleting file for new checkin. * BAEL-717: Singleton Session Bean. Added test case for Bean-Manged concurrency. Change in JNDI names. * BAEL-717: Singleton Session Bean. Changed the assert method parameter order and null check in test cases. * BAEL-717:Singleton Session Bean Removed volatile keyword for the variable countryStatesMap. Marking it as final. * BAEL 717 - Singleton EJB Bean Added new method setStates(). * BAEL-717: Singleton Session Bean. Renaming directory singleton-ejb-bean to ejb-beans. * BAEL-717: Singleton EJB Beans. Renaming directory name from singleton-ejb-bean to ejb-beans. * BAEL-717: Singleton Session Bean Renaming directory singleton-ejb-bean to ejb-beans.
This commit is contained in:
+83
@@ -0,0 +1,83 @@
|
||||
package com.baeldung.singletonbean;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.embeddable.EJBContainer;
|
||||
import javax.naming.Context;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CountryStateCacheBeanTest {
|
||||
|
||||
private EJBContainer ejbContainer = null;
|
||||
|
||||
private Context context = null;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
|
||||
ejbContainer = EJBContainer.createEJBContainer();
|
||||
context = ejbContainer.getContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallGetStatesFromContainerManagedBean_ReturnsStatesForCountry() throws Exception {
|
||||
|
||||
String[] expectedStates = { "Texas", "Alabama", "Alaska", "Arizona", "Arkansas" };
|
||||
|
||||
CountryState countryStateBean = (CountryState) context.lookup("java:global/ejb-beans/CountryStateContainerManagedBean");
|
||||
List<String> actualStates = countryStateBean.getStates("UnitedStates");
|
||||
assertNotNull(actualStates);
|
||||
assertArrayEquals(expectedStates, actualStates.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallGetStatesFromBeanManagedBean_ReturnsStatesForCountry() throws Exception {
|
||||
|
||||
String[] expectedStates = { "Texas", "Alabama", "Alaska", "Arizona", "Arkansas" };
|
||||
|
||||
CountryState countryStateBean = (CountryState) context.lookup("java:global/ejb-beans/CountryStateBeanManagedBean");
|
||||
List<String> actualStates = countryStateBean.getStates("UnitedStates");
|
||||
assertNotNull(actualStates);
|
||||
assertArrayEquals(expectedStates, actualStates.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallSetStatesFromContainerManagedBean_SetsStatesForCountry() throws Exception {
|
||||
|
||||
String[] expectedStates = { "California", "Florida", "Hawaii", "Pennsylvania", "Michigan" };
|
||||
|
||||
CountryState countryStateBean = (CountryState) context.lookup("java:global/ejb-beans/CountryStateContainerManagedBean");
|
||||
countryStateBean.setStates("UnitedStates", Arrays.asList(expectedStates));
|
||||
|
||||
List<String> actualStates = countryStateBean.getStates("UnitedStates");
|
||||
assertNotNull(actualStates);
|
||||
assertArrayEquals(expectedStates, actualStates.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallSetStatesFromBeanManagedBean_SetsStatesForCountry() throws Exception {
|
||||
|
||||
String[] expectedStates = { "California", "Florida", "Hawaii", "Pennsylvania", "Michigan" };
|
||||
|
||||
CountryState countryStateBean = (CountryState) context.lookup("java:global/ejb-beans/CountryStateBeanManagedBean");
|
||||
countryStateBean.setStates("UnitedStates", Arrays.asList(expectedStates));
|
||||
|
||||
List<String> actualStates = countryStateBean.getStates("UnitedStates");
|
||||
assertNotNull(actualStates);
|
||||
assertArrayEquals(expectedStates, actualStates.toArray());
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (ejbContainer != null)
|
||||
ejbContainer.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user