2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 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
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.aaf.auth.direct.test;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.Mockito.when;
26 import static org.mockito.MockitoAnnotations.initMocks;
28 import java.util.Date;
30 import javax.servlet.http.HttpServletRequest;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.Mock;
36 import org.mockito.Mockito;
37 import org.mockito.runners.MockitoJUnitRunner;
38 import org.onap.aaf.auth.dao.DAOException;
39 import org.onap.aaf.auth.dao.hl.Question;
40 import org.onap.aaf.auth.direct.DirectAAFUserPass;
41 import org.onap.aaf.auth.env.AuthzEnv;
42 import org.onap.aaf.auth.env.AuthzTrans;
43 import org.onap.aaf.auth.layer.Result;
44 import org.onap.aaf.misc.env.LogTarget;
47 @RunWith(MockitoJUnitRunner.class)
48 public class JU_DirectAAFUserPass {
60 HttpServletRequest request;
64 public void setUp() throws Exception {
66 when(env.warn()).thenReturn(new LogTarget() {
69 public void printf(String fmt, Object... vars) {}
72 public void log(Throwable e, Object... msgs) {
80 public void log(Object... msgs) {
84 public boolean isLoggable() {
89 when(env.error()).thenReturn(new LogTarget() {
92 public void printf(String fmt, Object... vars) {}
95 public void log(Throwable e, Object... msgs) {
103 public void log(Object... msgs) {
107 public boolean isLoggable() {
115 public void testUserPass() {
117 DirectAAFUserPass aafLocatorObj=null;
118 aafLocatorObj = new DirectAAFUserPass(env, question);
119 Result<Date> retVal1 = new Result<Date>(null,0,"",new String[0]);
120 Mockito.doReturn(trans).when(env).newTransNoAvg();
122 Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null);
123 } catch (DAOException e) {
126 boolean retVal = aafLocatorObj.validate(null, null, null, null);
132 public void testUserPassStateisRequest() {
134 DirectAAFUserPass aafLocatorObj=null;
135 aafLocatorObj = new DirectAAFUserPass(env, question);
136 Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]);
137 Mockito.doReturn(trans).when(env).newTransNoAvg();
139 Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null);
140 } catch (DAOException e) {
143 boolean retVal = aafLocatorObj.validate(null, null, null, request);
145 // System.out.println(retVal);
150 public void testUserPassStateNotNull() {
152 DirectAAFUserPass aafLocatorObj=null;
153 aafLocatorObj = new DirectAAFUserPass(env, question);
154 Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]);
155 Mockito.doReturn(trans).when(env).newTransNoAvg();
157 Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null);
158 } catch (DAOException e) {
161 boolean retVal = aafLocatorObj.validate(null, null, null, "test");
163 // System.out.println(retVal);
168 public void testUserPassTransChk() {
170 DirectAAFUserPass aafLocatorObj=null;
171 aafLocatorObj = new DirectAAFUserPass(env, question);
172 Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]);
173 Mockito.doReturn(trans).when(env).newTransNoAvg();
175 Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null);
176 } catch (DAOException e) {
179 boolean retVal = aafLocatorObj.validate(null, null, null, trans);
181 // System.out.println(retVal);
186 public void testUserPassTransIpNotNull() {
188 DirectAAFUserPass aafLocatorObj=null;
189 aafLocatorObj = new DirectAAFUserPass(env, question);
190 Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]);
191 Mockito.doReturn("test").when(trans).ip();
192 Mockito.doReturn(trans).when(env).newTransNoAvg();
194 Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null);
195 } catch (DAOException e) {
198 boolean retVal = aafLocatorObj.validate(null, null, null, trans);
200 // System.out.println(retVal);
205 public void testUserExceptionChk() {
207 DirectAAFUserPass aafLocatorObj=null;
208 aafLocatorObj = new DirectAAFUserPass(env, question);
209 Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]);
210 Mockito.doReturn(trans).when(env).newTransNoAvg();
212 Mockito.doThrow(DAOException.class).when(question).doesUserCredMatch(trans, null, null);
213 } catch (DAOException e) {
214 // TODO Auto-generated catch block
215 // e.printStackTrace();
217 boolean retVal = aafLocatorObj.validate(null, null, null, trans);
219 // System.out.println(retVal);