diff options
author | Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com> | 2018-07-09 13:41:00 -0400 |
---|---|---|
committer | Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com> | 2018-07-11 13:20:28 -0400 |
commit | a96a3e49cd472aa902c22143358b87562603d47c (patch) | |
tree | 7e97578788de44f6704252cf982af09adcc05e8d /ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java | |
parent | 9ac542482e4710e5566d147ca7a7a42500628ba2 (diff) |
Adding User Auth and permission aaf services
Issue-ID: PORTAL-334
Change-Id: I2826f2a06f7d818d918ae5f45b500a8da78cec42
Signed-off-by: Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java')
-rw-r--r-- | ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java index d93b03c1..9836c5f1 100644 --- a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java @@ -37,6 +37,7 @@ */ package org.onap.portalsdk.external.authorization.service; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -83,6 +84,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.databind.ObjectMapper; @@ -132,7 +134,7 @@ public class UserApiServiceImplTest { PowerMockito.mockStatic(SystemProperties.class); Mockito.when(EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_NAMESPACE)) .thenReturn("com.test.app2"); - Mockito.when(EcompExternalAuthUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(new HttpHeaders()); + Mockito.when(EcompExternalAuthUtils.base64encodeKeyForAAFBasicAuth(Matchers.anyString(), Matchers.anyString())).thenReturn(new HttpHeaders()); Mockito.when(EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_USER_DOMAIN)) .thenReturn("@test.com"); MockitoAnnotations.initMocks(this); @@ -286,6 +288,15 @@ public class UserApiServiceImplTest { @Test public void getRoleFunctionsTest() throws Exception { + JSONObject mockJsonObjectPerms = mockUserPerms(); + ResponseEntity<String> response = new ResponseEntity<>(mockJsonObjectPerms.toString(), HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), + Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(response); + List<RoleFunction> actual = UserApiServiceImpl.getRoleFunctions("test123"); + assertNotNull(actual); + } + + private JSONObject mockUserPerms() { JSONObject mockJsonObjectPerms = new JSONObject(); JSONObject mockJsonObjectPerm1 = new JSONObject(); JSONObject mockJsonObjectPerm2 = new JSONObject(); @@ -304,10 +315,39 @@ public class UserApiServiceImplTest { permsList.add(mockJsonObjectPerm1); permsList.add(mockJsonObjectPerm2); mockJsonObjectPerms.put("perm", permsList); + return mockJsonObjectPerms; + } + + @Test + public void checkUserExistsTest() throws Exception { + ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST), + Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(response); + ResponseEntity<String> actual = UserApiServiceImpl.checkUserExists("test", "test"); + assertNotNull(actual); + } + + @Test(expected = HttpClientErrorException.class) + public void checkUserExistsExceptionTest() throws Exception { + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST), + Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenThrow(new HttpClientErrorException(HttpStatus.UNAUTHORIZED)); + UserApiServiceImpl.checkUserExists("test", "test"); + } + + @Test + public void getIfUserPermsExistsTest() throws Exception { + JSONObject mockJsonObjectPerms = mockUserPerms(); ResponseEntity<String> response = new ResponseEntity<>(mockJsonObjectPerms.toString(), HttpStatus.OK); Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(response); - List<RoleFunction> actual = UserApiServiceImpl.getRoleFunctions("test123"); - assertNotNull(actual); + UserApiServiceImpl.getIfUserPermsExists("test123@test.com"); + } + + @Test(expected = HttpClientErrorException.class) + public void getIfUserPermsExistsInvalidUserTest() throws Exception { + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), + Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenThrow(new HttpClientErrorException(HttpStatus.UNAUTHORIZED)); + UserApiServiceImpl.getIfUserPermsExists("test1"); } + } |