1 /*******************************************************************************
2 * ============LICENSE_START====================================================
4 * * ===========================================================================
5 * * Copyright © 2017 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
11 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 ******************************************************************************/
23 package org.onap.aaf.cadi.aaf.test;
25 import static org.junit.Assert.*;
27 import java.util.ArrayList;
28 import java.util.List;
30 import static org.hamcrest.CoreMatchers.*;
32 import org.onap.aaf.cadi.Permission;
33 import org.onap.aaf.cadi.aaf.AAFPermission;
35 public class JU_AAFPermission {
37 private final static String type = "type";
38 private final static String instance = "instance";
39 private final static String action = "action";
40 private final static String key = type + '|' + instance + '|' + action;
41 private final static String role = "role";
43 private static List<String> roles;
47 roles = new ArrayList<String>();
52 public void constructor1Test() {
53 AAFPermission perm = new AAFPermission(type, instance, action);
54 assertThat(perm.getName(), is(type));
55 assertThat(perm.getInstance(), is(instance));
56 assertThat(perm.getAction(), is(action));
57 assertThat(perm.getKey(), is(key));
58 assertThat(perm.permType(), is("AAF"));
59 assertThat(perm.roles().size(), is(0));
60 assertThat(perm.toString(), is("AAFPermission:\n\tType: " + type +
61 "\n\tInstance: " + instance +
62 "\n\tAction: " + action +
67 public void constructor2Test() {
70 perm = new AAFPermission(type, instance, action, null);
71 assertThat(perm.getName(), is(type));
72 assertThat(perm.getInstance(), is(instance));
73 assertThat(perm.getAction(), is(action));
74 assertThat(perm.getKey(), is(key));
75 assertThat(perm.permType(), is("AAF"));
76 assertThat(perm.roles().size(), is(0));
77 assertThat(perm.toString(), is("AAFPermission:\n\tType: " + type +
78 "\n\tInstance: " + instance +
79 "\n\tAction: " + action +
82 perm = new AAFPermission(type, instance, action, roles);
83 assertThat(perm.getName(), is(type));
84 assertThat(perm.getInstance(), is(instance));
85 assertThat(perm.getAction(), is(action));
86 assertThat(perm.getKey(), is(key));
87 assertThat(perm.permType(), is("AAF"));
88 assertThat(perm.roles().size(), is(1));
89 assertThat(perm.roles().get(0), is(role));
90 assertThat(perm.toString(), is("AAFPermission:\n\tType: " + type +
91 "\n\tInstance: " + instance +
92 "\n\tAction: " + action +
97 public void matchTest() {
98 final AAFPermission controlPermission = new AAFPermission(type, instance, action);
100 AAFPermission aafperm;
102 aafperm = new AAFPermission(type, instance, action);
103 assertThat(controlPermission.match(aafperm), is(true));
105 perm = new PermissionStub(key);
106 assertThat(controlPermission.match(perm), is(true));
109 perm = new PermissionStub("not a valid key");
110 assertThat(controlPermission.match(perm), is(false));
111 perm = new PermissionStub("type");
112 assertThat(controlPermission.match(perm), is(false));
113 perm = new PermissionStub("type|instance|badAction");
114 assertThat(controlPermission.match(perm), is(false));
118 public void coverageTest() {
119 AAFPermissionStub aafps = new AAFPermissionStub();
120 assertThat(aafps.getName(), is(nullValue()));
121 assertThat(aafps.getInstance(), is(nullValue()));
122 assertThat(aafps.getAction(), is(nullValue()));
123 assertThat(aafps.getKey(), is(nullValue()));
124 assertThat(aafps.permType(), is("AAF"));
125 assertThat(aafps.roles().size(), is(0));
128 private class PermissionStub implements Permission {
131 public PermissionStub(String key) { this.key = key; }
132 @Override public String permType() { return null; }
133 @Override public String getKey() { return key; }
134 @Override public boolean match(Permission p) { return false; }
137 private class AAFPermissionStub extends AAFPermission {