From 388a40537831e61e3db987b50b4be144491e9ab5 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Thu, 23 Jun 2022 14:33:49 +0200 Subject: add junit coverage Issue-ID: SO-3796 Signed-off-by: Lukasz Muszkieta Change-Id: Ife3fe722b654eaaf31eda734ec73910d0c11530a --- .../so/security/UserDetailsServiceImplTest.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 common/src/test/java/org/onap/so/security/UserDetailsServiceImplTest.java diff --git a/common/src/test/java/org/onap/so/security/UserDetailsServiceImplTest.java b/common/src/test/java/org/onap/so/security/UserDetailsServiceImplTest.java new file mode 100644 index 0000000000..51de61a66a --- /dev/null +++ b/common/src/test/java/org/onap/so/security/UserDetailsServiceImplTest.java @@ -0,0 +1,45 @@ +package org.onap.so.security; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.util.ArrayList; +import org.junit.Test; +import java.util.List; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; + +public class UserDetailsServiceImplTest { + + private static final String USERNAME = "usernameTest"; + private static final String PASSWORD = "passTest"; + private static final String ROLE = "roleTest"; + + @Test + public void loadUserByUsername_Success() { + UserDetailsServiceImpl testedObject = new UserDetailsServiceImpl(); + testedObject.setUsercredentials(prepareUserCredentials()); + UserDetails result = testedObject.loadUserByUsername(USERNAME); + assertThat(result.getUsername()).isEqualTo(USERNAME); + assertThat(result.getPassword()).isEqualTo(PASSWORD); + } + + @Test + public void loadUserByUsername_userNotFoundEx() { + UserDetailsServiceImpl testedObject = new UserDetailsServiceImpl(); + testedObject.setUsercredentials(prepareUserCredentials()); + assertThatThrownBy(() -> testedObject.loadUserByUsername("notExistingUser")) + .isInstanceOf(UsernameNotFoundException.class); + } + + private List prepareUserCredentials() { + UserCredentials userCredentials = new UserCredentials(); + userCredentials.setUsername(USERNAME); + userCredentials.setPassword(PASSWORD); + userCredentials.setRole(ROLE); + List list = new ArrayList<>(); + list.add(userCredentials); + return list; + } + + +} -- cgit 1.2.3-korg