2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.portal.controller;
40 import static org.junit.Assert.assertEquals;
41 import static org.junit.Assert.assertNull;
43 import java.util.ArrayList;
44 import java.util.List;
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
49 import org.junit.Before;
50 import org.junit.Test;
51 import org.junit.runner.RunWith;
52 import org.mockito.InjectMocks;
53 import org.mockito.Matchers;
54 import org.mockito.Mock;
55 import org.mockito.Mockito;
56 import org.mockito.MockitoAnnotations;
57 import org.onap.portalapp.portal.core.MockEPUser;
58 import org.onap.portalapp.portal.domain.EPUser;
59 import org.onap.portalapp.portal.domain.MicroserviceParameter;
60 import org.onap.portalapp.portal.domain.WidgetCatalog;
61 import org.onap.portalapp.portal.domain.WidgetCatalogParameter;
62 import org.onap.portalapp.portal.domain.WidgetParameterResult;
63 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
64 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
65 import org.onap.portalapp.portal.framework.MockitoTestSuite;
66 import org.onap.portalapp.portal.service.MicroserviceServiceImpl;
67 import org.onap.portalapp.portal.service.WidgetMService;
68 import org.onap.portalapp.portal.service.WidgetMServiceImpl;
69 import org.onap.portalapp.portal.service.WidgetParameterServiceImpl;
70 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
71 import org.onap.portalapp.portal.utils.EcompPortalUtils;
72 import org.onap.portalapp.util.EPUserUtils;
73 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
74 import org.onap.portalsdk.core.util.SystemProperties;
75 import org.powermock.api.mockito.PowerMockito;
76 import org.powermock.core.classloader.annotations.PrepareForTest;
77 import org.powermock.modules.junit4.PowerMockRunner;
78 import org.springframework.http.HttpEntity;
79 import org.springframework.http.HttpMethod;
80 import org.springframework.http.HttpStatus;
81 import org.springframework.http.ResponseEntity;
82 import org.springframework.mock.web.MockHttpServletRequest;
83 import org.springframework.mock.web.MockHttpServletResponse;
84 import org.springframework.mock.web.MockMultipartFile;
85 import org.springframework.mock.web.MockMultipartHttpServletRequest;
86 import org.springframework.web.client.RestClientException;
87 import org.springframework.web.client.RestTemplate;
89 @SuppressWarnings("rawtypes")
90 @RunWith(PowerMockRunner.class)
91 @PrepareForTest({ EPUserUtils.class, CipherUtil.class, EcompPortalUtils.class, SystemProperties.class,
92 EPCommonSystemProperties.class, EPUserUtils.class })
93 public class WidgetsCatalogUnRestrictedControllerTest {
96 WidgetMService widgetMService = new WidgetMServiceImpl();
99 WidgetsCatalogUnRestrictedController widgetsCatalogControllerTest = new WidgetsCatalogUnRestrictedController();
102 public void setup() {
103 MockitoAnnotations.initMocks(this);
107 RestTemplate template = new RestTemplate();
109 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
111 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
112 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
114 NullPointerException nullPointerException = new NullPointerException();
116 MockEPUser mockUser = new MockEPUser();
119 @SuppressWarnings("unchecked")
121 public void getWidgetControllerTest() throws Exception {
122 PowerMockito.mockStatic(EcompPortalUtils.class);
123 PowerMockito.mockStatic(SystemProperties.class);
124 PowerMockito.mockStatic(EPCommonSystemProperties.class);
125 PowerMockito.mockStatic(CipherUtil.class);
126 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
127 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
128 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
129 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
131 Mockito.when(CipherUtil
132 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
134 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
135 Mockito.when(template.getForObject(Mockito.anyString(), Mockito.any(Class.class), Mockito.any(String.class)))
136 .thenReturn("test123");
137 String result = widgetsCatalogControllerTest.getWidgetController(1);