Fix up several JUnits 31/40731/1
authorIanHowell <ian.howell@att.com>
Fri, 30 Mar 2018 17:14:55 +0000 (12:14 -0500)
committerIanHowell <ian.howell@att.com>
Tue, 3 Apr 2018 15:41:03 +0000 (10:41 -0500)
Issue-ID: AAF-128
Change-Id: I3644847671e08f0b6d57cce9674dc8a3d60fcbc4
Signed-off-by: IanHowell <ian.howell@att.com>
Get Test coverage for MultiGet to 100%

Issue-ID: AAF-128
Change-Id: I5b591c0b7e0e7353dc669e75546961177ef8d152
Signed-off-by: IanHowell <ian.howell@att.com>
Get test coverage of UserChainManip to 100%

Issue-ID: AAF-128
Change-Id: I41d6a2c3f405d8959507ae02c934fffff7903e32
Signed-off-by: IanHowell <ian.howell@att.com>
Get test coverage of SecurityInfoC to 100%

Issue-ID: AAF-128
Change-Id: I04c088827915b14d1f597d5e1eeb7f8e9159e644
Signed-off-by: IanHowell <ian.howell@att.com>
Trial run at updating POMs for SONAR coverage

Change-Id: Ib2a68773fafbc660266ee5d496ffe842c10e7931
Signed-off-by: IanHowell <ian.howell@att.com>
auth/auth-core/pom.xml
auth/auth-deforg/pom.xml
cadi/cass/pom.xml
cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_AES.java
cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiExceptionTest.java [deleted file]
cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiWrapTest.java [deleted file]
cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_MultiGet.java [new file with mode: 0644]
cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_SecurityInfoC.java [new file with mode: 0644]
cadi/core/src/test/java/org/onap/aaf/cadi/test/util/JU_UserChainManip.java

index 8e21863..0bfc0ff 100644 (file)
                                        <serverId>ecomp-staging</serverId>
                                </configuration>
                        </plugin>               
