Rework the CldsUserJson
[clamp.git] / src / test / java / org / onap / clamp / clds / config / CldsUserJsonDecoderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 package org.onap.clamp.clds.config;
25
26 import static org.junit.Assert.assertArrayEquals;
27 import static org.junit.Assert.assertEquals;
28
29 import org.junit.Test;
30 import org.onap.clamp.clds.service.CldsUser;
31
32 public class CldsUserJsonDecoderTest {
33     private String   user1                      = "admin1";
34     private String   user2                      = "admin2";
35     private String   password                   = "5f4dcc3b5aa765d61d8327deb882cf99";
36     private String[] normalPermissionsArray     = { "permission-type-cl|dev|read", "permission-type-cl|dev|update",
37             "permission-type-cl-manage|dev|*", "permission-type-filter-vf|dev|*", "permission-type-template|dev|read",
38             "permission-type-template|dev|update" };
39     private String[] incompletePermissionsArray = { "permission-type-cl|dev|*", "permission-type-cl|dev|*",
40             "permission-type-cl-manage|dev|*", "permission-type-filter-vf|dev|*", "permission-type-template|dev|read",
41             "permission-type-template|dev|update" };
42
43     @Test
44     public void testDecodingDoubleUsers() {
45         CldsUser[] usersArray = CldsUserJsonDecoder
46                 .decodeJson(CldsUserJsonDecoderTest.class.getResourceAsStream("/clds/clds-users-two-users.json"));
47         assertEquals(usersArray.length, 2);
48         assertEquals(usersArray[0].getUser(), user1);
49         assertEquals(usersArray[1].getUser(), user2);
50         assertEquals(usersArray[0].getPassword(), password);
51         assertEquals(usersArray[1].getPassword(), password);
52         assertArrayEquals(usersArray[0].getPermissionsString(), normalPermissionsArray);
53         assertArrayEquals(usersArray[1].getPermissionsString(), normalPermissionsArray);
54     }
55
56     @Test
57     public void testDecodingNoPermission() {
58         CldsUser[] usersArray = CldsUserJsonDecoder
59                 .decodeJson(this.getClass().getResourceAsStream("/clds/clds-users-no-permission.json"));
60         assertEquals(usersArray.length, 1);
61         assertEquals(usersArray[0].getUser(), user1);
62         assertEquals(usersArray[0].getPassword(), null);
63         assertArrayEquals(usersArray[0].getPermissionsString(), new String[0]);
64     }
65
66     @Test
67     public void testDecodingIncompletePermissions() {
68         CldsUser[] usersArray = CldsUserJsonDecoder
69                 .decodeJson(this.getClass().getResourceAsStream("/clds/clds-users-incomplete-permissions.json"));
70         assertEquals(usersArray.length, 1);
71         assertEquals(usersArray[0].getUser(), user1);
72         assertEquals(usersArray[0].getPassword(), password);
73         assertArrayEquals(usersArray[0].getPermissionsString(), incompletePermissionsArray);
74     }
75 }