[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-BE-common-test / src / main / java / org / openecomp / portalapp / portal / test / controller / WidgetsCatalogMarkupControllerTest.java
1 package org.openecomp.portalapp.portal.test.controller;
2
3 import static org.junit.Assert.assertTrue;
4
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7
8 import org.junit.Before;
9 import org.junit.Test;
10 import org.junit.runner.RunWith;
11 import org.mockito.InjectMocks;
12 import org.mockito.Mock;
13 import org.mockito.Mockito;
14 import org.mockito.MockitoAnnotations;
15 import org.openecomp.portalapp.portal.controller.WidgetsCatalogMarkupController;
16 import org.openecomp.portalapp.portal.domain.WidgetServiceHeaders;
17 import org.openecomp.portalapp.portal.service.ConsulHealthService;
18 import org.openecomp.portalapp.portal.service.ConsulHealthServiceImpl;
19 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
20 import org.openecomp.portalapp.test.framework.MockitoTestSuite;
21 import org.openecomp.portalsdk.core.onboarding.util.CipherUtil;
22 import org.powermock.api.mockito.PowerMockito;
23 import org.powermock.core.classloader.annotations.PrepareForTest;
24 import org.powermock.modules.junit4.PowerMockRunner;
25 import org.springframework.web.client.RestClientException;
26 import org.springframework.web.client.RestTemplate;
27
28 @RunWith(PowerMockRunner.class)
29 @PrepareForTest(WidgetServiceHeaders.class)
30 public class WidgetsCatalogMarkupControllerTest extends MockitoTestSuite {
31         
32         @InjectMocks
33         WidgetsCatalogMarkupController widgetsCatalogMarkupController = new WidgetsCatalogMarkupController();
34         
35         @Mock
36         ConsulHealthService consulHealthService = new ConsulHealthServiceImpl();
37         
38         @Mock
39         RestTemplate template = new RestTemplate();
40         
41         @Before
42         public void setup() {
43                 MockitoAnnotations.initMocks(this);
44         }
45     @Mock
46     CipherUtil cipherUtil= new CipherUtil();
47     
48     @Mock
49     EcompPortalUtils EcompPortalUtils =new EcompPortalUtils();
50         
51         @Mock
52         WidgetServiceHeaders WidgetServiceHeaders ;
53         
54         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
55
56         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
57         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
58
59         @SuppressWarnings("static-access")
60         @Test
61         public void getWidgetMarkupTest() throws RestClientException, Exception
62         {
63                 String whatService = "widgets-service";
64                 PowerMockito.mockStatic(WidgetServiceHeaders.class);
65                 Mockito.when(template.getForObject("https://" + consulHealthService.getServiceLocation(whatService, null) + "/widget/microservices/markup/" + 1, String.class,
66                                 WidgetServiceHeaders.getInstance())).thenReturn("Success");
67                 String response = widgetsCatalogMarkupController.getWidgetMarkup(mockedRequest, mockedResponse, 1);
68                 assertTrue(response.equals("Success")); 
69         }
70         
71 }