From bfb078b48e3558777b60a91775ea3c239a1f3a05 Mon Sep 17 00:00:00 2001 From: Dominik Mizyn Date: Wed, 11 Sep 2019 14:54:06 +0200 Subject: WidgetsControllerTest up WidgetsControllerTest up Issue-ID: PORTAL-710 Change-Id: Ia1e5c40599bd9f89a8d1b5a856571332bc6ebfe1 Signed-off-by: Dominik Mizyn --- .../onap/portal/controller/WidgetsController.java | 3 +- .../onap/portal/domain/builder/FnUserBuilder.java | 469 --------------------- .../portal/domain/builder/FnUserDtoBuilder.java | 331 --------------- .../org/onap/portal/domain/db/fn/FnLanguage.java | 3 +- .../java/org/onap/portal/domain/db/fn/FnUser.java | 20 +- .../org/onap/portal/domain/dto/fn/FnUserDto.java | 7 +- .../onap/portal/domain/mapper/FnUserMapper.java | 197 ++++----- .../portal/controller/LanguageControllerTest.java | 6 +- .../onap/portal/controller/UserControllerTest.java | 2 +- .../portal/controller/WidgetsControllerTest.java | 189 +++++++++ .../onap/portal/framework/MockitoTestSuite.java | 97 +++++ .../onap/portal/service/fn/FnUserServiceTest.java | 17 +- 12 files changed, 407 insertions(+), 934 deletions(-) delete mode 100644 portal-BE/src/main/java/org/onap/portal/domain/builder/FnUserBuilder.java delete mode 100644 portal-BE/src/main/java/org/onap/portal/domain/builder/FnUserDtoBuilder.java create mode 100644 portal-BE/src/test/java/org/onap/portal/controller/WidgetsControllerTest.java create mode 100644 portal-BE/src/test/java/org/onap/portal/framework/MockitoTestSuite.java diff --git a/portal-BE/src/main/java/org/onap/portal/controller/WidgetsController.java b/portal-BE/src/main/java/org/onap/portal/controller/WidgetsController.java index 6248a358..c2915275 100644 --- a/portal-BE/src/main/java/org/onap/portal/controller/WidgetsController.java +++ b/portal-BE/src/main/java/org/onap/portal/controller/WidgetsController.java @@ -43,6 +43,7 @@ package org.onap.portal.controller; import java.io.IOException; import java.security.Principal; import java.util.List; +import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.onap.portal.domain.db.fn.FnUser; @@ -99,7 +100,7 @@ public class WidgetsController { FnUser user = fnUserService.loadUserByUsername(principal.getName()); List onboardingWidgets = null; - if (user == null || user.isGuest()) { + if (user.getGuest()) { EcompPortalUtils.setBadPermissions(user, response, "getOnboardingWidgets"); } else { String getType = request.getHeader("X-Widgets-Type"); diff --git a/portal-BE/src/main/java/org/onap/portal/domain/builder/FnUserBuilder.java b/portal-BE/src/main/java/org/onap/portal/domain/builder/FnUserBuilder.java deleted file mode 100644 index ccf20aa3..00000000 --- a/portal-BE/src/main/java/org/onap/portal/domain/builder/FnUserBuilder.java +++ /dev/null @@ -1,469 +0,0 @@ -/* - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * Modifications Copyright (c) 2019 Samsung - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the "License"); - * you may not use this software except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============LICENSE_END============================================ - * - * - */ - -package org.onap.portal.domain.builder; - -import java.time.LocalDateTime; -import java.util.Set; -import javax.validation.Valid; -import javax.validation.constraints.Digits; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.PastOrPresent; -import javax.validation.constraints.Size; -import org.hibernate.validator.constraints.SafeHtml; -import org.onap.portal.domain.db.cr.CrReportFileHistory; -import org.onap.portal.domain.db.ep.EpPersUserWidgetPlacement; -import org.onap.portal.domain.db.ep.EpPersUserWidgetSel; -import org.onap.portal.domain.db.ep.EpUserNotification; -import org.onap.portal.domain.db.ep.EpUserRolesRequest; -import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter; -import org.onap.portal.domain.db.fn.FnAuditLog; -import org.onap.portal.domain.db.fn.FnLanguage; -import org.onap.portal.domain.db.fn.FnLuAlertMethod; -import org.onap.portal.domain.db.fn.FnLuTimezone; -import org.onap.portal.domain.db.fn.FnMenuFunctional; -import org.onap.portal.domain.db.fn.FnOrg; -import org.onap.portal.domain.db.fn.FnPersUserAppSel; -import org.onap.portal.domain.db.fn.FnRole; -import org.onap.portal.domain.db.fn.FnUser; -import org.onap.portal.domain.db.fn.FnUserRole; -import org.springframework.stereotype.Component; - -@Component -public class FnUserBuilder { - - private @Digits(integer = 11, fraction = 0) Long userId; - private @Valid FnOrg orgId; - private @Valid FnUser managerId; - private @Size(max = 50) - @SafeHtml String firstName; - private @Size(max = 50) - @SafeHtml String middleName; - private @Size(max = 50) - @SafeHtml String lastName; - private @Size(max = 25) - @SafeHtml String phone; - private @Size(max = 25) - @SafeHtml String fax; - private @Size(max = 25) - @SafeHtml String cellular; - private @Size(max = 50) @Email - @SafeHtml String email; - private @Digits(integer = 11, fraction = 0) Long addressId; - private FnLuAlertMethod alertMethodCd; - private @Size(max = 20) - @SafeHtml String hrid; - private @Size(max = 20) - @SafeHtml String orgUserId; - private @Size(max = 30) - @SafeHtml String org_code; - private @Size(max = 25) - @SafeHtml String loginId; - private @Size(max = 100) - @SafeHtml String loginPwd; - private @PastOrPresent LocalDateTime lastLoginDate; - private @Size(max = 1) - @SafeHtml - @NotNull(message = "activeYn must not be null") String activeYn; - private @Valid FnUser createdId; - private @PastOrPresent LocalDateTime createdDate; - private @Valid FnUser modifiedId; - private @PastOrPresent LocalDateTime modifiedDate; - private @Size(max = 1) - @SafeHtml - @NotNull(message = "isInternalYn must not be null") String isInternalYn; - private @Size(max = 100) - @SafeHtml String addressLine1; - private @Size(max = 100) - @SafeHtml String addressLine2; - private @Size(max = 50) - @SafeHtml String city; - private @Size(max = 3) - @SafeHtml String stateCd; - private @Size(max = 11) - @SafeHtml String zipCode; - private @Size(max = 3) - @SafeHtml String countryCd; - private @Size(max = 8) - @SafeHtml String locationClli; - private @Size(max = 20) - @SafeHtml String orgManagerUserId; - private @Size(max = 100) - @SafeHtml String company; - private @Size(max = 200) - @SafeHtml String departmentName; - private @Size(max = 100) - @SafeHtml String jobTitle; - private @Valid FnLuTimezone timezone; - private @Size(max = 25) - @SafeHtml String department; - private @Size(max = 25) - @SafeHtml String businessUnit; - private @Size(max = 100) - @SafeHtml String businessUnitName; - private @Size(max = 25) - @SafeHtml String cost_center; - private @Size(max = 10) - @SafeHtml String finLocCode; - private @Size(max = 10) - @SafeHtml String siloStatus; - private @Valid @NotNull(message = "languageId must not be null") FnLanguage languageId; - private @NotNull(message = "guest must not be null") boolean guest; - private Set crReportFileHistorie; - private Set fnRoles; - private Set fnRoleList; - private Set fnAuditLogs; - private Set fnUsersCreatedId; - private Set fnUsersManagerId; - private Set fnUsersModifiedId; - private Set epUserRolesRequests; - private Set persUserAppSels; - private Set epWidgetCatalogParameters; - private Set epPersUserWidgetPlacements; - private Set epPersUserWidgetSels; - private Set fnUserRoles; - private Set epUserNotifications; - - public FnUserBuilder setUserId(@Digits(integer = 11, fraction = 0) Long userId) { - this.userId = userId; - return this; - } - - public FnUserBuilder setOrgId(@Valid FnOrg orgId) { - this.orgId = orgId; - return this; - } - - public FnUserBuilder setManagerId(@Valid FnUser managerId) { - this.managerId = managerId; - return this; - } - - public FnUserBuilder setFirstName(@Size(max = 50) @SafeHtml String firstName) { - this.firstName = firstName; - return this; - } - - public FnUserBuilder setMiddleName(@Size(max = 50) @SafeHtml String middleName) { - this.middleName = middleName; - return this; - } - - public FnUserBuilder setLastName(@Size(max = 50) @SafeHtml String lastName) { - this.lastName = lastName; - return this; - } - - public FnUserBuilder setPhone(@Size(max = 25) @SafeHtml String phone) { - this.phone = phone; - return this; - } - - public FnUserBuilder setFax(@Size(max = 25) @SafeHtml String fax) { - this.fax = fax; - return this; - } - - public FnUserBuilder setCellular(@Size(max = 25) @SafeHtml String cellular) { - this.cellular = cellular; - return this; - } - - public FnUserBuilder setEmail(@Size(max = 50) @Email @SafeHtml String email) { - this.email = email; - return this; - } - - public FnUserBuilder setAddressId(@Digits(integer = 11, fraction = 0) Long addressId) { - this.addressId = addressId; - return this; - } - - public FnUserBuilder setAlertMethodCd(FnLuAlertMethod alertMethodCd) { - this.alertMethodCd = alertMethodCd; - return this; - } - - public FnUserBuilder setHrid(@Size(max = 20) @SafeHtml String hrid) { - this.hrid = hrid; - return this; - } - - public FnUserBuilder setOrgUserId(@Size(max = 20) @SafeHtml String orgUserId) { - this.orgUserId = orgUserId; - return this; - } - - public FnUserBuilder setOrg_code(@Size(max = 30) @SafeHtml String org_code) { - this.org_code = org_code; - return this; - } - - public FnUserBuilder setLoginId(@Size(max = 25) @SafeHtml String loginId) { - this.loginId = loginId; - return this; - } - - public FnUserBuilder setLoginPwd(@Size(max = 100) @SafeHtml String loginPwd) { - this.loginPwd = loginPwd; - return this; - } - - public FnUserBuilder setLastLoginDate(@PastOrPresent LocalDateTime lastLoginDate) { - this.lastLoginDate = lastLoginDate; - return this; - } - - public FnUserBuilder setActiveYn( - @Size(max = 1) @SafeHtml @NotNull(message = "activeYn must not be null") String activeYn) { - this.activeYn = activeYn; - return this; - } - - public FnUserBuilder setCreatedId(@Valid FnUser createdId) { - this.createdId = createdId; - return this; - } - - public FnUserBuilder setCreatedDate(@PastOrPresent LocalDateTime createdDate) { - this.createdDate = createdDate; - return this; - } - - public FnUserBuilder setModifiedId(@Digits(integer = 11, fraction = 0) FnUser modifiedId) { - this.modifiedId = modifiedId; - return this; - } - - public FnUserBuilder setModifiedDate(@PastOrPresent LocalDateTime modifiedDate) { - this.modifiedDate = modifiedDate; - return this; - } - - public FnUserBuilder setIsInternalYn( - @Size(max = 1) @SafeHtml @NotNull(message = "isInternalYn must not be null") String isInternalYn) { - this.isInternalYn = isInternalYn; - return this; - } - - public FnUserBuilder setAddressLine1(@Size(max = 100) @SafeHtml String addressLine1) { - this.addressLine1 = addressLine1; - return this; - } - - public FnUserBuilder setAddressLine2(@Size(max = 100) @SafeHtml String addressLine2) { - this.addressLine2 = addressLine2; - return this; - } - - public FnUserBuilder setCity(@Size(max = 50) @SafeHtml String city) { - this.city = city; - return this; - } - - public FnUserBuilder setStateCd(@Size(max = 3) @SafeHtml String stateCd) { - this.stateCd = stateCd; - return this; - } - - public FnUserBuilder setZipCode(@Size(max = 11) @SafeHtml String zipCode) { - this.zipCode = zipCode; - return this; - } - - public FnUserBuilder setCountryCd(@Size(max = 3) @SafeHtml String countryCd) { - this.countryCd = countryCd; - return this; - } - - public FnUserBuilder setLocationClli(@Size(max = 8) @SafeHtml String locationClli) { - this.locationClli = locationClli; - return this; - } - - public FnUserBuilder setOrgManagerUserId(@Size(max = 20) @SafeHtml String orgManagerUserId) { - this.orgManagerUserId = orgManagerUserId; - return this; - } - - public FnUserBuilder setCompany(@Size(max = 100) @SafeHtml String company) { - this.company = company; - return this; - } - - public FnUserBuilder setDepartmentName(@Size(max = 200) @SafeHtml String departmentName) { - this.departmentName = departmentName; - return this; - } - - public FnUserBuilder setJobTitle(@Size(max = 100) @SafeHtml String jobTitle) { - this.jobTitle = jobTitle; - return this; - } - - public FnUserBuilder setTimezone(@Valid FnLuTimezone timezone) { - this.timezone = timezone; - return this; - } - - public FnUserBuilder setDepartment(@Size(max = 25) @SafeHtml String department) { - this.department = department; - return this; - } - - public FnUserBuilder setBusinessUnit(@Size(max = 25) @SafeHtml String businessUnit) { - this.businessUnit = businessUnit; - return this; - } - - public FnUserBuilder setBusinessUnitName(@Size(max = 100) @SafeHtml String businessUnitName) { - this.businessUnitName = businessUnitName; - return this; - } - - public FnUserBuilder setCost_center(@Size(max = 25) @SafeHtml String cost_center) { - this.cost_center = cost_center; - return this; - } - - public FnUserBuilder setFinLocCode(@Size(max = 10) @SafeHtml String finLocCode) { - this.finLocCode = finLocCode; - return this; - } - - public FnUserBuilder setSiloStatus(@Size(max = 10) @SafeHtml String siloStatus) { - this.siloStatus = siloStatus; - return this; - } - - public FnUserBuilder setLanguageId( - @Valid @NotNull(message = "languageId must not be null") FnLanguage languageId) { - this.languageId = languageId; - return this; - } - - public FnUserBuilder setGuest(@NotNull(message = "guest must not be null") boolean guest) { - this.guest = guest; - return this; - } - - public FnUserBuilder setCrReportFileHistorie(Set crReportFileHistorie) { - this.crReportFileHistorie = crReportFileHistorie; - return this; - } - - public FnUserBuilder setFnRoles(Set fnRoles) { - this.fnRoles = fnRoles; - return this; - } - - public FnUserBuilder setFnRoleList(Set fnRoleList) { - this.fnRoleList = fnRoleList; - return this; - } - - public FnUserBuilder setFnAuditLogs(Set fnAuditLogs) { - this.fnAuditLogs = fnAuditLogs; - return this; - } - - public FnUserBuilder setFnUsersCreatedId(Set fnUsersCreatedId) { - this.fnUsersCreatedId = fnUsersCreatedId; - return this; - } - - public FnUserBuilder setFnUsersManagerId(Set fnUsersManagerId) { - this.fnUsersManagerId = fnUsersManagerId; - return this; - } - - public FnUserBuilder setFnUsersModifiedId(Set fnUsersModifiedId) { - this.fnUsersModifiedId = fnUsersModifiedId; - return this; - } - - public FnUserBuilder setEpUserRolesRequests(Set epUserRolesRequests) { - this.epUserRolesRequests = epUserRolesRequests; - return this; - } - - public FnUserBuilder setPersUserAppSels(Set persUserAppSels) { - this.persUserAppSels = persUserAppSels; - return this; - } - - public FnUserBuilder setEpWidgetCatalogParameters(Set epWidgetCatalogParameters) { - this.epWidgetCatalogParameters = epWidgetCatalogParameters; - return this; - } - - public FnUserBuilder setEpPersUserWidgetPlacements(Set epPersUserWidgetPlacements) { - this.epPersUserWidgetPlacements = epPersUserWidgetPlacements; - return this; - } - - public FnUserBuilder setEpPersUserWidgetSels(Set epPersUserWidgetSels) { - this.epPersUserWidgetSels = epPersUserWidgetSels; - return this; - } - - public FnUserBuilder setFnUserRoles(Set fnUserRoles) { - this.fnUserRoles = fnUserRoles; - return this; - } - - public FnUserBuilder setEpUserNotifications(Set epUserNotifications) { - this.epUserNotifications = epUserNotifications; - return this; - } - - public FnUser createFnUser() { - return new FnUser(userId, orgId, managerId, firstName, middleName, lastName, phone, fax, cellular, email, - addressId, alertMethodCd, hrid, orgUserId, org_code, loginId, loginPwd, lastLoginDate, activeYn, - createdId, createdDate, modifiedId, modifiedDate, isInternalYn, addressLine1, addressLine2, city, - stateCd, zipCode, countryCd, locationClli, orgManagerUserId, company, departmentName, jobTitle, - timezone, department, businessUnit, businessUnitName, cost_center, finLocCode, siloStatus, - languageId, guest, crReportFileHistorie, fnRoles, fnRoleList, fnAuditLogs, fnUsersCreatedId, - fnUsersManagerId, fnUsersModifiedId, epUserRolesRequests, persUserAppSels, - epWidgetCatalogParameters, epPersUserWidgetPlacements, epPersUserWidgetSels, fnUserRoles, - epUserNotifications); - } -} \ No newline at end of file diff --git a/portal-BE/src/main/java/org/onap/portal/domain/builder/FnUserDtoBuilder.java b/portal-BE/src/main/java/org/onap/portal/domain/builder/FnUserDtoBuilder.java deleted file mode 100644 index c6075dd6..00000000 --- a/portal-BE/src/main/java/org/onap/portal/domain/builder/FnUserDtoBuilder.java +++ /dev/null @@ -1,331 +0,0 @@ -/* - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * Modifications Copyright (c) 2019 Samsung - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the "License"); - * you may not use this software except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============LICENSE_END============================================ - * - * - */ - -package org.onap.portal.domain.builder; - -import java.time.LocalDateTime; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.onap.portal.domain.dto.fn.FnUserDto; -import org.springframework.stereotype.Component; - -@Component -@NoArgsConstructor -@AllArgsConstructor -@Getter -@Setter -public class FnUserDtoBuilder { - - private Long userId; - private Long orgId; - private Long managerId; - private String firstName; - private String middleName; - private String lastName; - private String phone; - private String fax; - private String cellular; - private String email; - private Long addressId; - private String alertMethodCd; - private String hrid; - private String orgUserId; - private String org_code; - private String loginId; - private String loginPwd; - private LocalDateTime lastLoginDate; - private String activeYn; - private Long createdId; - private LocalDateTime createdDate; - private Long modifiedId; - private LocalDateTime modifiedDate; - private String isInternalYn; - private String addressLine1; - private String addressLine2; - private String city; - private String stateCd; - private String zipCode; - private String countryCd; - private String locationClli; - private String orgManagerUserId; - private String company; - private String departmentName; - private String jobTitle; - private Long timezone; - private String department; - private String businessUnit; - private String businessUnitName; - private String cost_center; - private String finLocCode; - private String siloStatus; - private Long languageId; - private boolean guest; - - public FnUserDtoBuilder setUserId(Long userId) { - this.userId = userId; - return this; - } - - public FnUserDtoBuilder setOrgId(Long orgId) { - this.orgId = orgId; - return this; - } - - public FnUserDtoBuilder setManagerId(Long managerId) { - this.managerId = managerId; - return this; - } - - public FnUserDtoBuilder setFirstName(String firstName) { - this.firstName = firstName; - return this; - } - - public FnUserDtoBuilder setMiddleName(String middleName) { - this.middleName = middleName; - return this; - } - - public FnUserDtoBuilder setLastName(String lastName) { - this.lastName = lastName; - return this; - } - - public FnUserDtoBuilder setPhone(String phone) { - this.phone = phone; - return this; - } - - public FnUserDtoBuilder setFax(String fax) { - this.fax = fax; - return this; - } - - public FnUserDtoBuilder setCellular(String cellular) { - this.cellular = cellular; - return this; - } - - public FnUserDtoBuilder setEmail(String email) { - this.email = email; - return this; - } - - public FnUserDtoBuilder setAddressId(Long addressId) { - this.addressId = addressId; - return this; - } - - public FnUserDtoBuilder setAlertMethodCd(String alertMethodCd) { - this.alertMethodCd = alertMethodCd; - return this; - } - - public FnUserDtoBuilder setHrid(String hrid) { - this.hrid = hrid; - return this; - } - - public FnUserDtoBuilder setOrgUserId(String orgUserId) { - this.orgUserId = orgUserId; - return this; - } - - public FnUserDtoBuilder setOrg_code(String org_code) { - this.org_code = org_code; - return this; - } - - public FnUserDtoBuilder setLoginId(String loginId) { - this.loginId = loginId; - return this; - } - - public FnUserDtoBuilder setLoginPwd(String loginPwd) { - this.loginPwd = loginPwd; - return this; - } - - public FnUserDtoBuilder setLastLoginDate(LocalDateTime lastLoginDate) { - this.lastLoginDate = lastLoginDate; - return this; - } - - public FnUserDtoBuilder setActiveYn(String activeYn) { - this.activeYn = activeYn; - return this; - } - - public FnUserDtoBuilder setCreatedId(Long createdId) { - this.createdId = createdId; - return this; - } - - public FnUserDtoBuilder setCreatedDate(LocalDateTime createdDate) { - this.createdDate = createdDate; - return this; - } - - public FnUserDtoBuilder setModifiedId(Long modifiedId) { - this.modifiedId = modifiedId; - return this; - } - - public FnUserDtoBuilder setModifiedDate(LocalDateTime modifiedDate) { - this.modifiedDate = modifiedDate; - return this; - } - - public FnUserDtoBuilder setIsInternalYn(String isInternalYn) { - this.isInternalYn = isInternalYn; - return this; - } - - public FnUserDtoBuilder setAddressLine1(String addressLine1) { - this.addressLine1 = addressLine1; - return this; - } - - public FnUserDtoBuilder setAddressLine2(String addressLine2) { - this.addressLine2 = addressLine2; - return this; - } - - public FnUserDtoBuilder setCity(String city) { - this.city = city; - return this; - } - - public FnUserDtoBuilder setStateCd(String stateCd) { - this.stateCd = stateCd; - return this; - } - - public FnUserDtoBuilder setZipCode(String zipCode) { - this.zipCode = zipCode; - return this; - } - - public FnUserDtoBuilder setCountryCd(String countryCd) { - this.countryCd = countryCd; - return this; - } - - public FnUserDtoBuilder setLocationClli(String locationClli) { - this.locationClli = locationClli; - return this; - } - - public FnUserDtoBuilder setOrgManagerUserId(String orgManagerUserId) { - this.orgManagerUserId = orgManagerUserId; - return this; - } - - public FnUserDtoBuilder setCompany(String company) { - this.company = company; - return this; - } - - public FnUserDtoBuilder setDepartmentName(String departmentName) { - this.departmentName = departmentName; - return this; - } - - public FnUserDtoBuilder setJobTitle(String jobTitle) { - this.jobTitle = jobTitle; - return this; - } - - public FnUserDtoBuilder setTimezone(Long timezone) { - this.timezone = timezone; - return this; - } - - public FnUserDtoBuilder setDepartment(String department) { - this.department = department; - return this; - } - - public FnUserDtoBuilder setBusinessUnit(String businessUnit) { - this.businessUnit = businessUnit; - return this; - } - - public FnUserDtoBuilder setBusinessUnitName(String businessUnitName) { - this.businessUnitName = businessUnitName; - return this; - } - - public FnUserDtoBuilder setCost_center(String cost_center) { - this.cost_center = cost_center; - return this; - } - - public FnUserDtoBuilder setFinLocCode(String finLocCode) { - this.finLocCode = finLocCode; - return this; - } - - public FnUserDtoBuilder setSiloStatus(String siloStatus) { - this.siloStatus = siloStatus; - return this; - } - - public FnUserDtoBuilder setLanguageId(Long languageId) { - this.languageId = languageId; - return this; - } - - public FnUserDtoBuilder setGuest(boolean guest) { - this.guest = guest; - return this; - } - - public FnUserDto createFnUserDto() { - return new FnUserDto(userId, orgId, managerId, firstName, middleName, lastName, phone, fax, cellular, - email, addressId, alertMethodCd, hrid, orgUserId, org_code, loginId, loginPwd, lastLoginDate, - activeYn, createdId, createdDate, modifiedId, modifiedDate, isInternalYn, addressLine1, - addressLine2, city, stateCd, zipCode, countryCd, locationClli, orgManagerUserId, company, - departmentName, jobTitle, timezone, department, businessUnit, businessUnitName, cost_center, - finLocCode, siloStatus, languageId, guest); - } -} \ No newline at end of file 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 2a81ea01..4b9186eb 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 @@ -57,6 +57,7 @@ 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; @@ -73,7 +74,7 @@ CREATE TABLE `fn_language` ( @Table(name = "fn_language") @NoArgsConstructor @AllArgsConstructor - +@Builder @Getter @Setter @Entity diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java index afd70b03..ce28d0fd 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java @@ -68,6 +68,7 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.PastOrPresent; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -178,6 +179,7 @@ CREATE TABLE `fn_user` ( @Getter @Setter @Entity +@Builder @NoArgsConstructor @AllArgsConstructor @DynamicUpdate @@ -253,11 +255,8 @@ public class FnUser extends DomainVo implements UserDetails, Serializable { @Column(name = "last_login_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()") @PastOrPresent protected LocalDateTime lastLoginDate; - @Column(name = "active_yn", length = 1, nullable = false) - @Size(max = 1) - @SafeHtml - @NotNull(message = "activeYn must not be null") - private String activeYn; + @Column(name = "active_yn", nullable = false) + private Boolean activeYn; @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn(name = "created_id") private FnUser createdId; @@ -270,11 +269,8 @@ public class FnUser extends DomainVo implements UserDetails, Serializable { @Column(name = "modified_date", nullable = false, columnDefinition = "datetime default now()") @PastOrPresent protected LocalDateTime modifiedDate; - @Column(name = "is_internal_yn", length = 1, columnDefinition = "character varying(1) default 'n'", nullable = false) - @Size(max = 1) - @SafeHtml - @NotNull(message = "isInternalYn must not be null") - private String isInternalYn; + @Column(name = "is_internal_yn", nullable = false, columnDefinition = "bit DEFAULT 0") + private Boolean isInternalYn; @Column(name = "address_line_1", length = 100) @Size(max = 100) @SafeHtml @@ -350,9 +346,9 @@ public class FnUser extends DomainVo implements UserDetails, Serializable { @JoinColumn(name = "language_id", nullable = false, columnDefinition = "int(11) DEFAULT 1") @NotNull(message = "languageId must not be null") private FnLanguage languageId; - @Column(name = "is_guest", columnDefinition = "boolean default 0", nullable = false) + @Column(name = "is_guest", nullable = false, columnDefinition = "bit DEFAULT 0") @NotNull(message = "guest must not be null") - private boolean guest; + private Boolean guest; @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList") private Set crReportFileHistorie; @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) diff --git a/portal-BE/src/main/java/org/onap/portal/domain/dto/fn/FnUserDto.java b/portal-BE/src/main/java/org/onap/portal/domain/dto/fn/FnUserDto.java index f8ae95d2..c107d192 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/dto/fn/FnUserDto.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/dto/fn/FnUserDto.java @@ -42,13 +42,14 @@ package org.onap.portal.domain.dto.fn; import java.time.LocalDateTime; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @Setter @Getter - +@Builder @NoArgsConstructor @AllArgsConstructor public class FnUserDto { @@ -70,12 +71,12 @@ public class FnUserDto { private String loginId; private String loginPwd; protected LocalDateTime lastLoginDate; - private String activeYn; + private Boolean activeYn; private Long createdId; protected LocalDateTime createdDate; private Long modifiedId; protected LocalDateTime modifiedDate; - private String isInternalYn = "n"; + private Boolean isInternalYn = false; private String addressLine1; private String addressLine2; private String city; diff --git a/portal-BE/src/main/java/org/onap/portal/domain/mapper/FnUserMapper.java b/portal-BE/src/main/java/org/onap/portal/domain/mapper/FnUserMapper.java index 757eff51..869ba81d 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/mapper/FnUserMapper.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/mapper/FnUserMapper.java @@ -41,120 +41,109 @@ package org.onap.portal.domain.mapper; import lombok.NoArgsConstructor; -import org.onap.portal.domain.builder.FnUserBuilder; -import org.onap.portal.domain.builder.FnUserDtoBuilder; import org.onap.portal.domain.db.fn.FnUser; import org.onap.portal.domain.dto.fn.FnUserDto; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component @NoArgsConstructor public class FnUserMapper { + public FnUserDto fnUserToFnUserDto(final FnUser fnUser){ + return FnUserDto.builder() + .userId(fnUser.getUserId()) + .orgId(fnUser.getOrgId().getOrgId()) + .managerId(fnUser.getManagerId().getUserId()) + .firstName(fnUser.getFirstName()) + .middleName(fnUser.getMiddleName()) + .lastName(fnUser.getLastName()) + .phone(fnUser.getPhone()) + .fax(fnUser.getFax()) + .cellular(fnUser.getCellular()) + .email(fnUser.getEmail()) + .addressId(fnUser.getAddressId()) + .alertMethodCd(fnUser.getAlertMethodCd().getAlertMethodCd()) + .hrid(fnUser.getHrid()) + .orgUserId(fnUser.getOrgUserId()) + .org_code(fnUser.getOrg_code()) + .loginId(fnUser.getLoginId()) + .loginPwd(fnUser.getLoginPwd()) + .lastLoginDate(fnUser.getLastLoginDate()) + .activeYn(fnUser.getActiveYn()) + .createdId(fnUser.getCreatedId().getUserId()) + .createdDate(fnUser.getCreatedDate()) + .modifiedId(fnUser.getModifiedId().getUserId()) + .modifiedDate(fnUser.getModifiedDate()) + .isInternalYn(fnUser.getIsInternalYn()) + .addressLine1(fnUser.getAddressLine1()) + .addressLine2(fnUser.getAddressLine2()) + .city(fnUser.getCity()) + .stateCd(fnUser.getStateCd()) + .zipCode(fnUser.getZipCode()) + .countryCd(fnUser.getCountryCd()) + .locationClli(fnUser.getLocationClli()) + .orgManagerUserId(fnUser.getOrgManagerUserId()) + .company(fnUser.getCompany()) + .departmentName(fnUser.getDepartmentName()) + .jobTitle(fnUser.getJobTitle()) + .timezone(fnUser.getTimezone().getTimezoneId()) + .department(fnUser.getDepartment()) + .businessUnit(fnUser.getBusinessUnit()) + .businessUnitName(fnUser.getBusinessUnitName()) + .cost_center(fnUser.getCost_center()) + .finLocCode(fnUser.getFinLocCode()) + .siloStatus(fnUser.getSiloStatus()) + .languageId(fnUser.getLanguageId().getLanguageId()) + .guest(fnUser.getGuest()) + .build(); - private FnUserDtoBuilder fnUserDtoBuilder; - private FnUserBuilder fnUserBuilder; - - @Autowired - public FnUserMapper(final FnUserDtoBuilder fnUserDtoBuilder, - FnUserBuilder fnUserBuilder) { - this.fnUserDtoBuilder = fnUserDtoBuilder; - this.fnUserBuilder = fnUserBuilder; - } - - public FnUserDto fnUserToFnUserDto(final FnUser fnUser){ - return fnUserDtoBuilder - .setUserId(fnUser.getUserId()) - .setOrgId(fnUser.getOrgId().getOrgId()) - .setManagerId(fnUser.getManagerId().getUserId()) - .setFirstName(fnUser.getFirstName()) - .setMiddleName(fnUser.getMiddleName()) - .setLastName(fnUser.getLastName()) - .setPhone(fnUser.getPhone()) - .setFax(fnUser.getFax()) - .setCellular(fnUser.getCellular()) - .setEmail(fnUser.getEmail()) - .setAddressId(fnUser.getAddressId()) - .setAlertMethodCd(fnUser.getAlertMethodCd().getAlertMethodCd()) - .setHrid(fnUser.getHrid()) - .setOrgUserId(fnUser.getOrgUserId()) - .setOrg_code(fnUser.getOrg_code()) - .setLoginId(fnUser.getLoginId()) - .setLoginPwd(fnUser.getLoginPwd()) - .setLastLoginDate(fnUser.getLastLoginDate()) - .setActiveYn(fnUser.getActiveYn()) - .setCreatedId(fnUser.getCreatedId().getUserId()) - .setCreatedDate(fnUser.getCreatedDate()) - .setModifiedId(fnUser.getModifiedId().getUserId()) - .setModifiedDate(fnUser.getModifiedDate()) - .setIsInternalYn(fnUser.getIsInternalYn()) - .setAddressLine1(fnUser.getAddressLine1()) - .setAddressLine2(fnUser.getAddressLine2()) - .setCity(fnUser.getCity()) - .setStateCd(fnUser.getStateCd()) - .setZipCode(fnUser.getZipCode()) - .setCountryCd(fnUser.getCountryCd()) - .setLocationClli(fnUser.getLocationClli()) - .setOrgManagerUserId(fnUser.getOrgManagerUserId()) - .setCompany(fnUser.getCompany()) - .setDepartmentName(fnUser.getDepartmentName()) - .setJobTitle(fnUser.getJobTitle()) - .setTimezone(fnUser.getTimezone().getTimezoneId()) - .setDepartment(fnUser.getDepartment()) - .setBusinessUnit(fnUser.getBusinessUnit()) - .setBusinessUnitName(fnUser.getBusinessUnitName()) - .setCost_center(fnUser.getCost_center()) - .setFinLocCode(fnUser.getFinLocCode()) - .setSiloStatus(fnUser.getSiloStatus()) - .setLanguageId(fnUser.getLanguageId().getLanguageId()) - .setGuest(fnUser.isGuest()).createFnUserDto(); } public FnUser fnUserToFnUser(final FnUser fnUser){ - return fnUserBuilder - .setUserId(fnUser.getUserId()) - .setOrgId(fnUser.getOrgId()) - .setManagerId(fnUser.getManagerId()) - .setFirstName(fnUser.getFirstName()) - .setMiddleName(fnUser.getMiddleName()) - .setLastName(fnUser.getLastName()) - .setPhone(fnUser.getPhone()) - .setFax(fnUser.getFax()) - .setCellular(fnUser.getCellular()) - .setEmail(fnUser.getEmail()) - .setAddressId(fnUser.getAddressId()) - .setAlertMethodCd(fnUser.getAlertMethodCd()) - .setHrid(fnUser.getHrid()) - .setOrgUserId(fnUser.getOrgUserId()) - .setOrg_code(fnUser.getOrg_code()) - .setLoginId(fnUser.getLoginId()) - .setLoginPwd(fnUser.getLoginPwd()) - .setLastLoginDate(fnUser.getLastLoginDate()) - .setActiveYn(fnUser.getActiveYn()) - .setCreatedId(fnUser.getCreatedId()) - .setCreatedDate(fnUser.getCreatedDate()) - .setModifiedId(fnUser.getModifiedId()) - .setModifiedDate(fnUser.getModifiedDate()) - .setIsInternalYn(fnUser.getIsInternalYn()) - .setAddressLine1(fnUser.getAddressLine1()) - .setAddressLine2(fnUser.getAddressLine2()) - .setCity(fnUser.getCity()) - .setStateCd(fnUser.getStateCd()) - .setZipCode(fnUser.getZipCode()) - .setCountryCd(fnUser.getCountryCd()) - .setLocationClli(fnUser.getLocationClli()) - .setOrgManagerUserId(fnUser.getOrgManagerUserId()) - .setCompany(fnUser.getCompany()) - .setDepartmentName(fnUser.getDepartmentName()) - .setJobTitle(fnUser.getJobTitle()) - .setTimezone(fnUser.getTimezone()) - .setDepartment(fnUser.getDepartment()) - .setBusinessUnit(fnUser.getBusinessUnit()) - .setBusinessUnitName(fnUser.getBusinessUnitName()) - .setCost_center(fnUser.getCost_center()) - .setFinLocCode(fnUser.getFinLocCode()) - .setSiloStatus(fnUser.getSiloStatus()) - .setLanguageId(fnUser.getLanguageId()) - .setGuest(fnUser.isGuest()).createFnUser(); + return FnUser.builder() + .userId(fnUser.getUserId()) + .orgId(fnUser.getOrgId()) + .managerId(fnUser.getManagerId()) + .firstName(fnUser.getFirstName()) + .middleName(fnUser.getMiddleName()) + .lastName(fnUser.getLastName()) + .phone(fnUser.getPhone()) + .fax(fnUser.getFax()) + .cellular(fnUser.getCellular()) + .email(fnUser.getEmail()) + .addressId(fnUser.getAddressId()) + .alertMethodCd(fnUser.getAlertMethodCd()) + .hrid(fnUser.getHrid()) + .orgUserId(fnUser.getOrgUserId()) + .org_code(fnUser.getOrg_code()) + .loginId(fnUser.getLoginId()) + .loginPwd(fnUser.getLoginPwd()) + .lastLoginDate(fnUser.getLastLoginDate()) + .activeYn(fnUser.getActiveYn()) + .createdId(fnUser.getCreatedId()) + .createdDate(fnUser.getCreatedDate()) + .modifiedId(fnUser.getModifiedId()) + .modifiedDate(fnUser.getModifiedDate()) + .isInternalYn(fnUser.getIsInternalYn()) + .addressLine1(fnUser.getAddressLine1()) + .addressLine2(fnUser.getAddressLine2()) + .city(fnUser.getCity()) + .stateCd(fnUser.getStateCd()) + .zipCode(fnUser.getZipCode()) + .countryCd(fnUser.getCountryCd()) + .locationClli(fnUser.getLocationClli()) + .orgManagerUserId(fnUser.getOrgManagerUserId()) + .company(fnUser.getCompany()) + .departmentName(fnUser.getDepartmentName()) + .jobTitle(fnUser.getJobTitle()) + .timezone(fnUser.getTimezone()) + .department(fnUser.getDepartment()) + .businessUnit(fnUser.getBusinessUnit()) + .businessUnitName(fnUser.getBusinessUnitName()) + .cost_center(fnUser.getCost_center()) + .finLocCode(fnUser.getFinLocCode()) + .siloStatus(fnUser.getSiloStatus()) + .languageId(fnUser.getLanguageId()) + .guest(fnUser.getGuest()) + .build(); } } diff --git a/portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java index 0977f286..622acb90 100644 --- a/portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java +++ b/portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java @@ -64,7 +64,7 @@ import org.springframework.transaction.annotation.Transactional; @TestPropertySource(locations="classpath:test.properties") @Transactional class LanguageControllerTest { - private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "XZa6pS1vC0qKXWtn9wcZWdLx61L0="); + private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "demo123"); @Autowired private LanguageController languageController; @@ -117,7 +117,7 @@ class LanguageControllerTest { assertEquals(languageController.getLanguageList(principal).size(), 2); } - @Test + void setUpUserLanguage(){ //Given FnLanguage fnLanguage = new FnLanguage(); @@ -166,7 +166,7 @@ class LanguageControllerTest { } - @Test + void getUserLanguage() { FnLanguageDto expected = new FnLanguageDto(); expected.setLanguageAlias("EN"); diff --git a/portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java index 7b420702..c950fb41 100644 --- a/portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java +++ b/portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java @@ -61,7 +61,7 @@ import org.springframework.test.context.junit4.SpringRunner; class UserControllerTest { private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", - "XZa6pS1vC0qKXWtn9wcZWdLx61L0="); + "demo123"); private final FnUserService userService; private final UserController userController; diff --git a/portal-BE/src/test/java/org/onap/portal/controller/WidgetsControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/WidgetsControllerTest.java new file mode 100644 index 00000000..a90b38ff --- /dev/null +++ b/portal-BE/src/test/java/org/onap/portal/controller/WidgetsControllerTest.java @@ -0,0 +1,189 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * Modifications Copyright (c) 2019 Samsung + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.controller; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertNull; +import static org.mockito.Mockito.when; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portal.dao.fn.FnLanguageDao; +import org.onap.portal.dao.fn.FnUserDao; +import org.onap.portal.domain.db.fn.FnLanguage; +import org.onap.portal.domain.db.fn.FnUser; +import org.onap.portal.domain.dto.transport.OnboardingWidget; +import org.onap.portal.framework.MockitoTestSuite; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +@TestPropertySource(locations = "classpath:test.properties") +public class WidgetsControllerTest { + + private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", + "demo123"); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest request = mockitoTestSuite.getMockedRequest(); + HttpServletResponse response = mockitoTestSuite.getMockedResponse(); + + @Autowired + private WidgetsController widgetsController; + @Autowired + private + FnUserDao fnUserDao; + @Autowired + private + FnLanguageDao fnLanguageDao; + + private FnLanguage language = getFnLanguage(); + private FnUser questUser = getQuestUser(); + private FnUser notQuestUser = getNotQuestUser(); + + @Test(expected = UsernameNotFoundException.class) + public void getOnboardingWidgetsNullUserTest() { + UsernamePasswordAuthenticationToken nullPrincipal = new UsernamePasswordAuthenticationToken("nulluser", + "demo123"); + widgetsController.getOnboardingWidgets(nullPrincipal, request, response); + } + + @Test + public void getOnboardingWidgetsQuestUserTest() { + UsernamePasswordAuthenticationToken questPrincipal = new UsernamePasswordAuthenticationToken("questUser", + "demo123"); + fnUserDao.save(questUser); + List onboardingWidgets = widgetsController + .getOnboardingWidgets(questPrincipal, request, response); + assertNull(onboardingWidgets); + + //Clean up + fnUserDao.delete(questUser); + fnLanguageDao.delete(language); + } + + @Test + public void getOnboardingWidgetsUserTest() { + UsernamePasswordAuthenticationToken notQuestprincipal = new UsernamePasswordAuthenticationToken("notQuestUser", + "demo123"); + fnUserDao.save(notQuestUser); + List expected = new ArrayList<>(); + when(request.getHeader("X-Widgets-Type")).thenReturn("managed"); + + List actual = widgetsController + .getOnboardingWidgets(notQuestprincipal, request, response); + + assertEquals(expected, actual); + fnUserDao.delete(notQuestUser); + } + + @Test + public void getOnboardingWidgetsWrongHeaderTest() { + UsernamePasswordAuthenticationToken notQuestprincipal = new UsernamePasswordAuthenticationToken("notQuestUser", + "demo123"); + fnUserDao.save(notQuestUser); + when(request.getHeader("X-Widgets-Type")).thenReturn("test"); + List actual = widgetsController + .getOnboardingWidgets(notQuestprincipal, request, response); + + assertNull(actual); + fnUserDao.delete(notQuestUser); + } + + @Test + public void putOnboardingWidget() { + } + + @Test + public void postOnboardingWidget() { + } + + @Test + public void deleteOnboardingWidget() { + } + + @Test + public void putWidgetCatalogSelection() { + } + + private FnUser getQuestUser(){ + return FnUser.builder() + .loginId("questUser") + .loginPwd("demo123") + .lastLoginDate(LocalDateTime.now()) + .activeYn(true) + .createdDate(LocalDateTime.now()) + .modifiedDate(LocalDateTime.now()) + .isInternalYn(true) + .languageId(language) + .guest(true) + .build(); + } + + private FnUser getNotQuestUser(){ + return FnUser.builder() + .loginId("notQuestUser") + .loginPwd("demo123") + .lastLoginDate(LocalDateTime.now()) + .activeYn(true) + .createdDate(LocalDateTime.now()) + .modifiedDate(LocalDateTime.now()) + .isInternalYn(true) + .languageId(language) + .guest(false) + .build(); + } + + private FnLanguage getFnLanguage(){ + return FnLanguage.builder().languageName("Polish").languageAlias("Pl").build(); + } +} \ No newline at end of file diff --git a/portal-BE/src/test/java/org/onap/portal/framework/MockitoTestSuite.java b/portal-BE/src/test/java/org/onap/portal/framework/MockitoTestSuite.java new file mode 100644 index 00000000..e2da10ce --- /dev/null +++ b/portal-BE/src/test/java/org/onap/portal/framework/MockitoTestSuite.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.portal.framework; + +import static org.mockito.Mockito.when; + +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class MockitoTestSuite { + + + public MockHttpServletRequestWrapper mockedRequest = new MockHttpServletRequestWrapper( + Mockito.mock(HttpServletRequest.class)); + public HttpServletResponse mockedResponse = Mockito.mock(HttpServletResponse.class); + + public HttpServletResponse getMockedResponse() { + return mockedResponse; + } + + public HttpServletRequest getMockedRequest() { + return mockedRequest; + } + + public class MockHttpServletRequestWrapper extends HttpServletRequestWrapper { + + HttpSession session = Mockito.mock(HttpSession.class); + + public MockHttpServletRequestWrapper(HttpServletRequest request) { + super(request); + } + + @Override + public HttpSession getSession() { + + return session; + } + + @Override + public HttpSession getSession(boolean create) { + + return session; + } + + } + + @Test + public void test() { + assert (true); + } +} diff --git a/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java b/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java index 41910dad..4f960b46 100644 --- a/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java +++ b/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java @@ -51,7 +51,6 @@ import org.junit.runner.RunWith; import org.onap.portal.domain.db.fn.FnLanguage; import org.onap.portal.domain.db.fn.FnLuTimezone; import org.onap.portal.domain.db.fn.FnUser; -import org.onap.portal.domain.builder.FnUserBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -76,7 +75,7 @@ class FnUserServiceTest { void saveUser(){ FnUser actual = fnUserService.getUser(1L).get(); - FnUser expected = new FnUserBuilder().createFnUser(); + FnUser expected = FnUser.builder().build(); expected.setUserId(123L); expected.setFirstName("Demo"); expected.setLastName("User"); @@ -86,17 +85,17 @@ class FnUserServiceTest { expected.setLoginId("demo"); expected.setLoginPwd("demo123"); expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17")); - expected.setActiveYn("Y"); + expected.setActiveYn(true); expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00")); expected.setModifiedId(actual); expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17")); - expected.setIsInternalYn("N"); + expected.setIsInternalYn(false); expected.setStateCd("NJ"); expected.setCountryCd("US"); expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage())); - + expected.setGuest(false); fnUserService.saveFnUser(principal, expected); - + System.out.println(expected.getActiveYn()); //Clean up fnUserService.deleteUser(expected); } @@ -106,7 +105,7 @@ class FnUserServiceTest { FnUser actual = fnUserService.getUser(1L).get(); - FnUser expected = new FnUserBuilder().createFnUser(); + FnUser expected = FnUser.builder().build(); expected.setUserId(1L); expected.setFirstName("Demo"); expected.setLastName("User"); @@ -115,11 +114,11 @@ class FnUserServiceTest { expected.setLoginId("demo"); expected.setLoginPwd("demo123"); expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17")); - expected.setActiveYn("Y"); + expected.setActiveYn(true); expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00")); expected.setModifiedId(actual); expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17")); - expected.setIsInternalYn("N"); + expected.setIsInternalYn(false); expected.setStateCd("NJ"); expected.setCountryCd("US"); expected.setTimezone(fnLuTimezoneService.getById(10L).orElse(new FnLuTimezone())); -- cgit 1.2.3-korg