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