Convert Sparky to Spring-Boot
[aai/sparky-be.git] / sparkybe-onap-service / src / test / java / org / onap / aai / sparky / editattributes / TestUserAuthorizationReader.java
1 /**
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25
26 package org.onap.aai.sparky.editattributes;
27
28 import static org.hamcrest.Matchers.containsInAnyOrder;
29 import static org.hamcrest.Matchers.empty;
30 import static org.junit.Assert.assertThat;
31
32 import java.io.File;
33 import java.nio.file.Paths;
34 import java.util.List;
35
36 import org.junit.BeforeClass;
37 import org.junit.Test;
38 import org.onap.aai.sparky.editattributes.UserAuthorizationReader;
39
40 /**
41  * The Class TestUserAuthorizationReader.
42  */
43 public class TestUserAuthorizationReader {
44
45   private static File userAuthFile;
46   private static File userAuthFileEmpty;
47
48   /**
49    * Sets the up before class.
50    *
51    * @throws Exception the exception
52    */
53   @BeforeClass
54   public static void setUpBeforeClass() throws Exception {
55     userAuthFile = Paths.get(TestData.USER_AUTH_FILE.getFilename()).toFile();
56     userAuthFileEmpty = Paths.get(TestData.USER_AUTH_FILE_EMPTY.getFilename()).toFile();
57   }
58
59   /**
60    * The Enum TestData.
61    */
62   enum TestData {
63     // @formatter:off
64     USER_AUTH_FILE(
65         "src/test/resources/user-auth-reader/authorized-users.config"), USER_AUTH_FILE_EMPTY(
66             "src/test/resources/user-auth-reader/authorized-users-empty.config");
67
68     private String filename;
69
70     /**
71      * Instantiates a new test data.
72      *
73      * @param filename the filename
74      */
75     TestData(String filename) {
76       this.filename = filename;
77     }
78
79     public String getFilename() {
80       return this.filename;
81     }
82     // @formatter:on
83   }
84
85   /**
86    * Test get users.
87    *
88    * @throws Exception the exception
89    */
90   @Test
91   public void testGetUsers() throws Exception {
92     UserAuthorizationReader userAuthorizationReader = new UserAuthorizationReader(userAuthFile);
93
94     // Method under test
95     List<String> userList = userAuthorizationReader.getUsers();
96
97     assertThat(userList, containsInAnyOrder("user1", "user2 user3", "user4"));
98   }
99
100   /**
101    * Test get users passing empty config.
102    *
103    * @throws Exception the exception
104    */
105   @Test
106   public void testGetUsersPassingEmptyConfig() throws Exception {
107     UserAuthorizationReader userConfigReader = new UserAuthorizationReader(userAuthFileEmpty);
108
109     List<String> userList = userConfigReader.getUsers();
110
111     assertThat(userList, empty());
112   }
113 }