Tests coverage up and some minor bug fixes
[portal.git] / portal-BE / src / test / java / org / onap / portal / controller / WidgetsCatalogControllerTest.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.controller;
42
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;
47
48 import java.time.LocalDateTime;
49 import java.util.Collections;
50 import java.util.HashSet;
51 import java.util.List;
52 import javax.transaction.Transactional;
53 import org.junit.Test;
54 import org.junit.runner.RunWith;
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.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;
70
71 @RunWith(SpringRunner.class)
72 @SpringBootTest
73 @TestPropertySource(locations = "classpath:test.properties")
74 public class WidgetsCatalogControllerTest {
75        private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
76                "demo123");
77        @Autowired
78        WidgetsCatalogController widgetsCatalogController;
79        @Autowired
80        FnLanguageService fnLanguageService;
81        @Autowired
82        EpWidgetCatalogParameterService epWidgetCatalogParameterService;
83        @Autowired
84        EpMicroserviceParameterService epMicroserviceParameterService;
85        @Autowired
86        EpWidgetCatalogService epWidgetCatalogService;
87
88        @Test
89        public void getUserWidgetCatalog() {
90               List<WidgetCatalog> actual = widgetsCatalogController.getUserWidgetCatalog("demo");
91               assertNull(actual);
92        }
93
94        @Test
95        public void getWidgetCatalog() {
96        }
97
98        @Test
99        public void updateWidgetCatalog() {
100        }
101
102        @Test
103        public void deleteOnboardingWidget() {
104        }
105
106        @Test
107        public void updateWidgetCatalogWithFiles() {
108        }
109
110        @Test
111        public void createWidgetCatalog() {
112        }
113
114        @Test
115        public void getWidgetFramework() {
116        }
117
118        @Test
119        public void getWidgetController() {
120        }
121
122        @Test
123        public void getWidgetCSS() {
124        }
125
126        @Test
127        public void getWidgetParameterResult() {
128        }
129
130        @Test
131        @Transactional
132        public void getUserParameterById() {
133               //Given
134               EpWidgetCatalog widget = EpWidgetCatalog.builder()
135                       .wdgName("Name")
136                       .wdgFileLoc("loc")
137                       .allUserFlag(true)
138                       .build();
139               epWidgetCatalogService.save(widget);
140               EpMicroserviceParameter parameter = new EpMicroserviceParameter();
141               epMicroserviceParameterService.save(parameter);
142               FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
143               fnLanguageService.save(principal, language);
144               FnUser user = buildFnUser();
145               language.setFnUsers(new HashSet<>(Collections.singleton(user)));
146               user.setLanguageId(language);
147               EpWidgetCatalogParameter data =  EpWidgetCatalogParameter.builder()
148                       .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
149               //When
150               epWidgetCatalogParameterService.saveUserParameter(data);
151               List<EpWidgetCatalogParameter> actual = widgetsCatalogController.getUserParameterById(parameter.getId());
152               //Then
153               assertEquals(1, actual.size());
154               //Clean
155        }
156
157        @Test
158        @Transactional
159        public void deleteUserParameterById() {
160               //Given
161               EpWidgetCatalog widget = EpWidgetCatalog.builder()
162                       .wdgName("Name")
163                       .wdgFileLoc("loc")
164                       .allUserFlag(true)
165                       .build();
166               epWidgetCatalogService.save(widget);
167               EpMicroserviceParameter parameter = new EpMicroserviceParameter();
168               epMicroserviceParameterService.save(parameter);
169               FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
170               fnLanguageService.save(principal, language);
171               FnUser user = buildFnUser();
172               language.setFnUsers(new HashSet<>(Collections.singleton(user)));
173               user.setLanguageId(language);
174               EpWidgetCatalogParameter data =  EpWidgetCatalogParameter.builder()
175                       .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
176               //When
177               assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
178               epWidgetCatalogParameterService.saveUserParameter(data);
179               //Then assert
180               assertEquals(1, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
181               assertTrue(widgetsCatalogController.deleteUserParameterById(parameter.getId()));
182               assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
183
184        }
185
186        @Test
187        public void doDownload() {
188        }
189
190        @Test
191        public void saveWidgetParameter() {
192        }
193
194        @Test
195        public void getUploadFlag() {
196        }
197
198        private FnUser buildFnUser(){
199               return FnUser.builder()
200                       .lastLoginDate(LocalDateTime.now())
201                       .activeYn(true)
202                       .modifiedDate(LocalDateTime.now())
203                       .createdDate(LocalDateTime.now())
204                       .isInternalYn(true)
205                       .guest(false)
206                       .build();
207        }
208 }