fixes for supporting non-gui application access provisioning
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / service / UserRolesCommonServiceImplTest.java
index 4d07c79..5846fa9 100644 (file)
@@ -81,19 +81,9 @@ import org.onap.portalapp.portal.domain.EPUserAppCatalogRoles;
 import org.onap.portalapp.portal.domain.EPUserAppRoles;
 import org.onap.portalapp.portal.domain.EPUserAppRolesRequest;
 import org.onap.portalapp.portal.domain.EPUserAppRolesRequestDetail;
+import org.onap.portalapp.portal.domain.EpAppType;
 import org.onap.portalapp.portal.domain.ExternalSystemAccess;
-import org.onap.portalapp.portal.transport.AppWithRolesForUser;
-import org.onap.portalapp.portal.transport.CentralV2Role;
-import org.onap.portalapp.portal.transport.EPUserAppCurrentRoles;
-import org.onap.portalapp.portal.transport.EcompUserAppRoles;
-import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
-import org.onap.portalapp.portal.transport.FieldsValidator;
-import org.onap.portalapp.portal.transport.FunctionalMenuItem;
-import org.onap.portalapp.portal.transport.FunctionalMenuRole;
-import org.onap.portalapp.portal.transport.RemoteRole;
-import org.onap.portalapp.portal.transport.RemoteUserWithRoles;
-import org.onap.portalapp.portal.transport.RoleInAppForUser;
-import org.onap.portalapp.portal.transport.UserApplicationRoles;
+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;
@@ -106,6 +96,7 @@ import org.onap.portalsdk.core.util.SystemProperties;
 import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
