diff options
author | 2019-10-01 14:52:49 +0200 | |
---|---|---|
committer | 2019-10-03 10:26:15 +0200 | |
commit | e90cfa3b65b9879d22fc4522f45a22f1014e224e (patch) | |
tree | eccba7283aa9c05a34120569829348ab69113a74 /portal-BE/src | |
parent | f2805494b772201a94334e2c2f72315cacd8266b (diff) |
WidgetsCatalogControllerTest up
WidgetsCatalogControllerTest up
Issue-ID: PORTAL-710
Change-Id: I09c2ee9ab72108b2f62939a3a5ac2441376774e2
Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
Diffstat (limited to 'portal-BE/src')
9 files changed, 250 insertions, 66 deletions
diff --git a/portal-BE/src/main/java/org/onap/portal/controller/WidgetsCatalogController.java b/portal-BE/src/main/java/org/onap/portal/controller/WidgetsCatalogController.java index decf625d..d1039f0c 100644 --- a/portal-BE/src/main/java/org/onap/portal/controller/WidgetsCatalogController.java +++ b/portal-BE/src/main/java/org/onap/portal/controller/WidgetsCatalogController.java @@ -49,12 +49,12 @@ import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; +import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter; import org.onap.portal.domain.db.fn.FnUser; import org.onap.portal.domain.dto.PortalRestResponse; import org.onap.portal.domain.dto.PortalRestStatusEnum; import org.onap.portal.domain.dto.ecomp.MicroserviceParameter; import org.onap.portal.domain.dto.ecomp.WidgetCatalog; -import org.onap.portal.domain.dto.ecomp.WidgetCatalogParameter; import org.onap.portal.domain.dto.ecomp.WidgetParameterResult; import org.onap.portal.domain.dto.ecomp.WidgetServiceHeaders; import org.onap.portal.logging.aop.EPAuditLog; @@ -323,7 +323,7 @@ public class WidgetsCatalogController { userResult.setParamId(param.getId()); userResult.setDefaultValue(param.getPara_value()); userResult.setParamKey(param.getPara_key()); - WidgetCatalogParameter userValue = epWidgetCatalogParameterService + EpWidgetCatalogParameter userValue = epWidgetCatalogParameterService .getUserParamById(widgetId, user.getId(), param.getId()); if (userValue == null) { @@ -338,7 +338,7 @@ public class WidgetsCatalogController { } @GetMapping(value = {"/portalApi/microservices/services/{paramId}"}) - public List<WidgetCatalogParameter> getUserParameterById(@PathVariable("paramId") long paramId) { + public List<EpWidgetCatalogParameter> getUserParameterById(@PathVariable("paramId") long paramId) { return epWidgetCatalogParameterService.getUserParameterById(paramId); } @@ -396,13 +396,13 @@ public class WidgetsCatalogController { @PostMapping(value = {"/portalApi/microservices/parameters"}) public PortalRestResponse<String> saveWidgetParameter(Principal principal, HttpServletRequest request, - @RequestBody WidgetCatalogParameter widgetParameters) { + @RequestBody EpWidgetCatalogParameter widgetParameters) { FnUser user = fnUserService.loadUserByUsername(principal.getName()); - widgetParameters.setUserId(user.getId()); + widgetParameters.setUserId(user); try { - WidgetCatalogParameter oldParam = epWidgetCatalogParameterService - .getUserParamById(widgetParameters.getWidgetId(), - widgetParameters.getUserId(), widgetParameters.getParamId()); + EpWidgetCatalogParameter oldParam = epWidgetCatalogParameterService + .getUserParamById(widgetParameters.getWidgetId().getWidgetId(), + widgetParameters.getUserId().getId(), widgetParameters.getParamId().getId()); if (oldParam != null) { widgetParameters.setId(oldParam.getId()); } diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalog.java b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalog.java index a19af285..2068e212 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalog.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalog.java @@ -60,6 +60,7 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -83,11 +84,11 @@ CREATE TABLE `ep_widget_catalog` ( @Getter @Setter @Entity +@Builder public class EpWidgetCatalog implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "widget_id", length = 11, nullable = false) - @Digits(integer = 11, fraction = 0) + @Column(name = "widget_id", nullable = false) private Long widgetId; @Column(name = "wdg_name", length = 100, columnDefinition = "varchar(100) default '?'", nullable = false) @Size(max = 100) @@ -106,12 +107,9 @@ public class EpWidgetCatalog implements Serializable { @NotNull @SafeHtml private String wdgFileLoc; - @Column(name = "all_user_flag", length = 1, columnDefinition = "char(1) not null default 'N'", nullable = false) - @Pattern(regexp = "[YNyn]") - @Size(max = 1) - @SafeHtml + @Column(name = "all_user_flag", length = 1, columnDefinition = "boolean default '0'", nullable = false) @NotNull - private String allUserFlag; + private Boolean allUserFlag; @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinTable( name = "ep_widget_microservice", diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalogParameter.java b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalogParameter.java index 2ac07cc3..8088a8fd 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalogParameter.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/ep/EpWidgetCatalogParameter.java @@ -59,11 +59,13 @@ import javax.validation.constraints.Digits; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.validator.constraints.SafeHtml; import org.onap.portal.domain.db.fn.FnUser; +import org.onap.portal.domain.dto.DomainVo; /* CREATE TABLE `ep_widget_catalog_parameter` ( @@ -85,7 +87,7 @@ CREATE TABLE `ep_widget_catalog_parameter` ( @NamedQueries({ @NamedQuery( name = "EpWidgetCatalogParameter.retrieveByParamId", - query = "FROM EpWidgetCatalogParameter WHERE paramId = :PARAMID"), + query = "FROM EpWidgetCatalogParameter WHERE paramId.id = :PARAMID"), @NamedQuery( name = "EpWidgetCatalogParameter.deleteWidgetCatalogParameter", query = "DELETE FROM EpWidgetCatalogParameter WHERE paramId = :PARAMID"), @@ -100,12 +102,14 @@ CREATE TABLE `ep_widget_catalog_parameter` ( @Index(name = "EP_WIDGET_CATALOG_WIDGET_PARAMETER_FK", columnList = "widget_id"), @Index(name = "EP_PARAMETER_ID_WIDGET_PARAMETER_FK", columnList = "param_id") }) -@NoArgsConstructor -@AllArgsConstructor + @Getter @Setter @Entity -public class EpWidgetCatalogParameter implements Serializable { +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class EpWidgetCatalogParameter extends DomainVo implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnLanguage.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnLanguage.java index 4b9186eb..0582508d 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnLanguage.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnLanguage.java @@ -42,6 +42,7 @@ package org.onap.portal.domain.db.fn; import com.fasterxml.jackson.annotation.JsonInclude; import java.io.Serializable; +import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -100,10 +101,10 @@ public class FnLanguage implements Serializable { @OneToMany( targetEntity = FnUser.class, mappedBy = "languageId", - cascade = CascadeType.ALL, - fetch = FetchType.LAZY + cascade = CascadeType.PERSIST, + fetch = FetchType.EAGER ) - private Set<FnUser> fnUsers; + private Set<FnUser> fnUsers = new HashSet<>(); @Override public String toString() { diff --git a/portal-BE/src/main/java/org/onap/portal/service/ep/EpMicroserviceParameterService.java b/portal-BE/src/main/java/org/onap/portal/service/ep/EpMicroserviceParameterService.java index 2544ae6a..e5f84e72 100644 --- a/portal-BE/src/main/java/org/onap/portal/service/ep/EpMicroserviceParameterService.java +++ b/portal-BE/src/main/java/org/onap/portal/service/ep/EpMicroserviceParameterService.java @@ -84,4 +84,8 @@ public class EpMicroserviceParameterService { private List<MicroserviceParameter> mapToMicroserviceParameterList(final List<EpMicroserviceParameter> list){ return list.stream().map(this::epWidgetCatalogParameterToMicroserviceParameter).collect(Collectors.toList()); } + + public EpMicroserviceParameter save(EpMicroserviceParameter epMicroserviceParameter){ + return epMicroserviceParameterDao.save(epMicroserviceParameter); + } } diff --git a/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogParameterService.java b/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogParameterService.java index 8488e5ad..f2497f85 100644 --- a/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogParameterService.java +++ b/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogParameterService.java @@ -42,13 +42,10 @@ package org.onap.portal.service.ep; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; +import javax.transaction.Transactional; import org.onap.portal.dao.ep.EpMicroserviceParameterDao; import org.onap.portal.dao.ep.EpWidgetCatalogParameterDao; -import org.onap.portal.dao.fn.EpWidgetCatalogDao; -import org.onap.portal.dao.fn.FnUserDao; import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter; -import org.onap.portal.domain.dto.ecomp.WidgetCatalogParameter; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -60,23 +57,17 @@ public class EpWidgetCatalogParameterService { private final EpWidgetCatalogParameterDao epWidgetCatalogParameterDao; private final EpMicroserviceParameterDao epMicroserviceParameterDao; - private final EpWidgetCatalogDao epWidgetCatalogDao; - private final FnUserDao fnUserDao; @Autowired public EpWidgetCatalogParameterService( final EpWidgetCatalogParameterDao epWidgetCatalogParameterDao, - final EpMicroserviceParameterDao epMicroserviceParameterDao, - EpWidgetCatalogDao epWidgetCatalogDao, FnUserDao fnUserDao) { + final EpMicroserviceParameterDao epMicroserviceParameterDao) { this.epWidgetCatalogParameterDao = epWidgetCatalogParameterDao; this.epMicroserviceParameterDao = epMicroserviceParameterDao; - this.epWidgetCatalogDao = epWidgetCatalogDao; - this.fnUserDao = fnUserDao; } - public List<WidgetCatalogParameter> getUserParameterById(Long paramId) { - return mapEpWidgetListToWidgetList( - epWidgetCatalogParameterDao.retrieveByParamId(paramId).orElse(new ArrayList<>())); + public List<EpWidgetCatalogParameter> getUserParameterById(Long paramId) { + return epWidgetCatalogParameterDao.retrieveByParamId(paramId).orElse(new ArrayList<>()); } public void deleteUserParameterById(Long paramId) { @@ -84,11 +75,11 @@ public class EpWidgetCatalogParameterService { epMicroserviceParameterDao.deleteMicroserviceParameterById(paramId); } - public WidgetCatalogParameter getUserParamById(Long widgetId, Long userId, Long paramId) { - WidgetCatalogParameter widgetParam = null; - List<WidgetCatalogParameter> list = mapEpWidgetListToWidgetList( - epWidgetCatalogParameterDao.getUserParamById(widgetId, userId, paramId) - .orElse(new ArrayList<>())); + public EpWidgetCatalogParameter getUserParamById(Long widgetId, Long userId, Long paramId) { + EpWidgetCatalogParameter widgetParam = null; + List<EpWidgetCatalogParameter> list = epWidgetCatalogParameterDao + .getUserParamById(widgetId, userId, paramId) + .orElse(new ArrayList<>()); if (list.size() != 0) { widgetParam = list.get(0); } @@ -97,31 +88,8 @@ public class EpWidgetCatalogParameterService { return widgetParam; } - public void saveUserParameter(WidgetCatalogParameter newParameter) { - epWidgetCatalogParameterDao.saveAndFlush(mapToEpWidgetCatalogParameter(newParameter)); - } - - private EpWidgetCatalogParameter mapToEpWidgetCatalogParameter(WidgetCatalogParameter wcp){ - - return new EpWidgetCatalogParameter(wcp.getId(), epWidgetCatalogDao.findById(wcp.getWidgetId()).get(), - fnUserDao.findById(wcp.getUserId()).get(), - epMicroserviceParameterDao.findById(wcp.getParamId()).get(), - wcp.getUserValue()); - } - - private List<EpWidgetCatalogParameter> mapToList(List<WidgetCatalogParameter> list){ - return list.stream().map(this::mapToEpWidgetCatalogParameter).collect(Collectors.toList()); - } - - private WidgetCatalogParameter mapEpWidgetCatalogParametertoWidgetCatalogParameter( - EpWidgetCatalogParameter ewcp) { - return new WidgetCatalogParameter(ewcp.getId(), ewcp.getWidgetId().getWidgetId(), - ewcp.getUserId().getId(), ewcp.getParamId().getId(), ewcp.getUserValue()); - } - - private List<WidgetCatalogParameter> mapEpWidgetListToWidgetList( - List<EpWidgetCatalogParameter> epWidgetCatalogParameters) { - return epWidgetCatalogParameters.stream().map(this::mapEpWidgetCatalogParametertoWidgetCatalogParameter) - .collect(Collectors.toList()); + @Transactional + public void saveUserParameter(EpWidgetCatalogParameter newParameter) { + epWidgetCatalogParameterDao.save(newParameter); } } diff --git a/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogService.java b/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogService.java new file mode 100644 index 00000000..f0c273ad --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/service/ep/EpWidgetCatalogService.java @@ -0,0 +1,21 @@ +package org.onap.portal.service.ep; + +import org.onap.portal.dao.fn.EpWidgetCatalogDao; +import org.onap.portal.domain.db.ep.EpWidgetCatalog; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class EpWidgetCatalogService { + + private final EpWidgetCatalogDao epWidgetCatalogDao; + + @Autowired + public EpWidgetCatalogService(EpWidgetCatalogDao epWidgetCatalogDao) { + this.epWidgetCatalogDao = epWidgetCatalogDao; + } + + public EpWidgetCatalog save(final EpWidgetCatalog epWidgetCatalog){ + return epWidgetCatalogDao.save(epWidgetCatalog); + } +} diff --git a/portal-BE/src/test/java/org/onap/portal/controller/WidgetMSControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/WidgetMSControllerTest.java new file mode 100644 index 00000000..2f9f4235 --- /dev/null +++ b/portal-BE/src/test/java/org/onap/portal/controller/WidgetMSControllerTest.java @@ -0,0 +1,41 @@ +package org.onap.portal.controller; + +import static org.junit.jupiter.api.Assertions.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.onap.portal.domain.dto.ecomp.PortalRestResponse; +import org.onap.portal.domain.dto.ecomp.PortalRestStatusEnum; +import org.onap.portal.framework.MockitoTestSuite; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +@TestPropertySource(locations = "classpath:test.properties") +class WidgetMSControllerTest { + + @Autowired + WidgetMSController widgetMSController; + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest request = mockitoTestSuite.getMockedRequest(); + HttpServletResponse response = mockitoTestSuite.getMockedResponse(); + + @Test + void getServiceLocation() { + PortalRestResponse<String> expected = new PortalRestResponse<>(); + expected.setMessage("Error!"); + expected.setResponse("Couldn't get the service location"); + expected.setStatus(PortalRestStatusEnum.ERROR); + PortalRestResponse<String> actual = widgetMSController.getServiceLocation(request, response, "portal"); + assertEquals(expected.getMessage(), actual.getMessage()); + assertEquals(expected.getResponse(), actual.getResponse()); + assertEquals(expected.getStatus(), actual.getStatus()); + } +}
\ No newline at end of file diff --git a/portal-BE/src/test/java/org/onap/portal/controller/WidgetsCatalogControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/WidgetsCatalogControllerTest.java new file mode 100644 index 00000000..8c2adc9d --- /dev/null +++ b/portal-BE/src/test/java/org/onap/portal/controller/WidgetsCatalogControllerTest.java @@ -0,0 +1,147 @@ +package org.onap.portal.controller; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import javax.transaction.Transactional; +import org.hibernate.Hibernate; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portal.dao.fn.EpWidgetCatalogDao; +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.domain.dto.ecomp.WidgetCatalog; +import org.onap.portal.service.ep.EpMicroserviceParameterService; +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; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +@TestPropertySource(locations = "classpath:test.properties") +public class WidgetsCatalogControllerTest { + private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", + "demo123"); + @Autowired + WidgetsCatalogController widgetsCatalogController; + @Autowired + FnLanguageService fnLanguageService; + @Autowired + FnUserService fnUserService; + @Autowired + EpWidgetCatalogParameterService epWidgetCatalogParameterService; + @Autowired + EpMicroserviceParameterService epMicroserviceParameterService; + @Autowired + EpWidgetCatalogService epWidgetCatalogService; + + @Test + public void getUserWidgetCatalog() { + List<WidgetCatalog> actual = widgetsCatalogController.getUserWidgetCatalog("demo"); + assertNull(actual); + } + + @Test + public void getWidgetCatalog() { + } + + @Test + public void updateWidgetCatalog() { + } + + @Test + public void deleteOnboardingWidget() { + } + + @Test + public void updateWidgetCatalogWithFiles() { + } + + @Test + public void createWidgetCatalog() { + } + + @Test + public void getWidgetFramework() { + } + + @Test + public void getWidgetController() { + } + + @Test + public void getWidgetCSS() { + } + + @Test + public void getWidgetParameterResult() { + } + + @Test + @Transactional + public void getUserParameterById() { + //Given + EpWidgetCatalog widget = EpWidgetCatalog.builder() + .widgetId(54L) + .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(principal, 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 + epWidgetCatalogParameterService.saveUserParameter(data); + List<EpWidgetCatalogParameter> actual = widgetsCatalogController.getUserParameterById(parameter.getId()); + //Then + assertEquals(1, actual.size()); + //Clean + } + + @Test + public void deleteUserParameterById() { + } + + @Test + public void doDownload() { + } + + @Test + public void saveWidgetParameter() { + } + + @Test + public void getUploadFlag() { + } + + private FnUser buildFnUser(){ + return FnUser.builder() + .lastLoginDate(LocalDateTime.now()) + .activeYn(true) + .modifiedDate(LocalDateTime.now()) + .createdDate(LocalDateTime.now()) + .isInternalYn(true) + .guest(false) + .build(); + } +}
\ No newline at end of file |