1 package org.openecomp.portalapp.portal.test.controller;
3 import static org.junit.Assert.assertTrue;
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
8 import org.junit.Before;
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.openecomp.portalsdk.core.util.SystemProperties;
23 import org.powermock.api.mockito.PowerMockito;
24 import org.powermock.core.classloader.annotations.PrepareForTest;
25 import org.powermock.modules.junit4.PowerMockRunner;
26 import org.springframework.web.client.RestClientException;
27 import org.springframework.web.client.RestTemplate;
29 @RunWith(PowerMockRunner.class)
30 @PrepareForTest(WidgetServiceHeaders.class)
31 public class WidgetsCatalogMarkupControllerTest extends MockitoTestSuite {
34 WidgetsCatalogMarkupController widgetsCatalogMarkupController = new WidgetsCatalogMarkupController();
37 ConsulHealthService consulHealthService = new ConsulHealthServiceImpl();
40 RestTemplate template = new RestTemplate();
44 MockitoAnnotations.initMocks(this);
47 CipherUtil cipherUtil= new CipherUtil();
50 EcompPortalUtils EcompPortalUtils =new EcompPortalUtils();
53 WidgetServiceHeaders WidgetServiceHeaders ;
55 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
57 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
58 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
60 @SuppressWarnings("static-access")
62 public void getWidgetMarkupTest() throws RestClientException, Exception
64 String whatService = "widgets-service";
65 PowerMockito.mockStatic(WidgetServiceHeaders.class);
66 Mockito.when(template.getForObject(EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, null) + "/widget/microservices/markup/" + 1, String.class,
67 WidgetServiceHeaders.getInstance())).thenReturn("Success");
68 String response = widgetsCatalogMarkupController.getWidgetMarkup(mockedRequest, mockedResponse, 1);
69 assertTrue(response.equals("Success"));