[DMAAP-KAFKA] Release image 1.1.0
[dmaap/kafka11aaf.git] / src / test / java / org / onap / dmaap / kafkaAuthorize / PlainLoginModule1Test.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
4  *  ================================================================================
5  *  Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  *  Modification copyright (C) 2021 Nordix Foundation.
7  *  ================================================================================
8  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  you may not use this file except in compliance with the License.
10  *  You may obtain a copy of the License at
11  *        http://www.apache.org/licenses/LICENSE-2.0
12 *  
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=========================================================
19  *  
20  *  
21  *******************************************************************************/
22 package org.onap.dmaap.kafkaAuthorize;
23
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.Map;
28 import javax.security.auth.Subject;
29 import javax.security.auth.callback.CallbackHandler;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.powermock.api.mockito.PowerMockito;
35 import org.powermock.core.classloader.annotations.PowerMockIgnore;
36 import org.powermock.core.classloader.annotations.PrepareForTest;
37
38 @PowerMockIgnore({"jdk.internal.reflect.*"})
39 @PrepareForTest({ PlainLoginModule1.class })
40 public class PlainLoginModule1Test {
41
42         static PlainLoginModule1 pLogin = new PlainLoginModule1();
43         static Subject subject;
44         @Mock
45         static CallbackHandler callbackHandler;
46
47         @Mock
48         static Map<String, String> mymap1;
49
50         @Mock
51         static Map<String, ?> mymap2;
52
53         @Before
54         public void setUp() {
55                 MockitoAnnotations.initMocks(this);
56                 PowerMockito.when(mymap1.get("username")).thenReturn("user1");
57                 PowerMockito.when(mymap1.get("password")).thenReturn("pass1");
58                 pLogin.initialize(subject, callbackHandler, mymap1, mymap2);
59         }
60
61         @Test
62         public void testLogin() {
63                 assertTrue(pLogin.login());
64         }
65         
66         @Test
67         public void testLogout() {
68                 assertTrue(pLogin.logout());
69         }
70         
71         @Test
72         public void testCommit() {
73                 assertTrue(pLogin.commit());
74         }
75         
76         @Test
77         public void testAbort() {
78                 assertFalse(pLogin.abort());
79         }
80 }