Add doc folder.
[portal.git] / ecomp-portal-BE-common-test / src / main / java / org / openecomp / portalapp / portal / test / controller / WidgetsCatalogController.java
1 package org.openecomp.portalapp.portal.test.controller;
2
3 import static org.junit.Assert.assertEquals;
4
5 import java.io.IOException;
6 import java.util.ArrayList;
7 import java.util.List;
8
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11
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;
46
47 @RunWith(PowerMockRunner.class)
48 @PrepareForTest({EPUserUtils.class})
49 public class WidgetsCatalogController {
50
51         @Mock
52         ConsulHealthService consulHealthService = new ConsulHealthServiceImpl();
53         
54         @Mock
55         MicroserviceService microserviceService = new MicroserviceServiceImpl();
56         
57         @Mock
58         WidgetParameterService widgetParameterService = new WidgetParameterServiceImpl();
59         
60         @InjectMocks
61         WidgetsCatalogController widgetsCatalogController = new WidgetsCatalogController();
62
63         @Before
64         public void setup() {
65                 MockitoAnnotations.initMocks(this);
66         }
67
68         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
69
70         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
71         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
72
73         NullPointerException nullPointerException = new NullPointerException();
74         
75         MockEPUser mockUser = new MockEPUser();
76         
77         /*public List<WidgetCatalog> getUserWidgetCatalog(HttpServletRequest request, HttpServletResponse response,
78                         @PathVariable("loginName") String loginName) throws RestClientException, Exception {
79                 List<WidgetCatalog> widgets = new ArrayList<>();
80                 try {
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.
92                         return null;
93                 }
94                 return widgets;
95         }
96         
97         @Test
98         public void getWidgetDataTest(){
99                 
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);
105                 
106                 PortalRestResponse<CommonWidgetMeta> actualResponse =   dashboardController.getWidgetData(mockedRequest, resourceType);
107                 assertEquals(expectedData,actualResponse);      
108                 
109                 
110         }*/
111 }