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====================================================
22 package org.onap.aaf.auth.batch.actions.test;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.MockitoAnnotations.initMocks;
27 import java.io.IOException;
28 import java.util.Properties;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.onap.aaf.auth.batch.actions.ActionDAO;
35 import org.onap.aaf.auth.common.Define;
36 import org.onap.aaf.auth.dao.hl.Function;
37 import org.onap.aaf.auth.dao.hl.Question;
38 import org.onap.aaf.auth.env.AuthzTrans;
39 import org.onap.aaf.auth.layer.Result;
40 import org.onap.aaf.cadi.CadiException;
41 import org.onap.aaf.cadi.PropAccess;
42 import org.onap.aaf.cadi.config.Config;
43 import org.onap.aaf.misc.env.APIException;
44 import org.onap.aaf.misc.env.LogTarget;
45 import org.onap.aaf.misc.env.TimeTaken;
47 import com.datastax.driver.core.Cluster;
48 import com.datastax.driver.core.ColumnDefinitions;
49 import com.datastax.driver.core.PreparedId;
50 import com.datastax.driver.core.PreparedStatement;
51 import com.datastax.driver.core.Session;
53 public class JU_ActionDAO {
65 private class ActionDAOStub extends ActionDAO {
67 public ActionDAOStub(AuthzTrans trans, ActionDAO predecessor) {
68 super(trans, predecessor);
69 // TODO Auto-generated constructor stub
72 public ActionDAOStub(AuthzTrans trans, Cluster cluster, boolean dryRun) throws APIException, IOException {
73 super(trans, cluster, dryRun);
74 // TODO Auto-generated constructor stub
78 public Result exec(AuthzTrans trans, Object data, Object t) {
79 // TODO Auto-generated method stub
86 public void setUp() throws APIException, IOException {
88 Session sessionObj=Mockito.mock(Session.class);
89 PreparedStatement psObj =Mockito.mock(PreparedStatement.class);
91 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init();
92 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn();
93 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug();
94 Mockito.doReturn("10").when(trans).getProperty(Config.AAF_USER_EXPIRES, Config.AAF_USER_EXPIRES_DEF);
95 Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start(Mockito.anyString(),Mockito.anyInt());
96 Mockito.doReturn(sessionObj).when(cluster).connect("authz");
97 Mockito.doReturn(psObj).when(sessionObj).prepare(Mockito.anyString());
99 Mockito.doReturn(Mockito.mock(ColumnDefinitions.class)).when(psObj).getVariables();
100 Mockito.doReturn(Mockito.mock(PreparedId.class)).when(psObj).getPreparedId();
101 Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties();
102 Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf");
104 actionObj = new ActionDAOStub(trans, cluster, true);
105 } catch (APIException e) {
106 // TODO Auto-generated catch block
108 } catch (IOException e) {
109 // TODO Auto-generated catch block
111 } catch (CadiException e) {
112 // TODO Auto-generated catch block
115 // Cluster.Initializer cInit = mock(Cluster.Initializer.class);
116 // Cluster.Builder cBuild = new Cluster.Builder();
117 // cBuild.addContactPoint("test");
119 // cluster.buildFrom(cBuild);
120 // cluster.builder();
122 // cluster.builder().getContactPoints();
126 // aTrans = mock(AuthzTrans.class);
127 // cluster = mock(Cluster.class);
128 // actionDAOStub = new ActionDAOStub(aTrans,cluster,true);
129 // actionDAOStub1 = new ActionDAOStub(aTrans, actionDAOStub);
133 public void testGetSession() {
135 Session session = actionObj.getSession(trans);
136 assertTrue(session.toString().contains("Mock for Session"));
137 } catch (APIException e) {
138 // TODO Auto-generated catch block
140 } catch (IOException e) {
141 // TODO Auto-generated catch block
147 public void testQuestion() {
148 Question retVal = actionObj.question();
149 assertTrue(retVal.toString().contains("org.onap.aaf.auth.dao.hl.Question"));
153 public void testFunction() {
154 Function retVal = actionObj.function();
155 assertTrue(retVal.toString().contains("org.onap.aaf.auth.dao.hl.Function"));
159 public void testClose() {
160 actionObj.close(trans);
161 // assertTrue(session.toString().contains("Mock for Session"));
165 public void testCloseFalse() {
166 actionObj = new ActionDAOStub(trans, Mockito.mock(ActionDAO.class));
167 actionObj.close(trans);
168 // assertTrue(session.toString().contains("Mock for Session"));