@@ -153,6 +144,9 @@ public class UserRolesCommonServiceImplTest {
 
        @Mock
        Transaction transaction;
+       
+       @Mock
+       AdminRolesService adminRolesService;
 
        @InjectMocks
        UserRolesCommonServiceImpl userRolesCommonServiceImpl = new UserRolesCommonServiceImpl();
@@ -175,24 +169,24 @@ public class UserRolesCommonServiceImplTest {
                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(false);
                app.setEnabled(false);
-               app.setCentralAuth(true);
+               app.setRolesInAAF(true);
                app.setUebKey("test");
                app.setUebSecret("test");
                app.setUebTopicName("test");
-               app.setAppType(1);
+               app.setAppType(EpAppType.GUI);
                return app;
        }
 
@@ -204,10 +198,14 @@ public class UserRolesCommonServiceImplTest {
                Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
                List<RoleInAppForUser> mockRoleInAppForUserList = getMockedRoleInAppUserList();
                List<CentralV2Role> mockCenV2Role = new ArrayList<>();
-               CentralV2Role cenV2Role = new CentralV2Role(1l, null, null, null, null, null, "test1", true, null,
-                               new TreeSet<>(), new TreeSet<>(), new TreeSet<>());
-               CentralV2Role cenV2Role2 = new CentralV2Role(16l, null, null, null, null, null, "test2", true, null,
-                               new TreeSet<>(), new TreeSet<>(), new TreeSet<>());
+        CentralV2Role cenV2Role = new CentralV2Role.CentralV2RoleBuilder().setId(1l).setCreated(null).setModified(null)
+                .setCreatedId(null).setModifiedId(null).setRowNum(null).setName("test1").setActive(true)
+                .setPriority(null).setRoleFunctions(new TreeSet<>()).setChildRoles(new TreeSet<>())
+                .setParentRoles(new TreeSet<>()).createCentralV2Role();
+        CentralV2Role cenV2Role2 = new CentralV2Role.CentralV2RoleBuilder().setId(16l).setCreated(null)
+                .setModified(null).setCreatedId(null).setModifiedId(null).setRowNum(null).setName("test2")
+                .setActive(true).setPriority(null).setRoleFunctions(new TreeSet<>()).setChildRoles(new TreeSet<>())
+                .setParentRoles(new TreeSet<>()).createCentralV2Role();
                mockCenV2Role.add(cenV2Role);
                mockCenV2Role.add(cenV2Role2);
                Mockito.when(externalAccessRolesServiceImpl.getRolesForApp(mockApp.getUebKey())).thenReturn(mockCenV2Role);
@@ -264,7 +262,7 @@ public class UserRolesCommonServiceImplTest {
                EPUser user = mockUser.mockEPUser();
                user.setId(1l);
                EPApp mockApp = mockApp();
-               mockApp.setCentralAuth(false);
+               mockApp.setRolesInAAF(false);
                EPRole mockEPRole = new EPRole();
                mockEPRole.setId(1l);
                mockEPRole.setName("test1");
@@ -359,15 +357,15 @@ public class UserRolesCommonServiceImplTest {
                mockEpUserList.add(user);
                EPApp mockApp = mockApp();
                mockApp.setId(2l);
-               mockApp.setCentralAuth(false);
+               mockApp.setRolesInAAF(false);
                Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
                List<RoleInAppForUser> mockRoleInAppForUserList = new ArrayList<>();
                RoleInAppForUser mockRoleInAppForUser = new RoleInAppForUser();
-               mockRoleInAppForUser.setIsApplied(false);
+           mockRoleInAppForUser.setIsApplied(true);
                mockRoleInAppForUser.setRoleId(333l);
                mockRoleInAppForUser.setRoleName("test1");
                RoleInAppForUser mockRoleInAppForUser2 = new RoleInAppForUser();
-               mockRoleInAppForUser2.setIsApplied(false);
+           mockRoleInAppForUser2.setIsApplied(true);
                mockRoleInAppForUser2.setRoleId(777l);
                mockRoleInAppForUser2.setRoleName("test2");
                RoleInAppForUser mockRoleInAppForUser3 = new RoleInAppForUser();
@@ -527,7 +525,7 @@ public class UserRolesCommonServiceImplTest {
                EPApp mockApp = mockApp();
                mockApp.setNameSpace("com.test.com");
                mockApp.setId(1l);
-               mockApp.setCentralAuth(true);
+               mockApp.setRolesInAAF(true);
                Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
                Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
                AppWithRolesForUser mockWithRolesForUser = new AppWithRolesForUser();
@@ -673,7 +671,7 @@ public class UserRolesCommonServiceImplTest {
                Mockito.when(session.createSQLQuery("update fn_role set app_id = null where app_id = 1 "))
                                .thenReturn(epsetAppWithUserRoleUpdateEPRoleQuery);
                ExternalRequestFieldsValidator actual = userRolesCommonServiceImpl.setAppWithUserRoleStateForUser(user, mockWithRolesForUser);
-               assertFalse(actual.isResult());
+               assertTrue(actual.isResult());
        }
 
        private List<EcompUserAppRoles> getCurrentUserRoles(EPUser user, EPApp mockApp) {
@@ -701,7 +699,7 @@ public class UserRolesCommonServiceImplTest {
                EPApp mockApp = mockApp();
                mockApp.setNameSpace("com.test.com");
                mockApp.setId(2l);
-               mockApp.setCentralAuth(false);
+               mockApp.setRolesInAAF(false);
                Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
                Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
                AppWithRolesForUser mockWithRolesForUser = new AppWithRolesForUser();
@@ -834,7 +832,7 @@ public class UserRolesCommonServiceImplTest {
                EPApp mockApp = mockApp();
                mockApp.setNameSpace("com.test.com");
                mockApp.setId(1l);
-               mockApp.setCentralAuth(true);
+               mockApp.setRolesInAAF(true);
                Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
                ExternalSystemUser externalSystemUser = new ExternalSystemUser();
                List<ExternalSystemRoleApproval> mockExternalSystemRoleApprovalList = new ArrayList<>();
@@ -1002,7 +1000,7 @@ public class UserRolesCommonServiceImplTest {
                EPApp mockApp = mockApp();
                mockApp.setId(2l);
                mockApp.setEnabled(true);
-               mockApp.setCentralAuth(false);
+               mockApp.setRolesInAAF(false);
                ExternalSystemUser externalSystemUser = new ExternalSystemUser();
                List<ExternalSystemRoleApproval> mockExternalSystemRoleApprovalList = new ArrayList<>();
                ExternalSystemRoleApproval mockExternalSystemRoleApproval = new ExternalSystemRoleApproval();
@@ -1190,7 +1188,7 @@ public class UserRolesCommonServiceImplTest {
                EPApp mockApp = mockApp();
                mockApp.setId(1l);
                mockApp.setEnabled(true);
-               mockApp.setCentralAuth(true);
+               mockApp.setRolesInAAF(true);
                EPUser user = mockUser.mockEPUser();
                EPUser user2 = mockUser.mockEPUser();
                user2.setActive(true);
@@ -1252,7 +1250,10 @@ public class UserRolesCommonServiceImplTest {
                mockUserApplicationRoles2.setRoles(mockRemoteRoleList2);
                mockUserApplicationRolesList.add(mockUserApplicationRoles);
                mockUserApplicationRolesList.add(mockUserApplicationRoles2);
-               Mockito.when((List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsers", null, null))
+               Map<String, Object> params = new HashMap<>();
+               params.put("id", 1l);
+               params.put("active", true);
+               Mockito.when((List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsersForApp", params, null))
                                .thenReturn(mockEpUserList);
                assertEquals(userRolesCommonServiceImpl.getUsersFromAppEndpoint(1l).size(),
                                mockUserApplicationRolesList.size());
@@ -1263,7 +1264,7 @@ public class UserRolesCommonServiceImplTest {
                EPApp mockApp = mockApp();
                mockApp.setId(2l);
                mockApp.setEnabled(true);
-               mockApp.setCentralAuth(false);
+               mockApp.setRolesInAAF(false);
                Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
                List<UserApplicationRoles> mockUserApplicationRolesNonCentralizedList = new ArrayList<>();
                UserApplicationRoles mockUserApplicationRoles = new UserApplicationRoles();
@@ -1318,7 +1319,7 @@ public class UserRolesCommonServiceImplTest {
                EPApp mockApp = mockApp();
                mockApp.setId(2l);
                mockApp.setEnabled(true);
-               mockApp.setCentralAuth(false);
+               mockApp.setRolesInAAF(false);
                EPUser user = mockUser.mockEPUser();
                AppWithRolesForUser appWithRolesForUser = new AppWithRolesForUser();
                List<RoleInAppForUser> mockRoleInAppForUserList = new ArrayList<>();
@@ -1371,7 +1372,7 @@ public class UserRolesCommonServiceImplTest {
                EPApp mockApp = mockApp();
                mockApp.setId(2l);
                mockApp.setEnabled(true);
-               mockApp.setCentralAuth(false);
+               mockApp.setRolesInAAF(false);
                List<EPRole> expected = new ArrayList<>();
                EPRole epRole = new EPRole();
                epRole.setAppId(mockApp.getId());
@@ -1400,7 +1401,7 @@ public class UserRolesCommonServiceImplTest {
                EPApp mockApp = mockApp();
                mockApp.setId(2l);
                mockApp.setEnabled(true);
-               mockApp.setCentralAuth(false);
+               mockApp.setRolesInAAF(false);
                EPUser user = mockUser.mockEPUser();
                List<EPUserApp> expected = new ArrayList<>();
                EPUserApp epUserApp = new EPUserApp();
@@ -1426,7 +1427,7 @@ public class UserRolesCommonServiceImplTest {
                EPApp mockApp = mockApp();
                mockApp.setId(2l);
                mockApp.setEnabled(true);
-               mockApp.setCentralAuth(false);
+               mockApp.setRolesInAAF(false);
                EPUser user = mockUser.mockEPUser();
                List<EPUserAppCatalogRoles> expected = new ArrayList<>();
                EPUserAppCatalogRoles epUserAppCatalogRoles = new EPUserAppCatalogRoles();
@@ -1458,7 +1459,7 @@ public class UserRolesCommonServiceImplTest {
                EPApp mockApp = mockApp();
                mockApp.setId(2l);
                mockApp.setEnabled(true);
-               mockApp.setCentralAuth(false);
+               mockApp.setRolesInAAF(false);
                EPUser user = mockUser.mockEPUser();
                List<EPUserApp> expected = new ArrayList<>();
                EPUserApp epUserApp = new EPUserApp();
@@ -1488,7 +1489,7 @@ public class UserRolesCommonServiceImplTest {
                EPApp mockApp2 = mockApp();
                mockApp.setId(2l);
                mockApp.setEnabled(true);
-               mockApp.setCentralAuth(false);
+               mockApp.setRolesInAAF(false);
                EPUser user = mockUser.mockEPUser();
                List<EPApp> mockEpAppList = new ArrayList<>();
                mockEpAppList.add(mockApp);