Add junits to batch & cass modules 82/92682/1
authorSai Gandham <sg481n@att.com>
Mon, 5 Aug 2019 13:41:06 +0000 (08:41 -0500)
committerSai Gandham <sg481n@att.com>
Mon, 5 Aug 2019 13:41:17 +0000 (08:41 -0500)
Issue-ID: AAF-111
Change-Id: I8067dcb4a57192cf0ac273d7364a60d03f300ba6
Signed-off-by: Sai Gandham <sg481n@att.com>
auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/approvalsets/JU_ApprovalSetTest.java [new file with mode: 0644]
auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/approvalsets/JU_Pending.java [new file with mode: 0644]
auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/approvalsets/JU_URApprovalSet.java [new file with mode: 0644]
auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/JU_BatchDataViewTest.java [new file with mode: 0644]
auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/JU_CQLBatchLoopTest.java [new file with mode: 0644]
auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/JU_CQLBatchTest.java [new file with mode: 0644]
auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_DAOException.java

diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/approvalsets/JU_ApprovalSetTest.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/approvalsets/JU_ApprovalSetTest.java
new file mode 100644 (file)
index 0000000..fe7bd6c
--- /dev/null
@@ -0,0 +1,150 @@
+/**
+ * ============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.approvalsets;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.aaf.auth.common.Define;
+import org.onap.aaf.auth.dao.cass.ApprovalDAO;
+import org.onap.aaf.auth.dao.cass.FutureDAO;
+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.ResultSet;
+import com.datastax.driver.core.Session;
+
+public class JU_ApprovalSetTest {
+    
+       @Mock
+    AuthzTrans trans;
+       @Mock
+       Cluster cluster;
+       @Mock
+       PropAccess access;
+       
+       @Mock
+       ApprovalSet actionObj;
+
+       @Mock
+       DataView dv;
+    
+    @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("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);
+                       GregorianCalendar start= new GregorianCalendar();
+                       actionObj = new ApprovalSet(start, "test", dv);
+               } catch (CadiException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+   }
+    
+    @Test
+       public void testPuntDate() {
+       actionObj.write(trans);
+       ApprovalDAO.Data dataObj = new ApprovalDAO.Data();
+       
+       Result<FutureDAO.Data> rs1 = new Result<FutureDAO.Data>(null,0,"test",new Object[0]);
+       Mockito.doReturn(rs1).when(dv).insert(Mockito.any(AuthzTrans.class), Mockito.any(FutureDAO.Data.class));
+       Mockito.doReturn(rs1).when(dv).insert(Mockito.any(AuthzTrans.class), Mockito.any(ApprovalDAO.Data.class));
+       actionObj.ladd.add(dataObj);
+       Result<Void> retVal = actionObj.write(trans);
+       
+       rs1 = new Result<FutureDAO.Data>(null,1,"test",new Object[0]);
+       Mockito.doReturn(rs1).when(dv).insert(Mockito.any(AuthzTrans.class), Mockito.any(ApprovalDAO.Data.class));
+       retVal = actionObj.write(trans);
+       assertTrue("Security - test".equals(retVal.details));
+       
+       actionObj.ladd.add(dataObj);
+       retVal = actionObj.write(trans);
+       assertTrue(retVal.details.contains("Security - test"));
+
+       Mockito.doReturn(rs1).when(dv).insert(Mockito.any(AuthzTrans.class), Mockito.any(FutureDAO.Data.class));
+       retVal = actionObj.write(trans);
+       assertTrue(retVal.details.contains("Security - test"));
+       
+       actionObj.setConstruct(null);
+       actionObj.setExpires(new GregorianCalendar());
+       actionObj.setMemo("");
+       actionObj.ladd = null;
+       actionObj.write(trans);
+       }
+    
+    @Test
+       public void testHasApprovals() {
+       assertFalse(actionObj.hasApprovals());
+       
+       ApprovalDAO.Data dataObj = new ApprovalDAO.Data();
+       actionObj.ladd.add(dataObj);
+       assertTrue(actionObj.hasApprovals());
+    }
+    
+    @Test
+       public void testApprovers() {
+       Set<String> retVal = actionObj.approvers();
+       assertTrue(retVal.size() == 0);
+       
+       ApprovalDAO.Data dataObj = new ApprovalDAO.Data();
+       actionObj.ladd.add(dataObj);
+       retVal = actionObj.approvers();
+       assertTrue(retVal.size() == 1);
+       
+    }
+}
diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/approvalsets/JU_Pending.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/approvalsets/JU_Pending.java
new file mode 100644 (file)
index 0000000..eca5ed7
--- /dev/null
@@ -0,0 +1,133 @@
+/**
+ * ============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.approvalsets;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.cadi.util.CSV.Writer;
+import org.onap.aaf.misc.env.APIException;
+
+import com.datastax.driver.core.Cluster;
+
+public class JU_Pending {
+
+    @Mock
+    AuthzTrans trans;
+    @Mock
+    Cluster cluster;
+    @Mock
+    PropAccess access;
+
+    @Mock
+    DataView dv;
+
+    @Before
+    public void setUp() throws APIException, IOException {
+        initMocks(this);
+    }
+
+    @Test
+    public void testRow() {
+        Writer approveCW = Mockito.mock(Writer.class);
+        Mockito.doNothing().when(approveCW).row(Mockito.anyString(),
+                Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+                Mockito.anyInt());
+        Pending pendingObj = new Pending(new Date());
+        pendingObj.row(approveCW, "key");
+        Date date = null;
+        pendingObj = new Pending(date);
+    }
+
+    @Test
+    public void testInc() {
+        List<String> inpList = new ArrayList<>();
+        inpList.add("test");
+        inpList.add("test");
+        inpList.add("test");
+        inpList.add(null);
+        inpList.add("10");
+        try {
+            Pending pendingObj = new Pending(inpList);
+            pendingObj.inc();
+            assertTrue(11 == pendingObj.qty());
+
+            Pending tempPending = new Pending(inpList);
+            pendingObj.inc(tempPending);
+            assertTrue(21 == pendingObj.qty());
+
+            tempPending.earliest = new Date();
+            pendingObj.earliest = new Date();
+            pendingObj.inc(tempPending);
+
+            Calendar calendar = Calendar.getInstance();
+            calendar.add(Calendar.DAY_OF_YEAR, 1);
+            pendingObj.earliest = calendar.getTime();
+            pendingObj.inc(tempPending);
+        } catch (ParseException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    @Test
+    public void testEarliest() {
+        List<String> inpList = new ArrayList<>();
+        try {
+            inpList.add("test");
+            inpList.add("test");
+            inpList.add("test");
+            inpList.add("2019-01-01");
+            inpList.add("10");
+            Pending.create();
+
+            Pending pendingObj = new Pending(inpList);
+            pendingObj.earliest(null);
+
+            pendingObj.earliest = null;
+            pendingObj.earliest(new Date());
+
+            Calendar calendar = Calendar.getInstance();
+            calendar.add(Calendar.DAY_OF_YEAR, 1);
+            pendingObj.earliest(calendar.getTime());
+            assertTrue(119 == pendingObj.earliest().getYear());
+            assertTrue(pendingObj.newApprovals());
+        } catch (ParseException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+}
diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/approvalsets/JU_URApprovalSet.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/approvalsets/JU_URApprovalSet.java
new file mode 100644 (file)
index 0000000..dd9527a
--- /dev/null
@@ -0,0 +1,234 @@
+/**
+ * ============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.approvalsets;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.aaf.auth.dao.cass.NsDAO;
+import org.onap.aaf.auth.dao.cass.RoleDAO;
+import org.onap.aaf.auth.dao.cass.UserRoleDAO;
+import org.onap.aaf.auth.dao.cass.UserRoleDAO.Data;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.layer.Result;
+import org.onap.aaf.auth.org.Organization;
+import org.onap.aaf.auth.org.Organization.Identity;
+import org.onap.aaf.auth.org.OrganizationException;
+import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.org.DefaultOrgIdentity;
+
+import com.datastax.driver.core.Cluster;
+
+public class JU_URApprovalSet {
+
+    @Mock
+    AuthzTrans trans;
+    @Mock
+    Cluster cluster;
+    @Mock
+    PropAccess access;
+
+    @Mock
+    DataView dv;
+
+    URApprovalSet approvalObj;
+
+    @Mock
+    Loader<UserRoleDAO.Data> lurdd;
+
+    @Before
+    public void setUp() {
+        initMocks(this);
+    }
+
+    @Test
+    public void testConstructor() {
+        GregorianCalendar start = new GregorianCalendar();
+        UserRoleDAO.Data urdd = new UserRoleDAO.Data();
+        urdd.rname = "owner";
+        urdd.expires = new Date();
+        Organization orgObj = Mockito.mock(Organization.class);
+        try {
+
+            Mockito.doReturn(urdd).when(lurdd).load();
+            Mockito.doReturn(orgObj).when(trans).org();
+            Mockito.doReturn(Mockito.mock(GregorianCalendar.class)).when(orgObj)
+                    .expiration(null, Organization.Expiration.UserInRole);
+
+            Result<RoleDAO.Data> rsRoleData = new Result<RoleDAO.Data>(null, 0,
+                    "test", new Object[0]);
+            Mockito.doReturn(rsRoleData).when(dv).roleByName(trans, urdd.role);
+            approvalObj = new URApprovalSet(trans, start, dv, lurdd);
+        } catch (CadiException e) {
+            assertTrue(e.getMessage().contains("Error - test"));
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        try {
+            urdd.rname = "admin";
+            RoleDAO.Data dataObj = new RoleDAO.Data();
+            Result<RoleDAO.Data> rsRoleData = new Result<RoleDAO.Data>(dataObj,
+                    0, "test", new Object[0]);
+            Mockito.doReturn(rsRoleData).when(dv).roleByName(trans, urdd.role);
+
+            Result<NsDAO.Data> rsNsData = new Result<NsDAO.Data>(null, 0,
+                    "test", new Object[0]);
+            Mockito.doReturn(rsNsData).when(dv).ns(trans, urdd.ns);
+            approvalObj = new URApprovalSet(trans, start, dv, lurdd);
+        } catch (CadiException e) {
+            assertTrue(e.getMessage().contains("Error - test"));
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        try {
+            urdd.rname = "rname";
+            NsDAO.Data dataObj = new NsDAO.Data();
+
+            Result<NsDAO.Data> rsNsData = new Result<NsDAO.Data>(dataObj, 0,
+                    "test", new Object[0]);
+            Mockito.doReturn(rsNsData).when(dv).ns(trans, urdd.ns);
+
+            Result<List<Data>> rsData = new Result<List<Data>>(null, 1, "test",
+                    new Object[0]);
+            Mockito.doReturn(rsData).when(dv).ursByRole(trans, urdd.role);
+            approvalObj = new URApprovalSet(trans, start, dv, lurdd);
+        } catch (CadiException e) {
+            assertTrue(e.getMessage()
+                    .contains("User 'null' in Role 'null' does not exist"));
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        try {
+
+            List<Data> dataAL = new ArrayList<>();
+            Data data = new Data();
+            data.user = "user";
+            urdd.user = "test";
+            dataAL.add(data);
+            Result<List<Data>> rsData = new Result<List<Data>>(dataAL, 0,
+                    "test", new Object[0]);
+            Mockito.doReturn(rsData).when(dv).ursByRole(trans, urdd.role);
+            approvalObj = new URApprovalSet(trans, start, dv, lurdd);
+        } catch (CadiException e) {
+            assertTrue(e.getMessage()
+                    .contains("User 'test' in Role 'null' does not exist"));
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        try {
+
+            List<Data> dataAL = new ArrayList<>();
+            Data data = new Data();
+            data.user = "user";
+            urdd.user = "user";
+            dataAL.add(data);
+            Result<List<Data>> rsData = new Result<List<Data>>(dataAL, 0,
+                    "test", new Object[0]);
+            Mockito.doReturn(rsData).when(dv).ursByRole(trans, urdd.role);
+
+            Result<List<UserRoleDAO.Data>> rsURData = new Result<List<UserRoleDAO.Data>>(
+                    null, 1, "test", new Object[0]);
+            Mockito.doReturn(rsURData).when(dv).ursByRole(trans,
+                    urdd.ns + ".owner");
+
+            approvalObj = new URApprovalSet(trans, start, dv, lurdd);
+
+            List<UserRoleDAO.Data> urDataAL = new ArrayList<>();
+            UserRoleDAO.Data urData = new UserRoleDAO.Data();
+            urData.user = "user";
+            urDataAL.add(urData);
+            rsURData = new Result<List<UserRoleDAO.Data>>(urDataAL, 0, "test",
+                    new Object[0]);
+            Mockito.doReturn(rsURData).when(dv).ursByRole(trans,
+                    urdd.ns + ".owner");
+            approvalObj = new URApprovalSet(trans, start, dv, lurdd);
+
+            List<Identity> identityAL = new ArrayList<Identity>();
+            Identity idenObj = Mockito.mock(DefaultOrgIdentity.class);
+            identityAL.add(idenObj);
+
+            try {
+                Mockito.doReturn(identityAL).when(orgObj).getApprovers(trans,
+                        urdd.user);
+            } catch (OrganizationException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+            approvalObj = new URApprovalSet(trans, start, dv, lurdd);
+
+            urDataAL = new ArrayList<>();
+            urData = new UserRoleDAO.Data();
+            urData.user = "user1";
+            urDataAL.add(urData);
+            rsURData = new Result<List<UserRoleDAO.Data>>(urDataAL, 0, "test",
+                    new Object[0]);
+            Mockito.doReturn(rsURData).when(dv).ursByRole(trans,
+                    urdd.ns + ".owner");
+            approvalObj = new URApprovalSet(trans, start, dv, lurdd);
+        } catch (CadiException e) {
+            assertTrue(e.getMessage()
+                    .contains("User 'null' in Role 'null' does not exist"));
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        try {
+            try {
+                Mockito.doThrow(new OrganizationException()).when(orgObj)
+                        .getApprovers(trans, urdd.user);
+            } catch (OrganizationException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+            approvalObj = new URApprovalSet(trans, start, dv, lurdd);
+        } catch (CadiException e) {
+            e.printStackTrace();
+            assertTrue(e.getMessage()
+                    .contains("User 'null' in Role 'null' does not exist"));
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+    }
+
+}
diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/JU_BatchDataViewTest.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/JU_BatchDataViewTest.java
new file mode 100644 (file)
index 0000000..b918c31
--- /dev/null
@@ -0,0 +1,174 @@
+/**
+ * ============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.helpers;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.aaf.auth.dao.cass.ApprovalDAO;
+import org.onap.aaf.auth.dao.cass.FutureDAO;
+import org.onap.aaf.auth.dao.cass.NsDAO;
+import org.onap.aaf.auth.dao.cass.RoleDAO;
+import org.onap.aaf.auth.dao.cass.UserRoleDAO;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.layer.Result;
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.misc.env.APIException;
+import org.onap.aaf.misc.env.TimeTaken;
+
+import com.datastax.driver.core.Session;
+
+public class JU_BatchDataViewTest {
+
+    @Mock
+    AuthzTrans trans;
+
+    @Mock
+    Session session;
+
+    @Mock
+    PropAccess access;
+
+    BatchDataView batchDataViewObj;
+
+    @Before
+    public void setUp() throws APIException, IOException {
+        initMocks(this);
+        batchDataViewObj = new BatchDataView(trans, session, true);
+        Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start(
+                Mockito.anyString(), Mockito.anyInt(), Mockito.anyString());
+    }
+
+    @Test
+    public void testNs() {
+        Result<NsDAO.Data> retVal = batchDataViewObj.ns(trans, "test");
+        assertTrue(retVal.status == 9);
+
+        NS n = new NS("test1", "test2", "test3", 1, 2);
+        NS.data.put("test", n);
+        retVal = batchDataViewObj.ns(trans, "test");
+        assertTrue(retVal.status == 0);
+    }
+
+    @Test
+    public void testRoleByName() {
+        Result<RoleDAO.Data> retVal = batchDataViewObj.roleByName(trans,
+                "test");
+        assertTrue(retVal.status == 9);
+
+        Role n = new Role("test1");
+        n.rdd = new RoleDAO.Data();
+        Role.byName.put("test", n);
+        retVal = batchDataViewObj.roleByName(trans, "test");
+        assertTrue(retVal.status == 0);
+
+        n.rdd = null;
+        Role.byName.put("test", n);
+        retVal = batchDataViewObj.roleByName(trans, "test");
+        assertTrue(retVal.status == 9);
+    }
+    @Test
+    public void testUrsByRole() {
+        Result<List<UserRoleDAO.Data>> retVal = batchDataViewObj
+                .ursByRole(trans, "test");
+        assertTrue(retVal.status == 9);
+
+        Role n = new Role("test1");
+        n.rdd = new RoleDAO.Data();
+        UserRole ur = new UserRole("user", "role", "ns", "rname", new Date());
+        (new UserRole.DataLoadVisitor()).visit(ur);
+        retVal = batchDataViewObj.ursByRole(trans, "role");
+        assertTrue(retVal.status == 0);
+
+    }
+    @Test
+    public void testUrsByUser() {
+        Result<List<UserRoleDAO.Data>> retVal = batchDataViewObj
+                .ursByUser(trans, "test");
+        assertTrue(retVal.status == 9);
+
+        Role n = new Role("test1");
+        n.rdd = new RoleDAO.Data();
+        UserRole ur = new UserRole("user", "role", "ns", "rname", new Date());
+        (new UserRole.DataLoadVisitor()).visit(ur);
+        retVal = batchDataViewObj.ursByUser(trans, "user");
+        assertTrue(retVal.status == 0);
+
+    }
+    @Test
+    public void testDeleteFuture() {
+        FutureDAO.Data dataObj = new FutureDAO.Data();
+        dataObj.id = new UUID(1000L, 1000L);
+        Result<FutureDAO.Data> retVal = batchDataViewObj.delete(trans, dataObj);
+        assertTrue(retVal.status == 0);
+
+    }
+    @Test
+    public void testDeleteApproval() {
+        ApprovalDAO.Data dataObj = new ApprovalDAO.Data();
+        dataObj.id = new UUID(1000L, 1000L);
+        Result<ApprovalDAO.Data> retVal = batchDataViewObj.delete(trans,
+                dataObj);
+        assertTrue(retVal.status == 0);
+
+    }
+
+    @Test
+    public void testInsertApproval() {
+        ApprovalDAO.Data dataObj = new ApprovalDAO.Data();
+        dataObj.id = new UUID(1000L, 1000L);
+        dataObj.memo = "memo";
+        dataObj.ticket = new UUID(1000L, 1000L);
+        Result<ApprovalDAO.Data> retVal = batchDataViewObj.insert(trans,
+                dataObj);
+        assertTrue(retVal.status == 0);
+
+    }
+    @Test
+    public void testInsertFuture() {
+        FutureDAO.Data dataObj = new FutureDAO.Data();
+        dataObj.id = new UUID(1000L, 1000L);
+        dataObj.memo = "memo";
+        dataObj.construct = ByteBuffer.allocate(1000);
+        Result<FutureDAO.Data> retVal = batchDataViewObj.insert(trans, dataObj);
+        assertTrue(retVal.status == 0);
+
+        dataObj.target_key = "memo";
+        retVal = batchDataViewObj.insert(trans, dataObj);
+        assertTrue(retVal.status == 0);
+    }
+    @Test
+    public void testFlush() {
+        batchDataViewObj.flush();
+
+    }
+}
diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/JU_CQLBatchLoopTest.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/JU_CQLBatchLoopTest.java
new file mode 100644 (file)
index 0000000..aef5d22
--- /dev/null
@@ -0,0 +1,177 @@
+/**
+ * ============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.helpers;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.misc.env.APIException;
+import org.onap.aaf.misc.env.LogTarget;
+
+import com.datastax.driver.core.Session;
+
+public class JU_CQLBatchLoopTest {
+
+    @Mock
+    AuthzTrans trans;
+
+    @Mock
+    Session session;
+
+    @Mock
+    LogTarget lg;
+
+    @Mock
+    CQLBatch cqlBatchObj;
+
+    CQLBatchLoop cqlBatchLoopObj;
+
+    @Before
+    public void setUp() throws APIException, IOException {
+        initMocks(this);
+        Mockito.doReturn(lg).when(trans).info();
+        Mockito.doReturn(new StringBuilder()).when(cqlBatchObj).begin();
+        cqlBatchLoopObj = new CQLBatchLoop(cqlBatchObj, 0, false);
+    }
+
+    @Test
+    public void testShowProgress() {
+        CQLBatchLoop tempLoopObj = cqlBatchLoopObj.showProgress();
+        Field f;
+        try {
+            f = CQLBatchLoop.class.getDeclaredField("showProgress");
+            f.setAccessible(true);
+            assertTrue(cqlBatchLoopObj.total() == 0);
+            assertTrue(f.getBoolean(tempLoopObj));
+        } catch (NoSuchFieldException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (SecurityException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IllegalArgumentException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IllegalAccessException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    @Test
+    public void testInc() {
+        StringBuilder sb = cqlBatchLoopObj.inc();
+        sb = cqlBatchLoopObj.inc();
+        assertTrue(cqlBatchLoopObj.batches() == 1);
+        Field f;
+        try {
+            f = CQLBatchLoop.class.getDeclaredField("showProgress");
+            f.setAccessible(true);
+            f.set(cqlBatchLoopObj, true);
+        } catch (NoSuchFieldException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (SecurityException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IllegalArgumentException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IllegalAccessException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        cqlBatchLoopObj.inc();
+        assertTrue(cqlBatchLoopObj.batches() == 2);
+        System.out.println(sb.toString());
+    }
+
+    @Test
+    public void testFlush() {
+        Field f, f1;
+        try {
+            f1 = CQLBatchLoop.class.getDeclaredField("i");
+            f1.setAccessible(true);
+
+            f1.set(cqlBatchLoopObj, -1);
+        } catch (NoSuchFieldException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (SecurityException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IllegalArgumentException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IllegalAccessException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        cqlBatchLoopObj.flush();
+        try {
+            f = CQLBatchLoop.class.getDeclaredField("current");
+            f1 = CQLBatchLoop.class.getDeclaredField("i");
+            f.setAccessible(true);
+            f1.setAccessible(true);
+
+            Field modifiersField = Field.class.getDeclaredField("modifiers");
+            modifiersField.setAccessible(true);
+            modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
+
+            StringBuilder sb = new StringBuilder("tets");
+            for (int i = 1; i < 25600; i++) {
+                sb = sb.append("test");
+            }
+            f.set(cqlBatchLoopObj, sb);
+            f1.set(cqlBatchLoopObj, 10);
+        } catch (NoSuchFieldException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (SecurityException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IllegalArgumentException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IllegalAccessException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        cqlBatchLoopObj.flush();
+    }
+
+    @Test
+    public void testReset() {
+        cqlBatchLoopObj.reset();
+        assertTrue(cqlBatchLoopObj.batches() == 0);
+        System.out.println(cqlBatchLoopObj.toString());
+    }
+}
diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/JU_CQLBatchTest.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/JU_CQLBatchTest.java
new file mode 100644 (file)
index 0000000..a826a98
--- /dev/null
@@ -0,0 +1,121 @@
+/**
+ * ============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.helpers;
+
+import static org.junit.Assert.assertNull;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.aaf.auth.env.AuthzTrans;
+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.ResultSet;
+import com.datastax.driver.core.Session;
+
+public class JU_CQLBatchTest {
+
+    @Mock
+    AuthzTrans trans;
+
+    @Mock
+    Session session;
+
+    @Mock
+    LogTarget lg;
+
+    CQLBatch cqlBatchObj;
+
+    @Before
+    public void setUp() throws APIException, IOException {
+        initMocks(this);
+        Mockito.doReturn(lg).when(trans).info();
+        cqlBatchObj = new CQLBatch(lg, session);
+        Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start(
+                Mockito.anyString(), Mockito.anyInt(), Mockito.anyString());
+
+        Mockito.doReturn(Mockito.mock(ResultSet.class)).when(session)
+                .execute(Mockito.anyString());
+    }
+
+    @Test
+    public void testExecute() {
+        ResultSet retVal = cqlBatchObj.execute();
+        assertNull(retVal);
+
+        Field f;
+        try {
+            f = CQLBatch.class.getDeclaredField("sb");
+            f.setAccessible(true);
+            f.set(cqlBatchObj, new StringBuilder("test"));
+            retVal = cqlBatchObj.execute();
+        } catch (NoSuchFieldException | SecurityException
+                | IllegalArgumentException | IllegalAccessException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+    }
+
+    @Test
+    public void testExecute2() {
+        ResultSet retVal = cqlBatchObj.execute(false);
+        assertNull(retVal);
+
+        Field f;
+        try {
+            f = CQLBatch.class.getDeclaredField("sb");
+            f.setAccessible(true);
+            f.set(cqlBatchObj, new StringBuilder("test"));
+            retVal = cqlBatchObj.execute(true);
+            cqlBatchObj.toString();
+        } catch (NoSuchFieldException | SecurityException
+                | IllegalArgumentException | IllegalAccessException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+    }
+
+    @Test
+    public void testSingleExec() {
+        ResultSet retVal = cqlBatchObj.singleExec(new StringBuilder("test"),
+                true);
+        assertNull(retVal);
+
+        retVal = cqlBatchObj.singleExec(new StringBuilder("test"), false);
+    }
+
+    @Test
+    public void testTouch() {
+        cqlBatchObj.touch("test", 0, 4, true);
+
+    }
+
+}
index 0e9d199..0ee0ce8 100644 (file)
@@ -31,20 +31,36 @@ import org.onap.aaf.auth.dao.DAOException;
 import org.powermock.api.mockito.PowerMockito;
 import org.powermock.modules.junit4.PowerMockRunner;
 
-@RunWith(PowerMockRunner.class)
 public class JU_DAOException {
-DAOException daoException;
+       DAOException daoException;
 
-    //DAOException daoException = new DAOException();
     String message = "message";
     Throwable cause;    
     @Before
     public void setUp(){
-    daoException = new DAOException();    
+       daoException = new DAOException();    
     }
 
     @Test
-    public void test(){
-        assertTrue(true);
+    public void testNoArgConstructor(){
+       assertNull(daoException.getMessage());
+    }
+    
+    @Test
+    public void testOneArgConstructorMsg(){
+       daoException = new DAOException("test message"); 
+       assertTrue("test message".equalsIgnoreCase(daoException.getMessage()));
+    }
+    
+    @Test
+    public void testOneArgConstructorThrowable(){
+       daoException = new DAOException(new Throwable()); 
+       assertTrue("java.lang.Throwable".equalsIgnoreCase(daoException.getMessage()));
+    }
+    
+    @Test
+    public void testTwoArgConstructor(){
+       daoException = new DAOException("test message", new Throwable()); 
+       assertTrue("test message".equalsIgnoreCase(daoException.getMessage()));
     }
 }