2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package com.att.nsa.dmaap.tools;
\r
23 import static org.junit.Assert.*;
\r
25 import java.lang.reflect.Constructor;
\r
26 import java.lang.reflect.InvocationTargetException;
\r
27 import java.lang.reflect.Method;
\r
29 import org.junit.After;
\r
30 import org.junit.Before;
\r
31 import org.junit.Test;
\r
33 public class ConfigToolTest {
\r
35 private String[] parts = new String[5];
\r
38 public void setUp() throws Exception {
\r
40 for (int i = 0; i < parts.length; i++) {
\r
41 parts[i] = "string" + (i + 1);
\r
46 public void tearDown() throws Exception {
\r
49 public void callMethodViaReflection(String outer, String inner, String methodName, Object... args) {
\r
51 String foreNameString = outer + "$" + inner;
\r
52 Object parent = new ConfigTool();
\r
54 Class<?> innerClass;
\r
56 innerClass = Class.forName(foreNameString);
\r
57 Constructor<?> constructor = innerClass.getDeclaredConstructor(ConfigTool.class);
\r
58 constructor.setAccessible(true);
\r
59 Object child = constructor.newInstance(parent);
\r
61 // invoking method on inner class object
\r
62 Method method = innerClass.getDeclaredMethod(methodName, null);
\r
63 method.setAccessible(true);// in case of unaccessible method
\r
64 method.invoke(child, args);
\r
65 } catch (ClassNotFoundException e) {
\r
66 // TODO Auto-generated catch block
\r
67 e.printStackTrace();
\r
68 } catch (NoSuchMethodException e) {
\r
69 // TODO Auto-generated catch block
\r
70 e.printStackTrace();
\r
71 } catch (SecurityException e) {
\r
72 // TODO Auto-generated catch block
\r
73 e.printStackTrace();
\r
74 } catch (InstantiationException e) {
\r
75 // TODO Auto-generated catch block
\r
76 e.printStackTrace();
\r
77 } catch (IllegalAccessException e) {
\r
78 // TODO Auto-generated catch block
\r
79 e.printStackTrace();
\r
80 } catch (IllegalArgumentException e) {
\r
81 // TODO Auto-generated catch block
\r
82 e.printStackTrace();
\r
83 } catch (InvocationTargetException e) {
\r
84 // TODO Auto-generated catch block
\r
85 e.printStackTrace();
\r
93 public void testGetMatches() {
\r
95 callMethodViaReflection("ConfigTool", "ListTopicCommand", "getMatches");
\r
102 public void testCheckReady() {
\r
104 callMethodViaReflection("ConfigTool", "ListTopicCommand", "checkReady", null);
\r
111 public void testExecute() {
\r
113 callMethodViaReflection("ConfigTool", "ListTopicCommand", "execute", parts, null, null);
\r
120 public void testDisplayHelp() {
\r
122 callMethodViaReflection("ConfigTool", "ListTopicCommand", "displayHelp", null);
\r
129 public void testGetMatches2() {
\r
131 callMethodViaReflection("ConfigTool", "WriteTopicCommand", "getMatches");
\r
138 public void testCheckReady2() {
\r
140 callMethodViaReflection("ConfigTool", "WriteTopicCommand", "checkReady", null);
\r
147 public void testExecute2() {
\r
149 callMethodViaReflection("ConfigTool", "WriteTopicCommand", "execute", parts, null, null);
\r
156 public void testDisplayHelp2() {
\r
158 callMethodViaReflection("ConfigTool", "WriteTopicCommand", "displayHelp", null);
\r
165 public void testGetMatches3() {
\r
167 callMethodViaReflection("ConfigTool", "ReadTopicCommand", "getMatches");
\r
174 public void testCheckReady3() {
\r
176 callMethodViaReflection("ConfigTool", "ReadTopicCommand", "checkReady", null);
\r
183 public void testExecute3() {
\r
185 callMethodViaReflection("ConfigTool", "ReadTopicCommand", "execute", parts, null, null);
\r
192 public void testDisplayHelp3() {
\r
194 callMethodViaReflection("ConfigTool", "ReadTopicCommand", "displayHelp", null);
\r
201 public void testGetMatches4() {
\r
203 callMethodViaReflection("ConfigTool", "InitSecureTopicCommand", "getMatches");
\r
210 public void testCheckReady4() {
\r
212 callMethodViaReflection("ConfigTool", "InitSecureTopicCommand", "checkReady", null);
\r
219 public void testExecute4() {
\r
221 callMethodViaReflection("ConfigTool", "InitSecureTopicCommand", "execute", parts, null, null);
\r
228 public void testDisplayHelp4() {
\r
230 callMethodViaReflection("ConfigTool", "InitSecureTopicCommand", "displayHelp", null);
\r
237 public void testGetMatches5() {
\r
239 callMethodViaReflection("ConfigTool", "SetTopicOwnerCommand", "getMatches");
\r
246 public void testCheckReady5() {
\r
248 callMethodViaReflection("ConfigTool", "SetTopicOwnerCommand", "checkReady", null);
\r
255 public void testExecute5() {
\r
257 callMethodViaReflection("ConfigTool", "SetTopicOwnerCommand", "execute", parts, null, null);
\r
264 public void testDisplayHelp5() {
\r
266 callMethodViaReflection("ConfigTool", "SetTopicOwnerCommand", "displayHelp", null);
\r
273 public void testGetMatches6() {
\r
275 callMethodViaReflection("ConfigTool", "ListApiKeysCommand", "getMatches");
\r
282 public void testCheckReady6() {
\r
284 callMethodViaReflection("ConfigTool", "ListApiKeysCommand", "checkReady", null);
\r
291 public void testExecute6() {
\r
293 callMethodViaReflection("ConfigTool", "ListApiKeysCommand", "execute", parts, null, null);
\r
300 public void testDisplayHelp6() {
\r
302 callMethodViaReflection("ConfigTool", "ListApiKeysCommand", "displayHelp", null);
\r
309 public void testGetMatches7() {
\r
311 callMethodViaReflection("ConfigTool", "PutApiCommand", "getMatches");
\r
318 public void testCheckReady7() {
\r
320 callMethodViaReflection("ConfigTool", "PutApiCommand", "checkReady", null);
\r
327 public void testExecute7() {
\r
329 callMethodViaReflection("ConfigTool", "PutApiCommand", "execute", parts, null, null);
\r
336 public void testDisplayHelp7() {
\r
338 callMethodViaReflection("ConfigTool", "PutApiCommand", "displayHelp", null);
\r
345 public void testGetMatches8() {
\r
347 callMethodViaReflection("ConfigTool", "writeApiKeyCommand", "getMatches");
\r
354 public void testCheckReady8() {
\r
356 callMethodViaReflection("ConfigTool", "writeApiKeyCommand", "checkReady", null);
\r
363 public void testExecute8() {
\r
365 callMethodViaReflection("ConfigTool", "writeApiKeyCommand", "execute", parts, null, null);
\r
372 public void testDisplayHelp8() {
\r
374 callMethodViaReflection("ConfigTool", "writeApiKeyCommand", "displayHelp", null);
\r
381 public void testGetMatches9() {
\r
383 callMethodViaReflection("ConfigTool", "EncryptApiKeysCommand", "getMatches");
\r
390 public void testCheckReady9() {
\r
392 callMethodViaReflection("ConfigTool", "EncryptApiKeysCommand", "checkReady", null);
\r
399 public void testExecute9() {
\r
401 callMethodViaReflection("ConfigTool", "EncryptApiKeysCommand", "execute", parts, null, null);
\r
408 public void testDisplayHelp9() {
\r
410 callMethodViaReflection("ConfigTool", "EncryptApiKeysCommand", "displayHelp", null);
\r
417 public void testGetMatches10() {
\r
419 callMethodViaReflection("ConfigTool", "DecryptApiKeysCommand", "getMatches");
\r
426 public void testCheckReady10() {
\r
428 callMethodViaReflection("ConfigTool", "DecryptApiKeysCommand", "checkReady", null);
\r
435 public void testExecute10() {
\r
437 callMethodViaReflection("ConfigTool", "DecryptApiKeysCommand", "execute", parts, null, null);
\r
444 public void testDisplayHelp10() {
\r
446 callMethodViaReflection("ConfigTool", "DecryptApiKeysCommand", "displayHelp", null);
\r
453 public void testGetMatches11() {
\r
455 callMethodViaReflection("ConfigTool", "NodeFetchCommand", "getMatches");
\r
462 public void testCheckReady11() {
\r
464 callMethodViaReflection("ConfigTool", "NodeFetchCommand", "checkReady", null);
\r
471 public void testExecute11() {
\r
473 callMethodViaReflection("ConfigTool", "NodeFetchCommand", "execute", parts, null, null);
\r
480 public void testDisplayHelp11() {
\r
482 callMethodViaReflection("ConfigTool", "NodeFetchCommand", "displayHelp", null);
\r
489 public void testGetMatches12() {
\r
491 callMethodViaReflection("ConfigTool", "DropOldConsumerGroupsCommand", "getMatches");
\r
498 public void testCheckReady12() {
\r
500 callMethodViaReflection("ConfigTool", "DropOldConsumerGroupsCommand", "checkReady", null);
\r
507 public void testExecute12() {
\r
509 callMethodViaReflection("ConfigTool", "DropOldConsumerGroupsCommand", "execute", parts, null, null);
\r
516 public void testDisplayHelp12() {
\r
518 callMethodViaReflection("ConfigTool", "DropOldConsumerGroupsCommand", "displayHelp", null);
\r