Sonar Fixes, Formatting
[aaf/authz.git] / auth / auth-cmd / src / test / java / org / onap / aaf / auth / cmd / test / perm / JU_Delete.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
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
10  * *
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * *
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====================================================
19  * *
20  * *
21  ******************************************************************************/
22
23 package org.onap.aaf.auth.cmd.test.perm;
24
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Mockito.when;
27
28 import org.hamcrest.core.AnyOf;
29 import org.junit.Before;
30
31 import org.onap.aaf.auth.cmd.test.HMangrStub;
32
33 import java.io.ByteArrayOutputStream;
34 import java.io.PrintStream;
35 import java.io.Writer;
36 import java.net.HttpURLConnection;
37 import java.net.URI;
38 import java.net.URISyntaxException;
39
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.mockito.Mock;
43 import org.mockito.MockitoAnnotations;
44 import org.mockito.runners.MockitoJUnitRunner;
45 import org.onap.aaf.auth.cmd.AAFcli;
46 import org.onap.aaf.auth.cmd.perm.Delete;
47 import org.onap.aaf.auth.cmd.perm.Perm;
48 import org.onap.aaf.auth.cmd.role.Role;
49 import org.onap.aaf.auth.env.AuthzEnv;
50 import org.onap.aaf.cadi.CadiException;
51 import org.onap.aaf.cadi.Locator;
52 import org.onap.aaf.cadi.LocatorException;
53 import org.onap.aaf.cadi.PropAccess;
54 import org.onap.aaf.cadi.SecuritySetter;
55 import org.onap.aaf.cadi.client.Future;
56 import org.onap.aaf.cadi.client.Rcli;
57 import org.onap.aaf.misc.env.APIException;
58
59 @RunWith(MockitoJUnitRunner.class)
60 public class JU_Delete {
61
62     @Mock private SecuritySetter<HttpURLConnection> ssMock;
63     @Mock private Locator<URI> locMock;
64     @Mock private Writer wrtMock;
65     @Mock private Rcli<HttpURLConnection> clientMock;
66     @Mock private Future<String> futureMock;
67
68     private static Delete del;
69
70     private PropAccess access;
71     private HMangrStub hman;
72     private AuthzEnv aEnv;
73     private AAFcli aafcli;
74
75     @Before
76     public void setUp() throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException {
77         MockitoAnnotations.initMocks(this);
78
79         when(clientMock.create(any(), any(), any(String.class))).thenReturn(futureMock);
80         when(clientMock.delete(any(), any(), any(String.class))).thenReturn(futureMock);
81         when(clientMock.update(any(), any(), any(String.class))).thenReturn(futureMock);
82
83         hman = new HMangrStub(access, locMock, clientMock);
84         access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
85         aEnv = new AuthzEnv();
86         aafcli = new AAFcli(access, aEnv, wrtMock, hman, null, ssMock);
87
88         Role role = new Role(aafcli);
89         Perm perm = new Perm(role);
90
91         del = new Delete(perm);
92     }
93
94     @Test
95     public void testExecError() throws APIException, LocatorException, CadiException, URISyntaxException {
96         del._exec(0, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"});
97     }
98
99     @Test
100     public void testExecSuccess1() throws APIException, LocatorException, CadiException, URISyntaxException {
101         when(futureMock.code()).thenReturn(202);
102         del._exec(0, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"});
103     }
104
105     @Test
106     public void testExecSuccess2() throws APIException, LocatorException, CadiException, URISyntaxException {
107         when(futureMock.get(any(Integer.class))).thenReturn(true);
108         del._exec(0, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"});
109     }
110
111     @Test
112     public void testDetailedHelp() {
113         StringBuilder sb = new StringBuilder();
114         del.detailedHelp(0, sb);
115     }
116
117 }