+
+ @Test
+ public void getUserWidgetCatalogTest() throws RestClientException, 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");
+ List<WidgetCatalog> widgetsList = new ArrayList<>();
+ WidgetCatalog widgetCatalog = new WidgetCatalog();
+ widgetCatalog.setId(1l);
+ widgetCatalog.setName("test");
+ widgetsList.add(widgetCatalog);
+ ResponseEntity<List> ans = new ResponseEntity<>(widgetsList, HttpStatus.OK);
+ 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");
+ assertEquals(expectedWidgets, widgetsList);
+ }
+
+ @Test
+ public void getUserWidgetCatalogExceptionTest() throws RestClientException, 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(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");
+ assertNull(expectedWidgets);
+ }
+
+ @Test
+ public void getWidgetCatalogTest() 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");
+ List<WidgetCatalog> widgetsList = new ArrayList<>();
+ WidgetCatalog widgetCatalog = new WidgetCatalog();
+ widgetCatalog.setId(1l);
+ widgetCatalog.setName("test");
+ widgetsList.add(widgetCatalog);
+ ResponseEntity<List> ans = new ResponseEntity<>(widgetsList, HttpStatus.OK);
+ 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();
+ assertEquals(expectedWidgets, widgetsList);
+ }
+
+ @Test
+ public void getWidgetCatalogExceptionTest() 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(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");
+ assertNull(expectedWidgets);
+ }
+
+ @Test
+ public void updateWidgetCatalogTest() 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(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
+ ResponseEntity<List> ans = new ResponseEntity<>(HttpStatus.OK);
+ 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();
+ widget.setId(1l);
+ widgetsCatalogController.updateWidgetCatalog(widget, 1);
+ }
+
+ @Test
+ public void deleteOnboardingWidgetTest() 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(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
+ ResponseEntity<List> ans = new ResponseEntity<>(HttpStatus.OK);
+ 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);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void updateWidgetCatalogWithFilesTest() 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(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
+ String ans = "success";
+ 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();
+ byte[] mockData = "test".getBytes();
+ String originalFilename = "Test_File.zip";
+ MockMultipartFile mockMultipartFile = new MockMultipartFile("file", originalFilename, "application/zip",
+ mockData);
+ request.addFile(mockMultipartFile);
+ String actual = widgetsCatalogController.updateWidgetCatalogWithFiles(request, 1l);
+ assertEquals(ans, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void createWidgetCatalogTest() 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(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
+ String ans = "success";
+ 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();
+ byte[] mockData = "test".getBytes();
+ String originalFilename = "Test_File.zip";
+ MockMultipartFile mockMultipartFile = new MockMultipartFile("file", originalFilename, "application/zip",
+ mockData);
+ request.addFile(mockMultipartFile);
+ String actual = widgetsCatalogController.createWidgetCatalog(request);
+ assertEquals(ans, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getWidgetFrameworkTest() 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(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);
+ }
+