Widget MS startup fix and Onboarding changes
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / controller / WidgetsCatalogControllerTest.java
index e77186b..5daacbd 100644 (file)
@@ -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<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 +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.<HttpEntity<?>>any(), Matchers.eq(List.class));
                List<WidgetCatalog> 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<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 +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.<HttpEntity<?>>any(), Matchers.eq(List.class));
                List<WidgetCatalog> 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<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 +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<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 +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<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 +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<byte[]> mockData = new ResponseEntity("testfile.zip".getBytes(), HttpStatus.OK);