Merge "Add more junits to auth-batch"
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / batch / actions / test / JU_CacheTouch.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.batch.actions.test;
23
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.MockitoAnnotations.initMocks;
26
27 import java.io.IOException;
28 import java.util.Properties;
29
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;
45
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;
51
52 public class JU_CacheTouch {
53     
54         @Mock
55     AuthzTrans trans;
56         @Mock
57         Cluster cluster;
58         @Mock
59         PropAccess access;
60         
61         @Mock
62         CacheTouch actionObj;
63
64     
65     @Before
66     public void setUp() throws APIException, IOException {
67         initMocks(this);
68         Session sessionObj=Mockito.mock(Session.class);
69         PreparedStatement psObj =Mockito.mock(PreparedStatement.class);
70                 try {
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());
79                         
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");
84                         Define.set(access);
85                         actionObj = new CacheTouch(trans, cluster, true);
86                 } catch (APIException e) {
87                         // TODO Auto-generated catch block
88                         e.printStackTrace();
89                 } catch (IOException e) {
90                         // TODO Auto-generated catch block
91                         e.printStackTrace();
92                 } catch (CadiException e) {
93                         // TODO Auto-generated catch block
94                         e.printStackTrace();
95                 }
96     }
97     
98     @Test
99         public void testExec() {
100                 Result<Void> session = actionObj.exec(trans,"test","test");
101                 assertTrue(session.toString().contains("Success"));
102                 
103         }
104     @Test
105         public void testExecElse() {
106                 try {
107                         actionObj = new CacheTouch(trans,  cluster, false);
108                 } catch (APIException | IOException e) {
109                         // TODO Auto-generated catch block
110                         e.printStackTrace();
111                 }
112                 Result<Void> session = actionObj.exec(trans,"test","test");
113                 assertTrue(session.toString().contains("No Cache Data named test"));
114                 
115         }
116     
117     @Test
118         public void test2Argonstructor() {
119                         actionObj = new CacheTouch(trans, Mockito.mock(ActionDAO.class));
120         
121                 
122         }
123    
124 }