AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-certman / src / test / java / org / onap / aaf / auth / cm / facade / JU_FacadeImpl.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 2017 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.cm.facade;
23
24 import static org.junit.Assert.*;
25 import static org.mockito.Mockito.CALLS_REAL_METHODS;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28
29 import java.io.IOException;
30
31 import javax.servlet.ServletOutputStream;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34 import javax.xml.namespace.QName;
35 import javax.xml.validation.Schema;
36
37 import org.junit.Before;
38 import org.junit.BeforeClass;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 import org.mockito.Mockito;
42 import org.mockito.runners.MockitoJUnitRunner;
43 import org.onap.aaf.auth.cm.AAF_CM;
44 import org.onap.aaf.auth.cm.facade.FacadeImpl;
45 import org.onap.aaf.auth.cm.mapper.Mapper;
46 import org.onap.aaf.auth.cm.service.CMService;
47 import org.onap.aaf.auth.env.AuthzEnv;
48 import org.onap.aaf.auth.env.AuthzTrans;
49 import org.onap.aaf.auth.layer.Result;
50 import org.onap.aaf.cadi.aaf.AAFPermission;
51 import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;
52 import org.onap.aaf.misc.env.APIException;
53 import org.onap.aaf.misc.env.Data;
54 import org.onap.aaf.misc.env.LogTarget;
55 import org.onap.aaf.misc.env.TimeTaken;
56 import org.onap.aaf.misc.env.Trans;
57 import org.onap.aaf.misc.rosetta.env.RosettaDF;
58 import org.onap.aaf.misc.rosetta.env.RosettaData;
59
60
61 @RunWith(MockitoJUnitRunner.class)
62 public class JU_FacadeImpl<REQ,CERT,ARTIFACTS,ERROR> {
63         
64         private static AuthzTrans trans;
65         private static HttpServletResponse resp;
66         private static AAF_CM certman;
67         private static FacadeImpl hImpl;
68         private static CMService service;
69         private Mapper<REQ,CERT,ARTIFACTS,ERROR> mapper;
70         private Data.TYPE dataType;
71         private static AuthzEnv env;
72         
73         private static FacadeImpl fImpl;
74         private static HttpServletRequest req;
75         
76         @Before
77         public void setUp() throws APIException, IOException {
78                 fImpl = mock(FacadeImpl.class);
79                 env = mock(AuthzEnv.class);
80                 resp = mock(HttpServletResponse.class);
81                 req = mock(HttpServletRequest.class);
82                 hImpl = mock(FacadeImpl.class, CALLS_REAL_METHODS);
83                 Result<Void> rvd = (Result) mock(Result.class);
84                 trans = mock(AuthzTrans.class);
85                 when(trans.error()).thenReturn(new LogTarget() {
86                         
87                         @Override
88                         public void printf(String fmt, Object... vars) {}
89                         
90                         @Override
91                         public void log(Throwable e, Object... msgs) {
92                                 e.getMessage();
93                                 e.printStackTrace();
94                                 msgs.toString();
95                                 
96                         }
97                         
98                         @Override
99                         public void log(Object... msgs) {
100                         }
101                         
102                         @Override
103                         public boolean isLoggable() {
104                                 
105                                 return false;
106                         }
107                 });
108                 when(trans.start(Mockito.anyString(), Mockito.anyInt())).thenReturn(new TimeTaken("Now", 1) {
109                         
110                         @Override
111                         public void output(StringBuilder sb) {
112                                 
113                         }
114                 });
115                 when(fImpl.check(Mockito.any(AuthzTrans.class), Mockito.any(HttpServletResponse.class), Mockito.anyString())).thenReturn(rvd);
116                 when(resp.getOutputStream()).thenReturn(new ServletOutputStream() {
117                         
118                         @Override
119                         public void write(int b) throws IOException {
120                                 
121                                 
122                         }
123                 });
124                 
125         }
126         
127         @Test
128         public void check() throws IOException {
129                 AAFPermission ap = new AAFPermission("str1","str3","str2");
130                 String perms = ap.getInstance();
131                 assertNotNull(hImpl.check(trans, resp, perms));
132         }
133         
134         @Test
135         public void checkNull() throws IOException {
136                 AAFPermission ap = new AAFPermission(null,"Str3","str2");
137                 String perms = ap.getInstance();
138                 assertNotNull(hImpl.check(trans, resp, perms));
139         }
140         
141         @Test
142         public void checkTwoNull() throws IOException {
143                 AAFPermission ap = new AAFPermission(null,null,"str2");
144                 String perms = ap.getInstance();
145                 assertNotNull(fImpl.check(trans, resp, perms));
146         }
147         
148         @Test
149         public void checkAllNull() throws IOException {
150                 AAFPermission ap = new AAFPermission(null,null,null);
151                 String perms = ap.getInstance();
152                 assertNotNull(fImpl.check(trans, resp, perms));
153         }
154         
155         @Test
156         public void checkTrans_null() throws IOException {
157                 AAFPermission ap = new AAFPermission("str1","str3","str2");
158                 String perms = ap.getInstance();
159                 assertNotNull(hImpl.check(null, resp, perms));
160         }
161         
162         @Test
163         public void checkRespNull() throws IOException {
164                 AAFPermission ap = new AAFPermission("str1","str3","str2");
165                 String perms = ap.getInstance();
166                 assertNotNull(hImpl.check(trans, null, perms));
167         }
168         
169         @Test
170         public void requestCert() {             
171                 assertNotNull(hImpl.requestCert(trans, req, resp, null));
172         }
173         
174         @Test
175         public void renewCert() {               
176                 assertNotNull(hImpl.renewCert(trans, req, resp, true));
177         }
178         
179         @Test
180         public void dropCert() {                
181                 assertNotNull(hImpl.renewCert(trans, req, resp, true));
182         }
183         
184         @Test
185         public void createArtifacts() {         
186                 assertNotNull(hImpl.createArtifacts(trans, req, resp));
187         }
188         
189         @Test
190         public void readArtifacts() {           
191                 assertNotNull(hImpl.readArtifacts(trans, req, resp));
192         }
193 }