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
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 *******************************************************************************/
21 package org.onap.dmaap.commonauth.kafka.base.authorization;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNull;
26 import static org.mockito.Mockito.when;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.MockitoAnnotations;
33 import org.onap.aaf.cadi.PropAccess;
34 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;
35 import org.powermock.modules.junit4.PowerMockRunner;
37 @RunWith(PowerMockRunner.class)
38 public class Cadi3AAFProviderTest {
40 public Cadi3AAFProvider cadi3AAFProvider;
43 private static AAFAuthn<?> aafAuthn;
46 private static PropAccess access;
49 public void setUp() throws Exception {
50 MockitoAnnotations.initMocks(this);
54 public void testHasPermission() {
55 System.setProperty("CADI_PROPERTIES", "src/test/resources/cadi.properties");
56 cadi3AAFProvider = new Cadi3AAFProvider();
57 assertFalse(cadi3AAFProvider.hasPermission("userID", "permission", "instance", "action"));
60 @Test(expected = NullPointerException.class)
61 public void tesAuthenticate() throws Exception {
62 System.setProperty("CADI_PROPERTIES", "src/test/resources/cadi.properties");
63 cadi3AAFProvider = new Cadi3AAFProvider();
64 when(aafAuthn.validate("userId", "password")).thenReturn("valid");
65 assertEquals(cadi3AAFProvider.authenticate("userId", "password"), "valid");
69 public void tesAuthenticateadmin() throws Exception {
70 System.setProperty("CADI_PROPERTIES", "src/test/resources/cadi.properties");
71 cadi3AAFProvider = new Cadi3AAFProvider();
72 when(aafAuthn.validate("admin", "password")).thenReturn("valid");
73 assertNull(cadi3AAFProvider.authenticate("admin", "password"));