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 ******************************************************************************/
22 package org.onap.aaf.auth.cm.facade;
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;
29 import java.io.IOException;
31 import javax.servlet.ServletOutputStream;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
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;
53 @RunWith(MockitoJUnitRunner.class)
54 public class JU_FacadeImpl<REQ,CERT,ARTIFACTS,ERROR> {
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;
65 private static FacadeImpl fImpl;
66 private static HttpServletRequest req;
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() {
80 public void printf(String fmt, Object... vars) {}
83 public void log(Throwable e, Object... msgs) {
91 public void log(Object... msgs) {
95 public boolean isLoggable() {
100 when(trans.start(Mockito.anyString(), Mockito.anyInt())).thenReturn(new TimeTaken("Now", 1) {
103 public void output(StringBuilder sb) {
107 when(fImpl.check(Mockito.any(AuthzTrans.class), Mockito.any(HttpServletResponse.class), Mockito.anyString())).thenReturn(rvd);
108 when(resp.getOutputStream()).thenReturn(new ServletOutputStream() {
111 public void write(int b) throws IOException {
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));
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));
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));
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));
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));
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));
162 public void requestCert() {
163 assertNotNull(hImpl.requestCert(trans, req, resp, null));
167 public void renewCert() {
168 assertNotNull(hImpl.renewCert(trans, req, resp, true));
172 public void dropCert() {
173 assertNotNull(hImpl.renewCert(trans, req, resp, true));
177 public void createArtifacts() {
178 assertNotNull(hImpl.createArtifacts(trans, req, resp));
182 public void readArtifacts() {
183 assertNotNull(hImpl.readArtifacts(trans, req, resp));