2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia 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 package org.onap.dmaap.dbcapi.authentication;
23 import org.junit.Test;
24 import org.onap.dmaap.dbcapi.aaf.DmaapPerm;
26 import java.util.Properties;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertTrue;
31 public class ApiPolicyTest {
33 private Properties properties = new Properties();
34 private ApiPolicy apiPolicy;
37 public void check_shouldExecuteAuthorizationApi() throws Exception {
38 properties.put("ApiPermission.Class", "org.onap.dmaap.dbcapi.authentication.ApiPolicyTest$DummyApiAuthorization");
39 apiPolicy = new ApiPolicy(properties);
41 apiPolicy.check("mechId", "pwd", new DmaapPerm("api.perm", "*", "GET"));
43 assertTrue(((DummyApiAuthorization) apiPolicy.getPerm()).isCheckExecuted());
47 public void isPermissionClassSet_shouldReturnTrueForValidApiPermClass() {
48 properties.put("ApiPermission.Class", "org.onap.dmaap.dbcapi.authentication.ApiPolicyTest$DummyApiAuthorization");
49 apiPolicy = new ApiPolicy(properties);
51 assertTrue(apiPolicy.isPermissionClassSet());
55 public void isPermissionClassSet_shouldReturnFalseWhenPropertyIsNotSet() {
56 apiPolicy = new ApiPolicy(properties);
58 assertFalse(apiPolicy.isPermissionClassSet());
62 public void isPermissionClassSet_shouldReturnFalseWhenWrongClassIsSet() {
63 properties.put("ApiPermission.Class", "org.onap.dmaap.dbcapi.authentication.NotExisting");
64 apiPolicy = new ApiPolicy(properties);
66 assertFalse(apiPolicy.isPermissionClassSet());
69 public static class DummyApiAuthorization implements ApiAuthorizationCheckInterface {
71 private boolean checkExecuted = false;
74 public void check(String mechid, String pwd, DmaapPerm p) {
78 boolean isCheckExecuted() {