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.assertNull;
45 import static org.junit.jupiter.api.Assertions.assertTrue;
47 import java.time.LocalDateTime;
48 import java.util.Collections;
49 import java.util.HashSet;
50 import java.util.List;
51 import javax.transaction.Transactional;
52 import org.junit.Test;
53 import org.junit.runner.RunWith;
54 import org.onap.portal.dao.fn.FnLanguageDao;
55 import org.onap.portal.domain.db.ep.EpMicroserviceParameter;
56 import org.onap.portal.domain.db.ep.EpWidgetCatalog;
57 import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter;
58 import org.onap.portal.domain.db.fn.FnLanguage;
59 import org.onap.portal.domain.db.fn.FnUser;
60 import org.onap.portal.domain.dto.ecomp.WidgetCatalog;
61 import org.onap.portal.service.ep.EpMicroserviceParameterService;
62 import org.onap.portal.service.ep.EpWidgetCatalogParameterService;
63 import org.onap.portal.service.ep.EpWidgetCatalogService;
64 import org.onap.portal.service.fn.FnLanguageService;
65 import org.onap.portal.service.fn.FnUserService;
66 import org.springframework.beans.factory.annotation.Autowired;
67 import org.springframework.boot.test.context.SpringBootTest;
68 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
69 import org.springframework.test.context.TestPropertySource;
70 import org.springframework.test.context.junit4.SpringRunner;
72 @RunWith(SpringRunner.class)
75 @TestPropertySource(locations = "classpath:test.properties")
76 public class WidgetsCatalogControllerTest {
77 private final UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
80 private WidgetsCatalogController widgetsCatalogController;
82 private FnUserService fnUserService;
84 private FnLanguageService fnLanguageService;
86 private EpWidgetCatalogParameterService epWidgetCatalogParameterService;
88 private EpMicroserviceParameterService epMicroserviceParameterService;
90 private EpWidgetCatalogService epWidgetCatalogService;
92 private FnLanguageDao fnLanguageDao;
95 public void getUserWidgetCatalog() {
96 List<WidgetCatalog> actual = widgetsCatalogController.getUserWidgetCatalog("demo");
101 public void getWidgetCatalog() {
105 public void updateWidgetCatalog() {
109 public void deleteOnboardingWidget() {
113 public void updateWidgetCatalogWithFiles() {
117 public void createWidgetCatalog() {
121 public void getWidgetFramework() {
125 public void getWidgetController() {
129 public void getWidgetCSS() {
133 public void getWidgetParameterResult() {
137 public void getUserParameterById() {
139 EpWidgetCatalog widget = EpWidgetCatalog.builder()
144 epWidgetCatalogService.save(widget);
145 EpMicroserviceParameter parameter = new EpMicroserviceParameter();
146 epMicroserviceParameterService.save(parameter);
147 FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
148 fnLanguageService.save(language);
149 FnUser user = buildFnUser();
150 language.setFnUsers(new HashSet<>(Collections.singleton(user)));
151 user.setLanguageId(language);
152 fnUserService.saveFnUser(user);
153 EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
154 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
156 epWidgetCatalogParameterService.saveUserParameter(data);
157 List<EpWidgetCatalogParameter> actual = widgetsCatalogController.getUserParameterById(parameter.getId());
159 assertEquals(1, actual.size());
164 public void deleteUserParameterById() {
166 EpWidgetCatalog widget = EpWidgetCatalog.builder()
171 epWidgetCatalogService.save(widget);
172 EpMicroserviceParameter parameter = new EpMicroserviceParameter();
173 epMicroserviceParameterService.save(parameter);
174 FnUser user = buildFnUser();
175 FnLanguage language = fnLanguageDao.getByLanguageAlias("EN");
176 user.setLanguageId(language);
177 fnUserService.saveFnUser(user);
178 EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
179 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
181 assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
182 epWidgetCatalogParameterService.saveUserParameter(data);
184 assertEquals(1, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
185 assertTrue(widgetsCatalogController.deleteUserParameterById(parameter.getId()));
186 assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
191 public void doDownload() {
195 public void saveWidgetParameter() {
197 EpWidgetCatalog widget = EpWidgetCatalog.builder()
202 epWidgetCatalogService.save(widget);
203 EpMicroserviceParameter parameter = new EpMicroserviceParameter();
204 epMicroserviceParameterService.save(parameter);
205 FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
206 fnLanguageService.save(language);
207 FnUser user = buildFnUser();
208 language.setFnUsers(new HashSet<>(Collections.singleton(user)));
209 user.setLanguageId(language);
210 EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
211 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
214 widgetsCatalogController.saveWidgetParameter(principal, data);
216 EpWidgetCatalogParameter actual = epWidgetCatalogParameterService.getById(data.getId());
218 assertEquals("TestData", actual.getUserValue());
223 public void saveWidgetParameterOldParamTest() {
225 EpWidgetCatalog widget = EpWidgetCatalog.builder()
230 epWidgetCatalogService.save(widget);
231 EpMicroserviceParameter parameter = new EpMicroserviceParameter();
232 epMicroserviceParameterService.save(parameter);
233 FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
234 fnLanguageService.save(language);
235 FnUser user = buildFnUser();
236 language.setFnUsers(new HashSet<>(Collections.singleton(user)));
237 user.setLanguageId(language);
238 fnUserService.saveFnUser(user);
240 EpWidgetCatalogParameter old = EpWidgetCatalogParameter.builder()
241 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
244 widgetsCatalogController.saveWidgetParameter(principal, old);
246 EpWidgetCatalogParameter newWidgetParameter = EpWidgetCatalogParameter.builder()
247 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData2").build();
249 widgetsCatalogController.saveWidgetParameter(principal, newWidgetParameter);
251 EpWidgetCatalogParameter oldOne = epWidgetCatalogParameterService.getById(old.getId());
254 assertEquals("TestData2", oldOne.getUserValue());
259 public void getUploadFlag() {
260 String expected = "";
261 String actual = widgetsCatalogController.getUploadFlag();
263 assertEquals(expected, actual);
266 private FnUser buildFnUser(){
267 return FnUser.builder()
268 .lastLoginDate(LocalDateTime.now())
270 .modifiedDate(LocalDateTime.now())
271 .createdDate(LocalDateTime.now())