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.*;
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;
34 import javax.xml.namespace.QName;
35 import javax.xml.validation.Schema;
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;
61 @RunWith(MockitoJUnitRunner.class)
62 public class JU_FacadeImpl<REQ,CERT,ARTIFACTS,ERROR> {
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;
73 private static FacadeImpl fImpl;
74 private static HttpServletRequest req;
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() {
88 public void printf(String fmt, Object... vars) {}
91 public void log(Throwable e, Object... msgs) {
99 public void log(Object... msgs) {
103 public boolean isLoggable() {
108 when(trans.start(Mockito.anyString(), Mockito.anyInt())).thenReturn(new TimeTaken("Now", 1) {
111 public void output(StringBuilder sb) {
115 when(fImpl.check(Mockito.any(AuthzTrans.class), Mockito.any(HttpServletResponse.class), Mockito.anyString())).thenReturn(rvd);
116 when(resp.getOutputStream()).thenReturn(new ServletOutputStream() {
119 public void write(int b) throws IOException {
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));
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));
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));
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));
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));
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));
170 public void requestCert() {
171 assertNotNull(hImpl.requestCert(trans, req, resp, null));
175 public void renewCert() {
176 assertNotNull(hImpl.renewCert(trans, req, resp, true));
180 public void dropCert() {
181 assertNotNull(hImpl.renewCert(trans, req, resp, true));
185 public void createArtifacts() {
186 assertNotNull(hImpl.createArtifacts(trans, req, resp));
190 public void readArtifacts() {
191 assertNotNull(hImpl.readArtifacts(trans, req, resp));