import org.onap.portalapp.portal.domain.EPRole;
import org.onap.portalapp.portal.domain.EPUser;
import org.onap.portalapp.portal.domain.EPUserApp;
+import org.onap.portalapp.portal.domain.EpAppType;
import org.onap.portalapp.portal.ecomp.model.UploadRoleFunctionExtSystem;
import org.onap.portalapp.portal.exceptions.InactiveApplicationException;
import org.onap.portalapp.portal.exceptions.InvalidUserException;
import org.onap.portalapp.portal.framework.MockitoTestSuite;
-import org.onap.portalapp.portal.transport.BulkUploadRoleFunction;
-import org.onap.portalapp.portal.transport.BulkUploadUserRoles;
-import org.onap.portalapp.portal.transport.CentralRole;
-import org.onap.portalapp.portal.transport.CentralUser;
-import org.onap.portalapp.portal.transport.CentralV2Role;
-import org.onap.portalapp.portal.transport.CentralizedAppRoles;
-import org.onap.portalapp.portal.transport.EcompUserRoles;
-import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
-import org.onap.portalapp.portal.transport.GlobalRoleWithApplicationRoleFunction;
-import org.onap.portalapp.portal.transport.LocalRole;
+import org.onap.portalapp.portal.transport.*;
import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
import org.onap.portalapp.portal.utils.EcompPortalUtils;
import org.onap.portalapp.portal.utils.PortalConstants;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(PortalConstants.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPUserUtils.class);
+ PowerMockito.mockStatic(Restrictions.class);
+ PowerMockito.mockStatic(Criterion.class);
Mockito.when(sessionFactory.openSession()).thenReturn(session);
Mockito.when(session.beginTransaction()).thenReturn(transaction);
}
app.setName("Test");
app.setImageUrl("test");
app.setNameSpace("com.test.app");
- app.setCentralAuth(true);
- app.setDescription("test");
- app.setNotes("test");
- app.setUrl("test");
+ app.setRolesInAAF(true);
+ app.setAppDescription("test");
+ app.setAppNotes("test");
+ app.setLandingPage("test");
app.setId((long) 10);
app.setAppRestEndpoint("test");
- app.setAlternateUrl("test");
+ app.setAlternateLandingPage("test");
app.setName("test");
app.setMlAppName("test");
app.setMlAppAdminId("test");
- app.setUsername("test");
- app.setAppPassword("test");
+ app.setAppBasicAuthUsername("test");
+ app.setAppBasicAuthPassword("test");
app.setOpen(false);
app.setEnabled(true);
app.setUebKey("test");
app.setUebSecret("test");
app.setUebTopicName("test");
- app.setAppType(1);
+ app.setAppType(EpAppType.GUI);
return app;
}
@Test
public void addRoleTest() throws Exception {
HttpHeaders headers = new HttpHeaders();
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
String uebKey = "test-ueb-key";
Role role = new Role();
role.setId((long) 25);
@Test
public void addRoleMethodNotAllowedTest() throws Exception {
HttpHeaders headers = new HttpHeaders();
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
Role role = new Role();
role.setId((long) 25);
EPApp app = mockApp();
EPApp app = new EPApp();
app.setName("Test");
app.setImageUrl("test");
- app.setDescription("test");
- app.setNotes("test");
- app.setUrl("test");
+ app.setAppDescription("test");
+ app.setAppNotes("test");
+ app.setLandingPage("test");
app.setId((long) 1);
app.setAppRestEndpoint("test");
- app.setAlternateUrl("test");
+ app.setAlternateLandingPage("test");
app.setName("test");
app.setMlAppName("test");
app.setMlAppAdminId("test");
- app.setUsername("test");
- app.setAppPassword("test");
+ app.setAppBasicAuthUsername("test");
+ app.setAppBasicAuthPassword("test");
app.setOpen(true);
app.setEnabled(false);
app.setUebKey("test");
app.setUebSecret("test");
app.setUebTopicName("test");
- app.setAppType(1);
+ app.setAppType(EpAppType.GUI);
return app;
}
@Test
public void deleteCentralRoleFunctionTest() throws Exception {
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
final Map<String, String> params = new HashMap<>();
EPApp app = mockApp();
params.put("functionCode", "menu_fun_code");
@Test
public void getRoleFunctionTest() throws Exception {
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
List<EPApp> appList = new ArrayList<>();
appList.add(app);
@Test
public void getRoleFunctionMutilpleFilterTest() throws Exception {
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
List<EPApp> appList = new ArrayList<>();
appList.add(app);
Mockito.when(EcompPortalUtils.getFunctionCode("test_type_1|type_code_1|*")).thenReturn("type_code_1");
Mockito.when(EcompPortalUtils.getFunctionType("test_type|type_code|*")).thenReturn("test_type");
Mockito.when(EcompPortalUtils.getFunctionAction("test_type|type_code|*")).thenReturn("*");
+ Mockito.when(EcompPortalUtils.encodeFunctionCode("type_code")).thenReturn("type_code");
List<CentralV2RoleFunction> getRoleFuncList = new ArrayList<>();
CentralV2RoleFunction getCenRole = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
CentralV2RoleFunction getCenRole2 = new CentralV2RoleFunction("test_type_1|type_code_1|*", "test_name_1");
@SuppressWarnings("deprecation")
@Test
public void getAllAppUsersTest() throws Exception {
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(EPUserUtils.class);
EPApp app = new EPApp();
app.setEnabled(true);
app.setId((long) 10);
globalRoles.add(globalRole);
Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
List<CentralV2Role> expected = new ArrayList<>();
- CentralV2Role cenV2Role = new CentralV2Role();
- CentralV2Role cenV2Role2 = new CentralV2Role();
+ CentralV2Role cenV2Role = new CentralV2Role.CentralV2RoleBuilder().createCentralV2Role();
+ CentralV2Role cenV2Role2 = new CentralV2Role.CentralV2RoleBuilder().createCentralV2Role();
expected.add(cenV2Role);
expected.add(cenV2Role2);
List<CentralV2Role> actual = externalAccessRolesServiceImpl.getRolesForApp(app.getUebKey());
@Test
public void saveRoleForPortalApplicationNewTest() throws Exception {
- PowerMockito.mockStatic(EcompPortalUtils.class);
EPApp app = mockApp();
app.setId(1l);
Role addRoleTest = new Role();
@Test
public void saveRoleForPortalApplicationUpdateTest() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
app.setId(1l);
Role addRoleTest = new Role();
@Test
public void saveRoleExitsInDbButNotInExtAuthSystemTest() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
app.setId(1l);
Role addRoleTest = new Role();
@Test
public void saveGlobalRoleForPortalApplicationUpdateTest() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
app.setId(1l);
Role addRoleTest = new Role();
@Test
public void saveRoleForPartnerApplicationUpdateTest() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
app.setId(2l);
Role addRoleTest = new Role();
@Test
public void saveGlobalRoleFunctionsForPartnerApplicationUpdateTest() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
app.setId(2l);
Role addRoleTest = new Role();
@Test
public void syncRoleFunctionFromExternalAccessSystemTest() {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
app.setId(2l);
JSONObject mockJsonObjectFinalPerm = new JSONObject();
@Test
public void syncApplicationRolesWithEcompDBTest() {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
app.setId(2l);
JSONObject mockJsonObjectRole = new JSONObject();
mockJsonObjectRole.put("name", "com.test.app.Test");
mockJsonObjectRole.put("perms", permsList);
mockJsonObjectRole.put("description",
- "{\"id\":\"2\",\"name\":\"test1\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"2\",\"appRoleId\":\"2\"}");
- mockJsonObjectRole2.put("name", "com.test.app.Test2");
+ "Test role");
+ mockJsonObjectRole2.put("name", "com.test.app.Test2_role");
List<JSONObject> permsList2 = new ArrayList<>();
permsList2.add(mockJsonObjectPerm1);
mockJsonObjectRole2.put("perms", permsList2);
Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
List<EPRole> getCurrentRoleList = new ArrayList<>();
EPRole getEPRole = new EPRole();
- getEPRole.setName("Test");
+ getEPRole.setName("Test role");
getEPRole.setId(2l);
getEPRole.setAppId(app.getId());
getEPRole.setAppRoleId(2l);
getEPRole.setActive(true);
EPRole getEPRole2 = new EPRole();
- getEPRole2.setName("Test3");
+ getEPRole2.setName("Test2_role");
getEPRole2.setId(3l);
- getEPRole.setAppId(app.getId());
- getEPRole.setAppRoleId(3l);
+ getEPRole2.setAppId(app.getId());
+ getEPRole2.setAppRoleId(3l);
getEPRole2.setActive(true);
+ EPRole getEPRole3 = new EPRole();
+ getEPRole3.setName("Test3_role");
+ getEPRole3.setId(3l);
+ getEPRole3.setAppId(app.getId());
+ getEPRole3.setAppRoleId(3l);
+ getEPRole3.setActive(true);
getCurrentRoleList.add(getEPRole);
getCurrentRoleList.add(getEPRole2);
+ getCurrentRoleList.add(getEPRole3);
final Map<String, Long> appParams = new HashMap<>();
appParams.put("appId", app.getId());
Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
getV2RoleFunction.add(centralV2RoleFunction);
final Map<String, String> extRoleParams = new HashMap<>();
List<EPRole> roleListDeactivate = new ArrayList<>();
- extRoleParams.put(APP_ROLE_NAME_PARAM, "Test3");
+ extRoleParams.put(APP_ROLE_NAME_PARAM, "Test3_role");
extRoleParams.put(APP_ID, app.getId().toString());
EPRole getEPRoleDeactivate = new EPRole();
- getEPRoleDeactivate.setName("Test3");
+ getEPRoleDeactivate.setName("Test3_role");
getEPRoleDeactivate.setId(3l);
getEPRoleDeactivate.setAppId(app.getId());
getEPRoleDeactivate.setAppRoleId(3l);
@Test
public void deleteDependencyRoleRecord() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
EPApp app = mockApp();
app.setId(2l);
@Test
public void deleteDependencyRoleRecordForPortal() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
EPApp app = mockApp();
app.setId(1l);
@Test
public void bulkUploadFunctionsTest() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
app.setId(2l);
List<EPApp> appList = new ArrayList<>();
@Test
public void bulkUploadRolesTest() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
app.setId(2l);
List<EPApp> appList = new ArrayList<>();
@Test
public void bulkUploadUserRolesTest() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
app.setId(2l);
EPUser user = mockUser.mockEPUser();
@SuppressWarnings("unchecked")
@Test
public void getActiveRolesTest() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
- PowerMockito.mockStatic(EPUserUtils.class);
- PowerMockito.mockStatic(Restrictions.class);
- PowerMockito.mockStatic(Criterion.class);
EPApp app = mockApp();
app.setId(1l);
List<EPApp> appList = new ArrayList<>();
@Test
public void bulkUploadRolesFunctionsTest() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
List<EPApp> appList = new ArrayList<>();
final Map<String, String> appUebkeyParams = new HashMap<>();
@Test
public void bulkUploadPartnerRoleFunctionsTest() throws Exception {
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(SystemProperties.class);
EPApp app = mockApp();
List<EPApp> appList = new ArrayList<>();
final Map<String, String> appUebkeyParams = new HashMap<>();
@Test
public void convertV2CentralRoleListToOldVerisonCentralRoleListTest() {
List<CentralV2Role> v2CenRoleList = new ArrayList<>();
- CentralV2Role cenV2Role = new CentralV2Role(2l, "test1");
+ CentralV2Role cenV2Role = new CentralV2Role.CentralV2RoleBuilder().setId(2l).setName("test1").createCentralV2Role();
CentralV2RoleFunction CentralV2Role = new CentralV2RoleFunction("testcode", "test_name");
SortedSet<CentralV2RoleFunction> setV2RoleFuncs = new TreeSet<>();
setV2RoleFuncs.add(CentralV2Role);
@Test
public void bulkUploadRoleFuncTest() throws Exception {
- PowerMockito.mockStatic(EcompPortalUtils.class);
EPApp app = mockApp();
UploadRoleFunctionExtSystem data = new UploadRoleFunctionExtSystem();
data.setRoleName("test");
@Test
public void bulkUploadGlobalRoleFuncTest() throws Exception {
- PowerMockito.mockStatic(EcompPortalUtils.class);
EPApp app = mockApp();
EPApp portalApp = mockApp();
portalApp.setId(1L);
@Test(expected = HttpClientErrorException.class)
public void bulkUploadRoleFuncExcpetionTest() throws Exception {
- PowerMockito.mockStatic(EcompPortalUtils.class);
UploadRoleFunctionExtSystem data = new UploadRoleFunctionExtSystem();
data.setRoleName("test");
data.setType("test");
@Test
public void syncApplicationUserRolesFromExtAuthSystemTest() throws Exception {
- PowerMockito.mockStatic(EcompPortalUtils.class);
- PowerMockito.mockStatic(EPCommonSystemProperties.class);
- PowerMockito.mockStatic(PortalConstants.class);
- PowerMockito.mockStatic(SystemProperties.class);
Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(new HttpHeaders());
Mockito.when(EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN)).thenReturn(true);
JSONObject mockJsonObjectRole = new JSONObject();
externalAccessRolesServiceImpl.syncApplicationUserRolesFromExtAuthSystem(user.getOrgUserId());
}
+ @Test
+ public void updateAppRoleDescriptionTest() {
+ EPApp app = mockUpdateAppRoleDescription();
+ ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
+ Integer actual = externalAccessRolesServiceImpl.updateAppRoleDescription(app.getUebKey());
+ Integer expected = 1;
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void updateAppRoleDescriptionExceptionTest() {
+ EPApp app = mockUpdateAppRoleDescription();
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenThrow(new HttpClientErrorException(HttpStatus.NOT_ACCEPTABLE));
+ Integer actual = externalAccessRolesServiceImpl.updateAppRoleDescription(app.getUebKey());
+ Integer expected = 0;
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void updateAppRoleDescriptionExceptionTest2() throws Exception {
+ EPApp app = mockUpdateAppRoleDescription();
+ Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenThrow(new NullPointerException());
+ Integer actual = externalAccessRolesServiceImpl.updateAppRoleDescription(app.getUebKey());
+ Integer expected = 0;
+ assertEquals(expected, actual);
+ }
+
+ private EPApp mockUpdateAppRoleDescription() {
+ EPApp app = mockApp();
+ app.setId(2l);
+ List<EPApp> appList = new ArrayList<>();
+ final Map<String, String> appUebkeyParams = new HashMap<>();
+ appList.add(app);
+ appUebkeyParams.put("appKey", app.getUebKey());
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
+ List<EPRole> epRoleList = new ArrayList<>();
+ EPRole getEPRole = new EPRole();
+ getEPRole.setName("Test");
+ getEPRole.setId(2l);
+ getEPRole.setAppRoleId(2l);
+ getEPRole.setActive(true);
+ epRoleList.add(getEPRole);
+ final Map<String, Long> appParams = new HashMap<>();
+ appParams.put("appId", app.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
+ .thenReturn(epRoleList);
+ return app;
+ }
+
}