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:
gautamshetty 2018-05-20 03:16:46 -05:00 committed by pauljervis
parent 0f960f423d
commit f1129ea16b
6 changed files with 46 additions and 7 deletions

View File

@ -9,4 +9,6 @@ public interface CountryState {
public List<String> getStates(String country); public List<String> getStates(String country);
public void setStates(String country, List<String> states);
} }

View File

@ -19,7 +19,7 @@ public class CountryStateBeanManagedBean implements CountryState {
private final Map<String, List<String>> countryStatesMap = new HashMap<String, List<String>>(); private final Map<String, List<String>> countryStatesMap = new HashMap<String, List<String>>();
@PostConstruct @PostConstruct
public synchronized void initialize() { public void initialize() {
List<String> states = new ArrayList<String>(); List<String> states = new ArrayList<String>();
states.add("Texas"); states.add("Texas");
@ -34,4 +34,8 @@ public class CountryStateBeanManagedBean implements CountryState {
public List<String> getStates(String country) { public List<String> getStates(String country) {
return countryStatesMap.get(country); return countryStatesMap.get(country);
} }
public synchronized void setStates(String country, List<String> states) {
countryStatesMap.put(country, states);
}
} }

View File

@ -38,4 +38,9 @@ public class CountryStateContainerManagedBean implements CountryState {
public List<String> getStates(String country) { public List<String> getStates(String country) {
return countryStatesMap.get(country); return countryStatesMap.get(country);
} }
@Lock(LockType.WRITE)
public void setStates(String country, List<String> states) {
countryStatesMap.put(country, states);
}
} }

View File

@ -3,6 +3,8 @@ package com.baeldung.singletonbean;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import javax.ejb.embeddable.EJBContainer; import javax.ejb.embeddable.EJBContainer;
@ -30,7 +32,7 @@ public class CountryStateCacheBeanTest {
String[] expectedStates = { "Texas", "Alabama", "Alaska", "Arizona", "Arkansas" }; 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"); List<String> actualStates = countryStateBean.getStates("UnitedStates");
assertNotNull(actualStates); assertNotNull(actualStates);
assertArrayEquals(expectedStates, actualStates.toArray()); assertArrayEquals(expectedStates, actualStates.toArray());
@ -41,7 +43,33 @@ public class CountryStateCacheBeanTest {
String[] expectedStates = { "Texas", "Alabama", "Alaska", "Arizona", "Arkansas" }; 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"); List<String> actualStates = countryStateBean.getStates("UnitedStates");
assertNotNull(actualStates); assertNotNull(actualStates);
assertArrayEquals(expectedStates, actualStates.toArray()); assertArrayEquals(expectedStates, actualStates.toArray());

View File

@ -73,6 +73,6 @@
<modules> <modules>
<module>ejb-remote-for-spring</module> <module>ejb-remote-for-spring</module>
<module>spring-ejb-client</module> <module>spring-ejb-client</module>
<module>singleton-ejb-bean</module> <module>ejb-beans</module>
</modules> </modules>
</project> </project>