1 package org.onap.portal.controller;
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4 import static org.junit.jupiter.api.Assertions.assertNull;
6 import java.time.LocalDateTime;
7 import java.util.Collections;
8 import java.util.HashSet;
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;
32 @RunWith(SpringRunner.class)
34 @TestPropertySource(locations = "classpath:test.properties")
35 public class WidgetsCatalogControllerTest {
36 private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
39 WidgetsCatalogController widgetsCatalogController;
41 FnLanguageService fnLanguageService;
43 FnUserService fnUserService;
45 EpWidgetCatalogParameterService epWidgetCatalogParameterService;
47 EpMicroserviceParameterService epMicroserviceParameterService;
49 EpWidgetCatalogService epWidgetCatalogService;
52 public void getUserWidgetCatalog() {
53 List<WidgetCatalog> actual = widgetsCatalogController.getUserWidgetCatalog("demo");
58 public void getWidgetCatalog() {
62 public void updateWidgetCatalog() {
66 public void deleteOnboardingWidget() {
70 public void updateWidgetCatalogWithFiles() {
74 public void createWidgetCatalog() {
78 public void getWidgetFramework() {
82 public void getWidgetController() {
86 public void getWidgetCSS() {
90 public void getWidgetParameterResult() {
95 public void getUserParameterById() {
97 EpWidgetCatalog widget = EpWidgetCatalog.builder()
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();
114 epWidgetCatalogParameterService.saveUserParameter(data);
115 List<EpWidgetCatalogParameter> actual = widgetsCatalogController.getUserParameterById(parameter.getId());
117 assertEquals(1, actual.size());
122 public void deleteUserParameterById() {
126 public void doDownload() {
130 public void saveWidgetParameter() {
134 public void getUploadFlag() {
137 private FnUser buildFnUser(){
138 return FnUser.builder()
139 .lastLoginDate(LocalDateTime.now())
141 .modifiedDate(LocalDateTime.now())
142 .createdDate(LocalDateTime.now())