a0e95ab89a75a58436aa8b49840d2b4559153bed
[aaf/authz.git] / auth / auth-cmd / src / test / java / org / onap / aaf / auth / cmd / test / ns / JU_Create.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.ns;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28
29 import java.io.Writer;
30 import java.net.HttpURLConnection;
31 import java.net.URI;
32 import java.net.URISyntaxException;
33
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.runners.MockitoJUnitRunner;
38 import org.onap.aaf.auth.cmd.AAFcli;
39 import org.onap.aaf.auth.cmd.ns.Create;
40 import org.onap.aaf.auth.cmd.ns.NS;
41 import org.onap.aaf.auth.env.AuthzEnv;
42 import org.onap.aaf.cadi.CadiException;
43 import org.onap.aaf.cadi.Locator;
44 import org.onap.aaf.cadi.Locator.Item;
45 import org.onap.aaf.cadi.LocatorException;
46 import org.onap.aaf.cadi.PropAccess;
47 import org.onap.aaf.cadi.SecuritySetter;
48 import org.onap.aaf.cadi.http.HMangr;
49 import org.onap.aaf.cadi.http.HRcli;
50 import org.onap.aaf.misc.env.APIException;
51
52 @RunWith(MockitoJUnitRunner.class)
53 public class JU_Create {
54
55     private static Create create;//might need to replace import with org.onap.aaf.auth.cmd.perm
56     PropAccess prop;
57     AuthzEnv aEnv;
58     Writer wtr;
59     Locator<URI> loc;
60     HMangr hman;    
61     AAFcli aafcli;
62     
63     @Before
64     public void setUp() throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException {
65         prop = new PropAccess();
66         aEnv = new AuthzEnv();
67         wtr = mock(Writer.class);
68         loc = mock(Locator.class);
69         SecuritySetter<HttpURLConnection> secSet = mock(SecuritySetter.class);
70         hman = new HMangr(aEnv, loc);    
71         aafcli = new AAFcli(prop, aEnv, wtr, hman, null, secSet);
72         NS ns = new NS(aafcli);
73         create = new Create(ns);
74     }
75     
76     
77
78     @Test
79     public void testExec() throws APIException, LocatorException, CadiException, URISyntaxException {
80         Item value = mock(Item.class);
81         Locator.Item item = new Locator.Item() {
82         };
83         when(loc.best()).thenReturn(value);
84         URI uri = new URI("http://www.oracle.com/technetwork/java/index.html");
85         when(loc.get(value)).thenReturn(uri);
86         SecuritySetter<HttpURLConnection> secSet = mock(SecuritySetter.class);
87         HRcli hcli = new HRcli(hman, uri, item, secSet);
88         String[] strArr = {"add","upd","del","add","upd","del"};
89         create._exec(0, strArr);
90         
91     }
92
93     @Test
94     public void detailedHelp() {
95         boolean hasNoError = true;
96         try {
97             create.detailedHelp(1, new StringBuilder("test"));
98         } catch (Exception e) {
99             hasNoError = false;
100         }
101         assertEquals(hasNoError, true);
102     }
103 }