2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.clds.config;
26 import static org.junit.Assert.assertArrayEquals;
27 import static org.junit.Assert.assertEquals;
29 import org.junit.Test;
30 import org.onap.clamp.clds.service.CldsUser;
32 public class CldsUserJsonDecoderTest {
34 private String user1 = "admin1";
35 private String user2 = "admin2";
36 private String password = "5f4dcc3b5aa765d61d8327deb882cf99";
37 private String[] normalPermissionsArray = {
38 "permission-type-cl|dev|read", "permission-type-cl|dev|update", "permission-type-cl-manage|dev|*",
39 "permission-type-filter-vf|dev|*", "permission-type-template|dev|read",
40 "permission-type-template|dev|update"
42 private String[] incompletePermissionsArray = {
43 "permission-type-cl|dev|*", "permission-type-cl|dev|*", "permission-type-cl-manage|dev|*",
44 "permission-type-filter-vf|dev|*", "permission-type-template|dev|read",
45 "permission-type-template|dev|update"
49 public void testDecodingDoubleUsers() {
50 CldsUser[] usersArray = CldsUserJsonDecoder
51 .decodeJson(CldsUserJsonDecoderTest.class.getResourceAsStream("/clds/clds-users-two-users.json"));
52 assertEquals(usersArray.length, 2);
53 assertEquals(usersArray[0].getUser(), user1);
54 assertEquals(usersArray[1].getUser(), user2);
55 assertEquals(usersArray[0].getPassword(), password);
56 assertEquals(usersArray[1].getPassword(), password);
57 assertArrayEquals(usersArray[0].getPermissionsString(), normalPermissionsArray);
58 assertArrayEquals(usersArray[1].getPermissionsString(), normalPermissionsArray);
62 public void testDecodingNoPermission() {
63 CldsUser[] usersArray = CldsUserJsonDecoder
64 .decodeJson(this.getClass().getResourceAsStream("/clds/clds-users-no-permission.json"));
65 assertEquals(usersArray.length, 1);
66 assertEquals(usersArray[0].getUser(), user1);
67 assertEquals(usersArray[0].getPassword(), null);
68 assertArrayEquals(usersArray[0].getPermissionsString(), new String[0]);
72 public void testDecodingIncompletePermissions() {
73 CldsUser[] usersArray = CldsUserJsonDecoder
74 .decodeJson(this.getClass().getResourceAsStream("/clds/clds-users-incomplete-permissions.json"));
75 assertEquals(usersArray.length, 1);
76 assertEquals(usersArray[0].getUser(), user1);
77 assertEquals(usersArray[0].getPassword(), password);
78 assertArrayEquals(usersArray[0].getPermissionsString(), incompletePermissionsArray);