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.cmd.test.perm;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Mockito.when;
27 import org.junit.Before;
29 import org.onap.aaf.auth.cmd.test.HMangrStub;
31 import java.io.ByteArrayOutputStream;
32 import java.io.PrintStream;
33 import java.io.Writer;
34 import java.net.HttpURLConnection;
36 import java.net.URISyntaxException;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.mockito.Mock;
41 import org.mockito.MockitoAnnotations;
42 import org.mockito.runners.MockitoJUnitRunner;
43 import org.onap.aaf.auth.cmd.AAFcli;
44 import org.onap.aaf.auth.cmd.ns.Create;
45 import org.onap.aaf.auth.cmd.ns.NS;
46 import org.onap.aaf.auth.env.AuthzEnv;
47 import org.onap.aaf.cadi.CadiException;
48 import org.onap.aaf.cadi.Locator;
49 import org.onap.aaf.cadi.LocatorException;
50 import org.onap.aaf.cadi.PropAccess;
51 import org.onap.aaf.cadi.SecuritySetter;
52 import org.onap.aaf.cadi.client.Future;
53 import org.onap.aaf.cadi.client.Rcli;
54 import org.onap.aaf.misc.env.APIException;
56 @RunWith(MockitoJUnitRunner.class)
57 public class JU_Create {
59 @Mock private SecuritySetter<HttpURLConnection> ssMock;
60 @Mock private Locator<URI> locMock;
61 @Mock private Writer wrtMock;
62 @Mock private Rcli<HttpURLConnection> clientMock;
63 @Mock private Future<Object> futureMock;
65 private static Create create;
68 private PropAccess access;
69 private HMangrStub hman;
70 private AuthzEnv aEnv;
71 private AAFcli aafcli;
74 public void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException {
75 MockitoAnnotations.initMocks(this);
77 when(clientMock.create(any(), any(), any())).thenReturn(futureMock);
78 when(clientMock.delete(any(), any(), any())).thenReturn(futureMock);
79 when(clientMock.update(any(), any(), any())).thenReturn(futureMock);
81 hman = new HMangrStub(access, locMock, clientMock);
82 access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
83 aEnv = new AuthzEnv();
84 aafcli = new AAFcli(access, aEnv, wrtMock, hman, null, ssMock);
88 create = new Create(ns);
92 public void testError() throws APIException, LocatorException, CadiException, URISyntaxException {
93 create._exec(0, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"});
94 create._exec(4, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"});
98 public void testSuccess1() throws APIException, LocatorException, CadiException, URISyntaxException {
99 when(futureMock.code()).thenReturn(202);
100 create._exec(0, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"});
104 public void testSuccess2() throws APIException, LocatorException, CadiException, URISyntaxException {
105 when(futureMock.get(any(Integer.class))).thenReturn(true);
106 create._exec(0, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"});
110 public void testDetailedHelp() {
111 StringBuilder sb = new StringBuilder();
112 create.detailedHelp(0, sb);