1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
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
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 *******************************************************************************/
22 package org.onap.dmaap.kafkaauthorize;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
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;
38 @PowerMockIgnore({"jdk.internal.reflect.*"})
39 @PrepareForTest({ PlainLoginModule1.class })
40 public class PlainLoginModule1Test {
42 static PlainLoginModule1 pLogin = new PlainLoginModule1();
43 static Subject subject;
45 static CallbackHandler callbackHandler;
48 static Map<String, String> mymap1;
51 static Map<String, ?> mymap2;
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);
62 public void testLogin() {
63 assertTrue(pLogin.login());
67 public void testLogout() {
68 assertTrue(pLogin.logout());
72 public void testCommit() {
73 assertTrue(pLogin.commit());
77 public void testAbort() {
78 assertFalse(pLogin.abort());