Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / user / UserAdminValidatorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  * Modifications copyright (c) 2019 Nokia
20  * ================================================================================
21  */
22
23 package org.openecomp.sdc.be.user;
24
25 import org.hamcrest.core.IsNull;
26 import org.junit.Test;
27
28 import static org.hamcrest.core.Is.is;
29 import static org.junit.Assert.assertThat;
30
31 public class UserAdminValidatorTest {
32
33         @Test
34         public void testGetInstance() {
35                 UserAdminValidator result = createTestSubject();
36                 assertThat(result, is(IsNull.notNullValue()));
37         }
38
39         @Test
40         public void testShouldValidateCorrectEmail() {
41                 UserAdminValidator validator = createTestSubject();
42                 String email = "test@test.com";
43                 boolean result = validator.validateEmail(email);
44                 assertThat(result, is(true));
45         }
46
47         @Test
48         public void testShouldNotValidateEmailWithoutAt() {
49                 UserAdminValidator validator = createTestSubject();
50                 String email = "test#test.com";
51                 boolean result = validator.validateEmail(email);
52                 assertThat(result, is(false));
53         }
54
55         @Test
56         public void testShouldNotValidateEmailWithoutDomainSuffix() {
57                 UserAdminValidator validator = createTestSubject();
58                 String email = "test@test";
59                 boolean result = validator.validateEmail(email);
60                 assertThat(result, is(false));
61         }
62
63         @Test
64         public void testShouldNotValidateEmailWithoutPrefix() {
65                 UserAdminValidator validator = createTestSubject();
66                 String email = "@test.com";
67                 boolean result = validator.validateEmail(email);
68                 assertThat(result, is(false));
69         }
70
71         @Test
72         public void testShouldValidateUserId() {
73                 UserAdminValidator testSubject = createTestSubject();
74                 String userId = "User";
75                 boolean result = testSubject.validateUserId(userId);
76                 assertThat(result, is(true));
77         }
78
79         @Test
80         public void testShouldNotValidateUserIdLongerThan25Characters() {
81                 UserAdminValidator testSubject = createTestSubject();
82                 String userId = "User1user2user3user4user5toLong";
83                 boolean result = testSubject.validateUserId(userId);
84                 assertThat(result, is(false));
85         }
86
87         @Test
88         public void testShouldNotValidateUserIdWithMulipleWords() {
89                 UserAdminValidator testSubject = createTestSubject();
90                 String userId = "User 1";
91                 boolean result = testSubject.validateUserId(userId);
92                 assertThat(result, is(false));
93         }
94
95         @Test
96         public void testShouldNotValidateEmptyUserId() {
97                 UserAdminValidator testSubject = createTestSubject();
98                 String userId = "";
99                 boolean result = testSubject.validateUserId(userId);
100                 assertThat(result, is(false));
101         }
102
103         @Test
104         public void testValidateCorrectRole() {
105                 UserAdminValidator testSubject = createTestSubject();
106                 String role = "ADMIN";
107                 boolean result = testSubject.validateRole(role);
108                 assertThat(result, is(true));
109         }
110
111         @Test
112         public void testValidateIncorrectRole() {
113                 UserAdminValidator testSubject = createTestSubject();
114                 String role = "DEVELOPER";
115                 boolean result = testSubject.validateRole(role);
116                 assertThat(result, is(false));
117         }
118
119         private UserAdminValidator createTestSubject() {
120                 return UserAdminValidator.getInstance();
121         }
122
123 }