X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fportalapp%2Fportal%2Fcontroller%2FWidgetsCatalogControllerTest.java;h=5daacbdcd241ab4c1d09c08d3b8660f7ab17d409;hb=HEAD;hp=e77186b1de9663e156edf88be9931409bab8b631;hpb=24608a9e1450c409dc3870440d29e91cc3a26bb9;p=portal.git 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..5daacbdc 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.ConsulHealthService; -import org.onap.portalapp.portal.service.ConsulHealthServiceImpl; 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; @@ -98,7 +96,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 +147,7 @@ public class WidgetsCatalogControllerTest { widgetCatalog.setName("test"); widgetsList.add(widgetCatalog); ResponseEntity 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.>any(), Matchers.eq(List.class))).thenReturn(ans); List expectedWidgets = widgetsCatalogController.getUserWidgetCatalog("guestT"); @@ -170,7 +168,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.>any(), Matchers.eq(List.class)); List expectedWidgets = widgetsCatalogController.getUserWidgetCatalog("guestT"); @@ -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); @@ -197,7 +195,7 @@ public class WidgetsCatalogControllerTest { widgetCatalog.setName("test"); widgetsList.add(widgetCatalog); ResponseEntity 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.>any(), Matchers.eq(List.class))).thenReturn(ans); List expectedWidgets = widgetsCatalogController.getWidgetCatalog(); @@ -218,7 +216,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.>any(), Matchers.eq(List.class)); List expectedWidgets = widgetsCatalogController.getUserWidgetCatalog("guestT"); @@ -239,9 +237,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 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.>any(), Matchers.eq(List.class))).thenReturn(ans); WidgetCatalog widget = new WidgetCatalog(); @@ -263,9 +261,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 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.>any(), Matchers.eq(List.class))).thenReturn(ans); widgetsCatalogController.deleteOnboardingWidget(1l); @@ -286,9 +284,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 +314,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,35 +344,13 @@ 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); assertNull(result); } - @SuppressWarnings("unchecked") - @Test - public void getWidgetControllerTest() throws Exception { - PowerMockito.mockStatic(EcompPortalUtils.class); - PowerMockito.mockStatic(SystemProperties.class); - PowerMockito.mockStatic(EPCommonSystemProperties.class); - PowerMockito.mockStatic(CipherUtil.class); - Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); - Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); - Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); - Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user")) - .thenReturn("test"); - 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(template.getForObject(Mockito.anyString(), Mockito.any(Class.class), Mockito.any(String.class))) - .thenReturn("test123"); - String result = widgetsCatalogController.getWidgetController(1); - assertNull(result); - } - @SuppressWarnings("unchecked") @Test public void getWidgetCSSTest() throws Exception { @@ -390,7 +366,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 +391,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 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.>any(), Matchers.eq(Long.class))).thenReturn(ans); List defaultParam = new ArrayList<>(); @@ -456,7 +432,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 mockData = new ResponseEntity("testfile.zip".getBytes(), HttpStatus.OK);