Domain model change
[portal.git] / portal-BE / src / test / java / org / onap / portal / service / ep / EpWidgetCatalogParameterServiceTest.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ===================================================================
9  *
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
14  *
15  *             http://www.apache.org/licenses/LICENSE-2.0
16  *
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.
22  *
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
27  *
28  *             https://creativecommons.org/licenses/by/4.0/
29  *
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.
35  *
36  * ============LICENSE_END============================================
37  *
38  *
39  */
40
41 package org.onap.portal.service.ep;
42
43 import static org.junit.jupiter.api.Assertions.assertEquals;
44
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;
65
66 @RunWith(SpringRunner.class)
67 @SpringBootTest
68 @Transactional
69 @TestPropertySource(locations = "classpath:test.properties")
70 class EpWidgetCatalogParameterServiceTest {
71
72        private final UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
73                "demo123");
74
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;
81
82        @Autowired
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;
95        }
96
97        @Test
98        void deleteUserParameterById() {
99        }
100
101        @Test
102        void deleteByParamId() {
103               //Given
104               EpWidgetCatalog widget = EpWidgetCatalog.builder()
105                       .wdgName("Name")
106                       .wdgFileLoc("loc")
107                       .allUserFlag(true)
108                       .build();
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();
116               //When
117               assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
118               epWidgetCatalogParameterService.saveUserParameter(data);
119               //Then
120               assertEquals(1, epWidgetCatalogParameterService.getUserParameterById(parameter.getId()).size());
121               epWidgetCatalogParameterService.deleteByParamId(parameter.getId());
122               assertEquals(0, epWidgetCatalogParameterService.getUserParameterById(parameter.getId()).size());
123               //Clean
124
125        }
126
127        @Test
128        void getUserParamById() {
129               //Given
130               EpWidgetCatalog widget = EpWidgetCatalog.builder()
131                       .wdgName("Name")
132                       .wdgFileLoc("loc")
133                       .allUserFlag(true)
134                       .build();
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();
142               //When
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());
148               //Then
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());
153
154        }
155
156        private FnUser buildFnUser() {
157               FnLanguage language = fnLanguageDao.getByLanguageAlias("EN");
158               return FnUser.builder()
159                       .lastLoginDate(LocalDateTime.now())
160                       .activeYn(true)
161                       .modifiedDate(LocalDateTime.now())
162                       .createdDate(LocalDateTime.now())
163                       .isInternalYn(true)
164                       .isSystemUser(true)
165                       .guest(false)
166                       .languageId(language)
167                       .build();
168        }
169 }