-                       <plugin>
-                               <groupId>org.jacoco</groupId>
-                               <artifactId>jacoco-maven-plugin</artifactId>
-                               <version>0.7.7.201606060606</version>
-                               <configuration>
-                                       <dumpOnExit>true</dumpOnExit>
-                                       <includes>
-                                               <include>org.onap.aaf.*</include>
-                                       </includes>
-                               </configuration>
-                               <executions>
-                                       <execution>
-                                               <id>pre-unit-test</id>
-                                               <goals>
-                                                       <goal>prepare-agent</goal>
-                                               </goals>
-                                               <configuration>
-                                                       <destFile>${project.build.directory}/coverage-reports/jacoco.exec</destFile>
-                                                       <!-- <append>true</append> -->
-                                               </configuration>
-                                       </execution>
-                                       <execution>
-                                               <id>pre-integration-test</id>
-                                               <phase>pre-integration-test</phase>
-                                               <goals>
-                                                       <goal>prepare-agent</goal>
-                                               </goals>
-                                               <configuration>
-                                                       <destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile>
-                                                       <!-- <append>true</append> -->
-                                               </configuration>
-                                       </execution>
-                                       <execution>
-                        <goals>
-                            <goal>merge</goal>
-                        </goals>
-                        <phase>post-integration-test</phase>
-                        <configuration>
-                            <fileSets>
-                                <fileSet implementation="org.apache.maven.shared.model.fileset.FileSet">
-                                    <directory>${project.build.directory}/coverage-reports</directory>
-                                    <includes>
-                                        <include>*.exec</include>
-                                    </includes>
-                                </fileSet>
-                            </fileSets>
-                            <destFile>${project.build.directory}/jacoco-dev.exec</destFile>
-                        </configuration>
-                    </execution>
-                               </executions>
-                       </plugin>
+                               <plugin>
+                                       <groupId>org.jacoco</groupId>
+                                       <artifactId>jacoco-maven-plugin</artifactId>
+                                       <version>${jacoco.version}</version>
+                                       <configuration>
+                                               <excludes>
+                                                       <exclude>**/gen/**</exclude>
+                                                       <exclude>**/generated-sources/**</exclude>
+                                                       <exclude>**/yang-gen/**</exclude>
+                                                       <exclude>**/pax/**</exclude>
+                                               </excludes>
+                                       </configuration>
+                                       <executions>
+                                               <execution>
+                                                       <id>pre-unit-test</id>
+                                                       <goals>
+                                                               <goal>prepare-agent</goal>
+                                                       </goals>
+                                                       <configuration>
+                                                               <destFile>${project.build.directory}/code-coverage/jacoco-ut.exec</destFile>
+                                                               <propertyName>surefireArgLine</propertyName>
+                                                       </configuration>
+                                               </execution>
+                                               <execution>
+                                                       <id>post-unit-test</id>
+                                                       <phase>test</phase>
+                                                       <goals>
+                                                               <goal>report</goal>
+                                                       </goals>
+                                                       <configuration>
+                                                               <dataFile>${project.build.directory}/code-coverage/jacoco-ut.exec</dataFile>
+                                                               <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
+                                                       </configuration>
+                                               </execution>
+                                               <execution>
+                                                       <id>pre-integration-test</id>
+                                                       <phase>pre-integration-test</phase>
+                                                       <goals>
+                                                               <goal>prepare-agent</goal>
+                                                       </goals>
+                                                       <configuration>
+                                                               <destFile>${project.build.directory}/code-coverage/jacoco-it.exec</destFile>
+                                                               <propertyName>failsafeArgLine</propertyName>
+                                                       </configuration>
+                                               </execution>
+
+                                               <execution>
+                                                       <id>post-integration-test</id>
+                                                       <phase>post-integration-test</phase>
+                                                       <goals>
+                                                               <goal>report</goal>
+                                                       </goals>
+                                                       <configuration>
+                                                               <dataFile>${project.build.directory}/code-coverage/jacoco-it.exec</dataFile>
+                                                               <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
+                                                       </configuration>
+                                               </execution>
+                                       </executions>
+                               </plugin>
           </plugins>
        </build>
        <distributionManagement>
index cf86a78..f5162b7 100644 (file)
                                                </excludes>
                                        </configuration>
                                        <executions>
-
                                                <execution>
                                                        <id>pre-unit-test</id>
                                                        <goals>
                                                                <propertyName>surefireArgLine</propertyName>
                                                        </configuration>
                                                </execution>
-
-
                                                <execution>
                                                        <id>post-unit-test</id>
                                                        <phase>test</phase>
                                                                <propertyName>failsafeArgLine</propertyName>
                                                        </configuration>
                                                </execution>
-
                                                <execution>
                                                        <id>post-integration-test</id>
                                                        <phase>post-integration-test</phase>
index e40827e..ae4d06a 100644 (file)
                                </configuration>
                        </plugin>               
                        <plugin>
-          <groupId>org.jacoco</groupId>
-          <artifactId>jacoco-maven-plugin</artifactId>
-          <version>${jacoco.version}</version>
-          <configuration>
-            <excludes>
-              <exclude>**/gen/**</exclude>
-              <exclude>**/generated-sources/**</exclude>
-              <exclude>**/yang-gen/**</exclude>
-              <exclude>**/pax/**</exclude>
-            </excludes>
-          </configuration>
-          <executions>
-
-            <execution>
-              <id>pre-unit-test</id>
-              <goals>
-                <goal>prepare-agent</goal>
-              </goals>
-              <configuration>
-                <destFile>${project.build.directory}/code-coverage/jacoco-ut.exec</destFile>
-                <propertyName>surefireArgLine</propertyName>
-              </configuration>
-            </execution>
-            
-       
-            <execution>
-              <id>post-unit-test</id>
-              <phase>test</phase>
-              <goals>
-                <goal>report</goal>
-              </goals>
-              <configuration>
-                <dataFile>${project.build.directory}/code-coverage/jacoco-ut.exec</dataFile>
-                <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
-              </configuration>
-            </execution>
-            <execution>
-              <id>pre-integration-test</id>
-              <phase>pre-integration-test</phase>
-              <goals>
-                <goal>prepare-agent</goal>
-              </goals>
-              <configuration>
-                <destFile>${project.build.directory}/code-coverage/jacoco-it.exec</destFile>
-
-                <propertyName>failsafeArgLine</propertyName>
-              </configuration>
-            </execution>
+                               <groupId>org.jacoco</groupId>
+                               <artifactId>jacoco-maven-plugin</artifactId>
+                               <version>${jacoco.version}</version>
+                               <configuration>
+                                       <excludes>
+                                               <exclude>**/gen/**</exclude>
+                                               <exclude>**/generated-sources/**</exclude>
+                                               <exclude>**/yang-gen/**</exclude>
+                                               <exclude>**/pax/**</exclude>
+                                       </excludes>
+                               </configuration>
+                               <executions>
+                                       <execution>
+                                               <id>pre-unit-test</id>
+                                               <goals>
+                                                       <goal>prepare-agent</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <destFile>${project.build.directory}/code-coverage/jacoco-ut.exec</destFile>
+                                                       <propertyName>surefireArgLine</propertyName>
+                                               </configuration>
+                                       </execution>
+                                       <execution>
+                                               <id>post-unit-test</id>
+                                               <phase>test</phase>
+                                               <goals>
+                                                       <goal>report</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <dataFile>${project.build.directory}/code-coverage/jacoco-ut.exec</dataFile>
+                                                       <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
+                                               </configuration>
+                                       </execution>
+                                       <execution>
+                                               <id>pre-integration-test</id>
+                                               <phase>pre-integration-test</phase>
+                                               <goals>
+                                                       <goal>prepare-agent</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <destFile>${project.build.directory}/code-coverage/jacoco-it.exec</destFile>
 
-       
-            <execution>
-              <id>post-integration-test</id>
-              <phase>post-integration-test</phase>
-              <goals>
-                <goal>report</goal>
-              </goals>
-              <configuration>
-                <dataFile>${project.build.directory}/code-coverage/jacoco-it.exec</dataFile>
-                <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
-              </configuration>
-            </execution>
-          </executions>
-        </plugin>
+                                                       <propertyName>failsafeArgLine</propertyName>
+                                               </configuration>
+                                       </execution>
+                                       <execution>
+                                               <id>post-integration-test</id>
+                                               <phase>post-integration-test</phase>
+                                               <goals>
+                                                       <goal>report</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <dataFile>${project.build.directory}/code-coverage/jacoco-it.exec</dataFile>
+                                                       <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
                </plugins>
                
        </build>
index 4fb9242..fc960be 100644 (file)
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 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.cadi.test;
-
-import static org.junit.Assert.*;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.reflect.Field;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import javax.crypto.CipherInputStream;
-import javax.crypto.CipherOutputStream;
-import javax.crypto.SecretKey;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.AES;
-import org.onap.aaf.cadi.CadiException;
-import org.onap.aaf.cadi.Symm;
-import org.junit.Before;
-
-public class JU_AES {
-       private AES aes;
-       private ByteArrayInputStream baisEncrypt;
-       private ByteArrayInputStream baisDecrypt;
-       private ByteArrayOutputStream baosEncrypt;
-       private ByteArrayOutputStream baosDecrypt;
-
-       @Before
-       public void setup() throws Exception {
-               byte[] keyBytes = new byte[AES.AES_KEY_SIZE/8];
-               char[] codeset = Symm.base64.codeset;
-               int offset = (Math.abs(codeset[0])+47)%(codeset.length-keyBytes.length);
-               for(int i=0;i<keyBytes.length;++i) {
-                       keyBytes[i] = (byte)codeset[i+offset];
-               }
-               aes = new AES(keyBytes,0,keyBytes.length);
-       }
-
-       @Test
-       public void newKeyTest() throws Exception {
-               SecretKey secretKey = AES.newKey();
-               assertEquals(secretKey.getAlgorithm(), AES.class.getSimpleName());
-       }
-
-       @Test
-       public void encryptDecrpytFromBytes() throws Exception {
-               String orig = "I'm a password, really";
-               byte[] encrypted = aes.encrypt(orig.getBytes());
-               byte[] decrypted = aes.decrypt(encrypted);
-               assertEquals(orig, new String(decrypted));
-               Field aeskeySpec_field = AES.class.getDeclaredField("aeskeySpec");
-               aeskeySpec_field.setAccessible(true);
-               aeskeySpec_field.set(aes, null);
-
-               try {
-                       aes.encrypt(orig.getBytes());
-                       fail("Should have thrown an exception");
-               } catch (CadiException e) {
-               }
-               try {
-                       aes.decrypt(encrypted);
-                       fail("Should have thrown an exception");
-               } catch (CadiException e) {
-               }
-       }
-
-       @Test
-       public void saveToFileTest() throws Exception {
-               String filePath = "test/output_key";
-               File keyfile = new File(filePath);
-               aes.save(keyfile);
-               assertTrue(Files.isReadable(Paths.get(filePath)));
-               assertFalse(Files.isWritable(Paths.get(filePath)));
-               assertFalse(Files.isExecutable(Paths.get(filePath)));
-               keyfile.delete();
-       }
-
-       @Test
-       public void encryptDecryptFromInputStream() throws Exception {
-               String orig = "I'm a password, really";
-               byte[] b64encrypted;
-               String output;
-
-               CipherInputStream cisEncrypt;
-               CipherInputStream cisDecrypt;
-               
-               // Test CipherInputStream
-               baisEncrypt = new ByteArrayInputStream(orig.getBytes());
-               cisEncrypt = aes.inputStream(baisEncrypt, true);
-               baosEncrypt = new ByteArrayOutputStream();
-               transferFromInputStreamToOutputStream(cisEncrypt, baosEncrypt);
-               cisEncrypt.close();
-
-               b64encrypted = baosEncrypt.toByteArray();
-
-               baisDecrypt = new ByteArrayInputStream(b64encrypted);
-               cisDecrypt = aes.inputStream(baisDecrypt, false);
-               baosDecrypt = new ByteArrayOutputStream();
-               transferFromInputStreamToOutputStream(cisDecrypt, baosDecrypt);
-               cisDecrypt.close();
-
-               output = new String(baosDecrypt.toByteArray());
-               assertEquals(orig, output);
-
-               Field aeskeySpec_field = AES.class.getDeclaredField("aeskeySpec");
-               aeskeySpec_field.setAccessible(true);
-               aeskeySpec_field.set(aes, null);
-
-               assertNull(aes.inputStream(baisEncrypt, true));
-       }
-
-       @Test
-       public void encryptDecryptFromOutputStream() throws Exception {
-               String orig = "I'm a password, really";
-               byte[] b64encrypted;
-               String output;
-
-               CipherOutputStream cosEncrypt;
-               CipherOutputStream cosDecrypt;
-               
-               // Test CipherOutputStream
-               baisEncrypt = new ByteArrayInputStream(orig.getBytes());
-               baosEncrypt = new ByteArrayOutputStream();
-               cosEncrypt = aes.outputStream(baosEncrypt, true);
-               transferFromInputStreamToOutputStream(baisEncrypt, cosEncrypt);
-               cosEncrypt.close();
-
-               b64encrypted = baosEncrypt.toByteArray();
-
-               baosDecrypt = new ByteArrayOutputStream();
-               cosDecrypt = aes.outputStream(baosDecrypt, false);
-               baisDecrypt = new ByteArrayInputStream(b64encrypted);
-               transferFromInputStreamToOutputStream(baisDecrypt, cosDecrypt);
-               cosDecrypt.close();
-
-               output = new String(baosDecrypt.toByteArray());
-               assertEquals(orig, output);
-
-               Field aeskeySpec_field = AES.class.getDeclaredField("aeskeySpec");
-               aeskeySpec_field.setAccessible(true);
-               aeskeySpec_field.set(aes, null);
-
-               assertNull(aes.outputStream(baosEncrypt, true));
-       }
-
-       public void transferFromInputStreamToOutputStream(InputStream is, OutputStream os) throws IOException {
-               byte[] buffer = new byte[200];
-               int len;
-               while ((len = is.read(buffer)) != -1) {
-                   os.write(buffer, 0, len);
-               }
-       }
-       
-}
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aaf\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * ===========================================================================\r
+ * * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * * you may not use this file except in compliance with the License.\r
+ * * You may obtain a copy of the License at\r
+ * *\r
+ *  *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * *\r
+ *  * Unless required by applicable law or agreed to in writing, software\r
+ * * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * * See the License for the specific language governing permissions and\r
+ * * limitations under the License.\r
+ * * ============LICENSE_END====================================================\r
+ * *\r
+ * *\r
+ ******************************************************************************/\r
+package org.onap.aaf.cadi.test;\r
+\r
+import static org.hamcrest.CoreMatchers.*;\r
+import static org.junit.Assert.*;\r
+import org.junit.*;\r
+\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+import java.io.PrintStream;\r
+import java.lang.reflect.Field;\r
+import java.nio.file.Files;\r
+import java.nio.file.Paths;\r
+\r
+import javax.crypto.CipherInputStream;\r
+import javax.crypto.CipherOutputStream;\r
+import javax.crypto.SecretKey;\r
+\r
+import org.onap.aaf.cadi.AES;\r
+import org.onap.aaf.cadi.CadiException;\r
+import org.onap.aaf.cadi.Symm;\r
+\r
+public class JU_AES {\r
+       private AES aes;\r
+       private ByteArrayInputStream baisEncrypt;\r
+       private ByteArrayInputStream baisDecrypt;\r
+       private ByteArrayOutputStream baosEncrypt;\r
+       private ByteArrayOutputStream baosDecrypt;\r
+\r
+       private ByteArrayOutputStream errStream;\r
+\r
+       @Before\r
+       public void setup() throws Exception {\r
+               byte[] keyBytes = new byte[AES.AES_KEY_SIZE/8];\r
+               char[] codeset = Symm.base64.codeset;\r
+               int offset = (Math.abs(codeset[0]) + 47) % (codeset.length - keyBytes.length);\r
+               for(int i = 0; i < keyBytes.length; ++i) {\r
+                       keyBytes[i] = (byte)codeset[i+offset];\r
+               }\r
+               aes = new AES(keyBytes, 0, keyBytes.length);\r
+\r
+               errStream = new ByteArrayOutputStream();\r
+               System.setErr(new PrintStream(errStream));\r
+       }\r
+\r
+       @After\r
+       public void tearDown() {\r
+               System.setErr(System.err);\r
+       }\r
+\r
+       @Test\r
+       public void newKeyTest() throws Exception {\r
+               SecretKey secretKey = AES.newKey();\r
+               assertThat(secretKey.getAlgorithm(), is(AES.class.getSimpleName()));\r
+       }\r
+\r
+       @Test\r
+       public void encryptDecrpytFromBytes() throws Exception {\r
+               String orig = "I'm a password, really";\r
+               byte[] encrypted = aes.encrypt(orig.getBytes());\r
+               byte[] decrypted = aes.decrypt(encrypted);\r
+               assertThat(new String(decrypted), is(orig));\r
\r
+               Field aeskeySpec_field = AES.class.getDeclaredField("aeskeySpec");\r
+               aeskeySpec_field.setAccessible(true);\r
+               aeskeySpec_field.set(aes, null);\r
+\r
+               try {\r
+                       aes.encrypt(orig.getBytes());\r
+                       fail("Should have thrown an exception");\r
+               } catch (CadiException e) {\r
+               }\r
+               try {\r
+                       aes.decrypt(encrypted);\r
+                       fail("Should have thrown an exception");\r
+               } catch (CadiException e) {\r
+               }\r
+       }\r
+\r
+       @Test\r
+       public void saveToFileTest() throws Exception {\r
+               String filePath = "test/output_key";\r
+               File keyfile = new File(filePath);\r
+               aes.save(keyfile);\r
+               assertTrue(Files.isReadable(Paths.get(filePath)));\r
+               assertFalse(Files.isWritable(Paths.get(filePath)));\r
+               assertFalse(Files.isExecutable(Paths.get(filePath)));\r
+               keyfile.delete();\r
+       }\r
+\r
+       @Test\r
+       public void encryptDecryptFromInputStream() throws Exception {\r
+               String orig = "I'm a password, really";\r
+               byte[] b64encrypted;\r
+               String output;\r
+\r
+               CipherInputStream cisEncrypt;\r
+               CipherInputStream cisDecrypt;\r
+               \r
+               // Test CipherInputStream\r
+               baisEncrypt = new ByteArrayInputStream(orig.getBytes());\r
+               cisEncrypt = aes.inputStream(baisEncrypt, true);\r
+               baosEncrypt = new ByteArrayOutputStream();\r
+               transferFromInputStreamToOutputStream(cisEncrypt, baosEncrypt);\r
+               cisEncrypt.close();\r
+\r
+               b64encrypted = baosEncrypt.toByteArray();\r
+\r
+               baisDecrypt = new ByteArrayInputStream(b64encrypted);\r
+               cisDecrypt = aes.inputStream(baisDecrypt, false);\r
+               baosDecrypt = new ByteArrayOutputStream();\r
+               transferFromInputStreamToOutputStream(cisDecrypt, baosDecrypt);\r
+               cisDecrypt.close();\r
+\r
+               output = new String(baosDecrypt.toByteArray());\r
+               assertThat(output, is(orig));\r
+\r
+               Field aeskeySpec_field = AES.class.getDeclaredField("aeskeySpec");\r
+               aeskeySpec_field.setAccessible(true);\r
+               aeskeySpec_field.set(aes, null);\r
+\r
+               assertNull(aes.inputStream(baisEncrypt, true));\r
+               assertThat(errStream.toString(), is("Error creating Aes CipherInputStream\n"));\r
+       }\r
+\r
+       @Test\r
+       public void encryptDecryptFromOutputStream() throws Exception {\r
+               String orig = "I'm a password, really";\r
+               byte[] b64encrypted;\r
+               String output;\r
+\r
+               CipherOutputStream cosEncrypt;\r
+               CipherOutputStream cosDecrypt;\r
+               \r
+               // Test CipherOutputStream\r
+               baisEncrypt = new ByteArrayInputStream(orig.getBytes());\r
+               baosEncrypt = new ByteArrayOutputStream();\r
+               cosEncrypt = aes.outputStream(baosEncrypt, true);\r
+               transferFromInputStreamToOutputStream(baisEncrypt, cosEncrypt);\r
+               cosEncrypt.close();\r
+\r
+               b64encrypted = baosEncrypt.toByteArray();\r
+\r
+               baosDecrypt = new ByteArrayOutputStream();\r
+               cosDecrypt = aes.outputStream(baosDecrypt, false);\r
+               baisDecrypt = new ByteArrayInputStream(b64encrypted);\r
+               transferFromInputStreamToOutputStream(baisDecrypt, cosDecrypt);\r
+               cosDecrypt.close();\r
+\r
+               output = new String(baosDecrypt.toByteArray());\r
+               assertThat(output, is(orig));\r
+\r
+               Field aeskeySpec_field = AES.class.getDeclaredField("aeskeySpec");\r
+               aeskeySpec_field.setAccessible(true);\r
+               aeskeySpec_field.set(aes, null);\r
+\r
+               assertNull(aes.outputStream(baosEncrypt, true));\r
+               assertThat(errStream.toString(), is("Error creating Aes CipherOutputStream\n"));\r
+       }\r
+\r
+       public void transferFromInputStreamToOutputStream(InputStream is, OutputStream os) throws IOException {\r
+               byte[] buffer = new byte[200];\r
+               int len;\r
+               while ((len = is.read(buffer)) != -1) {\r
+                   os.write(buffer, 0, len);\r
+               }\r
+       }\r
+       \r
+}\r
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiExceptionTest.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiExceptionTest.java
deleted file mode 100644 (file)
index 03b2037..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 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.cadi.test;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-import org.onap.aaf.cadi.CadiException;
-
-import static org.hamcrest.CoreMatchers.is;
-
-public class JU_CadiExceptionTest {
-       @Test
-       public void testCadiException() {
-               CadiException exception = new CadiException();
-               
-               assertNotNull(exception);
-       }
-
-       @Test
-       public void testCadiExceptionString() {
-               CadiException exception = new CadiException("New Exception");
-               assertNotNull(exception);
-               assertThat(exception.getMessage(), is("New Exception"));
-       }
-
-       @Test
-       public void testCadiExceptionThrowable() {
-               CadiException exception = new CadiException(new Throwable("New Exception"));
-               assertNotNull(exception);
-               assertThat(exception.getMessage(), is("java.lang.Throwable: New Exception"));
-       }
-
-       @Test
-       public void testCadiExceptionStringThrowable() {
-               CadiException exception = new CadiException("New Exception",new Throwable("New Exception"));
-               assertNotNull(exception);
-               assertThat(exception.getMessage(), is("New Exception"));
-
-       }
-       
-       @Test
-       public void testCadiException1() {
-               CadiException exception = new CadiException();
-               
-               assertNotNull(exception);
-       }
-
-       @Test
-       public void testCadiExceptionString1() {
-               CadiException exception = new CadiException("New Exception");
-               assertNotNull(exception);
-               assertThat(exception.getMessage(), is("New Exception"));
-       }
-
-       @Test
-       public void testCadiExceptionThrowable1() {
-               CadiException exception = new CadiException(new Throwable("New Exception"));
-               assertNotNull(exception);
-               assertThat(exception.getMessage(), is("java.lang.Throwable: New Exception"));
-       }
-
-       @Test
-       public void testCadiExceptionStringThrowable1() {
-               CadiException exception = new CadiException("New Exception",new Throwable("New Exception"));
-               assertNotNull(exception);
-               assertThat(exception.getMessage(), is("New Exception"));
-
-       }
-       
-       @Test
-       public void testCadiException2() {
-               CadiException exception = new CadiException();
-               
-               assertNotNull(exception);
-       }
-
-       @Test
-       public void testCadiExceptionString2() {
-               CadiException exception = new CadiException("New Exception");
-               assertNotNull(exception);
-               assertThat(exception.getMessage(), is("New Exception"));
-       }
-
-       @Test
-       public void testCadiExceptionThrowable2() {
-               CadiException exception = new CadiException(new Throwable("New Exception"));
-               assertNotNull(exception);
-               assertThat(exception.getMessage(), is("java.lang.Throwable: New Exception"));
-       }
-
-       @Test
-       public void testCadiExceptionStringThrowable2() {
-               CadiException exception = new CadiException("New Exception",new Throwable("New Exception"));
-               assertNotNull(exception);
-               assertThat(exception.getMessage(), is("New Exception"));
-
-       }
-
-
-
-}
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiWrapTest.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CadiWrapTest.java
deleted file mode 100644 (file)
index 14b2999..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 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.cadi.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.when;
-
-import java.security.Principal;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.onap.aaf.cadi.Access;
-import org.onap.aaf.cadi.CachingLur;
-import org.onap.aaf.cadi.CadiException;
-import org.onap.aaf.cadi.CadiWrap;
-import org.onap.aaf.cadi.Lur;
-import org.onap.aaf.cadi.Permission;
-import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.User;
-import org.onap.aaf.cadi.CachedPrincipal.Resp;
-import org.onap.aaf.cadi.filter.MapPermConverter;
-import org.onap.aaf.cadi.lur.EpiLur;
-import org.onap.aaf.cadi.principal.TaggedPrincipal;
-import org.onap.aaf.cadi.taf.TafResp;
-
-public class JU_CadiWrapTest {
-       
-       @Mock
-       private HttpServletRequest request;
-       
-       @Mock
-       private TafResp tafResp;
-       
-       @Mock
-       private TaggedPrincipal principle;
-
-       @Mock
-       private Lur lur;
-
-       @Before
-       public void setUp() throws Exception {
-               MockitoAnnotations.initMocks(this);
-       }
-
-       @Test
-       public void testInstantiate() throws CadiException {
-               Access a = new PropAccess();
-               when(tafResp.getAccess()).thenReturn(a);
-               
-               lur.fishAll(isA(Principal.class), isA(List.class));
-               
-               EpiLur lur1 = new EpiLur(lur);
-               
-               CadiWrap wrap = new CadiWrap(request, tafResp, lur1);
-               
-               assertNull(wrap.getUserPrincipal());
-               assertNull(wrap.getRemoteUser());
-               assertNull(wrap.getUser());
-               assertEquals(wrap.getPermissions(principle).size(), 0);
-               assertTrue(wrap.access() instanceof PropAccess);
-               
-               byte[] arr = {'1','2'};
-               wrap.setCred(arr);
-               
-               assertEquals(arr, wrap.getCred());
-               
-               wrap.setUser("User1");
-               assertEquals("User1", wrap.getUser());
-               
-               wrap.invalidate("1");
-
-               assertFalse(wrap.isUserInRole(null));
-               
-               wrap.set(tafResp, lur);
-               
-               wrap.invalidate("2");
-               
-               wrap.isUserInRole("User1");
-       }
-
-       @Test
-       public void testInstantiateWithPermConverter() throws CadiException {
-               Access a = new PropAccess();
-               when(tafResp.getAccess()).thenReturn(a);
-               when(tafResp.getPrincipal()).thenReturn(principle);
-               
-               // Anonymous object for testing purposes
-               CachingLur<Permission> lur1 = new CachingLur<Permission>() {
-                       @Override public Permission createPerm(String p) { return null; }
-                       @Override public boolean fish(Principal bait, Permission pond) { return true; }
-                       @Override public void fishAll(Principal bait, List<Permission> permissions) { }
-                       @Override public void destroy() { }
-                       @Override public boolean handlesExclusively(Permission pond) { return false; }
-                       @Override public boolean handles(Principal principal) { return false; }
-                       @Override public void remove(String user) { }
-                       @Override public Resp reload(User<Permission> user) { return null; }
-                       @Override public void setDebug(String commaDelimIDsOrNull) { }
-                       @Override public void clear(Principal p, StringBuilder sb) { }
-               };
-               
-               MapPermConverter pc = new MapPermConverter();
-               
-               CadiWrap wrap = new CadiWrap(request, tafResp, lur1, pc);
-               
-               assertNotNull(wrap.getUserPrincipal());
-               assertNull(wrap.getRemoteUser());
-               assertNull(wrap.getUser());
-               
-               byte[] arr = {'1','2'};
-               wrap.setCred(arr);
-               
-               assertEquals(arr, wrap.getCred());
-               
-               wrap.setUser("User1");
-               assertEquals("User1", wrap.getUser());
-               
-               wrap.invalidate("1");
-               wrap.setPermConverter(new MapPermConverter());
-               
-               assertTrue(wrap.getLur() instanceof CachingLur);
-               assertTrue(wrap.isUserInRole("User1"));
-               
-               wrap.set(tafResp, lur);
-               assertFalse(wrap.isUserInRole("Perm1"));
-       }
-}
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_MultiGet.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_MultiGet.java
new file mode 100644 (file)
index 0000000..e678421
--- /dev/null
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.cadi.test.config;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+import org.junit.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.cadi.config.Get;
+import org.onap.aaf.cadi.config.MultiGet;
+
+public class JU_MultiGet {
+
+       private String defaultVal = "some default value";
+
+       private ByteArrayOutputStream outStream;
+
+       private MultiGet multiGet;
+       private Get.AccessGet accessGet;
+       private PropAccess access;
+
+       @Before
+       public void setup() throws IOException {
+               outStream = new ByteArrayOutputStream();
+               System.setOut(new PrintStream(outStream));
+
+               access = new PropAccess();
+               access.setProperty("tag", "value");
+               accessGet = new Get.AccessGet(access);
+               multiGet = new MultiGet(accessGet, Get.NULL);
+       }
+
+       @After
+       public void tearDown() {
+               System.setOut(System.out);
+       }
+
+    @Test
+    public void getTest() {
+               assertThat(multiGet.get("tag", defaultVal, false), is("value"));
+               assertThat(multiGet.get("not_a_tag", defaultVal, false), is(defaultVal));
+       }
+
+}
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_SecurityInfoC.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/config/JU_SecurityInfoC.java
new file mode 100644 (file)
index 0000000..948bfad
--- /dev/null
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2017 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.cadi.test.config;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.junit.*;
+import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.cadi.SecuritySetter;
+import org.onap.aaf.cadi.config.SecurityInfoC;
+
+public class JU_SecurityInfoC {
+
+       ByteArrayOutputStream outStream;
+       ByteArrayOutputStream errStream;
+
+       @Before
+       public void setup() {
+               outStream = new ByteArrayOutputStream();
+               errStream = new ByteArrayOutputStream();
+
+               System.setOut(new PrintStream(outStream));
+               System.setErr(new PrintStream(errStream));
+       }
+
+       @After
+       public void tearDown() {
+               System.setOut(System.out);
+               System.setErr(System.err);
+       }
+
+       @Test
+       public void instanceTest() throws CadiException, MalformedURLException {
+               SecurityInfoC<HttpURLConnection> si = SecurityInfoC.instance(new PropAccess(), HttpURLConnection.class);
+               assertThat(si.defSS.getID(), is(SecurityInfoC.DEF_ID));
+               try {
+                       si.defSS.setSecurity(new HttpURLConnectionStub());
+                       fail("Should have thrown an exception");
+               } catch (CadiException e) {
+                       assertTrue(e instanceof CadiException);
+                       assertThat(e.getMessage(), is("No Client Credentials set."));
+               }
+               assertThat(si.defSS.setLastResponse(0), is(0));
+
+               // Try it again for coverage
+               SecurityInfoC<HttpURLConnection> siClone = SecurityInfoC.instance(new PropAccess(), HttpURLConnection.class);
+               assertThat(siClone, is(si));
+       }
+       
+       @Test
+       public void setTest() throws MalformedURLException, CadiException {
+               SecurityInfoC<HttpURLConnection> si = SecurityInfoC.instance(new PropAccess(), HttpURLConnection.class);
+               SecuritySetter<HttpURLConnection> ss = new SecuritySetterStub<HttpURLConnection>();
+               assertThat(si.set(ss), is(si));
+               assertThat(si.defSS.getID(), is("Example ID"));
+               try {
+                       si.defSS.setSecurity(new HttpURLConnectionStub());
+                       fail("Should have thrown an exception");
+               } catch (CadiException e) {
+                       assertTrue(e instanceof CadiException);
+                       assertThat(e.getMessage(), is("Example exception"));
+               }
+               assertThat(si.defSS.setLastResponse(0), is(0));
+               assertThat(si.defSS.setLastResponse(1), is(1));
+               assertThat(si.defSS.setLastResponse(-1), is(-1));
+       }
+
+       private class HttpURLConnectionStub extends HttpURLConnection {
+               public HttpURLConnectionStub() throws MalformedURLException { super(new URL("http://www.example.com")); } 
+               @Override public void disconnect() { } 
+               @Override public boolean usingProxy() { return false; } 
+               @Override public void connect() throws IOException { }
+       }
+
+       private class SecuritySetterStub<CT> implements SecuritySetter<CT> {
+               public String getID() { return "Example ID"; }
+               public void setSecurity(CT client) throws CadiException { throw new CadiException("Example exception"); }
+               public int setLastResponse(int respCode) { return respCode; }
+       }
+
+}
index d335eda..949d034 100644 (file)
@@ -6,9 +6,9 @@
  * * 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.
  ******************************************************************************/
 package org.onap.aaf.cadi.test.util;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
