summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2022-06-23 14:33:49 +0200
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>2022-06-23 14:33:49 +0200
commit388a40537831e61e3db987b50b4be144491e9ab5 (patch)
treeffe6b7133234ac956a9e12ab7cff55f7337ccf7e
parent366a173f798422b956625aa83d81fc863e0914a5 (diff)
add junit coverage
Issue-ID: SO-3796 Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com> Change-Id: Ife3fe722b654eaaf31eda734ec73910d0c11530a
-rw-r--r--common/src/test/java/org/onap/so/security/UserDetailsServiceImplTest.java45
1 files changed, 45 insertions, 0 deletions
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<UserCredentials> prepareUserCredentials() {
+ UserCredentials userCredentials = new UserCredentials();
+ userCredentials.setUsername(USERNAME);
+ userCredentials.setPassword(PASSWORD);
+ userCredentials.setRole(ROLE);
+ List<UserCredentials> list = new ArrayList<>();
+ list.add(userCredentials);
+ return list;
+ }
+
+
+}