2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
41 package org.onap.portal.controller;
43 import static org.junit.jupiter.api.Assertions.assertEquals;
44 import static org.junit.jupiter.api.Assertions.assertNotNull;
45 import static org.junit.jupiter.api.Assertions.assertNull;
46 import static org.junit.jupiter.api.Assertions.assertTrue;
48 import java.time.LocalDateTime;
49 import java.util.Collections;
50 import java.util.HashSet;
51 import java.util.List;
52 import javax.servlet.http.HttpServletRequest;
53 import javax.transaction.Transactional;
54 import org.junit.Test;
55 import org.junit.runner.RunWith;
56 import org.onap.portal.domain.db.ep.EpMicroserviceParameter;
57 import org.onap.portal.domain.db.ep.EpWidgetCatalog;
58 import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter;
59 import org.onap.portal.domain.db.fn.FnLanguage;
60 import org.onap.portal.domain.db.fn.FnUser;
61 import org.onap.portal.domain.dto.ecomp.WidgetCatalog;
62 import org.onap.portal.framework.MockitoTestSuite;
63 import org.onap.portal.service.ep.EpMicroserviceParameterService;
64 import org.onap.portal.service.ep.EpWidgetCatalogParameterService;
65 import org.onap.portal.service.ep.EpWidgetCatalogService;
66 import org.onap.portal.service.fn.FnLanguageService;
67 import org.springframework.beans.factory.annotation.Autowired;
68 import org.springframework.boot.test.context.SpringBootTest;
69 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
70 import org.springframework.test.context.TestPropertySource;
71 import org.springframework.test.context.junit4.SpringRunner;
73 @RunWith(SpringRunner.class)
76 @TestPropertySource(locations = "classpath:test.properties")
77 public class WidgetsCatalogControllerTest {
78 private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
81 private WidgetsCatalogController widgetsCatalogController;
83 private FnLanguageService fnLanguageService;
85 private EpWidgetCatalogParameterService epWidgetCatalogParameterService;
87 private EpMicroserviceParameterService epMicroserviceParameterService;
89 private EpWidgetCatalogService epWidgetCatalogService;
92 public void getUserWidgetCatalog() {
93 List<WidgetCatalog> actual = widgetsCatalogController.getUserWidgetCatalog("demo");
98 public void getWidgetCatalog() {
102 public void updateWidgetCatalog() {
106 public void deleteOnboardingWidget() {
110 public void updateWidgetCatalogWithFiles() {
114 public void createWidgetCatalog() {
118 public void getWidgetFramework() {
122 public void getWidgetController() {
126 public void getWidgetCSS() {
130 public void getWidgetParameterResult() {
134 public void getUserParameterById() {
136 EpWidgetCatalog widget = EpWidgetCatalog.builder()
141 epWidgetCatalogService.save(widget);
142 EpMicroserviceParameter parameter = new EpMicroserviceParameter();
143 epMicroserviceParameterService.save(parameter);
144 FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
145 fnLanguageService.save(principal, language);
146 FnUser user = buildFnUser();
147 language.setFnUsers(new HashSet<>(Collections.singleton(user)));
148 user.setLanguageId(language);
149 EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
150 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
152 epWidgetCatalogParameterService.saveUserParameter(data);
153 List<EpWidgetCatalogParameter> actual = widgetsCatalogController.getUserParameterById(parameter.getId());
155 assertEquals(1, actual.size());
160 public void deleteUserParameterById() {
162 EpWidgetCatalog widget = EpWidgetCatalog.builder()
167 epWidgetCatalogService.save(widget);
168 EpMicroserviceParameter parameter = new EpMicroserviceParameter();
169 epMicroserviceParameterService.save(parameter);
170 FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
171 fnLanguageService.save(principal, language);
172 FnUser user = buildFnUser();
173 language.setFnUsers(new HashSet<>(Collections.singleton(user)));
174 user.setLanguageId(language);
175 EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
176 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
178 assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
179 epWidgetCatalogParameterService.saveUserParameter(data);
181 assertEquals(1, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
182 assertTrue(widgetsCatalogController.deleteUserParameterById(parameter.getId()));
183 assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
188 public void doDownload() {
192 public void saveWidgetParameter() {
194 EpWidgetCatalog widget = EpWidgetCatalog.builder()
199 epWidgetCatalogService.save(widget);
200 EpMicroserviceParameter parameter = new EpMicroserviceParameter();
201 epMicroserviceParameterService.save(parameter);
202 FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
203 fnLanguageService.save(principal, language);
204 FnUser user = buildFnUser();
205 language.setFnUsers(new HashSet<>(Collections.singleton(user)));
206 user.setLanguageId(language);
207 EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
208 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
211 widgetsCatalogController.saveWidgetParameter(principal, data);
213 EpWidgetCatalogParameter actual = epWidgetCatalogParameterService.getById(data.getId());
215 assertEquals("TestData", actual.getUserValue());
220 public void saveWidgetParameterOldParamTest() {
222 EpWidgetCatalog widget = EpWidgetCatalog.builder()
227 epWidgetCatalogService.save(widget);
228 EpMicroserviceParameter parameter = new EpMicroserviceParameter();
229 epMicroserviceParameterService.save(parameter);
230 FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
231 fnLanguageService.save(principal, language);
232 FnUser user = buildFnUser();
233 language.setFnUsers(new HashSet<>(Collections.singleton(user)));
234 user.setLanguageId(language);
235 EpWidgetCatalogParameter old = EpWidgetCatalogParameter.builder()
236 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
239 widgetsCatalogController.saveWidgetParameter(principal, old);
241 EpWidgetCatalogParameter newWidgetParameter = EpWidgetCatalogParameter.builder()
242 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData2").build();
244 widgetsCatalogController.saveWidgetParameter(principal, newWidgetParameter);
246 EpWidgetCatalogParameter oldOne = epWidgetCatalogParameterService.getById(old.getId());
249 assertEquals("TestData2", oldOne.getUserValue());
254 public void getUploadFlag() {
255 String expected = "";
256 String actual = widgetsCatalogController.getUploadFlag();
258 assertEquals(expected, actual);
261 private FnUser buildFnUser(){
262 return FnUser.builder()
263 .lastLoginDate(LocalDateTime.now())
265 .modifiedDate(LocalDateTime.now())
266 .createdDate(LocalDateTime.now())