From 3c15cc2c764a240ccd91d07be2d8ec25f4d05392 Mon Sep 17 00:00:00 2001 From: "gabe.maurer" Date: Mon, 21 May 2018 13:11:08 -0500 Subject: Increased code coverage auth batch Issue-ID: AAF-233 Change-Id: Ic62eb1a1e3c6249ff00600c0dd81ab94085aa58f Signed-off-by: gabe.maurer --- .../org/onap/aaf/auth/actions/test/JU_Email.java | 19 ++++- .../onap/aaf/auth/actions/test/JU_EmailPrint.java | 92 ++++++++++++++++++++++ .../org/onap/aaf/auth/actions/test/JU_Message.java | 62 +++++++++++++++ 3 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_EmailPrint.java create mode 100644 auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_Message.java (limited to 'auth/auth-batch/src/test/java') diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_Email.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_Email.java index 0779a33d..70cd08a8 100644 --- a/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_Email.java +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_Email.java @@ -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 index 00000000..fb5d2bd5 --- /dev/null +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_EmailPrint.java @@ -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 index 00000000..fa7409ea --- /dev/null +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_Message.java @@ -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"); + } + +} -- cgit 1.2.3-korg