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.service.ep;
43 import static org.junit.jupiter.api.Assertions.assertEquals;
45 import java.time.LocalDateTime;
46 import java.util.Collections;
47 import java.util.HashSet;
48 import org.junit.jupiter.api.Test;
49 import org.junit.runner.RunWith;
50 import org.onap.portal.controller.WidgetsCatalogController;
51 import org.onap.portal.dao.fn.FnLanguageDao;
52 import org.onap.portal.domain.db.ep.EpMicroserviceParameter;
53 import org.onap.portal.domain.db.ep.EpWidgetCatalog;
54 import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter;
55 import org.onap.portal.domain.db.fn.FnLanguage;
56 import org.onap.portal.domain.db.fn.FnUser;
57 import org.onap.portal.service.fn.FnLanguageService;
58 import org.onap.portal.service.fn.FnUserService;
59 import org.springframework.beans.factory.annotation.Autowired;
60 import org.springframework.boot.test.context.SpringBootTest;
61 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
62 import org.springframework.test.context.TestPropertySource;
63 import org.springframework.test.context.junit4.SpringRunner;
64 import org.springframework.transaction.annotation.Transactional;
66 @RunWith(SpringRunner.class)
69 @TestPropertySource(locations = "classpath:test.properties")
70 class EpWidgetCatalogParameterServiceTest {
72 private final UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
75 private final EpWidgetCatalogParameterService epWidgetCatalogParameterService;
76 private final WidgetsCatalogController widgetsCatalogController;
77 private final FnUserService fnUserService;
78 private final EpMicroserviceParameterService epMicroserviceParameterService;
79 private final EpWidgetCatalogService epWidgetCatalogService;
80 private final FnLanguageDao fnLanguageDao;
83 public EpWidgetCatalogParameterServiceTest(
84 EpWidgetCatalogParameterService epWidgetCatalogParameterService,
85 WidgetsCatalogController widgetsCatalogController,
86 FnUserService fnUserService,
87 EpMicroserviceParameterService epMicroserviceParameterService,
88 EpWidgetCatalogService epWidgetCatalogService, FnLanguageDao fnLanguageDao) {
89 this.epWidgetCatalogParameterService = epWidgetCatalogParameterService;
90 this.widgetsCatalogController = widgetsCatalogController;
91 this.fnUserService = fnUserService;
92 this.epMicroserviceParameterService = epMicroserviceParameterService;
93 this.epWidgetCatalogService = epWidgetCatalogService;
94 this.fnLanguageDao = fnLanguageDao;
98 void deleteUserParameterById() {
102 void deleteByParamId() {
104 EpWidgetCatalog widget = EpWidgetCatalog.builder()
109 epWidgetCatalogService.save(widget);
110 EpMicroserviceParameter parameter = new EpMicroserviceParameter();
111 epMicroserviceParameterService.save(parameter);
112 FnUser user = buildFnUser();
113 fnUserService.saveFnUser(user);
114 EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
115 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
117 assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
118 epWidgetCatalogParameterService.saveUserParameter(data);
120 assertEquals(1, epWidgetCatalogParameterService.getUserParameterById(parameter.getId()).size());
121 epWidgetCatalogParameterService.deleteByParamId(parameter.getId());
122 assertEquals(0, epWidgetCatalogParameterService.getUserParameterById(parameter.getId()).size());
128 void getUserParamById() {
130 EpWidgetCatalog widget = EpWidgetCatalog.builder()
135 epWidgetCatalogService.save(widget);
136 EpMicroserviceParameter parameter = new EpMicroserviceParameter();
137 epMicroserviceParameterService.save(parameter);
138 FnUser user = buildFnUser();
139 fnUserService.saveFnUser(user);
140 EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
141 .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
143 assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
144 epWidgetCatalogParameterService.saveUserParameter(data);
145 Long id = data.getId();
146 assertEquals(1, epWidgetCatalogParameterService.getUserParameterById(parameter.getId()).size());
147 EpWidgetCatalogParameter actual = epWidgetCatalogParameterService.getUserParamById(widget.getWidgetId(), user.getId(), parameter.getId());
149 assertEquals(id, actual.getId());
150 assertEquals(data.getUserValue(), actual.getUserValue());
151 assertEquals(data.getWidgetId().getWidgetId(), actual.getWidgetId().getWidgetId());
152 assertEquals(data.getParamId().getId(), actual.getParamId().getId());
156 private FnUser buildFnUser() {
157 FnLanguage language = fnLanguageDao.getByLanguageAlias("EN");
158 return FnUser.builder()
159 .lastLoginDate(LocalDateTime.now())
161 .modifiedDate(LocalDateTime.now())
162 .createdDate(LocalDateTime.now())
166 .languageId(language)