+import org.junit.*;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
 import org.onap.aaf.cadi.UserChain;
 import org.onap.aaf.cadi.util.UserChainManip;
 
@@ -34,33 +32,36 @@ public class JU_UserChainManip {
        @Test
        public void build(){
                UserChain.Protocol baseAuth=UserChain.Protocol.BasicAuth;
-               assertEquals(UserChainManip.build(new StringBuilder(""), "app", "id", baseAuth, true).toString(), "app:id:BasicAuth:AS");
-       }
-       
+               StringBuilder sb = UserChainManip.build(new StringBuilder(""), "app", "id", baseAuth, true);
+               assertThat(sb.toString(), is("app:id:BasicAuth:AS"));
 
-       @Test
-       public void idToNS(){
-               assertEquals(UserChainManip.idToNS(null), "");
+               // for coverage
+               sb = UserChainManip.build(sb, "app", "id", baseAuth, true);
+               assertThat(sb.toString(), is("app:id:BasicAuth:AS,app:id:BasicAuth"));
+
+               sb = UserChainManip.build(new StringBuilder(""), "app", "id", baseAuth, false);
+               assertThat(sb.toString(), is("app:id:BasicAuth"));
        }
-       
+
        @Test
-       public void idToNS1(){
-               assertEquals(UserChainManip.idToNS("t@st"), "st");
+       public void idToNSTEST() {
+               assertThat(UserChainManip.idToNS(null), is(""));
+               assertThat(UserChainManip.idToNS(""), is(""));
+               assertThat(UserChainManip.idToNS("something"), is(""));
+               assertThat(UserChainManip.idToNS("something@@"), is(""));
+               assertThat(UserChainManip.idToNS("something@@."), is(""));
+               assertThat(UserChainManip.idToNS("something@com"), is("com"));
+               assertThat(UserChainManip.idToNS("something@random.com"), is("com.random"));
+               assertThat(UserChainManip.idToNS("@random.com"), is("com.random"));
+               assertThat(UserChainManip.idToNS("something@random.com."), is("com.random"));
+               assertThat(UserChainManip.idToNS("something@..random...com..."), is("com.random"));
+               assertThat(UserChainManip.idToNS("something@this.random.com"), is("com.random.this"));
        }
 
        @Test
-       public void test() {
-               assertEquals("",UserChainManip.idToNS(null));
-               assertEquals("",UserChainManip.idToNS(""));
-               assertEquals("",UserChainManip.idToNS("something"));
-               assertEquals("",UserChainManip.idToNS("something@@"));
-               assertEquals("",UserChainManip.idToNS("something@@."));
-               assertEquals("com",UserChainManip.idToNS("something@com"));
-               assertEquals("com.random",UserChainManip.idToNS("something@random.com"));
-               assertEquals("com.random",UserChainManip.idToNS("@random.com"));
-               assertEquals("com.random",UserChainManip.idToNS("something@random.com."));
-               assertEquals("com.random",UserChainManip.idToNS("something@..random...com..."));
-               assertEquals("com.random.this",UserChainManip.idToNS("something@this.random.com"));
+       public void coverageTest() {
+               @SuppressWarnings("unused")
+               UserChainManip ucm = new UserChainManip();
        }
 
 }