package org.onap.portal.controller;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.transaction.Transactional;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.onap.portal.dao.fn.FnLanguageDao;
import org.onap.portal.domain.db.ep.EpMicroserviceParameter;
import org.onap.portal.domain.db.ep.EpWidgetCatalog;
import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter;
import org.onap.portal.service.ep.EpWidgetCatalogParameterService;
import org.onap.portal.service.ep.EpWidgetCatalogService;
import org.onap.portal.service.fn.FnLanguageService;
+import org.onap.portal.service.fn.FnUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@RunWith(SpringRunner.class)
@SpringBootTest
+@Transactional
@TestPropertySource(locations = "classpath:test.properties")
public class WidgetsCatalogControllerTest {
- private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
+ private final UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
"demo123");
@Autowired
- WidgetsCatalogController widgetsCatalogController;
+ private WidgetsCatalogController widgetsCatalogController;
@Autowired
- FnLanguageService fnLanguageService;
+ private FnUserService fnUserService;
@Autowired
- EpWidgetCatalogParameterService epWidgetCatalogParameterService;
+ private FnLanguageService fnLanguageService;
@Autowired
- EpMicroserviceParameterService epMicroserviceParameterService;
+ private EpWidgetCatalogParameterService epWidgetCatalogParameterService;
@Autowired
- EpWidgetCatalogService epWidgetCatalogService;
+ private EpMicroserviceParameterService epMicroserviceParameterService;
+ @Autowired
+ private EpWidgetCatalogService epWidgetCatalogService;
+ @Autowired
+ private FnLanguageDao fnLanguageDao;
@Test
public void getUserWidgetCatalog() {
}
@Test
- @Transactional
public void getUserParameterById() {
//Given
EpWidgetCatalog widget = EpWidgetCatalog.builder()
EpMicroserviceParameter parameter = new EpMicroserviceParameter();
epMicroserviceParameterService.save(parameter);
FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
- fnLanguageService.save(principal, language);
+ fnLanguageService.save(language);
FnUser user = buildFnUser();
language.setFnUsers(new HashSet<>(Collections.singleton(user)));
user.setLanguageId(language);
+ fnUserService.saveFnUser(user);
EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
.widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
//When
}
@Test
- @Transactional
public void deleteUserParameterById() {
//Given
EpWidgetCatalog widget = EpWidgetCatalog.builder()
epWidgetCatalogService.save(widget);
EpMicroserviceParameter parameter = new EpMicroserviceParameter();
epMicroserviceParameterService.save(parameter);
- FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
- fnLanguageService.save(principal, language);
FnUser user = buildFnUser();
- language.setFnUsers(new HashSet<>(Collections.singleton(user)));
+ FnLanguage language = fnLanguageDao.getByLanguageAlias("EN");
user.setLanguageId(language);
+ fnUserService.saveFnUser(user);
EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
.widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
//When
@Test
public void saveWidgetParameter() {
+ //Given
+ EpWidgetCatalog widget = EpWidgetCatalog.builder()
+ .wdgName("Name")
+ .wdgFileLoc("loc")
+ .allUserFlag(true)
+ .build();
+ epWidgetCatalogService.save(widget);
+ EpMicroserviceParameter parameter = new EpMicroserviceParameter();
+ epMicroserviceParameterService.save(parameter);
+ FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
+ fnLanguageService.save(language);
+ FnUser user = buildFnUser();
+ language.setFnUsers(new HashSet<>(Collections.singleton(user)));
+ user.setLanguageId(language);
+ EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
+ .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
+
+ //When
+ widgetsCatalogController.saveWidgetParameter(principal, data);
+ //Then
+ EpWidgetCatalogParameter actual = epWidgetCatalogParameterService.getById(data.getId());
+
+ assertEquals("TestData", actual.getUserValue());
+
+ }
+
+ @Test
+ public void saveWidgetParameterOldParamTest() {
+ //Given
+ EpWidgetCatalog widget = EpWidgetCatalog.builder()
+ .wdgName("Name")
+ .wdgFileLoc("loc")
+ .allUserFlag(true)
+ .build();
+ epWidgetCatalogService.save(widget);
+ EpMicroserviceParameter parameter = new EpMicroserviceParameter();
+ epMicroserviceParameterService.save(parameter);
+ FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build();
+ fnLanguageService.save(language);
+ FnUser user = buildFnUser();
+ language.setFnUsers(new HashSet<>(Collections.singleton(user)));
+ user.setLanguageId(language);
+ fnUserService.saveFnUser(user);
+
+ EpWidgetCatalogParameter old = EpWidgetCatalogParameter.builder()
+ .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
+
+ //When
+ widgetsCatalogController.saveWidgetParameter(principal, old);
+
+ EpWidgetCatalogParameter newWidgetParameter = EpWidgetCatalogParameter.builder()
+ .widgetId(widget).userId(user).paramId(parameter).userValue("TestData2").build();
+
+ widgetsCatalogController.saveWidgetParameter(principal, newWidgetParameter);
+
+ EpWidgetCatalogParameter oldOne = epWidgetCatalogParameterService.getById(old.getId());
+
+ //Then
+ assertEquals("TestData2", oldOne.getUserValue());
+
}
@Test
public void getUploadFlag() {
+ String expected = "";
+ String actual = widgetsCatalogController.getUploadFlag();
+
+ assertEquals(expected, actual);
}
private FnUser buildFnUser(){
.modifiedDate(LocalDateTime.now())
.createdDate(LocalDateTime.now())
.isInternalYn(true)
+ .isSystemUser(true)
.guest(false)
.build();
}