Domain model change
[portal.git] / portal-BE / src / test / java / org / onap / portal / service / ep / EpWidgetCatalogParameterServiceTest.java
index f123f95..ad1ee60 100644 (file)
@@ -40,7 +40,7 @@
 
 package org.onap.portal.service.ep;
 
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.time.LocalDateTime;
 import java.util.Collections;
@@ -48,12 +48,14 @@ import java.util.HashSet;
 import org.junit.jupiter.api.Test;
 import org.junit.runner.RunWith;
 import org.onap.portal.controller.WidgetsCatalogController;
+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.domain.db.fn.FnLanguage;
 import org.onap.portal.domain.db.fn.FnUser;
 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;
@@ -63,29 +65,40 @@ import org.springframework.transaction.annotation.Transactional;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest
+@Transactional
 @TestPropertySource(locations = "classpath:test.properties")
 class EpWidgetCatalogParameterServiceTest {
-       private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
+
+       private final UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
                "demo123");
+
+       private final EpWidgetCatalogParameterService epWidgetCatalogParameterService;
+       private final WidgetsCatalogController widgetsCatalogController;
+       private final FnUserService fnUserService;
+       private final EpMicroserviceParameterService epMicroserviceParameterService;
+       private final EpWidgetCatalogService epWidgetCatalogService;
+       private final FnLanguageDao fnLanguageDao;
+
        @Autowired
-       private EpWidgetCatalogParameterService epWidgetCatalogParameterService;
-       @Autowired
-       private WidgetsCatalogController widgetsCatalogController;
-       @Autowired
-       private
-       FnLanguageService fnLanguageService;
-       @Autowired
-       private EpMicroserviceParameterService epMicroserviceParameterService;
-       @Autowired
-       private
-       EpWidgetCatalogService epWidgetCatalogService;
+       public EpWidgetCatalogParameterServiceTest(
+           EpWidgetCatalogParameterService epWidgetCatalogParameterService,
+           WidgetsCatalogController widgetsCatalogController,
+           FnUserService fnUserService,
+           EpMicroserviceParameterService epMicroserviceParameterService,
+           EpWidgetCatalogService epWidgetCatalogService, FnLanguageDao fnLanguageDao) {
+              this.epWidgetCatalogParameterService = epWidgetCatalogParameterService;
+              this.widgetsCatalogController = widgetsCatalogController;
+              this.fnUserService = fnUserService;
+              this.epMicroserviceParameterService = epMicroserviceParameterService;
+              this.epWidgetCatalogService = epWidgetCatalogService;
+              this.fnLanguageDao = fnLanguageDao;
+       }
 
        @Test
        void deleteUserParameterById() {
        }
 
        @Test
-       @Transactional
        void deleteByParamId() {
               //Given
               EpWidgetCatalog widget = EpWidgetCatalog.builder()
@@ -96,12 +109,9 @@ class EpWidgetCatalogParameterServiceTest {
               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)));
-              user.setLanguageId(language);
-              EpWidgetCatalogParameter data =  EpWidgetCatalogParameter.builder()
+              fnUserService.saveFnUser(user);
+              EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
                       .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
               //When
               assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
@@ -112,17 +122,48 @@ class EpWidgetCatalogParameterServiceTest {
               assertEquals(0, epWidgetCatalogParameterService.getUserParameterById(parameter.getId()).size());
               //Clean
 
+       }
+
+       @Test
+       void getUserParamById() {
+              //Given
+              EpWidgetCatalog widget = EpWidgetCatalog.builder()
+                      .wdgName("Name")
+                      .wdgFileLoc("loc")
+                      .allUserFlag(true)
+                      .build();
+              epWidgetCatalogService.save(widget);
+              EpMicroserviceParameter parameter = new EpMicroserviceParameter();
+              epMicroserviceParameterService.save(parameter);
+              FnUser user = buildFnUser();
+              fnUserService.saveFnUser(user);
+              EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder()
+                      .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build();
+              //When
+              assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size());
+              epWidgetCatalogParameterService.saveUserParameter(data);
+              Long id = data.getId();
+              assertEquals(1, epWidgetCatalogParameterService.getUserParameterById(parameter.getId()).size());
+              EpWidgetCatalogParameter actual = epWidgetCatalogParameterService.getUserParamById(widget.getWidgetId(), user.getId(), parameter.getId());
+              //Then
+              assertEquals(id, actual.getId());
+              assertEquals(data.getUserValue(), actual.getUserValue());
+              assertEquals(data.getWidgetId().getWidgetId(), actual.getWidgetId().getWidgetId());
+              assertEquals(data.getParamId().getId(), actual.getParamId().getId());
 
        }
 
-       private FnUser buildFnUser(){
+       private FnUser buildFnUser() {
+              FnLanguage language = fnLanguageDao.getByLanguageAlias("EN");
               return FnUser.builder()
                       .lastLoginDate(LocalDateTime.now())
                       .activeYn(true)
                       .modifiedDate(LocalDateTime.now())
                       .createdDate(LocalDateTime.now())
                       .isInternalYn(true)
+                      .isSystemUser(true)
                       .guest(false)
+                      .languageId(language)
                       .build();
        }
 }
\ No newline at end of file