summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoop Talasila <talasila@research.att.com>2019-08-28 18:53:02 +0000
committerGerrit Code Review <gerrit@onap.org>2019-08-28 18:53:02 +0000
commit2c5ca045a19a247f240c13fc1ffff8df577b4c46 (patch)
tree2b6977ec76dcc0675123cb0aff6a550a0d1df904
parent012d8970a7e08b2397b7b90d0a293118e254b021 (diff)
parente977510f26b63b1955bae683bbf348dbbc157f80 (diff)
Merge "Tests Coverage up"
-rw-r--r--portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java10
-rw-r--r--portal-BE/src/main/java/org/onap/portal/controller/UserController.java2
-rw-r--r--portal-BE/src/main/java/org/onap/portal/dao/fn/FnUserDao.java9
-rw-r--r--portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java21
-rw-r--r--portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java25
-rw-r--r--portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java46
-rw-r--r--portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java44
-rw-r--r--portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java21
8 files changed, 141 insertions, 37 deletions
diff --git a/portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java b/portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java
index 8f2e50e6..90ea0680 100644
--- a/portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java
+++ b/portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java
@@ -107,7 +107,7 @@ public class LanguageController {
response.setStatus(PortalRestStatusEnum.OK);
} else {
response.setMessage("FAILURE");
- response.setResponse("User for id:" + userId + " do not exist");
+ response.setResponse("User for id: " + userId + " do not exist");
response.setStatus(PortalRestStatusEnum.ERROR);
}
} catch (Exception e) {
@@ -120,11 +120,11 @@ public class LanguageController {
}
@GetMapping(value = "/languageSetting/user/{loginId}", produces = MediaType.APPLICATION_JSON_VALUE)
- public FnLanguage getUserLanguage(@PathVariable("loginId") final Long loginId) {
- if (fnUserService.getUser(loginId).isPresent()) {
- return Optional.of(fnUserService.getUser(loginId).get().getLanguageId()).orElse(new FnLanguage());
+ public FnLanguageDto getUserLanguage(final Principal principal, @PathVariable("loginId") final Long loginId) {
+ if (fnUserService.existById(loginId)) {
+ return fnLanguageMapper.fnLanguageToDto(Optional.of(fnUserService.getUser(loginId).get().getLanguageId()).orElse(new FnLanguage()));
}
- return new FnLanguage();
+ return new FnLanguageDto();
}
@PostMapping(value = "/language", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
diff --git a/portal-BE/src/main/java/org/onap/portal/controller/UserController.java b/portal-BE/src/main/java/org/onap/portal/controller/UserController.java
index d514dfae..d339e455 100644
--- a/portal-BE/src/main/java/org/onap/portal/controller/UserController.java
+++ b/portal-BE/src/main/java/org/onap/portal/controller/UserController.java
@@ -111,7 +111,7 @@ public class UserController {
user.setMiddleName(profileDetail.getMiddleName());
user.setLoginId(profileDetail.getLoginId());
if (!HIDDEN_DEFAULT_PASSWORD.equals(profileDetail.getLoginPassword())) {
- user.setLoginPwd(CipherUtil.encryptPKC(profileDetail.getLoginPassword()));
+ user.setLoginPwd(CipherUtil.encryptPKC(profileDetail.getLoginPassword(), "AGLDdG4D04BKm2IxIWEr8o==!"));
}
userService.saveFnUser(principal, user);
// Update user info in the session
diff --git a/portal-BE/src/main/java/org/onap/portal/dao/fn/FnUserDao.java b/portal-BE/src/main/java/org/onap/portal/dao/fn/FnUserDao.java
index 458cc669..8dbfb70f 100644
--- a/portal-BE/src/main/java/org/onap/portal/dao/fn/FnUserDao.java
+++ b/portal-BE/src/main/java/org/onap/portal/dao/fn/FnUserDao.java
@@ -58,5 +58,12 @@ public interface FnUserDao extends JpaRepository<FnUser, Long> {
FnUser getOne(Long integer);
@Query
- Optional<List<FnUser>> getUsersByOrgUserId(@Param("orgIds") String orgIds);
+ Optional<List<FnUser>> getUserWithOrgUserId(final @Param("orgId") String orgId);
+
+ @Query
+ Optional<List<FnUser>> getUsersByOrgIds(final @Param("orgIds") List<String> orgIds);
+
+ @Query
+ Optional<List<FnUser>> getActiveUsers();
+
}
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 cbca44c1..1399dd5c 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
@@ -43,7 +43,6 @@ package org.onap.portal.domain.db.fn;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Set;
-import java.util.UUID;
import java.util.stream.Collectors;
import javax.persistence.CascadeType;
import javax.persistence.Column;
@@ -58,6 +57,8 @@ import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@@ -72,7 +73,6 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicUpdate;
-import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.SafeHtml;
import org.onap.portal.domain.db.cr.CrReportFileHistory;
import org.onap.portal.domain.db.ep.EpPersUserWidgetPlacement;
@@ -148,13 +148,18 @@ CREATE TABLE `fn_user` (
)
*/
-@NamedNativeQueries({
- @NamedNativeQuery(
- name = "getUsersByOrgUserId",
- query = "SELECT * FROM FnUser WHERE where org_user_id in :orgIds"
+@NamedQueries({
+ @NamedQuery(
+ name = "FnUser.getUserWithOrgUserId",
+ query = "FROM FnUser WHERE orgUserId = :orgId"),
+ @NamedQuery(
+ name = "FnUser.getActiveUsers",
+ query = "FROM FnUser WHERE activeYn = 'Y'"),
+ @NamedQuery(
+ name = "FnUser.getUsersByOrgIds",
+ query = "FROM FnUser WHERE orgUserId IN :orgIds"
)
})
-
@Table(name = "fn_user", indexes = {
@Index(name = "fn_user_address_id", columnList = "address_id"),
@Index(name = "fn_user_alert_method_cd", columnList = "alert_method_cd"),
@@ -350,7 +355,7 @@ public class FnUser implements UserDetails {
private boolean guest;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList")
private Set<CrReportFileHistory> crReportFileHistorie;
- @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<FnRole> fnRoles;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<FnMenuFunctional> fnRoleList;
diff --git a/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java b/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java
index aedac493..8c5806ea 100644
--- a/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java
+++ b/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java
@@ -59,7 +59,7 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional
public class FnUserService implements UserDetailsService {
- private final FnUserDao fnUserDao;
+ private FnUserDao fnUserDao;
@Autowired
public FnUserService(FnUserDao fnUserDao) {
@@ -71,7 +71,7 @@ public class FnUserService implements UserDetailsService {
}
@Override
- public FnUser loadUserByUsername(String username) throws UsernameNotFoundException {
+ public FnUser loadUserByUsername(final String username) throws UsernameNotFoundException {
Optional<FnUser> fnUser = fnUserDao.findByLoginId(username);
if (fnUser.isPresent()) {
return fnUser.get();
@@ -80,36 +80,29 @@ public class FnUserService implements UserDetailsService {
}
}
- public Optional<FnUser> getUser(Long id) {
+ public Optional<FnUser> getUser(final Long id) {
return Optional.of(fnUserDao.getOne(id));
}
List<FnUser> getUserWithOrgUserId(final String orgUserIdValue){
- Optional<List<FnUser>> fnUsers = Optional.of(fnUserDao.findAll()
- .stream()
- .filter(fnUser -> orgUserIdValue.equals(fnUser.getOrgUserId()))
- .collect(Collectors.toList()));
- return fnUsers.orElse(new ArrayList<>());
+ return fnUserDao.getUserWithOrgUserId(orgUserIdValue).orElse(new ArrayList<>());
}
- List<FnUser> getUsersByOrgIdsNotificationsResult(List<String> orgIds){
+ List<FnUser> getUsersByOrgIds(final List<String> orgIds){
String ids = "(" + orgIds.stream().map(s -> "'" + s + "'").collect(Collectors.joining()) + ")";
- return fnUserDao.getUsersByOrgUserId(ids).orElse(new ArrayList<>());
+ return fnUserDao.getUsersByOrgIds(orgIds).orElse(new ArrayList<>());
}
- List<FnUser> getUsersByOrgIdsNotificationsResult(String orgIds){
- return fnUserDao.getUsersByOrgUserId(orgIds).orElse(new ArrayList<>());
- }
List<FnUser> getActiveUsers(){
- return fnUserDao.findAll().stream().filter(fnUser -> "Y".equals(fnUser.getActiveYn())).collect(Collectors.toList());
+ return fnUserDao.getActiveUsers().orElse(new ArrayList<>());
}
- public void deleteUser(FnUser fnUser){
+ public void deleteUser(final FnUser fnUser){
fnUserDao.delete(fnUser);
}
- public boolean existById(Long userId) {
+ public boolean existById(final Long userId) {
return fnUserDao.existsById(userId);
}
}
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 0f9f09ad..0977f286 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
@@ -41,6 +41,7 @@
package org.onap.portal.controller;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
@@ -49,6 +50,7 @@ import org.onap.portal.domain.db.fn.FnLanguage;
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.fn.FnLanguageDto;
import org.onap.portal.service.fn.FnUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -139,6 +141,50 @@ class LanguageControllerTest {
fnLanguageDao.delete(fnLanguage);
}
+ @Test
+ void setUpUserLanguageWrongUserId(){
+ //Given
+ FnLanguage fnLanguage = new FnLanguage();
+ fnLanguage.setLanguageName("Polish");
+ fnLanguage.setLanguageAlias("PL");
+
+ PortalRestResponse<String> expected = new PortalRestResponse<>();
+ expected.setMessage("FAILURE");
+ expected.setStatus(PortalRestStatusEnum.ERROR);
+ expected.setResponse("User for id: 345 do not exist");
+
+ languageController.saveLanguage(principal, fnLanguage);
+ PortalRestResponse<String> actual = languageController.setUpUserLanguage(principal, fnLanguage, 345L);
+
+ assertEquals(expected.getMessage(), actual.getMessage());
+ assertEquals(expected.getStatus(), actual.getStatus());
+ assertEquals(expected.getResponse(), actual.getResponse());
+ //Clean up
+ fnLanguageDao.delete(fnLanguage);
+ }
+
+
+ @Test
+ void getUserLanguage() {
+ FnLanguageDto expected = new FnLanguageDto();
+ expected.setLanguageAlias("EN");
+ expected.setLanguageName("English");
+
+ FnLanguageDto actual = languageController.getUserLanguage(principal, 1L);
+
+ assertEquals(expected.getLanguageAlias(), actual.getLanguageAlias());
+ assertEquals(expected.getLanguageName(), actual.getLanguageName());
+ }
+
+ @Test
+ void getUserLanguageNotExistingUser() {
+ FnLanguageDto expected = new FnLanguageDto();
+
+ FnLanguageDto actual = languageController.getUserLanguage(principal, 456L);
+
+ assertNull(actual.getLanguageAlias());
+ assertNull(actual.getLanguageName());
+ }
} \ No newline at end of file
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 b216799f..e3f1f7be 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
@@ -39,13 +39,17 @@
package org.onap.portal.controller;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import lombok.AllArgsConstructor;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
+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.ProfileDetail;
+import org.onap.portal.service.fn.FnUserService;
+import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
+import org.onap.portalsdk.core.onboarding.util.CipherUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -54,14 +58,18 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
-@TestPropertySource(locations="classpath:test.properties")
+@TestPropertySource(locations = "classpath:test.properties")
class UserControllerTest {
- private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
+ private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
+ "XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
+
+ private final FnUserService userService;
private final UserController userController;
@Autowired
- UserControllerTest(UserController userController) {
+ UserControllerTest(final FnUserService userService, final UserController userController) {
+ this.userService = userService;
this.userController = userController;
}
@@ -73,7 +81,8 @@ class UserControllerTest {
expectedDetails.setEmail("demo@openecomp.org");
expectedDetails.setLoginId("demo");
expectedDetails.setLoginPassword("*****");
- PortalRestResponse<ProfileDetail> expected = new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", expectedDetails);
+ PortalRestResponse<ProfileDetail> expected = new PortalRestResponse<>(PortalRestStatusEnum.OK, "success",
+ expectedDetails);
PortalRestResponse<ProfileDetail> actual = userController.getLoggedinUser(principal);
@@ -92,7 +101,8 @@ class UserControllerTest {
expectedDetails.setLoginPassword("*****");
PortalRestResponse<String> actual = userController.modifyLoggedinUser(principal, expectedDetails);
- PortalRestResponse<String> expected = new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "lastName must not be blank", null);
+ PortalRestResponse<String> expected = new PortalRestResponse<>(PortalRestStatusEnum.ERROR,
+ "lastName must not be blank", null);
assertEquals(expected, actual);
}
@@ -109,4 +119,26 @@ class UserControllerTest {
PortalRestResponse<String> expected = new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", null);
assertEquals(expected, actual);
}
+
+ @Test
+ void modifyLoggedinUserChangePassword() throws CipherUtilException {
+ ProfileDetail expectedDetails = new ProfileDetail();
+ expectedDetails.setFirstName("Demo");
+ expectedDetails.setLastName("User");
+ expectedDetails.setEmail("demo@openecomp.org");
+ expectedDetails.setLoginId("demo");
+ expectedDetails.setLoginPassword("123password");
+
+ FnUser user = userService.loadUserByUsername(principal.getName());
+ String oldPassword = user.getLoginPwd();
+
+ PortalRestResponse<String> actual = userController.modifyLoggedinUser(principal, expectedDetails);
+ PortalRestResponse<String> expected = new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", null);
+
+ FnUser user2 = userService.loadUserByUsername(principal.getName());
+ String newPassword = user2.getLoginPwd();
+
+ assertEquals(expected, actual);
+ assertNotEquals(oldPassword, newPassword);
+ }
} \ No newline at end of file
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 3f242fb4..26731eac 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
@@ -43,6 +43,10 @@ package org.onap.portal.service.fn;
import static org.junit.jupiter.api.Assertions.*;
import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.onap.portal.domain.db.fn.FnLanguage;
@@ -167,4 +171,21 @@ class FnUserServiceTest {
assertEquals(expected.getSiloStatus(), actual.getSiloStatus());
assertEquals(expected.getLanguageId(), actual.getLanguageId());
}
+
+ @Test
+ void getActiveUsers() {
+ assertEquals(12, fnUserService.getActiveUsers().size());
+ }
+
+ @Test
+ void getUserWithOrgUserId() {
+ assertEquals(1, fnUserService.getUserWithOrgUserId("cs0008").size());
+ }
+
+ @Test
+ void getUserWithOrgUserIds() {
+ List<String> ids = new ArrayList<>(Arrays.asList("cs0008", "op0001"));
+ assertEquals(2, fnUserService.getUsersByOrgIds(ids).size());
+ }
+
} \ No newline at end of file