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.domain.db.ep.EpMicroserviceParameter;
55 import org.onap.portal.domain.db.ep.EpWidgetCatalog;
56 import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter;
57 import org.onap.portal.domain.db.fn.FnLanguage;
58 import org.onap.portal.domain.db.fn.FnUser;
59 import org.onap.portal.domain.dto.ecomp.WidgetCatalog;
60 import org.onap.portal.service.microserviceParameter.EpMicroserviceParameterService;
61 import org.onap.portal.service.widgetCatalogParameter.EpWidgetCatalogParameterService;
62 import org.onap.portal.service.widgetCatalog.EpWidgetCatalogService;
63 import org.onap.portal.service.language.FnLanguageService;
64 import org.onap.portal.service.user.FnUserService;
65 import org.springframework.beans.factory.annotation.Autowired;
66 import org.springframework.boot.test.context.SpringBootTest;
67 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
68 import org.springframework.test.context.TestPropertySource;
69 import org.springframework.test.context.junit4.SpringRunner;
71 @RunWith(SpringRunner.class)
74 @TestPropertySource(locations = "classpath:test.properties")
75 public class WidgetsCatalogControllerTest {
76 private final UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
79 private WidgetsCatalogController widgetsCatalogController;
81 private FnUserService fnUserService;
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(language);
146 FnUser user = buildFnUser();
147 language.setFnUsers(new HashSet<>(Collections.singleton(user)));
148 user.setLanguageId(language);
149 fnUserService.saveFnUser(user);
150 EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
151 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
153 epWidgetCatalogParameterService.saveUserParameter(data);
154 List<EpWidgetCatalogParameter> actual = widgetsCatalogController.getUserParameterById(parameter.getId());
156 assertEquals(1, actual.size());
161 public void deleteUserParameterById() {
163 EpWidgetCatalog widget = EpWidgetCatalog.builder()
168 epWidgetCatalogService.save(widget);
169 EpMicroserviceParameter parameter = new EpMicroserviceParameter();
170 epMicroserviceParameterService.save(parameter);
171 FnUser user = buildFnUser();
172 FnLanguage language = fnLanguageService.getByLanguageAlias("EN");
173 user.setLanguageId(language);
174 fnUserService.saveFnUser(user);
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(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(language);
232 FnUser user = buildFnUser();
233 language.setFnUsers(new HashSet<>(Collections.singleton(user)));
234 user.setLanguageId(language);
235 fnUserService.saveFnUser(user);
237 EpWidgetCatalogParameter old = EpWidgetCatalogParameter.builder()
238 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
241 widgetsCatalogController.saveWidgetParameter(principal, old);
243 EpWidgetCatalogParameter newWidgetParameter = EpWidgetCatalogParameter.builder()
244 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData2").build();
246 widgetsCatalogController.saveWidgetParameter(principal, newWidgetParameter);
248 EpWidgetCatalogParameter oldOne = epWidgetCatalogParameterService.getById(old.getId());
251 assertEquals("TestData2", oldOne.getUserValue());
256 public void getUploadFlag() {
257 String expected = "";
258 String actual = widgetsCatalogController.getUploadFlag();
260 assertEquals(expected, actual);
263 private FnUser buildFnUser(){
264 return FnUser.builder()
265 .lastLoginDate(LocalDateTime.now())
267 .modifiedDate(LocalDateTime.now())
268 .createdDate(LocalDateTime.now())