+
+ @Test
+ public void getEpUserNullTest() throws Exception{
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ app.setUebKey("uebKey");
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(app)).thenReturn(response);
+ assertNull(externalAccessRolesController.getEcompUser(mockedRequest, mockedResponse, "test12"));
+ }
+
+ @Test
+ public void getEpUserTest() throws Exception{
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ app.setUebKey("uebKey");
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(app)).thenReturn(response);
+ String user = "{\"id\":null,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"orgId\":null,\"managerId\":null,\"firstName\":\"test\",\"middleInitial\":null,\"lastName\":null,\"phone\":null,\"fax\":null,\"cellular\":null,\"email\":null,\"addressId\":null,\"alertMethodCd\":null,\"hrid\":null,\"orgUserId\":null,\"orgCode\":null,\"address1\":null,\"address2\":null,\"city\":null,\"state\":null,\"zipCode\":null,\"country\":null,\"orgManagerUserId\":null,\"locationClli\":null,\"businessCountryCode\":null,\"businessCountryName\":null,\"businessUnit\":null,\"businessUnitName\":null,\"department\":null,\"departmentName\":null,\"companyCode\":null,\"company\":null,\"zipCodeSuffix\":null,\"jobTitle\":null,\"commandChain\":null,\"siloStatus\":null,\"costCenter\":null,\"financialLocCode\":null,\"loginId\":null,\"loginPwd\":null,\"lastLoginDate\":null,\"active\":false,\"internal\":false,\"selectedProfileId\":null,\"timeZoneId\":null,\"online\":false,\"chatId\":null,\"userApps\":[],\"pseudoRoles\":[],\"defaultUserApp\":null,\"roles\":[],\"fullName\":\"test null\"}";
+ Mockito.when(externalAccessRolesService.getV2UserWithRoles("test12", mockedRequest.getHeader(uebKey))).thenReturn(user);
+ User EPuser = new User();
+ EPuser.setFirstName("test");
+ Mockito.when(userservice.userMapper(user)).thenReturn(EPuser);
+ String res = "{\"orgId\":null,\"managerId\":null,\"firstName\":\"test\",\"middleInitial\":null,\"lastName\":null,\"phone\":null,\"email\":null,\"hrid\":null,\"orgUserId\":null,\"orgCode\":null,\"orgManagerUserId\":null,\"jobTitle\":null,\"loginId\":null,\"active\":false,\"roles\":[]}";
+ assertEquals(externalAccessRolesController.getEcompUser(mockedRequest, mockedResponse, "test12"),res);
+ }
+
+ @Test
+ public void getEpUserExceptionTest() throws Exception{
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(externalAccessRolesController.getEcompUser(mockedRequest, mockedResponse, "test12"));
+ }
+
+ @Test
+ public void getEPRolesOfApplicationTest() throws Exception
+ {
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ app.setUebKey("uebKey");
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(app)).thenReturn(response);
+ Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
+ List<CentralV2Role> cenRoleList = new ArrayList<>();
+ CentralV2Role role = new CentralV2Role();
+ role.setName("test");
+ cenRoleList.add(role);
+ Mockito.when(externalAccessRolesService.getActiveRoles(mockedRequest.getHeader(uebKey))).thenReturn(cenRoleList);
+ List<EcompRole> ecompRoles = new ArrayList<>();
+ EcompRole eprole = new EcompRole();
+ eprole.setName("test");
+ ecompRoles.add(eprole);
+ assertEquals(ecompRoles,externalAccessRolesController.getEcompRolesOfApplication(mockedRequest, mockedResponse));
+ }
+ @Test
+ public void getEPRolesOfApplicationNullTest() throws Exception
+ {
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ app.setUebKey("uebKey");
+ app.setCentralAuth(true);
+ applicationList.add(app);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(externalAccessRolesService.getNameSpaceIfExists(app)).thenReturn(response);
+ Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
+ List<CentralV2Role> cenRoleList = new ArrayList<>();
+ CentralV2Role role = new CentralV2Role();
+ role.setName("test");
+ cenRoleList.add(role);
+ Mockito.when(externalAccessRolesService.getActiveRoles(mockedRequest.getHeader(uebKey))).thenReturn(null);
+ assertNull(externalAccessRolesController.getEcompRolesOfApplication(mockedRequest, mockedResponse));
+
+ }
+
+ @Test
+ public void getEPRolesOfApplicationExceptionTest() throws Exception
+ {
+ List<EPApp> applicationList = new ArrayList<EPApp>();
+ EPApp app = mockApp();
+ app.setCentralAuth(true);
+ Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(externalAccessRolesController.getEcompRolesOfApplication(mockedRequest, mockedResponse));
+
+ }