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.batch.actions.CacheTouch;
36 import org.onap.aaf.auth.common.Define;
37 import org.onap.aaf.auth.env.AuthzTrans;
38 import org.onap.aaf.auth.layer.Result;
39 import org.onap.aaf.cadi.CadiException;
40 import org.onap.aaf.cadi.PropAccess;
41 import org.onap.aaf.cadi.config.Config;
42 import org.onap.aaf.misc.env.APIException;
43 import org.onap.aaf.misc.env.LogTarget;
44 import org.onap.aaf.misc.env.TimeTaken;
46 import com.datastax.driver.core.Cluster;
47 import com.datastax.driver.core.ColumnDefinitions;
48 import com.datastax.driver.core.PreparedId;
49 import com.datastax.driver.core.PreparedStatement;
50 import com.datastax.driver.core.Session;
52 public class JU_CacheTouch {
66 public void setUp() throws APIException, IOException {
68 Session sessionObj=Mockito.mock(Session.class);
69 PreparedStatement psObj =Mockito.mock(PreparedStatement.class);
71 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init();
72 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn();
73 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug();
74 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info();
75 Mockito.doReturn("10").when(trans).getProperty(Config.AAF_USER_EXPIRES, Config.AAF_USER_EXPIRES_DEF);
76 Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start(Mockito.anyString(),Mockito.anyInt());
77 Mockito.doReturn(sessionObj).when(cluster).connect("authz");
78 Mockito.doReturn(psObj).when(sessionObj).prepare(Mockito.anyString());
80 Mockito.doReturn(Mockito.mock(ColumnDefinitions.class)).when(psObj).getVariables();
81 Mockito.doReturn(Mockito.mock(PreparedId.class)).when(psObj).getPreparedId();
82 Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties();
83 Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf");
85 actionObj = new CacheTouch(trans, cluster, true);
86 } catch (APIException e) {
87 // TODO Auto-generated catch block
89 } catch (IOException e) {
90 // TODO Auto-generated catch block
92 } catch (CadiException e) {
93 // TODO Auto-generated catch block
99 public void testExec() {
100 Result<Void> session = actionObj.exec(trans,"test","test");
101 assertTrue(session.toString().contains("Success"));
105 public void testExecElse() {
107 actionObj = new CacheTouch(trans, cluster, false);
108 } catch (APIException | IOException e) {
109 // TODO Auto-generated catch block
112 Result<Void> session = actionObj.exec(trans,"test","test");
113 assertTrue(session.toString().contains("No Cache Data named test"));
118 public void test2Argonstructor() {
119 actionObj = new CacheTouch(trans, Mockito.mock(ActionDAO.class));