X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-batch%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fbatch%2Factions%2Ftest%2FJU_CacheTouch.java;fp=auth%2Fauth-batch%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fbatch%2Factions%2Ftest%2FJU_CacheTouch.java;h=99e11a5a367cf67c9ab293b4d8eb09c83b04dfe3;hb=3ceb063fb173412ad0f499ec07a753f678a80232;hp=0000000000000000000000000000000000000000;hpb=502e3991f592b334f8ffb12780eccebbbaf2e261;p=aaf%2Fauthz.git diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/actions/test/JU_CacheTouch.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/actions/test/JU_CacheTouch.java new file mode 100644 index 00000000..99e11a5a --- /dev/null +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/actions/test/JU_CacheTouch.java @@ -0,0 +1,124 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * =========================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END==================================================== + * + */ + +package org.onap.aaf.auth.batch.actions.test; + +import static org.junit.Assert.assertTrue; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.io.IOException; +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.auth.batch.actions.ActionDAO; +import org.onap.aaf.auth.batch.actions.CacheTouch; +import org.onap.aaf.auth.common.Define; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.layer.Result; +import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.misc.env.APIException; +import org.onap.aaf.misc.env.LogTarget; +import org.onap.aaf.misc.env.TimeTaken; + +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.ColumnDefinitions; +import com.datastax.driver.core.PreparedId; +import com.datastax.driver.core.PreparedStatement; +import com.datastax.driver.core.Session; + +public class JU_CacheTouch { + + @Mock + AuthzTrans trans; + @Mock + Cluster cluster; + @Mock + PropAccess access; + + @Mock + CacheTouch actionObj; + + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + Session sessionObj=Mockito.mock(Session.class); + PreparedStatement psObj =Mockito.mock(PreparedStatement.class); + try { + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); + Mockito.doReturn("10").when(trans).getProperty(Config.AAF_USER_EXPIRES, Config.AAF_USER_EXPIRES_DEF); + Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start(Mockito.anyString(),Mockito.anyInt()); + Mockito.doReturn(sessionObj).when(cluster).connect("authz"); + Mockito.doReturn(psObj).when(sessionObj).prepare(Mockito.anyString()); + + Mockito.doReturn(Mockito.mock(ColumnDefinitions.class)).when(psObj).getVariables(); + Mockito.doReturn(Mockito.mock(PreparedId.class)).when(psObj).getPreparedId(); + Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); + Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); + Define.set(access); + actionObj = new CacheTouch(trans, cluster, true); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testExec() { + Result session = actionObj.exec(trans,"test","test"); + assertTrue(session.toString().contains("Success")); + + } + @Test + public void testExecElse() { + try { + actionObj = new CacheTouch(trans, cluster, false); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Result session = actionObj.exec(trans,"test","test"); + assertTrue(session.toString().contains("No Cache Data named test")); + + } + + @Test + public void test2Argonstructor() { + actionObj = new CacheTouch(trans, Mockito.mock(ActionDAO.class)); + + + } + +}