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.approvalsets;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.MockitoAnnotations.initMocks;
28 import java.io.IOException;
29 import java.util.Date;
30 import java.util.GregorianCalendar;
31 import java.util.Properties;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.Mock;
37 import org.mockito.Mockito;
38 import org.onap.aaf.auth.common.Define;
39 import org.onap.aaf.auth.dao.cass.ApprovalDAO;
40 import org.onap.aaf.auth.dao.cass.FutureDAO;
41 import org.onap.aaf.auth.env.AuthzTrans;
42 import org.onap.aaf.auth.layer.Result;
43 import org.onap.aaf.cadi.CadiException;
44 import org.onap.aaf.cadi.PropAccess;
45 import org.onap.aaf.cadi.config.Config;
46 import org.onap.aaf.misc.env.APIException;
47 import org.onap.aaf.misc.env.LogTarget;
48 import org.onap.aaf.misc.env.TimeTaken;
50 import com.datastax.driver.core.Cluster;
51 import com.datastax.driver.core.ColumnDefinitions;
52 import com.datastax.driver.core.PreparedId;
53 import com.datastax.driver.core.PreparedStatement;
54 import com.datastax.driver.core.ResultSet;
55 import com.datastax.driver.core.Session;
57 public class JU_ApprovalSetTest {
67 ApprovalSet actionObj;
73 public void setUp() throws APIException, IOException {
75 Session sessionObj=Mockito.mock(Session.class);
76 PreparedStatement psObj =Mockito.mock(PreparedStatement.class);
78 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init();
79 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn();
80 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug();
81 Mockito.doReturn("10").when(trans).getProperty(Config.AAF_USER_EXPIRES, Config.AAF_USER_EXPIRES_DEF);
82 Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start(Mockito.anyString(),Mockito.anyInt());
83 Mockito.doReturn(sessionObj).when(cluster).connect("authz");
84 Mockito.doReturn(psObj).when(sessionObj).prepare(Mockito.anyString());
86 Mockito.doReturn(Mockito.mock(ColumnDefinitions.class)).when(psObj).getVariables();
87 Mockito.doReturn(Mockito.mock(PreparedId.class)).when(psObj).getPreparedId();
88 Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties();
89 Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf");
91 GregorianCalendar start= new GregorianCalendar();
92 actionObj = new ApprovalSet(start, "test", dv);
93 } catch (CadiException e) {
94 // TODO Auto-generated catch block
100 public void testPuntDate() {
101 actionObj.write(trans);
102 ApprovalDAO.Data dataObj = new ApprovalDAO.Data();
104 Result<FutureDAO.Data> rs1 = new Result<FutureDAO.Data>(null,0,"test",new Object[0]);
105 Mockito.doReturn(rs1).when(dv).insert(Mockito.any(AuthzTrans.class), Mockito.any(FutureDAO.Data.class));
106 Mockito.doReturn(rs1).when(dv).insert(Mockito.any(AuthzTrans.class), Mockito.any(ApprovalDAO.Data.class));
107 actionObj.ladd.add(dataObj);
108 Result<Void> retVal = actionObj.write(trans);
110 rs1 = new Result<FutureDAO.Data>(null,1,"test",new Object[0]);
111 Mockito.doReturn(rs1).when(dv).insert(Mockito.any(AuthzTrans.class), Mockito.any(ApprovalDAO.Data.class));
112 retVal = actionObj.write(trans);
113 assertTrue("Security - test".equals(retVal.details));
115 actionObj.ladd.add(dataObj);
116 retVal = actionObj.write(trans);
117 assertTrue(retVal.details.contains("Security - test"));
119 Mockito.doReturn(rs1).when(dv).insert(Mockito.any(AuthzTrans.class), Mockito.any(FutureDAO.Data.class));
120 retVal = actionObj.write(trans);
121 assertTrue(retVal.details.contains("Security - test"));
123 actionObj.setConstruct(null);
124 actionObj.setExpires(new GregorianCalendar());
125 actionObj.setMemo("");
126 actionObj.ladd = null;
127 actionObj.write(trans);
131 public void testHasApprovals() {
132 assertFalse(actionObj.hasApprovals());
134 ApprovalDAO.Data dataObj = new ApprovalDAO.Data();
135 actionObj.ladd.add(dataObj);
136 assertTrue(actionObj.hasApprovals());
140 public void testApprovers() {
141 Set<String> retVal = actionObj.approvers();
142 assertTrue(retVal.size() == 0);
144 ApprovalDAO.Data dataObj = new ApprovalDAO.Data();
145 actionObj.ladd.add(dataObj);
146 retVal = actionObj.approvers();
147 assertTrue(retVal.size() == 1);