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