Update Batch from Testing
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / batch / actions / test / JU_EmailPrint.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.batch.actions.test;
23
24 import static org.junit.Assert.*;
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.onap.aaf.auth.batch.actions.EmailPrint;
31 import org.onap.aaf.auth.env.AuthzTrans;
32 import org.onap.aaf.auth.org.Organization;
33 import org.onap.aaf.cadi.client.Future;
34 import org.onap.aaf.cadi.client.Rcli;
35
36 import static org.mockito.Mockito.*;
37
38 import java.io.ByteArrayOutputStream;
39 import java.io.PrintStream;
40 import java.lang.reflect.InvocationTargetException;
41 import java.lang.reflect.Method;
42
43 import org.junit.Test;
44
45 public class JU_EmailPrint {
46     
47     private ByteArrayOutputStream outStream;
48     private ByteArrayOutputStream errStream;
49     EmailPrint ePrint;
50     AuthzTrans trans;
51     Organization org;
52     StringBuilder strBuilder;
53     
54     @Before
55     public void setUp() {
56         outStream = new ByteArrayOutputStream();
57         errStream = new ByteArrayOutputStream();
58         System.setOut(new PrintStream(outStream));
59         System.setErr(new PrintStream(errStream));
60         ePrint = new EmailPrint();
61         trans = mock(AuthzTrans.class);
62         org = mock(Organization.class);
63         strBuilder = new StringBuilder();
64         strBuilder.append("test\nte\nst");
65         ePrint.addTo("test");
66         ePrint.addTo("test1");
67         ePrint.addTo("test2");
68         ePrint.addCC("test");
69         ePrint.addCC("test1");
70         ePrint.addCC("test2");
71         
72     }
73
74     @Test
75     public void testExec() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
76         Class c = ePrint.getClass();
77         Class[] cArg = new Class[3];
78         cArg[0] = AuthzTrans.class;
79         cArg[1] = Organization.class;
80         cArg[2] = StringBuilder.class;//Steps to test a protected method
81         Method execMethod = c.getDeclaredMethod("exec", cArg);
82         execMethod.setAccessible(true);
83         execMethod.invoke(ePrint, trans, org, strBuilder);
84     }
85     
86     @After
87     public void cleanUp() {
88         System.setErr(System.err);
89         System.setOut(System.out);
90     }
91
92 }