diff options
Diffstat (limited to 'ecomp-portal-BE-common/src/test')
8 files changed, 101 insertions, 63 deletions
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/music/conf/MusicSessionRepositoryHandlerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/music/conf/MusicSessionRepositoryHandlerTest.java index 3b622f2e..2b0c9fd8 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/music/conf/MusicSessionRepositoryHandlerTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/music/conf/MusicSessionRepositoryHandlerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal * =================================================================== - * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -87,6 +87,7 @@ public class MusicSessionRepositoryHandlerTest { @Test public void getTest() throws Exception { Mockito.when(MusicCore.get(Matchers.any(PreparedQueryObject.class))).thenReturn(resultSet); + Mockito.when(musicService.modEventualGet(Matchers.any(PreparedQueryObject.class))).thenReturn(resultSet); Mockito.when(musicService.getMetaAttribute("test_id")).thenReturn(ms); Session session = musicSessionRepositoryHandler.get("test_id"); assertNotNull(session); @@ -96,7 +97,8 @@ public class MusicSessionRepositoryHandlerTest { @Test public void getFailWithIdTest() throws Exception { Mockito.when(MusicCore.get(Matchers.any(PreparedQueryObject.class))).thenReturn(resultSet); - Mockito.when((musicService).getMetaAttribute("test_id")).thenThrow(new NullPointerException()); + Mockito.when(musicService.modEventualGet(Matchers.any(PreparedQueryObject.class))).thenReturn(resultSet); + Mockito.when(musicService.getMetaAttribute("test_id")).thenThrow(new NullPointerException()); Session session = musicSessionRepositoryHandler.get("test_id"); assertNull(session); } diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java index 79c85672..bee5d932 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java @@ -38,9 +38,11 @@ package org.onap.portalapp.portal.controller; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; @@ -55,8 +57,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.portalapp.portal.controller.FunctionalMenuController; import org.onap.portalapp.portal.core.MockEPUser; import org.onap.portalapp.portal.domain.EPUser; import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; @@ -72,12 +72,14 @@ import org.onap.portalapp.portal.transport.BusinessCardApplicationRolesList; import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItem; import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson; import org.onap.portalapp.portal.transport.FieldsValidator; +import org.onap.portalapp.portal.transport.FieldsValidator.FieldName; import org.onap.portalapp.portal.transport.FunctionalMenuItem; import org.onap.portalapp.portal.transport.FunctionalMenuItemWithRoles; -import org.onap.portalapp.portal.transport.FieldsValidator.FieldName; import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.domain.User; import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.UserUtils; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -166,14 +168,36 @@ public class FunctionalMenuControllerTest extends MockitoTestSuite { appRolesActual = mockBusinessCardApplicationRolesList(); Mockito.when(functionalMenuService.getUserAppRolesList(userid)).thenReturn(userAppRoleList); - - appRoles = functionalMenuController.getAppList(mockedRequest, userid); + User user = new User(); + user.setOrgUserId(userid); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + + appRoles = functionalMenuController.getAppList(mockedRequest, mockedResponse, userid); assertEquals(appRolesActual.size(), appRoles.size()); assertEquals(appRolesActual.get(0).getAppName(), appRoles.get(0).getAppName()); assertEquals(appRolesActual.get(0).getRoleNames(), appRoles.get(0).getRoleNames()); } + + @Test + public void getAppListTestForOtherUser() throws IOException { + + userAppRoleList = mockBusinessCardApplicationRole(); + appRolesActual = mockBusinessCardApplicationRolesList(); + + Mockito.when(functionalMenuService.getUserAppRolesList(userid)).thenReturn(userAppRoleList); + User user = new User(); + user.setOrgUserId(userid + "other"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(mockedResponse.getWriter()).thenReturn(new PrintWriter(System.out)); + + appRoles = functionalMenuController.getAppList(mockedRequest, mockedResponse, userid); + assertNull(appRoles); + assertEquals(0, mockedResponse.getStatus()); + + + } @Test public void editFunctionalMenuItemXSSTest(){ @@ -209,7 +233,10 @@ public class FunctionalMenuControllerTest extends MockitoTestSuite { businessCardApplicationRolesList.setRoleNames(roleNames1); appRolesActual.add(businessCardApplicationRolesList); Mockito.when(functionalMenuService.getUserAppRolesList(userid)).thenReturn(userAppRoleList); - appRoles = functionalMenuController.getAppList(mockedRequest, userid); + User user = new User(); + user.setOrgUserId(userid); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + appRoles = functionalMenuController.getAppList(mockedRequest, mockedResponse, userid); assertEquals(appRolesActual.size(), appRoles.size()); assertEquals(appRolesActual.get(0).getAppName(), appRoles.get(0).getAppName()); assertEquals(appRolesActual.get(0).getRoleNames(), appRoles.get(0).getRoleNames()); diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppControllerTest.java index caf3ac42..1e76ae19 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppControllerTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppControllerTest.java @@ -77,7 +77,12 @@ public class WebAnalyticsExtAppControllerTest { @InjectMocks - WebAnalyticsExtAppController webAnalyticsExtAppController = new WebAnalyticsExtAppController(); + WebAnalyticsExtAppController webAnalyticsExtAppController = new WebAnalyticsExtAppController() { + + protected void storeAuxAnalytics(Analytics analyticsMap, String appName) { + storeAnalyticsCalled = true; + } + }; @Mock AdminRolesService adminRolesService = new AdminRolesServiceImpl(); @@ -90,6 +95,8 @@ public class WebAnalyticsExtAppControllerTest { @Mock Analytics analytics; + Boolean storeAnalyticsCalled = false; + // @Mock // InputStream analyticsFileStream; @@ -167,8 +174,34 @@ public class WebAnalyticsExtAppControllerTest { public void testGetAnalyticsScript() { PowerMockito.mockStatic(SystemProperties.class); Mockito.when(SystemProperties.getProperty("frontend_url")).thenReturn("http://www.ecomp.com/test"); - webAnalyticsExtAppController.getAnalyticsScript(mockedRequest); + webAnalyticsExtAppController.getAnalyticsScript(mockedRequest); } + + @Test + public void storeAnalyticsAuxScriptIfAnalyticsCallTest() throws Exception + { + Analytics analytics= null; + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(null); + Mockito.when(SystemProperties.containsProperty(WebAnalyticsExtAppController.FEED_ML)).thenReturn(true); + Mockito.when(SystemProperties.getProperty(WebAnalyticsExtAppController.FEED_ML)).thenReturn("true"); + webAnalyticsExtAppController.storeAnalyticsScript(mockedRequest, analytics); + assertTrue(storeAnalyticsCalled); + + } + + @Test + public void storeAnalyticsAuxScriptIfAnalyticsNoCallTest() throws Exception + { + Analytics analytics= null; + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(null); + Mockito.when(SystemProperties.containsProperty(WebAnalyticsExtAppController.FEED_ML)).thenReturn(false); + Mockito.when(SystemProperties.getProperty(WebAnalyticsExtAppController.FEED_ML)).thenReturn("true"); + webAnalyticsExtAppController.storeAnalyticsScript(mockedRequest, analytics); + assertTrue(!storeAnalyticsCalled); + + } } diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetMSControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetMSControllerTest.java index ed75f273..2f91eae3 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetMSControllerTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetMSControllerTest.java @@ -51,17 +51,14 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.onap.portalapp.portal.controller.WidgetMSController; import org.onap.portalapp.portal.domain.BEProperty; import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.onap.portalapp.portal.exceptions.NoHealthyServiceException; import org.onap.portalapp.portal.framework.MockitoTestSuite; import org.onap.portalapp.portal.service.WidgetMService; import org.onap.portalapp.portal.service.WidgetMServiceImpl; -import com.orbitz.consul.ConsulException; -import com.orbitz.consul.model.health.ServiceHealth; - import io.searchbox.client.config.exception.NoServerConfiguredException; public class WidgetMSControllerTest { @@ -86,7 +83,7 @@ public class WidgetMSControllerTest { HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); NullPointerException nullPointerException = new NullPointerException(); - ConsulException consulException = new ConsulException(nullPointerException); + NoHealthyServiceException exception = new NoHealthyServiceException(""); @Test public void getServiceLocationTest() { @@ -101,29 +98,29 @@ public class WidgetMSControllerTest { @Test - public void getServiceLocationExceptionConsulExceptionTest() { + public void getServiceLocationExceptionConsulExceptionTest() throws Exception { PortalRestResponse<BEProperty> ecpectedPortalRestResponse = new PortalRestResponse<BEProperty>(); ecpectedPortalRestResponse.setMessage("Error!"); ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); PortalRestResponse<String> actualPortalRestRespone = new PortalRestResponse<String>(); - Mockito.when(consulHealthService.getServiceLocation(service, null)).thenThrow(consulException); + Mockito.when(consulHealthService.getServiceLocation(service, null)).thenThrow(exception); actualPortalRestRespone = consulClientController.getServiceLocation(mockedRequest, mockedResponse, service); assertTrue(actualPortalRestRespone.getMessage().equals(ecpectedPortalRestResponse.getMessage())); assertTrue(actualPortalRestRespone.getStatus().equals(ecpectedPortalRestResponse.getStatus())); } - public PortalRestResponse<List<ServiceHealth>> successResponse() { - PortalRestResponse<List<ServiceHealth>> ecpectedPortalRestResponse = new PortalRestResponse<List<ServiceHealth>>(); - List<ServiceHealth> healths = new ArrayList<ServiceHealth>(); + public PortalRestResponse<List<?>> successResponse() { + PortalRestResponse<List<?>> ecpectedPortalRestResponse = new PortalRestResponse<List<?>>(); + List<?> healths = new ArrayList<>(); ecpectedPortalRestResponse.setMessage("Success!"); ecpectedPortalRestResponse.setResponse(healths); ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); return ecpectedPortalRestResponse; } - public PortalRestResponse<List<ServiceHealth>> errorResponse() { - PortalRestResponse<List<ServiceHealth>> ecpectedPortalRestResponse = new PortalRestResponse<List<ServiceHealth>>(); - List<ServiceHealth> healths = new ArrayList<ServiceHealth>(); + public PortalRestResponse<List<?>> errorResponse() { + PortalRestResponse<List<?>> ecpectedPortalRestResponse = new PortalRestResponse<List<?>>(); + List<?> healths = new ArrayList<>(); ecpectedPortalRestResponse.setMessage("Error!"); ecpectedPortalRestResponse.setResponse(healths); ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogControllerTest.java index 502f0aa1..675e4f4c 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogControllerTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogControllerTest.java @@ -54,7 +54,6 @@ import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.onap.portalapp.portal.controller.WidgetsCatalogController; import org.onap.portalapp.portal.core.MockEPUser; import org.onap.portalapp.portal.domain.EPUser; import org.onap.portalapp.portal.domain.MicroserviceParameter; @@ -65,16 +64,15 @@ import org.onap.portalapp.portal.domain.WidgetServiceHeaders; import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; import org.onap.portalapp.portal.framework.MockitoTestSuite; -import org.onap.portalapp.portal.service.WidgetMService; -import org.onap.portalapp.portal.service.WidgetMServiceImpl; import org.onap.portalapp.portal.service.MicroserviceService; import org.onap.portalapp.portal.service.MicroserviceServiceImpl; +import org.onap.portalapp.portal.service.WidgetMService; +import org.onap.portalapp.portal.service.WidgetMServiceImpl; import org.onap.portalapp.portal.service.WidgetParameterService; import org.onap.portalapp.portal.service.WidgetParameterServiceImpl; import org.onap.portalapp.portal.utils.EPCommonSystemProperties; import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.onap.portalapp.util.EPUserUtils; -import org.onap.portalsdk.core.onboarding.exception.CipherUtilException; import org.onap.portalsdk.core.onboarding.util.CipherUtil; import org.onap.portalsdk.core.util.SystemProperties; import org.powermock.api.mockito.PowerMockito; @@ -178,7 +176,7 @@ public class WidgetsCatalogControllerTest { } @Test - public void getWidgetCatalogTest() throws CipherUtilException { + public void getWidgetCatalogTest() throws Exception { PowerMockito.mockStatic(EcompPortalUtils.class); PowerMockito.mockStatic(SystemProperties.class); PowerMockito.mockStatic(EPCommonSystemProperties.class); diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java index 785522d4..736f8341 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java @@ -95,6 +95,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; @@ -142,6 +143,9 @@ public class UserRolesCommonServiceImplTest { @Mock Transaction transaction; + + @Mock + AdminRolesService adminRolesService; @InjectMocks UserRolesCommonServiceImpl userRolesCommonServiceImpl = new UserRolesCommonServiceImpl(); @@ -356,11 +360,11 @@ public class UserRolesCommonServiceImplTest { 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(); @@ -666,7 +670,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) { @@ -1245,7 +1249,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()); diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/WidgetMServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/WidgetMServiceImplTest.java index 2ed86bfe..9da834e4 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/WidgetMServiceImplTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/WidgetMServiceImplTest.java @@ -37,54 +37,28 @@ */ package org.onap.portalapp.portal.service; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.*; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import com.orbitz.consul.Consul; -import com.orbitz.consul.HealthClient; -import com.orbitz.consul.model.ConsulResponse; -import com.orbitz.consul.model.health.ServiceHealth; -import com.orbitz.consul.Consul.Builder; -import com.orbitz.consul.model.health.Node; -import com.orbitz.consul.model.health.Service; + @RunWith(PowerMockRunner.class) -@PrepareForTest({ Consul.class ,EcompPortalUtils.class}) +@PrepareForTest({ EcompPortalUtils.class}) public class WidgetMServiceImplTest { private static final String TEST="test"; @InjectMocks WidgetMServiceImpl widgetMServiceImpl; - @Mock - Builder builder; - @Mock - Consul consul ; - @Mock - HealthClient healthClient; - @Mock - ServiceHealth serviceHealth; - @Mock - ConsulResponse<List<ServiceHealth>> response; - @Mock - Node node; - @Mock - Service service; + @Before public void setup() { diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java index 52f30518..dafa527c 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java @@ -60,12 +60,12 @@ public class AppWithRolesForUserTest { @Test public void roleInAppForUserTest(){ AppWithRolesForUser appWithRolesForUser = mockAppWithRolesForUser(); - appWithRolesForUser.setSystemUser(false); + appWithRolesForUser.setIsSystemUser(false); assertEquals(appWithRolesForUser.getOrgUserId(), "test"); assertEquals(appWithRolesForUser.getAppId(), new Long(1)); assertEquals(appWithRolesForUser.getAppName(), "test"); assertEquals(appWithRolesForUser.getAppRoles(), null); - assertEquals(appWithRolesForUser.isSystemUser(), false); + assertEquals(appWithRolesForUser.getIsSystemUser(), false); assertEquals(appWithRolesForUser.toString(), "AppWithRolesForUser(orgUserId=test, isSystemUser=false, appId=1, appName=test, appRoles=null)"); } } |