WidgetsCatalogControllerTest up
[portal.git] / portal-BE / src / test / java / org / onap / portal / controller / WidgetsCatalogControllerTest.java
1 package org.onap.portal.controller;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4 import static org.junit.jupiter.api.Assertions.assertNull;
5
6 import java.time.LocalDateTime;
7 import java.util.Collections;
8 import java.util.HashSet;
9 import java.util.List;
10 import javax.transaction.Transactional;
11 import org.hibernate.Hibernate;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 import org.onap.portal.dao.fn.EpWidgetCatalogDao;
15 import org.onap.portal.domain.db.ep.EpMicroserviceParameter;
16 import org.onap.portal.domain.db.ep.EpWidgetCatalog;
17 import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter;
18 import org.onap.portal.domain.db.fn.FnLanguage;
19 import org.onap.portal.domain.db.fn.FnUser;
20 import org.onap.portal.domain.dto.ecomp.WidgetCatalog;
21 import org.onap.portal.service.ep.EpMicroserviceParameterService;
22 import org.onap.portal.service.ep.EpWidgetCatalogParameterService;
23 import org.onap.portal.service.ep.EpWidgetCatalogService;
24 import org.onap.portal.service.fn.FnLanguageService;
25 import org.onap.portal.service.fn.FnUserService;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.boot.test.context.SpringBootTest;
28 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
29 import org.springframework.test.context.TestPropertySource;
30 import org.springframework.test.context.junit4.SpringRunner;
31
32 @RunWith(SpringRunner.class)
33 @SpringBootTest
34 @TestPropertySource(locations = "classpath:test.properties")
35 public class WidgetsCatalogControllerTest {
36        private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
37                "demo123");
38        @Autowired
39        WidgetsCatalogController widgetsCatalogController;
40        @Autowired
41        FnLanguageService fnLanguageService;
42        @Autowired
43        FnUserService fnUserService;
44        @Autowired
45        EpWidgetCatalogParameterService epWidgetCatalogParameterService;
46        @Autowired
47        EpMicroserviceParameterService epMicroserviceParameterService;
48        @Autowired
49        EpWidgetCatalogService epWidgetCatalogService;
50
51        @Test
52        public void getUserWidgetCatalog() {
53               List<WidgetCatalog> actual = widgetsCatalogController.getUserWidgetCatalog("demo");
54               assertNull(actual);
55        }
56
57        @Test
58        public void getWidgetCatalog() {
59        }
60
61        @Test
62        public void updateWidgetCatalog() {
63        }
64
65        @Test
66        public void deleteOnboardingWidget() {
67        }
68
69        @Test
70        public void updateWidgetCatalogWithFiles() {
71        }
72
73        @Test
74        public void createWidgetCatalog() {
75        }
76
77        @Test
78        public void getWidgetFramework() {
79        }
80
81        @Test
82        public void getWidgetController() {
83        }
84
85        @Test
86        public void getWidgetCSS() {
87        }
88
89        @Test
90        public void getWidgetParameterResult() {
91        }
92
93        @Test
94        @Transactional
95        public void getUserParameterById() {
96               //Given
97               EpWidgetCatalog widget = EpWidgetCatalog.builder()
98                       .widgetId(54L)
99                       .wdgName("Name")
100                       .wdgFileLoc("loc")
101                       .allUserFlag(true)
102                       .build();
103               epWidgetCatalogService.save(widget);
104               EpMicroserviceParameter parameter = new EpMicroserviceParameter();
105               epMicroserviceParameterService.save(parameter);
106               FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
107               fnLanguageService.save(principal, language);
108               FnUser user = buildFnUser();
109               language.setFnUsers(new HashSet<>(Collections.singleton(user)));
110               user.setLanguageId(language);
111               EpWidgetCatalogParameter data =  EpWidgetCatalogParameter.builder()
112                       .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
113               //When
114               epWidgetCatalogParameterService.saveUserParameter(data);
115               List<EpWidgetCatalogParameter> actual = widgetsCatalogController.getUserParameterById(parameter.getId());
116               //Then
117               assertEquals(1, actual.size());
118               //Clean
119        }
120
121        @Test
122        public void deleteUserParameterById() {
123        }
124
125        @Test
126        public void doDownload() {
127        }
128
129        @Test
130        public void saveWidgetParameter() {
131        }
132
133        @Test
134        public void getUploadFlag() {
135        }
136
137        private FnUser buildFnUser(){
138               return FnUser.builder()
139                       .lastLoginDate(LocalDateTime.now())
140                       .activeYn(true)
141                       .modifiedDate(LocalDateTime.now())
142                       .createdDate(LocalDateTime.now())
143                       .isInternalYn(true)
144                       .guest(false)
145                       .build();
146        }
147 }