From: Jonathan Gathman Date: Mon, 14 May 2018 19:32:52 +0000 (+0000) Subject: Merge "Improve coverage of cadi-core" X-Git-Tag: Beijing-2.1.1~46 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=be48ad6eea34d43a32348ab70819c7f4d79fbc22;hp=247428284bad1129b98a18be86438316401ebdda;p=aaf%2Fauthz.git Merge "Improve coverage of cadi-core" --- diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_InputIterator.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_InputIterator.java new file mode 100644 index 00000000..fbb0d23a --- /dev/null +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_InputIterator.java @@ -0,0 +1,76 @@ +/** + * ============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.helpers.test; + +import static org.junit.Assert.*; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.auth.helpers.InputIterator; + +import static org.mockito.Mockito.*; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintStream; +import java.io.Reader; + +import org.junit.Test; + +public class JU_InputIterator { + + InputIterator inputIterator; + File f; + BufferedReader bReader; + PrintStream pStream; + + @Before + public void setUp() throws IOException { + f = new File("file"); + f.createNewFile(); + bReader = new BufferedReader(new FileReader(f)); + pStream = new PrintStream(f); + inputIterator = new InputIterator(bReader, pStream, "prompt", "instructions"); + } + + @Test + public void test() { + inputIterator.iterator(); + inputIterator.iterator().hasNext(); + inputIterator.iterator().next(); + inputIterator.iterator().remove(); + } + + @After + public void cleanUp() { + if(f.exists()) { + f.delete(); + } + } +} diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_MiscID.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_MiscID.java new file mode 100644 index 00000000..816cda80 --- /dev/null +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_MiscID.java @@ -0,0 +1,97 @@ +/** + * ============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.helpers.test; + +import static org.junit.Assert.*; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.auth.BatchException; +import org.onap.aaf.auth.helpers.MiscID; + +import com.datastax.driver.core.Row; + +import junit.framework.Assert; + +import static org.mockito.Mockito.*; +import org.junit.Test; + +public class JU_MiscID { + + MiscID miscId; + + @Before + public void setUp() { + miscId = new MiscID(); + } + + @Test + public void testRowSet() { + Row row = mock(Row.class); + miscId.set(row); + } + + @Test + public void testStringSet() throws BatchException { + String[] strArr = {"id", "sponsor", "created", "renewal"}; + miscId.set(strArr); + } + + @Test + public void testHashcode() throws BatchException { + String[] strArr = {"id", "sponsor", "created", "renewal"}; + miscId.set(strArr); + Assert.assertEquals(3355, miscId.hashCode()); + } + + @Test + public void testEquals() throws BatchException { + String[] strArr = {"id", "sponsor", "created", "renewal"}; + miscId.set(strArr); + Assert.assertFalse(miscId.equals("id")); + Assert.assertTrue(miscId.equals(miscId)); + } + + @Test + public void testInsertStmt() throws IllegalArgumentException, IllegalAccessException { + String expected = "INSERT INTO authz.miscid (id,created,sponsor,renewal) VALUES ('null','null','null','null')"; + String result = miscId.insertStmt().toString(); + Assert.assertEquals(expected, result); + } + + @Test + public void testUpdateStmt() throws IllegalArgumentException, IllegalAccessException, BatchException { + String expected = "UPDATE authz.miscid SET sponser='sponsor1',created='created1',renewal='renewal1' WHERE id='id'"; + String[] strArr = {"id", "sponsor", "created", "renewal"}; + miscId.set(strArr); + MiscID miscId1 = new MiscID(); + String[] strArr1 = {"id", "sponsor1", "created1", "renewal1"}; + miscId1.set(strArr1); + StringBuilder result = miscId.updateStmt(miscId1); + + Assert.assertEquals(expected, result.toString()); + } + + +} diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_MonthData.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_MonthData.java new file mode 100644 index 00000000..21ead4f2 --- /dev/null +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_MonthData.java @@ -0,0 +1,79 @@ +/** + * ============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.helpers.test; + +import static org.junit.Assert.*; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.auth.helpers.MonthData; + +import static org.mockito.Mockito.*; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import org.junit.Test; + +public class JU_MonthData { + + File f; + MonthData mData; + BufferedWriter bw = null; + FileWriter fw = null; + + @Before + public void setUp() throws IOException { + mData = new MonthData("env"); + f = new File("Monthlyenv.dat"); + f.createNewFile(); + bw = new BufferedWriter(new FileWriter(f)); + bw.write("#test"+ "\n"); + bw.write("long,tester"+ "\n"); + bw.write("1,2,3,4,5"+ "\n"); + bw.close(); + + mData = new MonthData("env"); + } + + @Test + public void testAdd() { + mData.add(2, "target", 10, 1, 1); + } + + @Test + public void testNotExists() { + mData.notExists(2); + } + + @After + public void cleanUp() { + if(f.exists()) { + f.delete(); + } + } + +} diff --git a/auth/auth-cass/docker/dinstall.sh b/auth/auth-cass/docker/dinstall.sh index f0c41940..15b63483 100644 --- a/auth/auth-cass/docker/dinstall.sh +++ b/auth/auth-cass/docker/dinstall.sh @@ -1,30 +1,32 @@ #!/bin/bash +DOCKER=/usr/bin/docker -if [ "`docker ps -a | grep aaf_cass`" == "" ]; then - docker run --name aaf_cass -d cassandra:3.11 +if [ "`$DOCKER ps -a | grep aaf_cass`" == "" ]; then + $DOCKER run --name aaf_cass -d cassandra:3.11 echo "aaf_cass Starting" - echo "Check for running Docker Container aaf_cass, then run again." - # we have to exit here so that the calling script can load CQL files - exit -else for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do - if [ "`docker container logs aaf_cass | grep 'listening for CQL clients'`" == "" ]; then + if [ "`$DOCKER container logs aaf_cass | grep 'listening for CQL clients'`" == "" ]; then echo "Sleep 10" sleep 10 else - YESCQL="yes" break fi done + echo "Check for running Docker Container aaf_cass, then run again." + exit fi -if [ "$YESCQL" == "" ]; then - echo "CQL Never started... exiting" - exit -fi +sleep 20 +echo "Running containers" +$DOCKER container ps -docker exec aaf_cass mkdir -p /opt/app/cass_init -docker cp "../src/main/cql/." aaf_cass:/opt/app/cass_init +echo "Creating /opt/app/cass_init dir on aaf_cass" +$DOCKER exec aaf_cass mkdir -p /opt/app/cass_init +echo "cp the following files to /opt/app/cass_init dir on aaf_cass" +ls ../src/main/cql +$DOCKER cp "../src/main/cql/." aaf_cass:/opt/app/cass_init +echo "The following files are on /opt/app/cass_init dir on aaf_cass" +$DOCKER exec -it aaf_cass ls /opt/app/cass_init echo "Docker Installed Basic Cassandra on aaf_cass. Executing the following " echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently" @@ -36,10 +38,8 @@ echo " cqlsh -u root -p root -f osaaf.cql" echo "" echo "The following will give you a temporary identity with which to start working, or emergency" echo " cqlsh -u root -p root -f temp_identity.cql" -echo "Sleeping for 20 seconds" - echo "Create Keyspaces and Tables" -docker exec -it aaf_cass bash -c '\ +$DOCKER exec -it aaf_cass bash -c '\ cd /opt/app/cass_init; \ echo "Creating Keyspace";cqlsh -u root -p root -f keyspace.cql;\ echo "Creating init";cqlsh -u root -p root -f init.cql;\ @@ -47,4 +47,4 @@ echo "Creating osaaf";cqlsh -u root -p root -f osaaf.cql;\ echo "Creating temp Identity";cqlsh -u root -p root -f temp_identity.cql' echo "Inspecting aafcassadra. Use to get the IP address to update org.osaaf.cassandra.props" -docker inspect aaf_cass | grep '"IPAddress' | head -1 +$DOCKER inspect aaf_cass | grep '"IPAddress' | head -1