1 /*******************************************************************************
2 * ============LICENSE_START====================================================
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
11 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 ******************************************************************************/
23 package org.onap.aaf.auth.cm.facade;
25 import static org.junit.Assert.assertNotNull;
26 import static org.mockito.Mockito.CALLS_REAL_METHODS;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.when;
30 import java.io.IOException;
32 import javax.servlet.ServletOutputStream;
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.http.HttpServletResponse;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.Mockito;
40 import org.mockito.runners.MockitoJUnitRunner;
41 import org.onap.aaf.auth.cm.AAF_CM;
42 import org.onap.aaf.auth.cm.mapper.Mapper;
43 import org.onap.aaf.auth.cm.service.CMService;
44 import org.onap.aaf.auth.env.AuthzEnv;
45 import org.onap.aaf.auth.env.AuthzTrans;
46 import org.onap.aaf.auth.layer.Result;
47 import org.onap.aaf.cadi.aaf.AAFPermission;
48 import org.onap.aaf.misc.env.APIException;
49 import org.onap.aaf.misc.env.Data;
50 import org.onap.aaf.misc.env.LogTarget;
51 import org.onap.aaf.misc.env.TimeTaken;
54 @RunWith(MockitoJUnitRunner.class)
55 public class JU_FacadeImpl<REQ,CERT,ARTIFACTS,ERROR> {
57 private static AuthzTrans trans;
58 private static HttpServletResponse resp;
59 private static AAF_CM certman;
60 private static FacadeImpl hImpl;
61 private static CMService service;
62 private Mapper<REQ,CERT,ARTIFACTS,ERROR> mapper;
63 private Data.TYPE dataType;
64 private static AuthzEnv env;
66 private static FacadeImpl fImpl;
67 private static HttpServletRequest req;
70 public void setUp() throws APIException, IOException {
71 fImpl = mock(FacadeImpl.class);
72 env = mock(AuthzEnv.class);
73 resp = mock(HttpServletResponse.class);
74 req = mock(HttpServletRequest.class);
75 hImpl = mock(FacadeImpl.class, CALLS_REAL_METHODS);
76 Result<Void> rvd = (Result) mock(Result.class);
77 trans = mock(AuthzTrans.class);
78 when(trans.error()).thenReturn(new LogTarget() {
81 public void printf(String fmt, Object... vars) {}
84 public void log(Throwable e, Object... msgs) {
92 public void log(Object... msgs) {
96 public boolean isLoggable() {
101 when(trans.start(Mockito.anyString(), Mockito.anyInt())).thenReturn(new TimeTaken("Now", 1) {
104 public void output(StringBuilder sb) {
108 when(fImpl.check(Mockito.any(AuthzTrans.class), Mockito.any(HttpServletResponse.class), Mockito.anyString())).thenReturn(rvd);
109 when(resp.getOutputStream()).thenReturn(new ServletOutputStream() {
112 public void write(int b) throws IOException {
121 public void check() throws IOException {
122 AAFPermission ap = new AAFPermission("str0","str1","str3","str2");
123 String perms = ap.getInstance();
124 assertNotNull(hImpl.check(trans, resp, perms));
128 public void checkNull() throws IOException {
129 AAFPermission ap = new AAFPermission(null,null,"Str3","str2");
130 String perms = ap.getInstance();
131 assertNotNull(hImpl.check(trans, resp, perms));
135 public void checkTwoNull() throws IOException {
136 AAFPermission ap = new AAFPermission(null,null,null,"str2");
137 String perms = ap.getInstance();
138 assertNotNull(fImpl.check(trans, resp, perms));
142 public void checkAllNull() throws IOException {
143 AAFPermission ap = new AAFPermission(null,null,null,null);
144 String perms = ap.getInstance();
145 assertNotNull(fImpl.check(trans, resp, perms));
149 public void checkTrans_null() throws IOException {
150 AAFPermission ap = new AAFPermission("str0","str1","str3","str2");
151 String perms = ap.getInstance();
152 assertNotNull(hImpl.check(null, resp, perms));
156 public void checkRespNull() throws IOException {
157 AAFPermission ap = new AAFPermission("str0","str1","str3","str2");
158 String perms = ap.getInstance();
159 assertNotNull(hImpl.check(trans, null, perms));
163 public void requestCert() {
164 assertNotNull(hImpl.requestCert(trans, req, resp, null));
168 public void renewCert() {
169 assertNotNull(hImpl.renewCert(trans, req, resp, true));
173 public void dropCert() {
174 assertNotNull(hImpl.renewCert(trans, req, resp, true));
178 public void createArtifacts() {
179 assertNotNull(hImpl.createArtifacts(trans, req, resp));
183 public void readArtifacts() {
184 assertNotNull(hImpl.readArtifacts(trans, req, resp));