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 static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
26 import java.util.Properties;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.dmaap.dbcapi.aaf.DmaapPerm;
31 public class ApiPolicyTest {
33 private Properties properties = new Properties();
34 private ApiPolicy apiPolicy;
37 public void setUp() throws Exception {
38 System.setProperty("ConfigFile", "src/test/resources/dmaapbc.properties");
42 public void check_shouldExecuteAuthorizationApi() throws Exception {
43 properties.put("ApiPermission.Class", "org.onap.dmaap.dbcapi.authentication.ApiPolicyTest$DummyApiAuthorization");
44 apiPolicy = new ApiPolicy(properties);
46 apiPolicy.check("mechId", "pwd", new DmaapPerm("api.perm", "*", "GET"));
48 assertTrue(((DummyApiAuthorization) apiPolicy.getPerm()).isCheckExecuted());
52 public void isPermissionClassSet_shouldReturnTrueForValidApiPermClass() {
53 properties.put("ApiPermission.Class", "org.onap.dmaap.dbcapi.authentication.ApiPolicyTest$DummyApiAuthorization");
54 apiPolicy = new ApiPolicy(properties);
56 assertTrue(apiPolicy.isPermissionClassSet());
60 public void isPermissionClassSet_shouldReturnFalseWhenPropertyIsNotSet() {
61 apiPolicy = new ApiPolicy(properties);
63 assertFalse(apiPolicy.isPermissionClassSet());
67 public void isPermissionClassSet_shouldReturnFalseWhenWrongClassIsSet() {
68 properties.put("ApiPermission.Class", "org.onap.dmaap.dbcapi.authentication.NotExisting");
69 apiPolicy = new ApiPolicy(properties);
71 assertFalse(apiPolicy.isPermissionClassSet());
74 public static class DummyApiAuthorization implements ApiAuthorizationCheckInterface {
76 private boolean checkExecuted = false;
79 public void check(String mechid, String pwd, DmaapPerm p) {
83 boolean isCheckExecuted() {