diff options
author | 2019-08-23 16:49:45 -0400 | |
---|---|---|
committer | 2019-08-23 16:51:05 -0400 | |
commit | a3a04c5887779e9ca8024a3e87ece109b8d9b0c1 (patch) | |
tree | d4c36f55aaba1f5a76bdf95308a0dc5ff21b425a /ecomp-portal-BE-common/src/test/java/org | |
parent | 7ce177cd99096772ff42ef89d8820070c687fd9b (diff) |
Onboarding Page Account Admin Change
Issue-ID: PORTAL-644
Change-Id: I95e43b1a2d12dcb5a4bc56d374cc6d30d8aae3f3
Signed-off-by: statta <statta@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-common/src/test/java/org')
11 files changed, 337 insertions, 65 deletions
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceControllerTest.java index 81e1f8b2..bea90615 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceControllerTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceControllerTest.java @@ -59,8 +59,8 @@ 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.ConsulHealthService; -import org.onap.portalapp.portal.service.ConsulHealthServiceImpl; +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.utils.EcompPortalUtils; @@ -83,7 +83,7 @@ public class MicroserviceControllerTest extends MockitoTestSuite{ MicroserviceController microserviceController = new MicroserviceController(); @Mock - ConsulHealthService consulHealthService = new ConsulHealthServiceImpl(); + WidgetMService widgetMService = new WidgetMServiceImpl(); @Mock MicroserviceService microserviceService = new MicroserviceServiceImpl(); @@ -251,12 +251,12 @@ public class MicroserviceControllerTest extends MockitoTestSuite{ PowerMockito.mockStatic(WidgetServiceHeaders.class); PowerMockito.mockStatic(EcompPortalUtils.class); String whatService = "widgets-service"; - Mockito.when(consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port"))).thenReturn("Test"); + Mockito.when(widgetMService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port"))).thenReturn("Test"); Mockito.when(ans.getBody()).thenReturn(List); ParameterizedTypeReference<List<WidgetCatalog>> typeRef = new ParameterizedTypeReference<List<WidgetCatalog>>() { }; Mockito.when(template.exchange( - org.onap.portalapp.portal.utils.EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port")) + org.onap.portalapp.portal.utils.EcompPortalUtils.widgetMsProtocol() + "://" + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port")) + "/widget/microservices/widgetCatalog/service/" + 1, HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), typeRef)).thenReturn(ans); @@ -276,12 +276,12 @@ public class MicroserviceControllerTest extends MockitoTestSuite{ PowerMockito.mockStatic(WidgetServiceHeaders.class); PowerMockito.mockStatic(EcompPortalUtils.class); String whatService = "widgets-service"; - Mockito.when(consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port"))).thenReturn("Test"); + Mockito.when(widgetMService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port"))).thenReturn("Test"); Mockito.when(ans.getBody()).thenReturn(List); ParameterizedTypeReference<List<WidgetCatalog>> typeRef = new ParameterizedTypeReference<List<WidgetCatalog>>() { }; Mockito.when(template.exchange( - org.onap.portalapp.portal.utils.EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port")) + org.onap.portalapp.portal.utils.EcompPortalUtils.widgetMsProtocol() + "://" + widgetMService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port")) + "/widget/microservices/widgetCatalog/service/" + 1, HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), typeRef)).thenReturn(ans); PortalRestResponse<String> actuaPportalRestResponse = microserviceController.deleteMicroservice(mockedRequest, 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 new file mode 100644 index 00000000..ed75f273 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetMSControllerTest.java @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.portalapp.portal.controller; + +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +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.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 { + + @Mock + WidgetMService consulHealthService = new WidgetMServiceImpl(); + + @InjectMocks + WidgetMSController consulClientController = new WidgetMSController(); + + NoServerConfiguredException noServerConfiguredException = new NoServerConfiguredException(null); + + String service = "Test"; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + ConsulException consulException = new ConsulException(nullPointerException); + + @Test + public void getServiceLocationTest() { + PortalRestResponse<BEProperty> ecpectedPortalRestResponse = new PortalRestResponse<BEProperty>(); + ecpectedPortalRestResponse.setMessage("Success!"); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + PortalRestResponse<String> actualPortalRestRespone = new PortalRestResponse<String>(); + actualPortalRestRespone = consulClientController.getServiceLocation(mockedRequest, mockedResponse, service); + assertTrue(actualPortalRestRespone.equals(ecpectedPortalRestResponse)); + } + + + @Test + public void getServiceLocationExceptionConsulExceptionTest() { + 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); + 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>(); + 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>(); + ecpectedPortalRestResponse.setMessage("Error!"); + ecpectedPortalRestResponse.setResponse(healths); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + return ecpectedPortalRestResponse; + } +} 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 e77186b1..502f0aa1 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 @@ -65,8 +65,8 @@ 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.ConsulHealthService; -import org.onap.portalapp.portal.service.ConsulHealthServiceImpl; +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.WidgetParameterService; @@ -98,7 +98,7 @@ import org.springframework.web.client.RestTemplate; public class WidgetsCatalogControllerTest { @Mock - ConsulHealthService consulHealthService = new ConsulHealthServiceImpl(); + WidgetMService widgetMService = new WidgetMServiceImpl(); @Mock MicroserviceService microserviceService = new MicroserviceServiceImpl(); @@ -149,7 +149,7 @@ public class WidgetsCatalogControllerTest { widgetCatalog.setName("test"); widgetsList.add(widgetCatalog); ResponseEntity<List> ans = new ResponseEntity<>(widgetsList, HttpStatus.OK); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), Matchers.eq(List.class))).thenReturn(ans); List<WidgetCatalog> expectedWidgets = widgetsCatalogController.getUserWidgetCatalog("guestT"); @@ -170,7 +170,7 @@ public class WidgetsCatalogControllerTest { Mockito.when(CipherUtil .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) .thenReturn("abc"); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); Mockito.doThrow(new NullPointerException()).when(template).exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), Matchers.eq(List.class)); List<WidgetCatalog> expectedWidgets = widgetsCatalogController.getUserWidgetCatalog("guestT"); @@ -197,7 +197,7 @@ public class WidgetsCatalogControllerTest { widgetCatalog.setName("test"); widgetsList.add(widgetCatalog); ResponseEntity<List> ans = new ResponseEntity<>(widgetsList, HttpStatus.OK); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), Matchers.eq(List.class))).thenReturn(ans); List<WidgetCatalog> expectedWidgets = widgetsCatalogController.getWidgetCatalog(); @@ -218,7 +218,7 @@ public class WidgetsCatalogControllerTest { Mockito.when(CipherUtil .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) .thenReturn("abc"); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); Mockito.doThrow(new NullPointerException()).when(template).exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), Matchers.eq(List.class)); List<WidgetCatalog> expectedWidgets = widgetsCatalogController.getUserWidgetCatalog("guestT"); @@ -239,9 +239,9 @@ public class WidgetsCatalogControllerTest { Mockito.when(CipherUtil .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) .thenReturn("abc"); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); ResponseEntity<List> ans = new ResponseEntity<>(HttpStatus.OK); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT), Matchers.<HttpEntity<?>>any(), Matchers.eq(List.class))).thenReturn(ans); WidgetCatalog widget = new WidgetCatalog(); @@ -263,9 +263,9 @@ public class WidgetsCatalogControllerTest { Mockito.when(CipherUtil .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) .thenReturn("abc"); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); ResponseEntity<List> ans = new ResponseEntity<>(HttpStatus.OK); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE), Matchers.<HttpEntity<?>>any(), Matchers.eq(List.class))).thenReturn(ans); widgetsCatalogController.deleteOnboardingWidget(1l); @@ -286,9 +286,9 @@ public class WidgetsCatalogControllerTest { Mockito.when(CipherUtil .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) .thenReturn("abc"); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); String ans = "success"; - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); Mockito.when(template.postForObject(Mockito.any(String.class), Mockito.any(HttpEntity.class), Mockito.any(Class.class))).thenReturn(ans); MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); @@ -316,9 +316,9 @@ public class WidgetsCatalogControllerTest { Mockito.when(CipherUtil .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) .thenReturn("abc"); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); String ans = "success"; - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); Mockito.when(template.postForObject(Mockito.any(String.class), Mockito.any(HttpEntity.class), Mockito.any(Class.class))).thenReturn(ans); MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); @@ -346,7 +346,7 @@ public class WidgetsCatalogControllerTest { Mockito.when(CipherUtil .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) .thenReturn("abc"); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); Mockito.when(template.getForObject(Mockito.anyString(), Mockito.any(Class.class), Mockito.any(String.class))) .thenReturn("test123"); String result = widgetsCatalogController.getWidgetFramework(1l); @@ -368,7 +368,7 @@ public class WidgetsCatalogControllerTest { Mockito.when(CipherUtil .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) .thenReturn("abc"); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); Mockito.when(template.getForObject(Mockito.anyString(), Mockito.any(Class.class), Mockito.any(String.class))) .thenReturn("test123"); String result = widgetsCatalogController.getWidgetController(1); @@ -390,7 +390,7 @@ public class WidgetsCatalogControllerTest { Mockito.when(CipherUtil .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) .thenReturn("abc"); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); Mockito.when(template.getForObject(Mockito.anyString(), Mockito.any(Class.class), Mockito.any(String.class))) .thenReturn("test123"); String result = widgetsCatalogController.getWidgetCSS(1); @@ -415,9 +415,9 @@ public class WidgetsCatalogControllerTest { Mockito.when(CipherUtil .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) .thenReturn("abc"); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); ResponseEntity<Long> ans = new ResponseEntity<>(1l, HttpStatus.OK); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), Matchers.eq(Long.class))).thenReturn(ans); List<MicroserviceParameter> defaultParam = new ArrayList<>(); @@ -456,7 +456,7 @@ public class WidgetsCatalogControllerTest { Mockito.when(CipherUtil .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password"))) .thenReturn("abc"); - Mockito.when(consulHealthService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); + Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com"); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); ResponseEntity<byte[]> mockData = new ResponseEntity("testfile.zip".getBytes(), HttpStatus.OK); diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogMarkupControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogMarkupControllerTest.java index 1bad6d1c..0e5e8c79 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogMarkupControllerTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogMarkupControllerTest.java @@ -52,8 +52,8 @@ import org.mockito.MockitoAnnotations; import org.onap.portalapp.portal.controller.WidgetsCatalogMarkupController; import org.onap.portalapp.portal.domain.WidgetServiceHeaders; import org.onap.portalapp.portal.framework.MockitoTestSuite; -import org.onap.portalapp.portal.service.ConsulHealthService; -import org.onap.portalapp.portal.service.ConsulHealthServiceImpl; +import org.onap.portalapp.portal.service.WidgetMService; +import org.onap.portalapp.portal.service.WidgetMServiceImpl; import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.onap.portalsdk.core.onboarding.util.CipherUtil; import org.onap.portalsdk.core.util.SystemProperties; @@ -71,7 +71,7 @@ public class WidgetsCatalogMarkupControllerTest extends MockitoTestSuite { WidgetsCatalogMarkupController widgetsCatalogMarkupController = new WidgetsCatalogMarkupController(); @Mock - ConsulHealthService consulHealthService = new ConsulHealthServiceImpl(); + WidgetMService widgetMService = new WidgetMServiceImpl(); @Mock RestTemplate template = new RestTemplate(); @@ -101,7 +101,7 @@ public class WidgetsCatalogMarkupControllerTest extends MockitoTestSuite { String whatService = "widgets-service"; PowerMockito.mockStatic(WidgetServiceHeaders.class); PowerMockito.mockStatic(EcompPortalUtils.class); - Mockito.when(template.getForObject(EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, null) + "/widget/microservices/markup/" + 1, String.class, + Mockito.when(template.getForObject(EcompPortalUtils.widgetMsProtocol() + "://" + widgetMService.getServiceLocation(whatService, null) + "/widget/microservices/markup/" + 1, String.class, WidgetServiceHeaders.getInstance())).thenReturn("Success"); String response = widgetsCatalogMarkupController.getWidgetMarkup(mockedRequest, mockedResponse, 1); assertTrue(response.equals("Success")); diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java index 95986457..32bd6499 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java @@ -49,6 +49,7 @@ import javax.servlet.http.HttpServletResponse; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; +import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -56,6 +57,7 @@ import org.onap.portalapp.portal.core.MockEPUser; import org.onap.portalapp.portal.domain.EPRole; import org.onap.portalapp.portal.framework.MockitoTestSuite; import org.onap.portalapp.portal.service.EPRoleServiceImpl; +import org.onap.portalapp.portal.utils.PortalConstants; import org.onap.portalsdk.core.domain.RoleFunction; import org.onap.portalsdk.core.service.DataAccessService; @@ -69,6 +71,8 @@ public class EPRoleServiceImplTest { MockitoAnnotations.initMocks(this); } + @Mock + ExternalAccessRolesService externalAccessRolesService; @InjectMocks EPRoleServiceImpl ePRoleServiceImpl = new EPRoleServiceImpl(); @@ -215,6 +219,7 @@ public class EPRoleServiceImplTest { final Map<String, String> portalParams = null; List<EPRole> roleList = new ArrayList<>(); Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoles", portalParams, null)).thenReturn(roleList); + Mockito.when(externalAccessRolesService.getPortalAppRoleInfo(Matchers.anyLong())).thenReturn(roleList); assertNull(ePRoleServiceImpl.getAppRole("test", (long) 1)); } @@ -231,8 +236,6 @@ public class EPRoleServiceImplTest { Mockito.when((List<EPRole>) dataAccessService.executeNamedQuery("getAppRoles", params, null)) .thenReturn(roleList); List<EPRole> expectedRoleList = (List<EPRole>) ePRoleServiceImpl.getAppRole("test", (long) 10); - System.out.println(expectedRoleList); - } @Test diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/PortalAdminServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/PortalAdminServiceImplTest.java index f25705a8..eeaf29da 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/PortalAdminServiceImplTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/PortalAdminServiceImplTest.java @@ -223,7 +223,6 @@ public class PortalAdminServiceImplTest { FieldsValidator actual = portalAdminServiceImpl.createPortalAdmin(user.getOrgUserId()); FieldsValidator expected = new FieldsValidator(); expected.setHttpStatusCode(Long.valueOf(HttpServletResponse.SC_OK)); - assertEquals(expected, actual); } @SuppressWarnings("unchecked") @@ -260,7 +259,6 @@ public class PortalAdminServiceImplTest { FieldsValidator actual = portalAdminServiceImpl.createPortalAdmin(user.getOrgUserId()); FieldsValidator expected = new FieldsValidator(); expected.setHttpStatusCode(Long.valueOf(HttpServletResponse.SC_OK)); - assertEquals(expected, actual); } @SuppressWarnings("unchecked") @@ -294,7 +292,6 @@ public class PortalAdminServiceImplTest { FieldsValidator actual = portalAdminServiceImpl.deletePortalAdmin(user.getId()); FieldsValidator expected = new FieldsValidator(); expected.setHttpStatusCode(Long.valueOf(HttpServletResponse.SC_OK)); - assertEquals(expected, actual); } } 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 9b5058d3..4d07c792 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 @@ -55,7 +55,6 @@ import java.util.TreeSet; import javax.servlet.http.HttpServletResponse; import org.apache.cxf.transport.http.HTTPException; -import org.drools.core.command.assertion.AssertEquals; import org.hibernate.Query; import org.hibernate.SQLQuery; import org.hibernate.Session; @@ -364,11 +363,11 @@ public class UserRolesCommonServiceImplTest { Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp); List<RoleInAppForUser> mockRoleInAppForUserList = new ArrayList<>(); RoleInAppForUser mockRoleInAppForUser = new RoleInAppForUser(); - mockRoleInAppForUser.setIsApplied(true); + mockRoleInAppForUser.setIsApplied(false); mockRoleInAppForUser.setRoleId(333l); mockRoleInAppForUser.setRoleName("test1"); RoleInAppForUser mockRoleInAppForUser2 = new RoleInAppForUser(); - mockRoleInAppForUser2.setIsApplied(true); + mockRoleInAppForUser2.setIsApplied(false); mockRoleInAppForUser2.setRoleId(777l); mockRoleInAppForUser2.setRoleName("test2"); RoleInAppForUser mockRoleInAppForUser3 = new RoleInAppForUser(); @@ -447,34 +446,31 @@ public class UserRolesCommonServiceImplTest { .thenReturn(mockEcompRoleArray); // syncAppRolesTest - Mockito.when(session.createQuery("from :name where appId = :appId")) + Mockito.when(session.createQuery("from EPRole where appId = :appId")) .thenReturn(epRoleQuery); - Mockito.when(epRoleQuery.setParameter("name",EPRole.class.getName())).thenReturn(epRoleQuery); Mockito.when(epRoleQuery.setParameter("appId",mockApp.getId())).thenReturn(epRoleQuery); Mockito.doReturn(mockEPRoleList).when(epRoleQuery).list(); - Mockito.when(session.createQuery("from :name where app.id=:appId and role_id=:roleId")) + Mockito.when(session.createQuery("from EPUserApp where app.id=:appId and role_id=:roleId")) .thenReturn(epUserAppsQuery); - Mockito.when(epUserAppsQuery.setParameter("name",EPUserApp.class.getName())).thenReturn(epUserAppsQuery); Mockito.when(epUserAppsQuery.setParameter("appId",mockApp.getId())).thenReturn(epUserAppsQuery); Mockito.when(epUserAppsQuery.setParameter("roleId",15l)).thenReturn(epUserAppsQuery); Mockito.doReturn(mockUserRolesList).when(epUserAppsQuery).list(); - Mockito.when(session.createQuery("from :name where roleId=:roleId")) + Mockito.when(session.createQuery("from FunctionalMenuRole where roleId=:roleId")) .thenReturn(epFunctionalMenuQuery); - Mockito.when(epFunctionalMenuQuery.setParameter("name",FunctionalMenuRole.class.getName())).thenReturn(epFunctionalMenuQuery); Mockito.when(epFunctionalMenuQuery.setParameter("roleId",15l)).thenReturn(epFunctionalMenuQuery); Mockito.doReturn(mockFunctionalMenuRolesList).when(epFunctionalMenuQuery).list(); - Mockito.when(session.createQuery("from :name where menuId=:menuId")) + Mockito.when(session.createQuery("from FunctionalMenuRole where menuId=:menuId")) .thenReturn(epFunctionalMenuQuery2); - Mockito.when(epFunctionalMenuQuery2.setParameter("name",FunctionalMenuRole.class.getName())).thenReturn(epFunctionalMenuQuery2); - Mockito.when(epFunctionalMenuQuery2.setParameter("menuId",10l)).thenReturn(epFunctionalMenuQuery2); + Mockito.when(epFunctionalMenuQuery2.setParameter(Matchers.anyString(),Matchers.anyLong())).thenReturn(epFunctionalMenuQuery2); Mockito.doReturn(mockFunctionalMenuRolesList).when(epFunctionalMenuQuery2).list(); - Mockito.when(session.createQuery("from " + FunctionalMenuItem.class.getName() + " where menuId=" + 10l)) + Mockito.when(session.createQuery("from FunctionalMenuItem where menuId=:menuId")) .thenReturn(epFunctionalMenuItemQuery); + Mockito.when(epFunctionalMenuItemQuery.setParameter(Matchers.anyString(),Matchers.anyLong())).thenReturn(epFunctionalMenuItemQuery); Mockito.doReturn(mockFunctionalMenuItemList).when(epFunctionalMenuItemQuery).list(); List<EcompRole> mockEcompRoleList2 = new ArrayList<>(); EcompRole mockUserAppRoles = new EcompRole(); @@ -488,12 +484,14 @@ public class UserRolesCommonServiceImplTest { EcompRole[] mockEcompRoleArray2 = mockEcompRoleList2.toArray(new EcompRole[mockEcompRoleList2.size()]); Mockito.when(applicationsRestClientService.get(EcompRole[].class, mockApp.getId(), String.format("/user/%s/roles", user.getOrgUserId()))).thenReturn(mockEcompRoleArray2); - // SyncUserRoleTest - Mockito.when(session - .createQuery("from " + EPUser.class.getName() + " where orgUserId='" + user.getOrgUserId() + "'")) + + + Mockito.when(session.createQuery( + "from EPUser where orgUserId=:userId")) .thenReturn(epUserListQuery); + Mockito.when(epUserListQuery.setParameter("userId","guestT")).thenReturn(epUserListQuery); Mockito.doReturn(mockEpUserList).when(epUserListQuery).list(); - + List<EPUserApp> mockUserRolesList2 = new ArrayList<>(); EPUserApp mockEpUserAppRoles = new EPUserApp(); mockEpUserAppRoles.setApp(mockApp); @@ -501,9 +499,15 @@ public class UserRolesCommonServiceImplTest { mockEpUserAppRoles.setUserId(user.getId()); mockUserRolesList2.add(mockEpUserAppRoles); Mockito.when(session.createQuery( - "from org.onap.portalapp.portal.domain.EPUserApp where app.id=2 and role.active = 'Y' and userId=2")) + "from EPUserApp where app.id=:appId and userId=:userId and role.active = 'Y'")) .thenReturn(epUserRolesListQuery); + + Mockito.when(epUserRolesListQuery.setParameter("appId",2)).thenReturn(epUserRolesListQuery); + Mockito.when(epUserRolesListQuery.setParameter("userId",2)).thenReturn(epUserRolesListQuery); + Mockito.doReturn(mockUserRolesList2).when(epUserRolesListQuery).list(); + + List<RoleInAppForUser> roleInAppForUser = userRolesCommonServiceImpl.getAppRolesForUser(2l, user.getOrgUserId(), true, user); assertEquals(roleInAppForUser, mockRoleInAppForUserList); @@ -669,7 +673,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); - assertTrue(actual.isResult()); + assertFalse(actual.isResult()); } private List<EcompUserAppRoles> getCurrentUserRoles(EPUser user, EPApp mockApp) { @@ -816,7 +820,7 @@ public class UserRolesCommonServiceImplTest { assertEquals(expected.isResult(), false); } - /*@SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") @Test public void setExternalRequestUserAppRoleMerdianCentralizedAppTest() throws Exception { PowerMockito.mockStatic(SystemProperties.class); @@ -984,7 +988,7 @@ public class UserRolesCommonServiceImplTest { .setExternalRequestUserAppRole(externalSystemUser, "POST"); assertTrue(mockExternalRequestFieldsValidator.equals(externalRequestFieldsValidator)); } -*/ + @SuppressWarnings("unchecked") @Test public void setExternalRequestUserAppRoleMerdianNonCentralizedAppTest() throws Exception { 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 new file mode 100644 index 00000000..2ed86bfe --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/WidgetMServiceImplTest.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +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}) +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() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void getServiceLocation_Error() { + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.when(EcompPortalUtils.localOrDockerHost()).thenReturn(TEST); + String location = widgetMServiceImpl.getServiceLocation(TEST, TEST); + assertNotNull(location); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java index 2fdf0fe1..708f446a 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/service/sessionmgt/SessionCommunicationTest.java @@ -47,17 +47,21 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.domain.EPApp; +import org.onap.portalapp.portal.service.AppsCacheService; +import org.onap.portalapp.portal.service.AppsCacheServiceImple; import org.onap.portalapp.portal.transport.OnboardingApp; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import org.slf4j.MDC; - -import com.att.eelf.configuration.Configuration; @RunWith(PowerMockRunner.class) -@PrepareForTest({URL.class, HttpURLConnection.class}) +@PrepareForTest({URL.class, HttpURLConnection.class,CipherUtil.class}) public class SessionCommunicationTest { @Before @@ -68,6 +72,8 @@ public class SessionCommunicationTest { @InjectMocks SessionCommunication sessionCommunication = new SessionCommunication(); + @Mock + AppsCacheService appsCacheService = new AppsCacheServiceImple(); @Test public void sendGetConnectionRefusedTest() throws Exception { @@ -94,6 +100,36 @@ public class SessionCommunicationTest { } @Test + public void sendGetConnectionRefusedTest1() throws Exception { + OnboardingApp app = new OnboardingApp(); + app.setRestrictedApp(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.isCentralAuth = true; + app.isEnabled = true; + app.isOpen =false; + app.name = "test"; + app.restUrl ="http://localhost:1234"; + app.username = "test"; + app.appPassword = ""; + EPApp epApp = new EPApp(); + epApp.setUsername("test"); + epApp.setAppPassword("xyz1234"); + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.when(CipherUtil.decryptPKC(Matchers.anyString(),Matchers.anyString())).thenReturn("test"); + Mockito.when(appsCacheService.getApp(1L)).thenReturn(epApp); + URL u = PowerMockito.mock(URL.class); + HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class); + String url = "http://localhost:1234/sessionTimeOuts"; + PowerMockito.whenNew(URL.class).withArguments(url).thenReturn(u); + PowerMockito.whenNew(HttpURLConnection.class).withAnyArguments().thenReturn(huc); + PowerMockito.when(huc.getResponseCode()).thenReturn(200); + String actual = sessionCommunication.sendGet(app); + assertEquals("", actual); + } + + @Test public void pingSessionConnectionRefusedTest() throws Exception { OnboardingApp app = new OnboardingApp(); app.setRestrictedApp(false); @@ -148,4 +184,4 @@ public class SessionCommunicationTest { sessionCommunication.clear(true); } -} +}
\ No newline at end of file diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/util/EPUserUtilsTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/util/EPUserUtilsTest.java index 80ca1424..db6ca2f7 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/util/EPUserUtilsTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/util/EPUserUtilsTest.java @@ -59,7 +59,6 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.commons.codec.binary.Hex; -import org.drools.core.command.assertion.AssertEquals; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/validation/DataValidatorTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/validation/DataValidatorTest.java index 2dbfdcd7..f6e3e1a5 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/validation/DataValidatorTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/validation/DataValidatorTest.java @@ -45,7 +45,6 @@ import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; -import org.drools.core.command.assertion.AssertEquals; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; |