summaryrefslogtreecommitdiffstats
path: root/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_AAFCli.java
blob: abe4c34219115d03377e1ebe6bd3031e8b0ba6cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*******************************************************************************
 * ============LICENSE_START====================================================
 * * org.onap.aaf
 * * ===========================================================================
 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
 * * ===========================================================================
 * * Licensed under the Apache License, Version 2.0 (the "License");
 * * you may not use this file except in compliance with the License.
 * * You may obtain a copy of the License at
 * * 
 *  *      http://www.apache.org/licenses/LICENSE-2.0
 * * 
 *  * Unless required by applicable law or agreed to in writing, software
 * * distributed under the License is distributed on an "AS IS" BASIS,
 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * * See the License for the specific language governing permissions and
 * * limitations under the License.
 * * ============LICENSE_END====================================================
 * *
 * *
 ******************************************************************************/

package org.onap.aaf.auth.cmd.test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.security.GeneralSecurityException;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.aaf.auth.cmd.AAFcli;
import org.onap.aaf.auth.env.AuthzEnv;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.Locator;
import org.onap.aaf.cadi.LocatorException;
import org.onap.aaf.cadi.config.Config;
import org.onap.aaf.cadi.config.SecurityInfo;
import org.onap.aaf.cadi.config.SecurityInfoC;
import org.onap.aaf.cadi.http.HBasicAuthSS;
import org.onap.aaf.cadi.http.HMangr;
import org.onap.aaf.cadi.locator.PropertyLocator;
import org.onap.aaf.misc.env.APIException;

@RunWith(MockitoJUnitRunner.class)
public class JU_AAFCli {

    private static AAFcli cli;
    private static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF);

    @BeforeClass
    public static void setUp() throws Exception, Exception {
        cli = getAAfCli();
    }

    @Test
    public void eval() throws Exception {
        assertTrue(cli.eval("#startswith"));
    }

    @Test
    public void eval_empty() throws Exception {
        assertTrue(cli.eval(""));
    }

    @Test
    public void eval1() throws Exception {
        assertTrue(cli.eval("@[123"));
    }

//    @Test
//    public void eval2() throws Exception {
//        assertFalse(cli.eval("as @[ 123"));
//    }

    @Test
    public void eval3() throws Exception {
        try {
            cli.eval("expect @[ 123");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            assertTrue(e instanceof CadiException);
        }
    }

    public void eval31() throws Exception {
        try {
            cli.eval("expect 1 @[ 123");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            assertTrue(e instanceof CadiException);
        }
    }

    @Test
    public void eval4() throws Exception {
        try {
            cli.eval("sleep @[ 123");
        } catch (Exception e) {
            assertTrue(e instanceof NumberFormatException);
        }
    }

    @Test
    public void eval41() throws Exception {
        assertTrue(cli.eval("sleep 1 @[ 123"));
    }

    @Test
    public void eval5() throws Exception {
        try {
            cli.eval("delay @[ 123");
        } catch (Exception e) {
            assertTrue(e instanceof NumberFormatException);
        }
    }

    @Test
    public void eval51() throws Exception {
        assertTrue(cli.eval("delay 1 @[ 123"));
    }

    @Test
    public void eval7() throws Exception {
        assertFalse(cli.eval("exit @[ 123"));
    }

    @Test
    public void eval8() throws Exception {
        assertTrue(cli.eval("REQUEST @[ 123"));
    }

    @Test
    public void eval9() throws Exception {
        assertTrue(cli.eval("FORCE @[ 123"));
    }

    @Test
    public void eval10() throws Exception {
        assertTrue(cli.eval("set @[ 123"));
    }
    
    @Test
    public void eval11() throws Exception {
        assertTrue(cli.eval("DETAILS @[ 123"));
    }
    
    @Test
    public void eval12() throws Exception {
        assertTrue(cli.eval(". |/, .\"0 \" "));
    }

    @Test
    public void keyboardHelp() throws Exception {
        boolean noError=true;
        try {
            cli.keyboardHelp();
        } catch (Exception e) {
            noError=false;
        }
        assertTrue(noError);
    }

    @Test
    public void setProp() throws Exception {
        boolean noError=true;
        try {
            cli.keyboardHelp();
        } catch (Exception e) {
            noError=false;
        }
        assertTrue(noError);
    }
    
    @Test
    public void eval_randomString() throws Exception {
        assertTrue(cli.eval("Some random string @#&*& to check complete 100 coverage"));
    }

    public static AAFcli getAAfCli() throws APIException, LocatorException, GeneralSecurityException, IOException, CadiException {
        final AuthzEnv env = new AuthzEnv(System.getProperties());
        String aafUrl = "https://DME2RESOLVE";
        SecurityInfoC<HttpURLConnection> si = mock(SecurityInfoC.class);
        env.loadToSystemPropsStartsWith("AAF", "DME2");
        Locator loc;
        loc = new PropertyLocator(aafUrl);
        TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF));
        HMangr hman = new HMangr(env, loc).readTimeout(TIMEOUT).apiVersion(Config.AAF_DEFAULT_API_VERSION);

        // TODO: Consider requiring a default in properties
        env.setProperty(Config.AAF_DEFAULT_REALM,
                System.getProperty(Config.AAF_DEFAULT_REALM, Config.getDefaultRealm()));
        
        HBasicAuthSS ss = mock(HBasicAuthSS.class);
        env.setProperty(Config.AAF_APPPASS, "test");
        return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss);
    }
    
    @Test
    public void testVerbose() {
        cli.verbose(true);
        cli.verbose(false);
    }
    
    @Test
    public void testClose() {
        cli.close();
    }
    
    @Test
    public void testTimeout() {
        Assert.assertNotNull(cli.timeout());
    }
    
    @Test
    public void testTest() {
        Assert.assertNotNull(cli.isTest());
    }
    
    @Test
    public void testIsDetailed() {
        Assert.assertNotNull(cli.isDetailed());
    }
    
    @Test
    public void testAddRequest() {
        Assert.assertNotNull(cli.addRequest());
    }
    
    @Test
    public void testForceString() {
        cli.clearSingleLineProperties();
        Assert.assertNull(cli.forceString());
    }
    
    @Test
    public void testClearSingleLineProperties() {
        cli.clearSingleLineProperties();
    }
    
    @Test
    public void testGui() {
        cli.gui(true);
        cli.gui(false);
    }
    
    @Test
    public void testMain() {
        String[] strArr = {"\\*","test1"};
        //cli.main(strArr);
    }
    
}