updating test cases for more coverage
[dmaap/kafka11aaf.git] / src / test / java / org / onap / dmaap / commonauth / kafka / base / authorization / Cadi3AAFProviderTest.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
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
11 *  
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=========================================================
18  *  
19  *  
20  *******************************************************************************/
21 package org.onap.dmaap.commonauth.kafka.base.authorization;
22
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;
27
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.AAFPermission;
35 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;
36 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
37 import org.onap.aaf.cadi.aaf.v2_0.AbsAAFLur;
38 import org.powermock.core.classloader.annotations.PowerMockIgnore;
39 import org.powermock.modules.junit4.PowerMockRunner;
40
41
42 @RunWith(PowerMockRunner.class)
43 @PowerMockIgnore("javax.net.ssl.*")
44 public class Cadi3AAFProviderTest {
45
46         public Cadi3AAFProvider cadi3AAFProvider;
47
48         @Mock
49         private static AAFAuthn<?> aafAuthn;
50         
51         @Mock
52         private static AAFConHttp aafCon;
53         
54         @Mock
55         private static AbsAAFLur<AAFPermission> aafLur;
56
57         @Mock
58         private static PropAccess access;
59
60         @Before
61         public void setUp() throws Exception {
62                 MockitoAnnotations.initMocks(this);
63         }
64
65         @Test
66         public void testHasPermission() {
67                 System.setProperty("CADI_PROPERTIES", "src/test/resources/cadi.properties");
68                 cadi3AAFProvider = new Cadi3AAFProvider();
69                 assertFalse(cadi3AAFProvider.hasPermission("userID", "permission", "instance", "action"));
70         }
71
72         @Test
73         public void testHasAdminPermission() {
74                 System.setProperty("CADI_PROPERTIES", "src/test/resources/cadi.properties");
75                 cadi3AAFProvider = new Cadi3AAFProvider();
76                 assertEquals(cadi3AAFProvider.hasPermission("admin", "permission", "instance", "action"), true);
77         }
78         
79         @Test(expected = NullPointerException.class)
80         public void tesAuthenticate() throws Exception {
81                 System.setProperty("CADI_PROPERTIES", "src/test/resources/cadi.properties");
82                 cadi3AAFProvider = new Cadi3AAFProvider();
83                 when(aafAuthn.validate("userId", "password")).thenReturn("valid");
84                 assertEquals(cadi3AAFProvider.authenticate("userId", "password"), "valid");
85         }
86
87         @Test
88         public void tesAuthenticateadmin() throws Exception {
89                 System.setProperty("CADI_PROPERTIES", "src/test/resources/cadi.properties");
90                 cadi3AAFProvider = new Cadi3AAFProvider();
91                 when(aafAuthn.validate("admin", "password")).thenReturn("valid");
92                 assertNull(cadi3AAFProvider.authenticate("admin", "password"));
93         }
94         
95 }