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:
parent
0f960f423d
commit
f1129ea16b
|
@ -8,5 +8,7 @@ import javax.ejb.Local;
|
|||
public interface CountryState {
|
||||
|
||||
public List<String> getStates(String country);
|
||||
|
||||
public void setStates(String country, List<String> states);
|
||||
|
||||
}
|
|
@ -19,7 +19,7 @@ public class CountryStateBeanManagedBean implements CountryState {
|
|||
private final Map<String, List<String>> countryStatesMap = new HashMap<String, List<String>>();
|
||||
|
||||
@PostConstruct
|
||||
public synchronized void initialize() {
|
||||
public void initialize() {
|
||||
|
||||
List<String> states = new ArrayList<String>();
|
||||
states.add("Texas");
|
||||
|
@ -34,4 +34,8 @@ public class CountryStateBeanManagedBean implements CountryState {
|
|||
public List<String> getStates(String country) {
|
||||
return countryStatesMap.get(country);
|
||||
}
|
||||
|
||||
public synchronized void setStates(String country, List<String> states) {
|
||||
countryStatesMap.put(country, states);
|
||||
}
|
||||
}
|
|
@ -38,4 +38,9 @@ public class CountryStateContainerManagedBean implements CountryState {
|
|||
public List<String> getStates(String country) {
|
||||
return countryStatesMap.get(country);
|
||||
}
|
||||
|
||||
@Lock(LockType.WRITE)
|
||||
public void setStates(String country, List<String> states) {
|
||||
countryStatesMap.put(country, states);
|
||||
}
|
||||
}
|
|
@ -3,6 +3,8 @@ 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;
|
||||
|
@ -24,29 +26,55 @@ public class CountryStateCacheBeanTest {
|
|||
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/singleton-ejb-bean/CountryStateContainerManagedBean");
|
||||
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/singleton-ejb-bean/CountryStateBeanManagedBean");
|
||||
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)
|
|
@ -73,6 +73,6 @@
|
|||
<modules>
|
||||
<module>ejb-remote-for-spring</module>
|
||||
<module>spring-ejb-client</module>
|
||||
<module>singleton-ejb-bean</module>
|
||||
<module>ejb-beans</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
|
Loading…
Reference in New Issue