Increased code coverage auth batch 53/48353/1
authorgabe.maurer <gabe.maurer@att.com>
Mon, 21 May 2018 18:11:08 +0000 (13:11 -0500)
committergabe.maurer <gabe.maurer@att.com>
Mon, 21 May 2018 18:12:22 +0000 (13:12 -0500)
Issue-ID: AAF-233
Change-Id: Ic62eb1a1e3c6249ff00600c0dd81ab94085aa58f
Signed-off-by: gabe.maurer <gabe.maurer@att.com>
auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_Email.java
auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_EmailPrint.java [new file with mode: 0644]
auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_Message.java [new file with mode: 0644]

index 0779a33..70cd08a 100644 (file)
@@ -37,6 +37,7 @@ import org.onap.aaf.auth.org.OrganizationException;
 
 import static org.mockito.Mockito.*;
 
+import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
 import java.io.PrintStream;
 import java.util.Collection;
@@ -47,12 +48,21 @@ import org.junit.Test;
 
 public class JU_Email {
        
+       private ByteArrayOutputStream outStream;
+       private ByteArrayOutputStream errStream;
        Email email;
        Identity usersI;
        Message msg;
+       PrintStream ps;
        
        @Before
-       public void setUp() {
+       public void setUp() throws FileNotFoundException {
+               outStream = new ByteArrayOutputStream();
+               errStream = new ByteArrayOutputStream();
+               ps = new PrintStream(errStream);
+               System.setOut(new PrintStream(outStream));
+               System.setErr(ps);
+               
                usersI = mock(Identity.class);
                msg = new Message();
                email = new Email();
@@ -124,7 +134,6 @@ public class JU_Email {
        
        @Test
        public void testLog() throws FileNotFoundException {
-               PrintStream ps = new PrintStream("test");
                email.addTo("email");
                email.addCC("email");
                email.log(ps, "email");
@@ -132,5 +141,11 @@ public class JU_Email {
                email.addCC("emails");
                email.log(ps, "emails");
        }
+       
+       @After
+       public void cleanUp() {
+               System.setErr(System.err);
+               System.setOut(System.out);
+       }
 
 }
diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_EmailPrint.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_EmailPrint.java
new file mode 100644 (file)
index 0000000..fb5d2bd
--- /dev/null
@@ -0,0 +1,92 @@
+/**
+ * ============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.actions.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.actions.EmailPrint;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.org.Organization;
+import org.onap.aaf.cadi.client.Future;
+import org.onap.aaf.cadi.client.Rcli;
+
+import static org.mockito.Mockito.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.junit.Test;
+
+public class JU_EmailPrint {
+       
+       private ByteArrayOutputStream outStream;
+       private ByteArrayOutputStream errStream;
+       EmailPrint ePrint;
+       AuthzTrans trans;
+       Organization org;
+       StringBuilder strBuilder;
+       
+       @Before
+       public void setUp() {
+               outStream = new ByteArrayOutputStream();
+               errStream = new ByteArrayOutputStream();
+               System.setOut(new PrintStream(outStream));
+               System.setErr(new PrintStream(errStream));
+               ePrint = new EmailPrint();
+               trans = mock(AuthzTrans.class);
+               org = mock(Organization.class);
+               strBuilder = new StringBuilder();
+               strBuilder.append("test\nte\nst");
+               ePrint.addTo("test");
+               ePrint.addTo("test1");
+               ePrint.addTo("test2");
+               ePrint.addCC("test");
+               ePrint.addCC("test1");
+               ePrint.addCC("test2");
+               
+       }
+
+       @Test
+       public void testExec() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+               Class c = ePrint.getClass();
+               Class[] cArg = new Class[3];
+               cArg[0] = AuthzTrans.class;
+               cArg[1] = Organization.class;
+               cArg[2] = StringBuilder.class;//Steps to test a protected method
+               Method execMethod = c.getDeclaredMethod("exec", cArg);
+               execMethod.setAccessible(true);
+               execMethod.invoke(ePrint, trans, org, strBuilder);
+       }
+       
+       @After
+       public void cleanUp() {
+               System.setErr(System.err);
+               System.setOut(System.out);
+       }
+
+}
diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_Message.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_Message.java
new file mode 100644 (file)
index 0000000..fa7409e
--- /dev/null
@@ -0,0 +1,62 @@
+/**
+ * ============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.actions.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.actions.Message;
+
+import static org.mockito.Mockito.*;
+import org.junit.Test;
+
+public class JU_Message {
+       
+       Message msg;
+       
+       @Before
+       public void setUp() {
+               msg = new Message();
+       }
+
+       @Test
+       public void testLine() {
+               msg.line("test");
+       }
+       
+       @Test
+       public void testClear() {
+               msg.clear();
+       }
+       
+       @Test
+       public void testMsg() {
+               StringBuilder sb = new StringBuilder();
+               msg.line("test");
+               msg.line("test1");
+               msg.msg(sb, "indent");
+       }
+
+}