2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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 package org.onap.dmaap.tools;
23 import static org.junit.Assert.*;
25 import java.lang.reflect.Constructor;
26 import java.lang.reflect.InvocationTargetException;
27 import java.lang.reflect.Method;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
33 public class ConfigToolTest {
35 private String[] parts = new String[5];
38 public void setUp() throws Exception {
40 for (int i = 0; i < parts.length; i++) {
41 parts[i] = "string" + (i + 1);
46 public void tearDown() throws Exception {
49 public void callMethodViaReflection(String outer, String inner, String methodName, Object... args) {
51 String foreNameString = outer + "$" + inner;
52 Object parent = new ConfigTool();
56 innerClass = Class.forName(foreNameString);
57 Constructor<?> constructor = innerClass.getDeclaredConstructor(ConfigTool.class);
58 constructor.setAccessible(true);
59 Object child = constructor.newInstance(parent);
61 // invoking method on inner class object
62 Method method = innerClass.getDeclaredMethod(methodName, null);
63 method.setAccessible(true);// in case of unaccessible method
64 method.invoke(child, args);
65 } catch (ClassNotFoundException e) {
66 // TODO Auto-generated catch block
68 } catch (NoSuchMethodException e) {
69 // TODO Auto-generated catch block
71 } catch (SecurityException e) {
72 // TODO Auto-generated catch block
74 } catch (InstantiationException e) {
75 // TODO Auto-generated catch block
77 } catch (IllegalAccessException e) {
78 // TODO Auto-generated catch block
80 } catch (IllegalArgumentException e) {
81 // TODO Auto-generated catch block
83 } catch (InvocationTargetException e) {
84 // TODO Auto-generated catch block
93 public void testGetMatches() {
95 callMethodViaReflection("ConfigTool", "ListTopicCommand", "getMatches");
102 public void testCheckReady() {
104 callMethodViaReflection("ConfigTool", "ListTopicCommand", "checkReady", null);
111 public void testExecute() {
113 callMethodViaReflection("ConfigTool", "ListTopicCommand", "execute", parts, null, null);
120 public void testDisplayHelp() {
122 callMethodViaReflection("ConfigTool", "ListTopicCommand", "displayHelp", null);
129 public void testGetMatches2() {
131 callMethodViaReflection("ConfigTool", "WriteTopicCommand", "getMatches");
138 public void testCheckReady2() {
140 callMethodViaReflection("ConfigTool", "WriteTopicCommand", "checkReady", null);
147 public void testExecute2() {
149 callMethodViaReflection("ConfigTool", "WriteTopicCommand", "execute", parts, null, null);
156 public void testDisplayHelp2() {
158 callMethodViaReflection("ConfigTool", "WriteTopicCommand", "displayHelp", null);
165 public void testGetMatches3() {
167 callMethodViaReflection("ConfigTool", "ReadTopicCommand", "getMatches");
174 public void testCheckReady3() {
176 callMethodViaReflection("ConfigTool", "ReadTopicCommand", "checkReady", null);
183 public void testExecute3() {
185 callMethodViaReflection("ConfigTool", "ReadTopicCommand", "execute", parts, null, null);
192 public void testDisplayHelp3() {
194 callMethodViaReflection("ConfigTool", "ReadTopicCommand", "displayHelp", null);
201 public void testGetMatches4() {
203 callMethodViaReflection("ConfigTool", "InitSecureTopicCommand", "getMatches");
210 public void testCheckReady4() {
212 callMethodViaReflection("ConfigTool", "InitSecureTopicCommand", "checkReady", null);
219 public void testExecute4() {
221 callMethodViaReflection("ConfigTool", "InitSecureTopicCommand", "execute", parts, null, null);
228 public void testDisplayHelp4() {
230 callMethodViaReflection("ConfigTool", "InitSecureTopicCommand", "displayHelp", null);
237 public void testGetMatches5() {
239 callMethodViaReflection("ConfigTool", "SetTopicOwnerCommand", "getMatches");
246 public void testCheckReady5() {
248 callMethodViaReflection("ConfigTool", "SetTopicOwnerCommand", "checkReady", null);
255 public void testExecute5() {
257 callMethodViaReflection("ConfigTool", "SetTopicOwnerCommand", "execute", parts, null, null);
264 public void testDisplayHelp5() {
266 callMethodViaReflection("ConfigTool", "SetTopicOwnerCommand", "displayHelp", null);
273 public void testGetMatches6() {
275 callMethodViaReflection("ConfigTool", "ListApiKeysCommand", "getMatches");
282 public void testCheckReady6() {
284 callMethodViaReflection("ConfigTool", "ListApiKeysCommand", "checkReady", null);
291 public void testExecute6() {
293 callMethodViaReflection("ConfigTool", "ListApiKeysCommand", "execute", parts, null, null);
300 public void testDisplayHelp6() {
302 callMethodViaReflection("ConfigTool", "ListApiKeysCommand", "displayHelp", null);
309 public void testGetMatches7() {
311 callMethodViaReflection("ConfigTool", "PutApiCommand", "getMatches");
318 public void testCheckReady7() {
320 callMethodViaReflection("ConfigTool", "PutApiCommand", "checkReady", null);
327 public void testExecute7() {
329 callMethodViaReflection("ConfigTool", "PutApiCommand", "execute", parts, null, null);
336 public void testDisplayHelp7() {
338 callMethodViaReflection("ConfigTool", "PutApiCommand", "displayHelp", null);
345 public void testGetMatches8() {
347 callMethodViaReflection("ConfigTool", "writeApiKeyCommand", "getMatches");
354 public void testCheckReady8() {
356 callMethodViaReflection("ConfigTool", "writeApiKeyCommand", "checkReady", null);
363 public void testExecute8() {
365 callMethodViaReflection("ConfigTool", "writeApiKeyCommand", "execute", parts, null, null);
372 public void testDisplayHelp8() {
374 callMethodViaReflection("ConfigTool", "writeApiKeyCommand", "displayHelp", null);
381 public void testGetMatches9() {
383 callMethodViaReflection("ConfigTool", "EncryptApiKeysCommand", "getMatches");
390 public void testCheckReady9() {
392 callMethodViaReflection("ConfigTool", "EncryptApiKeysCommand", "checkReady", null);
399 public void testExecute9() {
401 callMethodViaReflection("ConfigTool", "EncryptApiKeysCommand", "execute", parts, null, null);
408 public void testDisplayHelp9() {
410 callMethodViaReflection("ConfigTool", "EncryptApiKeysCommand", "displayHelp", null);
417 public void testGetMatches10() {
419 callMethodViaReflection("ConfigTool", "DecryptApiKeysCommand", "getMatches");
426 public void testCheckReady10() {
428 callMethodViaReflection("ConfigTool", "DecryptApiKeysCommand", "checkReady", null);
435 public void testExecute10() {
437 callMethodViaReflection("ConfigTool", "DecryptApiKeysCommand", "execute", parts, null, null);
444 public void testDisplayHelp10() {
446 callMethodViaReflection("ConfigTool", "DecryptApiKeysCommand", "displayHelp", null);
453 public void testGetMatches11() {
455 callMethodViaReflection("ConfigTool", "NodeFetchCommand", "getMatches");
462 public void testCheckReady11() {
464 callMethodViaReflection("ConfigTool", "NodeFetchCommand", "checkReady", null);
471 public void testExecute11() {
473 callMethodViaReflection("ConfigTool", "NodeFetchCommand", "execute", parts, null, null);
480 public void testDisplayHelp11() {
482 callMethodViaReflection("ConfigTool", "NodeFetchCommand", "displayHelp", null);
489 public void testGetMatches12() {
491 callMethodViaReflection("ConfigTool", "DropOldConsumerGroupsCommand", "getMatches");
498 public void testCheckReady12() {
500 callMethodViaReflection("ConfigTool", "DropOldConsumerGroupsCommand", "checkReady", null);
507 public void testExecute12() {
509 callMethodViaReflection("ConfigTool", "DropOldConsumerGroupsCommand", "execute", parts, null, null);
516 public void testDisplayHelp12() {
518 callMethodViaReflection("ConfigTool", "DropOldConsumerGroupsCommand", "displayHelp", null);