35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottpackage com.iplanet.dpro.session.service;
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottimport com.iplanet.am.util.SystemProperties;
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottimport com.iplanet.services.naming.WebtopNaming;
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottimport com.sun.identity.shared.Constants;
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottimport com.sun.identity.shared.debug.Debug;
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottimport org.forgerock.openam.session.SessionServiceURLService;
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottimport org.powermock.api.mockito.PowerMockito;
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottimport org.powermock.core.classloader.annotations.PrepareForTest;
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottimport org.powermock.modules.testng.PowerMockTestCase;
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottimport org.testng.annotations.Test;
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshottimport static org.fest.assertions.Assertions.assertThat;
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshottimport static org.mockito.BDDMockito.given;
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshottimport static org.mockito.Matchers.anyString;
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshottimport static org.mockito.Mockito.mock;
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott@PrepareForTest({ SystemProperties.class, WebtopNaming.class })
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottpublic class SessionServerConfigTest extends PowerMockTestCase {
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott @Test
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott public void localServerIsPrimaryServerIfNoSiteSetup() throws Exception {
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott // Given
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott PowerMockito.mockStatic(SystemProperties.class);
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott given(SystemProperties.get(Constants.AM_SERVER_PROTOCOL)).willReturn("http");
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott given(SystemProperties.get(Constants.AM_SERVER_HOST)).willReturn("openam.example.com");
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott given(SystemProperties.get(Constants.AM_SERVER_PORT)).willReturn("8080");
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott given(SystemProperties.get(Constants.AM_SERVICES_DEPLOYMENT_DESCRIPTOR)).willReturn("/openam");
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott String primary = "01";
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott PowerMockito.mockStatic(WebtopNaming.class);
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott given(WebtopNaming.getServerID("http", "openam.example.com", "8080", "/openam")).willReturn(primary);
6e9ce46f56bfb7663e3af5aa571d51e8f61f0240Gabor Melkvi given(WebtopNaming.getAMServerID()).willReturn("01");
6e9ce46f56bfb7663e3af5aa571d51e8f61f0240Gabor Melkvi given(WebtopNaming.getLocalServer()).willReturn("http://openam.example.com:8080/openam");
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott // When
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott SessionServerConfig config = new SessionServerConfig(mock(Debug.class), mock(SessionServiceURLService.class));
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott // Then
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott assertThat(config.getPrimaryServerID()).isEqualTo(primary);
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott }
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott @Test
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott public void localServerAndPrimaryServerDifferIfSiteSetup() throws Exception {
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott // Given
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott PowerMockito.mockStatic(SystemProperties.class);
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott given(SystemProperties.get(Constants.AM_SERVER_PROTOCOL)).willReturn("http");
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott given(SystemProperties.get(Constants.AM_SERVER_HOST)).willReturn("openam.example.com");
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott given(SystemProperties.get(Constants.AM_SERVER_PORT)).willReturn("8080");
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott given(SystemProperties.get(Constants.AM_SERVICES_DEPLOYMENT_DESCRIPTOR)).willReturn("/openam");
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott String primary = "01";
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott PowerMockito.mockStatic(WebtopNaming.class);
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott given(WebtopNaming.getServerID("http", "openam.example.com", "8080", "/openam")).willReturn(primary);
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott given(WebtopNaming.isSiteEnabled(anyString())).willReturn(true); // enable site
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott given(WebtopNaming.getSiteID(anyString())).willReturn("02");
6e9ce46f56bfb7663e3af5aa571d51e8f61f0240Gabor Melkvi given(WebtopNaming.getAMServerID()).willReturn("01");
6e9ce46f56bfb7663e3af5aa571d51e8f61f0240Gabor Melkvi given(WebtopNaming.getLocalServer()).willReturn("http://openam.example.com:8080/openam");
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott // When
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott SessionServerConfig config = new SessionServerConfig(mock(Debug.class), mock(SessionServiceURLService.class));
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott // Then
1d407e39b7d8f68d9a2b1e178f35fab037d9835aRobert Wapshott assertThat(config.getPrimaryServerID()).isNotEqualTo(primary);
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott }
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott}