1 package org.openecomp.portalapp.portal.test.controller;
 
   3 import static org.junit.Assert.assertEquals;
 
   5 import java.io.IOException;
 
   6 import java.util.ArrayList;
 
   9 import javax.servlet.http.HttpServletRequest;
 
  10 import javax.servlet.http.HttpServletResponse;
 
  12 import org.junit.Before;
 
  13 import org.junit.Test;
 
  14 import org.junit.runner.RunWith;
 
  15 import org.mockito.InjectMocks;
 
  16 import org.mockito.Mock;
 
  17 import org.mockito.MockitoAnnotations;
 
  18 import org.openecomp.portalapp.portal.controller.DashboardController;
 
  19 import org.openecomp.portalapp.portal.domain.WidgetCatalog;
 
  20 import org.openecomp.portalapp.portal.domain.WidgetServiceHeaders;
 
  21 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
 
  22 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
 
  23 import org.openecomp.portalapp.portal.service.ConsulHealthService;
 
  24 import org.openecomp.portalapp.portal.service.ConsulHealthServiceImpl;
 
  25 import org.openecomp.portalapp.portal.service.DashboardSearchService;
 
  26 import org.openecomp.portalapp.portal.service.DashboardSearchServiceImpl;
 
  27 import org.openecomp.portalapp.portal.service.MicroserviceService;
 
  28 import org.openecomp.portalapp.portal.service.MicroserviceServiceImpl;
 
  29 import org.openecomp.portalapp.portal.service.WidgetParameterService;
 
  30 import org.openecomp.portalapp.portal.service.WidgetParameterServiceImpl;
 
  31 import org.openecomp.portalapp.portal.test.core.MockEPUser;
 
  32 import org.openecomp.portalapp.portal.transport.CommonWidgetMeta;
 
  33 import org.openecomp.portalapp.portal.utils.CustomLoggingFilter;
 
  34 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
 
  35 import org.openecomp.portalapp.test.framework.MockitoTestSuite;
 
  36 import org.openecomp.portalapp.util.EPUserUtils;
 
  37 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
 
  38 import org.openecomp.portalsdk.core.util.SystemProperties;
 
  39 import org.powermock.core.classloader.annotations.PrepareForTest;
 
  40 import org.powermock.modules.junit4.PowerMockRunner;
 
  41 import org.springframework.http.HttpEntity;
 
  42 import org.springframework.http.HttpMethod;
 
  43 import org.springframework.http.ResponseEntity;
 
  44 import org.springframework.web.bind.annotation.PathVariable;
 
  45 import org.springframework.web.client.RestClientException;
 
  47 @RunWith(PowerMockRunner.class)
 
  48 @PrepareForTest({EPUserUtils.class})
 
  49 public class WidgetsCatalogController {
 
  52         ConsulHealthService consulHealthService = new ConsulHealthServiceImpl();
 
  55         MicroserviceService microserviceService = new MicroserviceServiceImpl();
 
  58         WidgetParameterService widgetParameterService = new WidgetParameterServiceImpl();
 
  61         WidgetsCatalogController widgetsCatalogController = new WidgetsCatalogController();
 
  65                 MockitoAnnotations.initMocks(this);
 
  68         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
 
  70         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
 
  71         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
 
  73         NullPointerException nullPointerException = new NullPointerException();
 
  75         MockEPUser mockUser = new MockEPUser();
 
  77         /*public List<WidgetCatalog> getUserWidgetCatalog(HttpServletRequest request, HttpServletResponse response,
 
  78                         @PathVariable("loginName") String loginName) throws RestClientException, Exception {
 
  79                 List<WidgetCatalog> widgets = new ArrayList<>();
 
  81                         CustomLoggingFilter d;
 
  82                         ResponseEntity<ArrayList> ans = template.exchange(
 
  83                                         EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService,
 
  84                                                         SystemProperties.getProperty("microservices.widget.local.port"))
 
  85                                                         + "/widget/microservices/widgetCatalog/" + loginName,
 
  86                                         HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), ArrayList.class);
 
  87                         widgets = ans.getBody();
 
  88                 } catch (Exception e) {
 
  89                         logger.error(EELFLoggerDelegate.errorLogger, "getUserWidgetCatalog failed", e);
 
  90                         // returning null because null help check on the UI if there was a
 
  91                         // communication problem with Microservice.
 
  98         public void getWidgetDataTest(){
 
 100                 String resourceType = null;
 
 101                 List<WidgetCatalog> expectedData = new ArrayList<WidgetCatalog>();
 
 102                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
 
 103                 expectedData.setMessage("Unexpected resource type null");
 
 104                 expectedData.setResponse(null);
 
 106                 PortalRestResponse<CommonWidgetMeta> actualResponse =   dashboardController.getWidgetData(mockedRequest, resourceType);
 
 107                 assertEquals(expectedData,actualResponse);