From 0d97a835fa2052ded5a31e8921baf641c8e9bb57 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Mon, 11 Dec 2017 20:34:44 +0530 Subject: Make Http as separate plugin Issue-ID: CLI-66 Change-Id: I8ad78f417f6dbb00e29effdd3ed8ec1939aee81d Signed-off-by: Kanagaraj Manickam k00365106 --- .../org/onap/cli/cmd/sample/OnapCommandSample.java | 4 +- .../onap/cli/cmd/sample/OnapCommandSampleTest.java | 69 +++---- .../org/onap/cli/fw/OnapCommandRegistrarTest.java | 139 ------------- .../cli/fw/ad/OnapAuthClientCommandBasedTest.java | 134 ------------- .../java/org/onap/cli/fw/ad/OnapServiceTest.java | 38 ---- .../org/onap/cli/fw/cmd/OnapHttpCommandTest.java | 81 -------- .../cli/fw/cmd/OnapSchemaValidateCommandTest.java | 3 +- .../org/onap/cli/fw/conf/OnapCommandConfgTest.java | 22 --- .../onap/cli/fw/error/OnapCommandErrorTest.java | 54 +----- .../org/onap/cli/fw/http/HttpInputOutputTest.java | 67 ------- .../onap/cli/fw/http/OnapHttpConnectionTest.java | 205 -------------------- .../cli/fw/input/OnapCommandParameterTest.java | 16 +- .../org/onap/cli/fw/input/ParameterTypeTest.java | 22 +-- .../OnapCommandResultAttributeScopeTest.java | 6 +- .../onap/cli/fw/output/OnapCommandResultTest.java | 44 ++--- .../org/onap/cli/fw/output/PrintDirectionTest.java | 6 +- .../org/onap/cli/fw/output/ResultTypeTest.java | 10 +- .../cli/fw/output/print/OnapCommandPrintTest.java | 10 +- .../cli/fw/registrar/OnapCommandRegistrarTest.java | 150 +++++++++++++++ .../org/onap/cli/fw/schema/ValidateSchemaTest.java | 39 +--- .../onap/cli/fw/utils/OnapCommandUtilsTest.java | 214 ++------------------- .../cli/fw/utils/OpenCommandRegistrarTest.java | 41 ---- 22 files changed, 266 insertions(+), 1108 deletions(-) delete mode 100644 framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java delete mode 100644 framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientCommandBasedTest.java delete mode 100644 framework/src/test/java/org/onap/cli/fw/ad/OnapServiceTest.java delete mode 100644 framework/src/test/java/org/onap/cli/fw/cmd/OnapHttpCommandTest.java delete mode 100644 framework/src/test/java/org/onap/cli/fw/http/HttpInputOutputTest.java delete mode 100644 framework/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java create mode 100644 framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java delete mode 100644 framework/src/test/java/org/onap/cli/fw/utils/OpenCommandRegistrarTest.java (limited to 'framework/src/test/java/org') diff --git a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java index c76df290..b225a3a0 100644 --- a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java +++ b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java @@ -16,10 +16,10 @@ package org.onap.cli.cmd.sample; -import org.onap.cli.fw.OnapCommand; -import org.onap.cli.fw.OnapCommandSchema; +import org.onap.cli.fw.cmd.OnapCommand; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandExecutionFailed; +import org.onap.cli.fw.schema.OnapCommandSchema; /** * This command helps to test the Command functionalities. diff --git a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java index 51ed776f..a83cda52 100644 --- a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java +++ b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java @@ -19,20 +19,20 @@ package org.onap.cli.cmd.sample; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; import org.junit.Test; -import org.onap.cli.fw.OnapCommand; -import org.onap.cli.fw.OnapCommandRegistrar; -import org.onap.cli.fw.conf.Constants; +import org.onap.cli.fw.cmd.OnapCommand; +import org.onap.cli.fw.conf.OnapCommandConstants; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandExecutionFailed; import org.onap.cli.fw.error.OnapCommandNotInitialized; import org.onap.cli.fw.input.OnapCommandParameter; -import org.onap.cli.fw.input.ParameterType; +import org.onap.cli.fw.input.OnapCommandParameterType; import org.onap.cli.fw.output.OnapCommandResultAttribute; +import org.onap.cli.fw.registrar.OnapCommandRegistrar; public class OnapCommandSampleTest { @Test @@ -42,13 +42,13 @@ public class OnapCommandSampleTest { OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test"); - List parameters = new ArrayList(); + Set parameters = new HashSet(); OnapCommandParameter v = new OnapCommandParameter(); - v.setName(Constants.DEFAULT_PARAMETER_VERSION); + v.setName(OnapCommandConstants.DEFAULT_PARAMETER_VERSION); v.setValue("true"); parameters.add(v); OnapCommandParameter h = new OnapCommandParameter(); - h.setName(Constants.DEFAULT_PARAMETER_HELP); + h.setName(OnapCommandConstants.DEFAULT_PARAMETER_HELP); h.setValue("false"); parameters.add(h); sample.setParameters(parameters); @@ -61,11 +61,11 @@ public class OnapCommandSampleTest { public void sampleTestHelp() { OnapCommandSample sample = new OnapCommandSample(); try { - List parameters = new ArrayList(); + Set parameters = new HashSet(); OnapCommandParameter v = new OnapCommandParameter(); - v.setName(Constants.DEFAULT_PARAMETER_HELP); + v.setName(OnapCommandConstants.DEFAULT_PARAMETER_HELP); v.setValue("true"); - v.setParameterType(ParameterType.BOOL); + v.setParameterType(OnapCommandParameterType.BOOL); parameters.add(v); sample.setParameters(parameters); sample.execute(); @@ -78,39 +78,32 @@ public class OnapCommandSampleTest { try { OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test"); - List parameters = new ArrayList(); + Set parameters = new HashSet(); OnapCommandParameter v = new OnapCommandParameter(); - v.setName(Constants.DEFAULT_PARAMETER_VERSION); + v.setName(OnapCommandConstants.DEFAULT_PARAMETER_VERSION); v.setValue("false"); parameters.add(v); OnapCommandParameter h = new OnapCommandParameter(); - h.setName(Constants.DEFAULT_PARAMETER_HELP); + h.setName(OnapCommandConstants.DEFAULT_PARAMETER_HELP); h.setValue("false"); parameters.add(h); OnapCommandParameter f = new OnapCommandParameter(); - f.setName(Constants.DEFAULT_PARAMETER_OUTPUT_FORMAT); + f.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_FORMAT); f.setValue("table"); parameters.add(f); OnapCommandParameter l = new OnapCommandParameter(); - l.setName(Constants.DEFAULT_PARAMETER_OUTPUT_ATTR_LONG); + l.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_ATTR_LONG); l.setValue("true"); parameters.add(l); OnapCommandParameter t = new OnapCommandParameter(); - t.setName(Constants.DEFAULT_PARAMETER_OUTPUT_NO_TITLE); + t.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_NO_TITLE); t.setValue("true"); parameters.add(t); - OnapCommandParameter a = new OnapCommandParameter(); - a.setName(Constants.DEFAULT_PARAMETER_NO_AUTH); - a.setValue("true"); - parameters.add(a); OnapCommandParameter d = new OnapCommandParameter(); - d.setName(Constants.DEFAULT_PARAMETER_DEBUG); + d.setName(OnapCommandConstants.DEFAULT_PARAMETER_DEBUG); d.setValue("true"); parameters.add(d); - OnapCommandParameter m = new OnapCommandParameter(); - m.setName(Constants.DEAFULT_PARAMETER_HOST_URL); - m.setValue("http://localhost"); - parameters.add(m); + sample.setParameters(parameters); sample.execute(); @@ -132,39 +125,31 @@ public class OnapCommandSampleTest { OnapCommandSample sample = new OnapCommandSample(); sample.failCase = true; - List parameters = new ArrayList(); + Set parameters = new HashSet(); OnapCommandParameter v = new OnapCommandParameter(); - v.setName(Constants.DEFAULT_PARAMETER_VERSION); + v.setName(OnapCommandConstants.DEFAULT_PARAMETER_VERSION); v.setValue("false"); parameters.add(v); OnapCommandParameter h = new OnapCommandParameter(); - h.setName(Constants.DEFAULT_PARAMETER_HELP); + h.setName(OnapCommandConstants.DEFAULT_PARAMETER_HELP); h.setValue("false"); parameters.add(h); OnapCommandParameter f = new OnapCommandParameter(); - f.setName(Constants.DEFAULT_PARAMETER_OUTPUT_FORMAT); + f.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_FORMAT); f.setValue("table"); parameters.add(f); OnapCommandParameter l = new OnapCommandParameter(); - l.setName(Constants.DEFAULT_PARAMETER_OUTPUT_ATTR_LONG); + l.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_ATTR_LONG); l.setValue("true"); parameters.add(l); OnapCommandParameter t = new OnapCommandParameter(); - t.setName(Constants.DEFAULT_PARAMETER_OUTPUT_NO_TITLE); + t.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_NO_TITLE); t.setValue("true"); parameters.add(t); - OnapCommandParameter a = new OnapCommandParameter(); - a.setName(Constants.DEFAULT_PARAMETER_NO_AUTH); - a.setValue("true"); - parameters.add(a); OnapCommandParameter d = new OnapCommandParameter(); - d.setName(Constants.DEFAULT_PARAMETER_DEBUG); + d.setName(OnapCommandConstants.DEFAULT_PARAMETER_DEBUG); d.setValue("true"); parameters.add(d); - OnapCommandParameter m = new OnapCommandParameter(); - m.setName(Constants.DEAFULT_PARAMETER_HOST_URL); - m.setValue("http://localhost"); - parameters.add(m); sample.setParameters(parameters); sample.execute(); } diff --git a/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java b/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java deleted file mode 100644 index 3f9f780d..00000000 --- a/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * 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. - */ - -package org.onap.cli.fw; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.net.URL; - -import org.junit.Before; -import org.junit.Test; -import org.onap.cli.fw.error.OnapCommandException; -import org.onap.cli.fw.error.OnapCommandHelpFailed; -import org.onap.cli.fw.error.OnapCommandNotFound; - -public class OnapCommandRegistrarTest { - - OnapCommandRegistrar registerar; - - @Before - public void setup() throws OnapCommandException { - registerar = OnapCommandRegistrar.getRegistrar(); - createDir(); - } - - private void createDir() { - URL url = OnapCommandRegistrarTest.class.getClassLoader().getResource("open-cli-schema"); - if (url != null) { - String path = url.getPath(); - path = path.replaceFirst("open-cli-schema", "data"); - File file = new File(path); - if (!file.exists()) { - file.mkdir(); - } else { - File f1 = new File(path + "/cli-schema.json"); - f1.delete(); - } - } - } - - @Test - public void oclipCommandNotFoundTest() throws OnapCommandException { - try { - registerar = OnapCommandRegistrar.getRegistrar(); - registerar.get("Test1"); - fail("This should have thrown an exception"); - } catch (OnapCommandNotFound e) { - //pass // NOSONAR - } catch (Exception e) { - fail("This should have thrown an OnapCommandNotFound exception"); - } - } - - @Test - public void helpTest() throws OnapCommandException { - String help = registerar.getHelp(); - assertNotNull(help); - } - - @Test - public void versionTest() throws OnapCommandHelpFailed { - String version = registerar.getVersion(); - assertNotNull(version); - } - - @Test - public void listTest() { - registerar.listCommands(); - } - - @Test - public void testProfile() throws OnapCommandException { - try { - OnapCommandRegistrar.getRegistrar().setProfile("test"); - OnapCommandRegistrar.getRegistrar().addParamCache("a", "b"); - OnapCommandRegistrar.getRegistrar().getParamCache(); - OnapCommandRegistrar.getRegistrar().removeParamCache("a"); - - OnapCommandRegistrar.getRegistrar().setInteractiveMode(false); - assertTrue(!OnapCommandRegistrar.getRegistrar().isInteractiveMode()); - - OnapCommandRegistrar.getRegistrar().setEnabledProductVersion("open-cli"); - assertEquals("open-cli", OnapCommandRegistrar.getRegistrar().getEnabledProductVersion()); - OnapCommandRegistrar.getRegistrar().getAvailableProductVersions(); - assertTrue(OnapCommandRegistrar.getRegistrar().listCommandsForEnabledProductVersion().contains("schema-refresh")); - - assertTrue(OnapCommandRegistrar.getRegistrar().listCommandInfo().size() > 2); - } catch (Exception e) { - fail("failed to test the profile"); - } - } -} - -@OnapCommandSchema(schema = "sample-test-schema.yaml") -class OnapCommandTest extends OnapCommand { - - public OnapCommandTest() { - - } - - public static final String CMD_NAME = "test"; - - protected void run() throws OnapCommandException { - - } - -} - -@OnapCommandSchema(schema = "test-schema.yaml") -class OnapCommandTest1 extends OnapCommand { - - public OnapCommandTest1() { - - } - - public static final String CMD_NAME = "test1"; - - protected void run() throws OnapCommandException { - - } - -} diff --git a/framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientCommandBasedTest.java b/framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientCommandBasedTest.java deleted file mode 100644 index 58b44f4a..00000000 --- a/framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientCommandBasedTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * 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. - */ - -package org.onap.cli.fw.ad; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.junit.Before; -import org.junit.Test; -import org.onap.cli.fw.OnapCommand; -import org.onap.cli.fw.OnapCommandRegistrar; -import org.onap.cli.fw.cmd.OnapHttpCommand; -import org.onap.cli.fw.conf.Constants; -import org.onap.cli.fw.conf.OnapCommandConfg; -import org.onap.cli.fw.error.OnapCommandException; -import org.onap.cli.fw.error.OnapCommandProductVersionInvalid; - -public class OnapAuthClientCommandBasedTest { - - @Before - public void setup() throws OnapCommandProductVersionInvalid, OnapCommandException { - OnapCommandRegistrar.getRegistrar().setEnabledProductVersion(OnapCommandConfg.getProductName()); - } - - @Test - public void internalCommandTest() { - try { - OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("sample-test"); - cmd.getInfo().setService(OnapCommandConfg.getProductName()); - - cmd.execute(); - } catch (OnapCommandException e) { - fail("Internal command failed to run"); - e.printStackTrace(System.out); - } - } - - @Test - public void yesCatalogYesAuthTest() throws OnapCommandException { - try { - OnapHttpCommand cmd = getCommand("sample-test-schema-yes-auth-yes-catalog.yaml"); - cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080"); - cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_USERNAME).setValue("test"); - cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_PASSWORD).setValue("password"); - - cmd.execute(); - } catch (OnapCommandException e) { - fail("External command Yes Auth Yes Catalog failed to run"); - e.printStackTrace(System.out); - } - } - - @Test - public void yesCatalogNoAuthTest() throws OnapCommandException { - try { - OnapHttpCommand cmd = getCommand("sample-test-schema-no-auth-yes-catalog.yaml"); - cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080"); - - cmd.execute(); - } catch (OnapCommandException e) { - fail("External command Yes Auth No Catalog failed to run " + e.getMessage()); - e.printStackTrace(System.out); - } - } - - @Test - public void noCatalogYesAuthTest() throws OnapCommandException { - try { - OnapHttpCommand cmd = getCommand("sample-test-schema-yes-auth-no-catalog.yaml"); - cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080"); - cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_USERNAME).setValue("test"); - cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_PASSWORD).setValue("password"); - - cmd.execute(); - } catch (OnapCommandException e) { - fail("External command Yes Auth No Catalog failed to run"); - e.printStackTrace(System.out); - } - } - - @Test - public void noCatalogYesAuthWithAdditionalParamsTest() throws OnapCommandException { - try { - OnapHttpCommand cmd = getCommand("sample-test-schema-yes-auth-with-additional-params-no-catalog.yaml"); - assertTrue(cmd.getParametersMap().containsKey("string-param")); - } catch (OnapCommandException e) { - fail("External command Yes Auth No Catalog failed to run"); - e.printStackTrace(System.out); - } - } - - @Test - public void noCatalogNoAuthTest() throws OnapCommandException { - try { - OnapHttpCommand cmd = getCommand("sample-test-schema-no-auth-no-catalog.yaml"); - cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080"); - - cmd.execute(); - } catch (OnapCommandException e) { - fail("External command No Auth No Catalog failed to run"); - e.printStackTrace(System.out); - } - } - - private OnapHttpCommand getCommand(String yaml) throws OnapCommandException { - OnapHttpCommand cmd = new OnapHttpCommand() { - @Override - protected void processRequest() throws OnapCommandException { - if (!this.getService().isModeDirect()) { - String url = this.authClient.getServiceUrl(); - assert url.equals(this.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).getValue() + "/"); - } - } - }; - - cmd.initializeSchema(yaml); - - return cmd; - } - } diff --git a/framework/src/test/java/org/onap/cli/fw/ad/OnapServiceTest.java b/framework/src/test/java/org/onap/cli/fw/ad/OnapServiceTest.java deleted file mode 100644 index 9ceba67d..00000000 --- a/framework/src/test/java/org/onap/cli/fw/ad/OnapServiceTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * 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. - */ - -package org.onap.cli.fw.ad; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.cli.fw.conf.Constants; - -public class OnapServiceTest { - - @Test - public void serviceTest() { - OnapService ser = new OnapService(); - ser.setName("name"); - ser.setVersion("1.0"); - ser.setBasePath("basePath"); - ser.setAuthType(Constants.AUTH_NONE); - assertTrue(ser.getName().equals("name") && ser.getVersion().equals("1.0") - && ser.getBasePath().equals("basePath") && ser.isNoAuth()); - - } - -} diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapHttpCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapHttpCommandTest.java deleted file mode 100644 index 3fced8ab..00000000 --- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapHttpCommandTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * 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. - */ - -package org.onap.cli.fw.cmd; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.junit.Ignore; -import org.junit.Test; -import org.onap.cli.fw.error.OnapCommandException; -import org.onap.cli.fw.http.HttpInput; -import org.onap.cli.fw.input.OnapCommandParameter; -import org.onap.cli.fw.input.ParameterType; - -public class OnapHttpCommandTest { - - @Ignore - @Test(expected = OnapCommandException.class) - public void runTest() throws OnapCommandException { - OnapCommandParameter param1 = new OnapCommandParameter(); - param1.setLongOption("host-username"); - param1.setName("host-username"); - param1.setParameterType(ParameterType.STRING); - OnapCommandParameter param2 = new OnapCommandParameter(); - param2.setLongOption("host-password"); - param2.setName("host-password"); - param2.setParameterType(ParameterType.STRING); - OnapCommandParameter param3 = new OnapCommandParameter(); - param3.setLongOption("host-url"); - param3.setName("host-url"); - param3.setParameterType(ParameterType.STRING); - OnapCommandParameter param4 = new OnapCommandParameter(); - param4.setLongOption("string-param"); - param4.setName("string-param"); - param4.setParameterType(ParameterType.STRING); - OnapCommandParameter param5 = new OnapCommandParameter(); - param5.setLongOption("long-opt"); - param5.setName("long-opt"); - param5.setParameterType(ParameterType.STRING); - - List paramslist = new ArrayList<>(); - paramslist.add(param1); - paramslist.add(param2); - paramslist.add(param3); - paramslist.add(param4); - paramslist.add(param5); - - HttpInput inp = new HttpInput(); - inp.setBody("body"); - inp.setMethod("method"); - inp.setReqCookies(new HashMap()); - inp.setReqHeaders(new HashMap()); - inp.setReqQueries(new HashMap()); - inp.setUri("uri"); - - OnapHttpCommand com = new OnapHttpCommand(); - com.setParameters(paramslist); - com.getParameters(); - com.getParametersMap(); - com.setInput(inp); - com.initializeSchema("sample-test-schema.yaml"); - com.execute(); - - } - -} diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java index 8d8de2f7..f094203b 100644 --- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java +++ b/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java @@ -18,9 +18,8 @@ package org.onap.cli.fw.cmd; import org.junit.Ignore; import org.junit.Test; -import org.onap.cli.fw.OnapCommand; -import org.onap.cli.fw.OnapCommandRegistrar; import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.registrar.OnapCommandRegistrar; import org.onap.cli.fw.schema.ValidateSchemaTest; diff --git a/framework/src/test/java/org/onap/cli/fw/conf/OnapCommandConfgTest.java b/framework/src/test/java/org/onap/cli/fw/conf/OnapCommandConfgTest.java index 2c25991b..d6ef3a34 100644 --- a/framework/src/test/java/org/onap/cli/fw/conf/OnapCommandConfgTest.java +++ b/framework/src/test/java/org/onap/cli/fw/conf/OnapCommandConfgTest.java @@ -16,28 +16,6 @@ package org.onap.cli.fw.conf; -import java.io.IOException; -import java.util.Properties; - -import org.junit.Assert; -import org.junit.Test; - public class OnapCommandConfgTest { - @Test - public void versionTest() { - String str = OnapCommandConfg.getVersion(); - Assert.assertTrue(str != null); - } - - @Test - public void isAuthIgnoredTest() throws IOException { - Properties prps = new Properties(); - prps.load(OnapCommandConfg.class.getClassLoader().getResourceAsStream("open-cli.properties")); - boolean auth = OnapCommandConfg.isAuthIgnored(); - Assert.assertTrue(auth == Boolean.valueOf(prps.getProperty("cli.ignore_auth"))); - Assert.assertTrue(OnapCommandConfg.isCookiesBasedAuth() == Boolean - .valueOf(prps.getProperty("cli.http.api_key_use_cookies"))); - } - } diff --git a/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java b/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java index 899f2e3b..58c0f432 100644 --- a/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java +++ b/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java @@ -44,12 +44,6 @@ public class OnapCommandErrorTest { assertEquals("0x3002::Failed to parse the result format of command name, failed", failed.getMessage()); } - @Test - public void oclipCommandHttpHeaderNotFoundTest() { - OnapCommandHttpHeaderNotFound failed = new OnapCommandHttpHeaderNotFound("name"); - assertEquals("0x3003::Http header name is not returned from the service", failed.getMessage()); - } - @Test public void oclipCommandClientInitialzationFailedTest() { OnapCommandClientInitialzationFailed failed = new OnapCommandClientInitialzationFailed("Test", @@ -106,22 +100,6 @@ public class OnapCommandErrorTest { assertEquals("0x9001::Command failed to print help message, Failed", failed.getMessage()); } - @Test - public void oclipCommandHttpFailureTest1() { - OnapCommandHttpFailure failed = new OnapCommandHttpFailure("Failed"); - assertEquals("0x3001::Failed", failed.getMessage()); - - failed = new OnapCommandHttpFailure(new Exception("failed"), 201); - assertEquals("201::0x3001::failed", failed.getMessage()); - } - - @Test - public void oclipCommandHttpFailureTest2() { - OnapCommandHttpFailure failed = new OnapCommandHttpFailure("Failed", 203); - - assertEquals("203::0x3001::Failed", failed.getMessage()); - } - @Test public void oclipCommandInvalidParameterTypeTest() { OnapCommandInvalidParameterType failed = new OnapCommandInvalidParameterType("Failed"); @@ -141,7 +119,7 @@ public class OnapCommandErrorTest { OnapCommandInvalidRegistration failed = new OnapCommandInvalidRegistration(OnapCommandErrorTest.class); assertEquals("0x2001::Invalid commad class org.onap.cli.fw.error.OnapCommandErrorTest registration, " - + "it should be derived from org.onap.cli.fw.OnapCommand", failed.getMessage()); + + "it should be derived from org.onap.cli.fw.cmd.OnapCommand", failed.getMessage()); } @Test @@ -165,29 +143,6 @@ public class OnapCommandErrorTest { assertEquals("0xb003::Command schema open_cli_schema_version 1.0 is invalid or missing", failed.getMessage()); } - @Test - public void oclipCommandLoginFailedTest1() { - OnapCommandLoginFailed failed = new OnapCommandLoginFailed(new Exception("Failed")); - - assertEquals("0x4001::Login failed, Failed", failed.getMessage()); - } - - @Test - public void oclipCommandLoginFailedTest2() { - OnapCommandLoginFailed failed = new OnapCommandLoginFailed("Failed", 201); - - assertEquals("201::0x4001::Login failed, Failed", failed.getMessage()); - } - - @Test - public void oclipCommandLogoutFailedTest() { - OnapCommandLogoutFailed failed = new OnapCommandLogoutFailed(new Exception("Failed")); - assertEquals("0x4002::Logout failed, Failed", failed.getMessage()); - - failed = new OnapCommandLogoutFailed(200); - assertEquals("200::0x4002::Logout failed", failed.getMessage()); - } - @Test public void oclipCommandNotFoundTest() { OnapCommandNotFound failed = new OnapCommandNotFound("Test", "1.0"); @@ -253,13 +208,6 @@ public class OnapCommandErrorTest { assertEquals("0xb002::Command schema is missing for command Test", failed.getMessage()); } - @Test - public void oclipCommandServiceNotFoundTest() { - OnapCommandServiceNotFound failed = new OnapCommandServiceNotFound("Service"); - - assertEquals("0xd001::Service Service is not found in MSB", failed.getMessage()); - } - @Test public void oclipCommandOutputFormatNotsupportedTest() { OnapCommandOutputFormatNotsupported failed = new OnapCommandOutputFormatNotsupported("Format"); diff --git a/framework/src/test/java/org/onap/cli/fw/http/HttpInputOutputTest.java b/framework/src/test/java/org/onap/cli/fw/http/HttpInputOutputTest.java deleted file mode 100644 index 0a3a817e..00000000 --- a/framework/src/test/java/org/onap/cli/fw/http/HttpInputOutputTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2016-17 Huawei Technologies Co., Ltd. - * - * 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. - */ - -package org.onap.cli.fw.http; - -import static org.junit.Assert.assertTrue; - -import java.util.HashMap; - -import org.junit.Test; - -public class HttpInputOutputTest { - - @Test - public void httpInputTest() { - HttpInput inp = new HttpInput(); - inp.setBody("body"); - inp.setMethod("method"); - inp.setReqCookies(null); - inp.setReqHeaders(null); - inp.setReqQueries(null); - inp.setUri("uri"); - - assertTrue("body".equals(inp.getBody()) && "method".equals(inp.getMethod()) && null == inp.getReqCookies() - && inp.getReqHeaders().isEmpty() && inp.getReqQueries().isEmpty() && "uri".equals(inp.getUri())); - - inp.setReqCookies(new HashMap()); - inp.setReqHeaders(new HashMap()); - inp.setReqQueries(new HashMap()); - - assertTrue( - "\nURL: uri\nMethod: method\nRequest Queries: {}\nRequest Body: body\nRequest Headers: {}\nRequest Cookies: {}\nbinaryData=false" - .equals(inp.toString())); - } - - @Test - public void httpResultTest() { - HttpResult out = new HttpResult(); - out.setBody("body"); - out.setRespCookies(null); - out.setRespHeaders(null); - out.setStatus(205); - - assertTrue("body".equals(out.getBody()) && null == out.getRespCookies() && null == out.getRespHeaders() - && 205 == out.getStatus()); - - out.setRespCookies(new HashMap()); - out.setRespHeaders(new HashMap()); - out.setStatus(200); - assertTrue("\nHTTP Status: 200\nResponse Body: body\nResponse Headers: {}\nResponse Cookies: {}" - .equals(out.toString())); - } - -} diff --git a/framework/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java b/framework/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java deleted file mode 100644 index 785092c2..00000000 --- a/framework/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * 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. - */ - -package org.onap.cli.fw.http; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.protocol.HttpContext; -import org.junit.Before; -import org.junit.Test; -import org.onap.cli.fw.error.OnapCommandHttpFailure; - -import mockit.Invocation; -import mockit.Mock; -import mockit.MockUp; - -public class OnapHttpConnectionTest { - HttpInput inp = null; - OnapHttpConnection con = null; - - @Before - public void setup() { - mockHttpRequest(null); - inp = new HttpInput(); - inp.setMethod("get"); - inp.setBody("body"); - Map map1 = new HashMap<>(); - map1.put("header1", "value1"); - inp.setReqHeaders(map1); - Map map2 = new HashMap<>(); - map2.put("query1", "value1"); - inp.setReqQueries(map2); - Map map = new HashMap<>(); - map.put("cookie1", "value1"); - inp.setReqCookies(map); - inp.setUri("http://192.168.99.10:80"); - } - - @Test(expected = OnapCommandHttpFailure.class) - public void httpUnSecuredGetExceptionTest() throws OnapCommandHttpFailure { - new MockUp() { - @Mock - public CloseableHttpResponse execute(HttpUriRequest request, HttpContext context) - throws IOException, ClientProtocolException { - - throw new IOException("IO Exception"); - } - }; - inp.setMethod("get"); - con = new OnapHttpConnection(true); - con.getDebugInfo(); - con.get(inp); - - } - - @Test(expected = OnapCommandHttpFailure.class) - public void httpUnSecuredPostExceptionTest() throws OnapCommandHttpFailure { - new MockUp() { - @Mock - public CloseableHttpResponse execute(HttpUriRequest request, HttpContext context) - throws IOException, ClientProtocolException { - - throw new IOException("IO Exception"); - } - }; - - inp.setMethod("post"); - con = new OnapHttpConnection(true); - con.post(inp); - } - - - @Test(expected = OnapCommandHttpFailure.class) - public void httpUnSecuredPostExceptionTest1() throws OnapCommandHttpFailure { - new MockUp() { - @Mock - public CloseableHttpResponse execute(HttpUriRequest request, HttpContext context) - throws IOException, ClientProtocolException { - - throw new IOException("IO Exception"); - } - }; - - inp.setMethod("post"); - inp.setBinaryData(true); - con = new OnapHttpConnection(true); - con.post(inp); - } - - @Test(expected = OnapCommandHttpFailure.class) - public void httpUnSecuredPutExceptionTest() throws OnapCommandHttpFailure { - new MockUp() { - @Mock - public CloseableHttpResponse execute(HttpUriRequest request, HttpContext context) - throws IOException, ClientProtocolException { - - throw new IOException("IO Exception"); - } - }; - inp.setMethod("put"); - con = new OnapHttpConnection(true); - con.put(inp); - } - - @Test(expected = OnapCommandHttpFailure.class) - public void httpUnSecuredDeleteExceptionTest() throws OnapCommandHttpFailure { - new MockUp() { - @Mock - public CloseableHttpResponse execute(HttpUriRequest request, HttpContext context) - throws IOException, ClientProtocolException { - - throw new IOException("IO Exception"); - } - }; - inp.setMethod("delete"); - con = new OnapHttpConnection(true); - con.delete(inp); - } - - @Test(expected = IllegalArgumentException.class) - public void httpUnSecuredOtherExceptionTest() throws OnapCommandHttpFailure { - new MockUp() { - @Mock - public CloseableHttpResponse execute(HttpUriRequest request, HttpContext context) - throws IOException, ClientProtocolException { - - throw new IOException("IO Exception"); - } - }; - inp.setMethod("other"); - con = new OnapHttpConnection(true); - con.request(inp); - } - - @Test() - public void httpUnSecuredCloseExceptionTest() throws OnapCommandHttpFailure { - inp.setMethod("other"); - con = new OnapHttpConnection(true); - con.close(); - } - - @Test - public void httpSecuredGetExceptionTest() { - - // ProtocolVersion p = new ProtocolVersion("http",1,0); - // HttpResponse hr = DefaultHttpResponseFactory.INSTANCE.newHttpResponse(p, 200 , null) ; - - new MockUp() { - @Mock - public CloseableHttpResponse execute(HttpUriRequest request, HttpContext context) - throws IOException, ClientProtocolException { - - throw new IOException("IO Exception"); - } - }; - try { - HttpInput inp = new HttpInput(); - inp.setMethod("get"); - inp.setBody("body"); - inp.setReqHeaders(new HashMap()); - inp.setReqQueries(new HashMap()); - inp.setUri("https://192.168.99.10:80"); - OnapHttpConnection con = new OnapHttpConnection(false); - con.get(inp); - } catch (OnapCommandHttpFailure e) { - assertEquals("0x3001::IO Exception", e.getMessage()); - } - } - - private static void mockHttpRequest(HttpResult result) { - new MockUp() { - boolean isMock = false; - - @Mock - public HttpResult request(Invocation inv, HttpInput input) throws OnapCommandHttpFailure { - if (isMock) { - return result; - } else { - return inv.proceed(input); - } - } - }; - } -} diff --git a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java index 44656f9f..82781b43 100644 --- a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java +++ b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java @@ -36,7 +36,7 @@ public class OnapCommandParameterTest { param.setLongOption("longOption"); param.setName("name"); param.setOptional(true); - param.setParameterType(ParameterType.JSON); + param.setParameterType(OnapCommandParameterType.JSON); param.setSecured(false); param.setShortOption("shortOption"); param.setValue("value"); @@ -44,15 +44,15 @@ public class OnapCommandParameterTest { assertTrue(param.getDefaultValue().equals("defaultValue") && param.getDescription().equals("description") && param.getLongOption().equals("longOption") && param.getName().equals("name") && param.getShortOption().equals("shortOption") && param.getValue().equals("value") - && param.isOptional() && !param.isSecured() && param.getParameterType().equals(ParameterType.JSON)); + && param.isOptional() && !param.isSecured() && param.getParameterType().equals(OnapCommandParameterType.JSON)); assertTrue("value".equals(param.getValue())); - param.setParameterType(ParameterType.ARRAY); + param.setParameterType(OnapCommandParameterType.ARRAY); param.setValue(Arrays.asList("1", "2", "3")); assertTrue("[\"1\",\"2\",\"3\"]".equals(param.getValue())); - param.setParameterType(ParameterType.MAP); + param.setParameterType(OnapCommandParameterType.MAP); Map map = new HashMap<>(); map.put("One", "1"); map.put("Two", "2"); @@ -82,7 +82,7 @@ public class OnapCommandParameterTest { param.setOptional(false); param.setValue(""); param.setDefaultValue(""); - param.setParameterType(ParameterType.STRING); + param.setParameterType(OnapCommandParameterType.STRING); try { param.validate(); } catch (OnapCommandException e) { @@ -94,7 +94,7 @@ public class OnapCommandParameterTest { public void oclipCommandInvalidParameterValueArrayExeceptionTest() throws OnapCommandInvalidParameterValue { OnapCommandParameter param = new OnapCommandParameter(); param.setName("name"); - param.setParameterType(ParameterType.ARRAY); + param.setParameterType(OnapCommandParameterType.ARRAY); param.setValue("value"); assertTrue("[\"1\",\"2\",\"3\"]".equals(param.getValue())); @@ -104,7 +104,7 @@ public class OnapCommandParameterTest { public void oclipCommandInvalidParameterValueMapExeceptionTest() throws OnapCommandInvalidParameterValue { OnapCommandParameter param = new OnapCommandParameter(); param.setName("name"); - param.setParameterType(ParameterType.MAP); + param.setParameterType(OnapCommandParameterType.MAP); param.setValue("value"); assertTrue("{\"One\":\"1\",\"Two\":\"2\",\"Three\":\"3\"}".equals(param.getValue())); } @@ -113,7 +113,7 @@ public class OnapCommandParameterTest { public void oclipCommandInvalidParameterValueBinaryExeceptionTest() throws OnapCommandException { OnapCommandParameter param = new OnapCommandParameter(); param.setName("name"); - param.setParameterType(ParameterType.BINARY); + param.setParameterType(OnapCommandParameterType.BINARY); param.setValue("value"); param.validate(); } diff --git a/framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java b/framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java index 877f08f5..a42b9120 100644 --- a/framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java +++ b/framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java @@ -27,22 +27,22 @@ public class ParameterTypeTest { public void paramTypeGetTest() { try { - assertTrue(ParameterType.JSON.equals(ParameterType.get("json")) - && ParameterType.YAML.equals(ParameterType.get("yaml")) - && ParameterType.STRING.equals(ParameterType.get("string")) - && ParameterType.DIGIT.equals(ParameterType.get("digit")) - && ParameterType.URL.equals(ParameterType.get("url")) - && ParameterType.BOOL.equals(ParameterType.get("bool")) - && ParameterType.MAP.equals(ParameterType.get("map")) - && ParameterType.BINARY.equals(ParameterType.get("binary")) - && ParameterType.TEXT.equals(ParameterType.get("text")) - && ParameterType.ARRAY.equals(ParameterType.get("array"))); + assertTrue(OnapCommandParameterType.JSON.equals(OnapCommandParameterType.get("json")) + && OnapCommandParameterType.YAML.equals(OnapCommandParameterType.get("yaml")) + && OnapCommandParameterType.STRING.equals(OnapCommandParameterType.get("string")) + && OnapCommandParameterType.DIGIT.equals(OnapCommandParameterType.get("digit")) + && OnapCommandParameterType.URL.equals(OnapCommandParameterType.get("url")) + && OnapCommandParameterType.BOOL.equals(OnapCommandParameterType.get("bool")) + && OnapCommandParameterType.MAP.equals(OnapCommandParameterType.get("map")) + && OnapCommandParameterType.BINARY.equals(OnapCommandParameterType.get("binary")) + && OnapCommandParameterType.TEXT.equals(OnapCommandParameterType.get("text")) + && OnapCommandParameterType.ARRAY.equals(OnapCommandParameterType.get("array"))); } catch (OnapCommandInvalidParameterType e) { fail("Shouldn't have thrown this exception : " + e.getMessage()); } try { - ParameterType.get("name"); + OnapCommandParameterType.get("name"); } catch (OnapCommandInvalidParameterType e) { assertTrue("0x7001::Parameter type name is invalid".equals(e.getMessage())); } diff --git a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeScopeTest.java b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeScopeTest.java index 7ab3fe52..8f5f861a 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeScopeTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeScopeTest.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertTrue; import java.util.Collections; import org.junit.Test; -import org.onap.cli.fw.input.ParameterType; +import org.onap.cli.fw.input.OnapCommandParameterType; public class OnapCommandResultAttributeScopeTest { @Test @@ -31,11 +31,11 @@ public class OnapCommandResultAttributeScopeTest { att.setName("name"); att.setScope(OnapCommandResultAttributeScope.LONG); att.setSecured(true); - att.setType(ParameterType.DIGIT); + att.setType(OnapCommandParameterType.DIGIT); att.setValues(Collections.emptyList()); assertTrue("description".equals(att.getDescription()) && "name".equals(att.getName()) && OnapCommandResultAttributeScope.LONG.equals(att.getScope()) - && ParameterType.DIGIT.equals(att.getType()) && att.getValues().isEmpty()); + && OnapCommandParameterType.DIGIT.equals(att.getType()) && att.getValues().isEmpty()); } } diff --git a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java index 9c832c24..667ed02a 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java @@ -26,7 +26,7 @@ import java.util.List; import org.junit.Ignore; import org.junit.Test; import org.onap.cli.fw.error.OnapCommandException; -import org.onap.cli.fw.input.ParameterType; +import org.onap.cli.fw.input.OnapCommandParameterType; public class OnapCommandResultTest { @@ -37,16 +37,16 @@ public class OnapCommandResultTest { res.setIncludeSeparator(true); res.setIncludeTitle(true); res.setOutput("Output"); - res.setPrintDirection(PrintDirection.LANDSCAPE); + res.setPrintDirection(OnapCommandPrintDirection.LANDSCAPE); res.setRecords(new ArrayList()); res.setScope(OnapCommandResultAttributeScope.LONG); - res.setType(ResultType.TABLE); + res.setType(OnapCommandResultType.TABLE); res.setDebug(true); assertTrue("debugInfo".equals(res.getDebugInfo()) && res.isIncludeSeparator() - && "Output".equals(res.getOutput()) && PrintDirection.LANDSCAPE.equals(res.getPrintDirection()) + && "Output".equals(res.getOutput()) && OnapCommandPrintDirection.LANDSCAPE.equals(res.getPrintDirection()) && res.getRecords().isEmpty() && OnapCommandResultAttributeScope.LONG.equals(res.getScope()) - && ResultType.TABLE.equals(res.getType())); + && OnapCommandResultType.TABLE.equals(res.getType())); String help = res.print(); @@ -61,18 +61,18 @@ public class OnapCommandResultTest { res.setIncludeSeparator(true); res.setIncludeTitle(true); res.setOutput("Output"); - res.setPrintDirection(PrintDirection.LANDSCAPE); + res.setPrintDirection(OnapCommandPrintDirection.LANDSCAPE); OnapCommandResultAttribute att = new OnapCommandResultAttribute(); att.setName("param"); att.setDescription("description"); - att.setType(ParameterType.STRING); + att.setType(OnapCommandParameterType.STRING); att.setValues(new ArrayList(Arrays.asList(new String[] { "value" }))); List list = new ArrayList(); list.add(att); res.setRecords(list); res.setScope(OnapCommandResultAttributeScope.LONG); - res.setType(ResultType.TABLE); + res.setType(OnapCommandResultType.TABLE); res.getRecordsMap(); String expRes = "+--------+\n|param |\n+--------+\n|value |\n+--------+\n"; String result = res.print(); @@ -88,19 +88,19 @@ public class OnapCommandResultTest { res.setIncludeSeparator(true); res.setIncludeTitle(true); res.setOutput("Output"); - res.setPrintDirection(PrintDirection.LANDSCAPE); + res.setPrintDirection(OnapCommandPrintDirection.LANDSCAPE); OnapCommandResultAttribute att = new OnapCommandResultAttribute(); att.setName("param"); att.setDescription("description"); - att.setType(ParameterType.JSON); + att.setType(OnapCommandParameterType.JSON); att.setValues( new ArrayList(Arrays.asList(new String[] { "{\"id\": \"0001\",\"value\": \"result\"}" }))); List list = new ArrayList(); list.add(att); res.setRecords(list); res.setScope(OnapCommandResultAttributeScope.LONG); - res.setType(ResultType.JSON); + res.setType(OnapCommandResultType.JSON); // Will be handled after the json print is implemented String result = res.print(); @@ -118,25 +118,25 @@ public class OnapCommandResultTest { res.setIncludeSeparator(true); res.setIncludeTitle(true); res.setOutput("Output"); - res.setPrintDirection(PrintDirection.LANDSCAPE); + res.setPrintDirection(OnapCommandPrintDirection.LANDSCAPE); OnapCommandResultAttribute att = new OnapCommandResultAttribute(); att.setName("param"); att.setDescription("description"); - att.setType(ParameterType.STRING); + att.setType(OnapCommandParameterType.STRING); att.setValues(new ArrayList(Arrays.asList(new String[] { "value" }))); List list = new ArrayList(); list.add(att); OnapCommandResultAttribute a1 = new OnapCommandResultAttribute(); a1.setName("param1"); a1.setDescription("description1"); - a1.setType(ParameterType.STRING); + a1.setType(OnapCommandParameterType.STRING); a1.setValues(new ArrayList(Arrays.asList(new String[] { "value1" }))); list.add(a1); res.setRecords(list); res.setScope(OnapCommandResultAttributeScope.LONG); - res.setType(ResultType.CSV); + res.setType(OnapCommandResultType.CSV); String expRes = "param,param1\r\n"; String result = res.print(); @@ -152,25 +152,25 @@ public class OnapCommandResultTest { res.setIncludeSeparator(true); res.setIncludeTitle(true); res.setOutput("Output"); - res.setPrintDirection(PrintDirection.PORTRAIT); + res.setPrintDirection(OnapCommandPrintDirection.PORTRAIT); OnapCommandResultAttribute att = new OnapCommandResultAttribute(); att.setName("param"); att.setDescription("description"); - att.setType(ParameterType.STRING); + att.setType(OnapCommandParameterType.STRING); att.setValues(new ArrayList(Arrays.asList(new String[] { "value" }))); List list = new ArrayList(); list.add(att); OnapCommandResultAttribute a1 = new OnapCommandResultAttribute(); a1.setName("param1"); a1.setDescription("description1"); - a1.setType(ParameterType.STRING); + a1.setType(OnapCommandParameterType.STRING); a1.setValues(new ArrayList(Arrays.asList(new String[] { "value1" }))); list.add(a1); res.setRecords(list); res.setScope(OnapCommandResultAttributeScope.LONG); - res.setType(ResultType.CSV); + res.setType(OnapCommandResultType.CSV); String expRes = "property,value\r\nparam,value\r\n"; String result = res.print(); assertEquals(expRes, result); @@ -183,19 +183,19 @@ public class OnapCommandResultTest { res.setIncludeSeparator(true); res.setIncludeTitle(true); res.setOutput("Output"); - res.setPrintDirection(PrintDirection.PORTRAIT); + res.setPrintDirection(OnapCommandPrintDirection.PORTRAIT); OnapCommandResultAttribute att = new OnapCommandResultAttribute(); att.setName("param"); att.setDescription("description"); - att.setType(ParameterType.STRING); + att.setType(OnapCommandParameterType.STRING); att.setValues(new ArrayList(Arrays.asList(new String[] { "value" }))); List list = new ArrayList(); list.add(att); res.setRecords(list); res.setScope(OnapCommandResultAttributeScope.LONG); - res.setType(ResultType.TABLE); + res.setType(OnapCommandResultType.TABLE); String expRes = "+----------+--------+\n|property |value |\n+----------+--------+" + "\n|param |value |\n+----------+--------+\n"; diff --git a/framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java b/framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java index d1ad7950..ae8dd2e1 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java @@ -27,14 +27,14 @@ public class PrintDirectionTest { public void printDirectionGetTest() { try { - assertTrue(PrintDirection.LANDSCAPE.equals(PrintDirection.get("landscape")) - && PrintDirection.PORTRAIT.equals(PrintDirection.get("portrait"))); + assertTrue(OnapCommandPrintDirection.LANDSCAPE.equals(OnapCommandPrintDirection.get("landscape")) + && OnapCommandPrintDirection.PORTRAIT.equals(OnapCommandPrintDirection.get("portrait"))); } catch (OnapCommandInvalidPrintDirection e) { fail("Shouldn't have thrown this exception : " + e.getMessage()); } try { - PrintDirection.get("name"); + OnapCommandPrintDirection.get("name"); } catch (OnapCommandInvalidPrintDirection e) { assertTrue("0x8003::Print direction name is invalid".equals(e.getMessage())); } diff --git a/framework/src/test/java/org/onap/cli/fw/output/ResultTypeTest.java b/framework/src/test/java/org/onap/cli/fw/output/ResultTypeTest.java index 3c4c5665..a6590b3d 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/ResultTypeTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/ResultTypeTest.java @@ -24,19 +24,19 @@ import org.junit.Test; public class ResultTypeTest { @Test public void resultTypeGetTest() { - assertTrue(ResultType.TABLE.equals(ResultType.get("table")) && ResultType.CSV.equals(ResultType.get("csv")) - && ResultType.JSON.equals(ResultType.get("json")) && ResultType.YAML.equals(ResultType.get("yaml")) - && ResultType.TEXT.equals(ResultType.get("text"))); + assertTrue(OnapCommandResultType.TABLE.equals(OnapCommandResultType.get("table")) && OnapCommandResultType.CSV.equals(OnapCommandResultType.get("csv")) + && OnapCommandResultType.JSON.equals(OnapCommandResultType.get("json")) && OnapCommandResultType.YAML.equals(OnapCommandResultType.get("yaml")) + && OnapCommandResultType.TEXT.equals(OnapCommandResultType.get("text"))); } @Test public void isTabularFormTest() { - assertTrue(ResultType.isTabularForm("table")); + assertTrue(OnapCommandResultType.isTabularForm("table")); } @Test public void isTabularFormNotTest() { - assertFalse(ResultType.isTabularForm("text")); + assertFalse(OnapCommandResultType.isTabularForm("text")); } } diff --git a/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java b/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java index 84c868b3..812e58e2 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java @@ -25,7 +25,7 @@ import java.util.List; import org.junit.Ignore; import org.junit.Test; import org.onap.cli.fw.error.OnapCommandOutputPrintingFailed; -import org.onap.cli.fw.output.PrintDirection; +import org.onap.cli.fw.output.OnapCommandPrintDirection; public class OnapCommandPrintTest { @@ -33,7 +33,7 @@ public class OnapCommandPrintTest { @Ignore public void printCsvTest() throws OnapCommandOutputPrintingFailed { OnapCommandPrint pr = new OnapCommandPrint(); - pr.setDirection(PrintDirection.LANDSCAPE); + pr.setDirection(OnapCommandPrintDirection.LANDSCAPE); pr.setPrintTitle(true); pr.addColumn("name1", new ArrayList(Arrays.asList(new String[] { "value1" }))); String exp = "name1\r\n"; @@ -45,7 +45,7 @@ public class OnapCommandPrintTest { public void printTableTest() throws OnapCommandOutputPrintingFailed { OnapCommandPrint pr = new OnapCommandPrint(); List getColumnsData = new ArrayList(); - pr.setDirection(PrintDirection.LANDSCAPE); + pr.setDirection(OnapCommandPrintDirection.LANDSCAPE); pr.setPrintTitle(true); pr.addColumn("name2", new ArrayList(Arrays.asList(new String[] { "value2" }))); String exp = "+--------+\n|name2 |\n+--------+\n|value2 |\n+--------+\n"; @@ -58,7 +58,7 @@ public class OnapCommandPrintTest { public void printTableNullColumnHeaderTest() throws OnapCommandOutputPrintingFailed { OnapCommandPrint pr = new OnapCommandPrint(); List getColumnsData = new ArrayList(); - pr.setDirection(PrintDirection.LANDSCAPE); + pr.setDirection(OnapCommandPrintDirection.LANDSCAPE); pr.setPrintTitle(true); pr.addColumn("name2", new ArrayList(Arrays.asList(new String[] { "value2" }))); String exp = "+--------+\n|name2 |\n+--------+\n|value2 |\n+--------+\n"; @@ -71,7 +71,7 @@ public class OnapCommandPrintTest { public void printTableEmptyColumnValuesTest() throws OnapCommandOutputPrintingFailed { OnapCommandPrint pr = new OnapCommandPrint(); List getColumnsData = new ArrayList(); - pr.setDirection(PrintDirection.LANDSCAPE); + pr.setDirection(OnapCommandPrintDirection.LANDSCAPE); pr.setPrintTitle(true); pr.addColumn("name2", new ArrayList(Arrays.asList(new String[] { "" }))); String exp = "+--------+\n|name2 |\n+--------+\n| |\n+--------+\n"; diff --git a/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java b/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java new file mode 100644 index 00000000..539ec245 --- /dev/null +++ b/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java @@ -0,0 +1,150 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * 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. + */ + +package org.onap.cli.fw.registrar; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.net.URL; + +import org.junit.Before; +import org.junit.Test; +import org.onap.cli.fw.cmd.OnapCommand; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.error.OnapCommandHelpFailed; +import org.onap.cli.fw.error.OnapCommandNotFound; +import org.onap.cli.fw.schema.OnapCommandSchema; + +public class OnapCommandRegistrarTest { + + OnapCommandRegistrar registerar; + + @Before + public void setup() throws OnapCommandException { + registerar = OnapCommandRegistrar.getRegistrar(); + createDir(); + } + + private void createDir() { + URL url = OnapCommandRegistrarTest.class.getClassLoader().getResource("open-cli-schema"); + if (url != null) { + String path = url.getPath(); + path = path.replaceFirst("open-cli-schema", "data"); + File file = new File(path); + if (!file.exists()) { + file.mkdir(); + } else { + File f1 = new File(path + "/cli-schema.json"); + f1.delete(); + } + } + } + + @Test + public void oclipCommandNotFoundTest() throws OnapCommandException { + try { + registerar = OnapCommandRegistrar.getRegistrar(); + registerar.get("Test1"); + fail("This should have thrown an exception"); + } catch (OnapCommandNotFound e) { + //pass // NOSONAR + } catch (Exception e) { + fail("This should have thrown an OnapCommandNotFound exception"); + } + } + + @Test + public void helpTest() throws OnapCommandException { + String help = registerar.getHelp(); + assertNotNull(help); + } + + @Test + public void versionTest() throws OnapCommandHelpFailed { + String version = registerar.getVersion(); + assertNotNull(version); + } + + @Test + public void listTest() { + registerar.listCommands(); + } + + @Test + public void testProfile() throws OnapCommandException { + try { + OnapCommandRegistrar.getRegistrar().setProfile("test"); + OnapCommandRegistrar.getRegistrar().addParamCache("a", "b"); + OnapCommandRegistrar.getRegistrar().getParamCache(); + OnapCommandRegistrar.getRegistrar().removeParamCache("a"); + + OnapCommandRegistrar.getRegistrar().setInteractiveMode(false); + assertTrue(!OnapCommandRegistrar.getRegistrar().isInteractiveMode()); + + OnapCommandRegistrar.getRegistrar().setEnabledProductVersion("open-cli"); + assertEquals("open-cli", OnapCommandRegistrar.getRegistrar().getEnabledProductVersion()); + OnapCommandRegistrar.getRegistrar().getAvailableProductVersions(); + assertTrue(OnapCommandRegistrar.getRegistrar().listCommandsForEnabledProductVersion().contains("sample-test")); + + assertTrue(OnapCommandRegistrar.getRegistrar().listCommandInfo().size() > 2); + } catch (Exception e) { + fail("failed to test the profile"); + } + } + + + @Test + public void test() throws OnapCommandException { + OnapCommandRegistrar registrar = OnapCommandRegistrar.getRegistrar(); + OnapCommand cmd = registrar.get("sample-test"); + cmd.printVersion(); + registrar.listCommands(); + } +} + +@OnapCommandSchema(schema = "sample-test-schema.yaml") +class OnapCommandTest extends OnapCommand { + + public OnapCommandTest() { + + } + + public static final String CMD_NAME = "test"; + + protected void run() throws OnapCommandException { + + } + +} + +@OnapCommandSchema(schema = "test-schema.yaml") +class OnapCommandTest1 extends OnapCommand { + + public OnapCommandTest1() { + + } + + public static final String CMD_NAME = "test1"; + + protected void run() throws OnapCommandException { + + } + +} diff --git a/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java b/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java index a900fe6d..8153b6db 100644 --- a/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java +++ b/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java @@ -21,11 +21,9 @@ import static org.junit.Assert.assertTrue; import java.util.List; import org.junit.Test; -import org.onap.cli.fw.OnapCommand; -import org.onap.cli.fw.cmd.OnapHttpCommand; +import org.onap.cli.fw.cmd.OnapCommand; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandInvalidSchema; -import org.onap.cli.fw.utils.OnapCommandSchemaLoaderUtils; public class ValidateSchemaTest { @@ -36,7 +34,7 @@ public class ValidateSchemaTest { @Override protected void run() throws OnapCommandException {} }; - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "fdsfds.yaml", true, true); + OnapCommandSchemaLoader.loadSchema(cmd, "fdsfds.yaml", true, true); } @Test(expected = OnapCommandInvalidSchema.class) @@ -45,7 +43,7 @@ public class ValidateSchemaTest { @Override protected void run() throws OnapCommandException {} }; - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "fdsfds", true, true); + OnapCommandSchemaLoader.loadSchema(cmd, "fdsfds", true, true); } @Test(expected = OnapCommandInvalidSchema.class) @@ -54,7 +52,7 @@ public class ValidateSchemaTest { @Override protected void run() throws OnapCommandException {} }; - OnapCommandSchemaLoaderUtils.loadSchema(cmd, + OnapCommandSchemaLoader.loadSchema(cmd, ValidateSchemaTest.class.getClassLoader().getResource("open-cli.properties").getFile(), true, true); } @@ -65,7 +63,7 @@ public class ValidateSchemaTest { @Override protected void run() throws OnapCommandException {} }; - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "schema-invalid-file-null.yaml", true, true); + OnapCommandSchemaLoader.loadSchema(cmd, "schema-invalid-file-null.yaml", true, true); } @Test @@ -74,7 +72,7 @@ public class ValidateSchemaTest { @Override protected void run() throws OnapCommandException {} }; - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "schema-validate-pass.yaml", true, true); + OnapCommandSchemaLoader.loadSchema(cmd, "schema-validate-pass.yaml", true, true); } @@ -84,49 +82,32 @@ public class ValidateSchemaTest { @Override protected void run() throws OnapCommandException {} }; - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "schema-invalid-file.yaml", true, true); + OnapCommandSchemaLoader.loadSchema(cmd, "schema-invalid-file.yaml", true, true); } @Test public void validateTest() throws OnapCommandException { - OnapCommand cmd1 = new OnapCommand() { - @Override - protected void run() throws OnapCommandException {} - }; - List errorList1 = OnapCommandSchemaLoaderUtils.loadSchema(cmd1, "schema-validate-http.yaml", true, true); - assertTrue(errorList1.size() > 0); - OnapCommand cmd2 = new OnapCommand() { @Override protected void run() throws OnapCommandException {} }; - List errorList2 = OnapCommandSchemaLoaderUtils.loadSchema(cmd2, "schema-validate-basic.yaml", true, true); + List errorList2 = OnapCommandSchemaLoader.loadSchema(cmd2, "schema-validate-basic.yaml", true, true); assertTrue(errorList2.size() > 0); OnapCommand cmd3 = new OnapCommand() { @Override protected void run() throws OnapCommandException {} }; - List errorList3 = OnapCommandSchemaLoaderUtils.loadSchema(cmd2, "schema-validate-invalidschematype.yaml", true, true); + List errorList3 = OnapCommandSchemaLoader.loadSchema(cmd2, "schema-validate-invalidschematype.yaml", true, true); assertTrue(errorList3.size() > 0); - OnapCommand cmd4 = new OnapCommand() { - @Override - protected void run() throws OnapCommandException {} - }; - List errorList4 = OnapCommandSchemaLoaderUtils.loadSchema(cmd2, "schema-validate-invalid.yaml", true, true); - - OnapHttpCommand oclipHttpCommand = new OnapHttpCommand(); - errorList4.addAll(OnapCommandSchemaLoaderUtils.loadHttpSchema(oclipHttpCommand, - "schema-validate-invalid.yaml", true, true)); - assertTrue(errorList4.size() > 0); OnapCommand cmd5 = new OnapCommand() { @Override protected void run() throws OnapCommandException {} }; - List errorList5 = OnapCommandSchemaLoaderUtils.loadSchema(cmd5, "schema-validate-pass.yaml", true, true); + List errorList5 = OnapCommandSchemaLoader.loadSchema(cmd5, "schema-validate-pass.yaml", true, true); assertTrue(errorList5.size() == 0); } diff --git a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java index 8cac03bf..317920f8 100644 --- a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java +++ b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java @@ -23,9 +23,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; -import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -35,29 +33,20 @@ import org.junit.FixMethodOrder; import org.junit.Ignore; import org.junit.Test; import org.junit.runners.MethodSorters; -import org.onap.cli.fw.OnapCommand; -import org.onap.cli.fw.OnapCommandSchema; -import org.onap.cli.fw.cmd.OnapHttpCommand; +import org.onap.cli.fw.cmd.OnapCommand; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandHelpFailed; -import org.onap.cli.fw.error.OnapCommandHttpHeaderNotFound; -import org.onap.cli.fw.error.OnapCommandHttpInvalidResponseBody; -import org.onap.cli.fw.error.OnapCommandInvalidParameterType; -import org.onap.cli.fw.error.OnapCommandInvalidPrintDirection; -import org.onap.cli.fw.error.OnapCommandInvalidResultAttributeScope; import org.onap.cli.fw.error.OnapCommandInvalidSchema; import org.onap.cli.fw.error.OnapCommandInvalidSchemaVersion; import org.onap.cli.fw.error.OnapCommandParameterNameConflict; -import org.onap.cli.fw.error.OnapCommandParameterNotFound; import org.onap.cli.fw.error.OnapCommandParameterOptionConflict; import org.onap.cli.fw.error.OnapCommandSchemaNotFound; -import org.onap.cli.fw.http.HttpInput; -import org.onap.cli.fw.http.HttpResult; import org.onap.cli.fw.info.OnapCommandInfo; import org.onap.cli.fw.input.OnapCommandParameter; -import org.onap.cli.fw.input.ParameterType; import org.onap.cli.fw.output.OnapCommandResult; -import org.springframework.core.io.Resource; +import org.onap.cli.fw.schema.OnapCommandSchema; +import org.onap.cli.fw.schema.OnapCommandSchemaInfo; +import org.onap.cli.fw.schema.OnapCommandSchemaLoader; import mockit.Invocation; import mockit.Mock; @@ -65,21 +54,9 @@ import mockit.MockUp; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class OnapCommandUtilsTest { - - @Test(expected = OnapCommandInvalidSchema.class) - public void oclipCommandUtilsInputStreamNullTest() throws OnapCommandException { - OnapCommandSchemaLoaderUtils.validateSchemaVersion("sample-test1-schema-http1.yaml", "1.0"); - } - - @Test - public void oclipCommandUtilsInputStreamNotNullTest() throws OnapCommandException { - Map map = OnapCommandSchemaLoaderUtils.validateSchemaVersion("sample-test1-schema-http.yaml", "1.0"); - assertTrue(map != null); - } - @Test public void externalSchemaTest() { - SchemaInfo schema = new SchemaInfo(); + OnapCommandSchemaInfo schema = new OnapCommandSchemaInfo(); schema.setCmdName("cmdName"); schema.setSchemaName("schemaName"); schema.setVersion("version"); @@ -91,7 +68,7 @@ public class OnapCommandUtilsTest { @Test public void schemaFileNotFoundTest() throws OnapCommandException { - Map map = OnapCommandSchemaLoaderUtils.validateSchemaVersion("sample-test-schema.yaml", "1.0"); + Map map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-schema.yaml", "1.0"); assertTrue(map.size() > 0); } @@ -100,7 +77,7 @@ public class OnapCommandUtilsTest { public void invalidSchemaFileTest() throws OnapCommandException { Map map = null; try { - map = OnapCommandSchemaLoaderUtils.validateSchemaVersion("sample-test-schema1.yaml", "1.0"); + map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-schema1.yaml", "1.0"); } catch (OnapCommandInvalidSchemaVersion e) { fail("Test should not have thrown this exception : " + e.getMessage()); } catch (OnapCommandInvalidSchema e) { @@ -114,7 +91,7 @@ public class OnapCommandUtilsTest { public void validateWrongSchemaVersionTest() throws OnapCommandException { Map map = null; try { - map = OnapCommandSchemaLoaderUtils.validateSchemaVersion("sample-test-invalid-schema.yaml", "1.0"); + map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-invalid-schema.yaml", "1.0"); } catch (OnapCommandInvalidSchemaVersion e) { fail("Test should not have thrown this exception : " + e.getMessage()); } catch (OnapCommandInvalidSchema e) { @@ -128,7 +105,7 @@ public class OnapCommandUtilsTest { public void validateSchemaVersionTest() throws OnapCommandException { Map map = null; try { - map = OnapCommandSchemaLoaderUtils.validateSchemaVersion("sample-test-schema.yaml", "1.1"); + map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-schema.yaml", "1.1"); } catch (OnapCommandInvalidSchemaVersion e) { assertEquals("0xb003::Command schema open_cli_schema_version 1.0 is invalid or missing", e.getMessage()); } catch (OnapCommandInvalidSchema e) { @@ -141,32 +118,32 @@ public class OnapCommandUtilsTest { @Test public void loadOnapCommandSchemaWithOutDefaultTest() throws OnapCommandException { OnapCommand cmd = new OnapCommandSample(); - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "sample-test-schema.yaml", false, false); + OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", false, false); assertTrue("sample-test".equals(cmd.getName()) && cmd.getParameters().size() == 9); } @Test(expected = OnapCommandParameterNameConflict.class) public void loadOnapCommandSchemaWithDuplicateNameTest() throws OnapCommandException { OnapCommand cmd = new OnapCommandSample(); - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-name.yaml", false, false); + OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-invalid-schema-duplicate-name.yaml", false, false); } @Test(expected = OnapCommandParameterOptionConflict.class) public void loadOnapCommandSchemaWithDuplicateShortOptionTest() throws OnapCommandException { OnapCommand cmd = new OnapCommandSample(); - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-shortoption.yaml", false, false); + OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-invalid-schema-duplicate-shortoption.yaml", false, false); } @Test(expected = OnapCommandParameterOptionConflict.class) public void loadOnapCommandSchemaWithDuplicateLongOptionTest() throws OnapCommandException { OnapCommand cmd = new OnapCommandSample(); - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-longoption.yaml", false, false); + OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-invalid-schema-duplicate-longoption.yaml", false, false); } @Test public void loadOnapCommandSchemaWithDefaultTest() throws OnapCommandException { OnapCommand cmd = new OnapCommandSample(); - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "sample-test-schema.yaml", true, false); + OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", true, false); assertTrue("sample-test".equals(cmd.getName()) && cmd.getParameters().size() > 9); for (OnapCommandParameter com : cmd.getParameters()) { @@ -177,49 +154,11 @@ public class OnapCommandUtilsTest { assertTrue(map.size() == 15); } - @Test - public void loadOnapCommandSchemaAuthRequiredTest() throws OnapCommandException { - OnapCommand cmd = new OnapCommandSample(); - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "sample-test-schema-auth-required.yaml", true, false); - assertTrue("sample-test".equals(cmd.getName())); - - Map map = OnapCommandUtils.getInputMap(cmd.getParameters()); - assertTrue(map.size() == 7); - } - - @Test - public void loadHttpBasedSchemaExceptionTest() throws OnapCommandException { - OnapHttpCommand cmd = new OnapHttpCommandSample(); - cmd.setName("sample-test-http"); - try { - OnapCommandSchemaLoaderUtils.loadHttpSchema(cmd, "sample-test-schema.yaml", true, false); - } catch (OnapCommandParameterNameConflict | OnapCommandParameterOptionConflict - | OnapCommandInvalidParameterType | OnapCommandInvalidPrintDirection - | OnapCommandInvalidResultAttributeScope | OnapCommandSchemaNotFound | OnapCommandInvalidSchema - | OnapCommandInvalidSchemaVersion e) { - assertTrue(e.getMessage().contains("0xb001::Command schema sample-test-schema.yaml is invalid")); - } - } - - @Test - public void loadHttpBasedSchemaTest() throws OnapCommandException { - OnapHttpCommand cmd = new OnapHttpCommandSample(); - cmd.setName("sample-create-http"); - try { - OnapCommandSchemaLoaderUtils.loadHttpSchema(cmd, "sample-test-schema-http.yaml", true, true); - assertTrue(cmd.getSuccessStatusCodes().size() == 2); - } catch (OnapCommandParameterNameConflict | OnapCommandParameterOptionConflict - | OnapCommandInvalidParameterType | OnapCommandInvalidPrintDirection - | OnapCommandInvalidResultAttributeScope | OnapCommandSchemaNotFound | OnapCommandInvalidSchema - | OnapCommandInvalidSchemaVersion e) { - fail("Test should not have thrown this exception : " + e.getMessage()); - } - } @Test public void helpCommandTest() throws IOException, OnapCommandException { OnapCommand cmd = new OnapCommandSample(); - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "sample-test-schema.yaml", true, false); + OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", true, false); String actualResult = OnapCommandHelperUtils.help(cmd); @@ -231,7 +170,7 @@ public class OnapCommandUtilsTest { @Test public void findOnapCommandsTest() { List> cmds = OnapCommandDiscoveryUtils.discoverCommandPlugins(); - assertTrue(cmds.size() == 7); + assertTrue(cmds.size() == 3); } @Test @@ -264,105 +203,12 @@ public class OnapCommandUtilsTest { } - @Test - public void formMethodNameFromAttributeTest() { - - String str = ""; - String name = OnapCommandUtils.formMethodNameFromAttributeName(str, "test"); - - assertEquals("", name); - - str = null; - name = OnapCommandUtils.formMethodNameFromAttributeName(str, "test"); - - assertEquals(null, name); - - str = "test-get"; - name = OnapCommandUtils.formMethodNameFromAttributeName(str, ""); - assertEquals("TestGet", name); - - } - - @Test - public void populateParametersTest() throws OnapCommandException { - - HttpInput input = new HttpInput(); - input.setBody("body"); - input.setMethod("method"); - Map mapHead = new HashMap<>(); - mapHead.put("key2", "${value2}"); - input.setReqHeaders(mapHead); - Map query = new HashMap<>(); - query.put("key3", "{${value3}}"); - input.setReqQueries(query); - input.setUri("uri"); - - Map params = new HashMap<>(); - OnapCommandParameter param = new OnapCommandParameter(); - param.setDefaultValue("defaultValue2"); - param.setParameterType(ParameterType.STRING); - params.put("value2", param); - OnapCommandParameter param1 = new OnapCommandParameter(); - param1.setDefaultValue("{\"defaultValue3\"}"); - param1.setParameterType(ParameterType.JSON); - params.put("value3", param1); - - HttpInput input1 = OnapCommandUtils.populateParameters(params, input); - String expected = "\nURL: uri\nMethod: method\nRequest Queries: {key3={\"defaultValue3\"}}\n" - + "Request Body: body\nRequest Headers: {key2=defaultValue2}\nRequest Cookies: {}\nbinaryData=false"; - assertEquals(expected, input1.toString()); - - input.setBody("${body}"); - - HttpInput input2 = null; - try { - input2 = OnapCommandUtils.populateParameters(params, input); - } catch (OnapCommandParameterNotFound e) { - assertEquals("0x7005::Command input parameter body is not valid", e.getMessage()); - } - - } - - @Test(expected = OnapCommandHttpHeaderNotFound.class) - public void populateOutputsTest() throws OnapCommandException { - HttpResult output = new HttpResult(); - output.setBody( - "{\"serviceName\":\"test\",\"version\":\"v1\",\"url\":\"/api/test/v1\",\"protocol\":\"REST\",\"visualRange\":\"1\",\"lb_policy\":\"hash\",\"nodes\":[{\"ip\":\"127.0.0.1\",\"port\":\"8012\",\"ttl\":0,\"nodeId\":\"test_127.0.0.1_8012\",\"expiration\":\"2017-02-10T05:33:25Z\",\"created_at\":\"2017-02-10T05:33:25Z\",\"updated_at\":\"2017-02-10T05:33:25Z\"}],\"status\":\"1\"}"); - Map mapHead = new HashMap<>(); - mapHead.put("head1", "value1"); - output.setRespHeaders(mapHead); - output.setStatus(0); - - Map params = new HashMap<>(); - params.put("head", "$h{head1}"); - params.put("body", "$b{$.serviceName}"); - params.put("key", "value"); - - Map> input1 = OnapCommandUtils.populateOutputs(params, output); - assertEquals("{head=[value1], body=[test], key=[value]}", input1.toString()); - - params.put("body", "$b{{$.serviceName}"); - try { - input1 = OnapCommandUtils.populateOutputs(params, output); - } catch (OnapCommandHttpInvalidResponseBody e) { - assertEquals( - "0x3004::Http response body does not have json entry {$.serviceName, Missing property in path $['{$']", - e.getMessage()); - } - output.setBody("{}"); - input1 = OnapCommandUtils.populateOutputs(params, output); - params.put("head", "$h{head2}"); - output.setBody("{\"test\"}"); - input1 = OnapCommandUtils.populateOutputs(params, output); - } - - @Test(expected = OnapCommandHelpFailed.class) public void zendExceptionHelpTest1() throws OnapCommandException { mockPrintMethodException(); OnapCommand cmd = new OnapCommandSample(); - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "sample-test-schema.yaml", true, false); + OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", true, false); OnapCommandHelperUtils.help(cmd); @@ -372,7 +218,7 @@ public class OnapCommandUtilsTest { @Test public void test() throws OnapCommandException { OnapCommandSampleInfo cmd = new OnapCommandSampleInfo(); - OnapCommandSchemaLoaderUtils.loadSchema(cmd, "sample-test-info.yaml", true, false); + OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-info.yaml", true, false); OnapCommandInfo info = cmd.getInfo(); assert info != null; } @@ -391,30 +237,6 @@ public class OnapCommandUtilsTest { } } - @OnapCommandSchema(schema = "sample-test-schema-http.yaml") - class OnapHttpCommandSample extends OnapHttpCommand { - - @Override - protected void run() throws OnapCommandException { - } - } - - private void mockExternalResources() { - new MockUp() { - boolean isMock = true; - - @Mock - public Resource[] getExternalResources(Invocation inv, String pattern) throws IOException { - if (isMock) { - isMock = false; - throw new IOException(); - } else { - return inv.proceed(pattern); - } - } - }; - } - private void mockPrintMethodException() { new MockUp() { boolean isMock = true; diff --git a/framework/src/test/java/org/onap/cli/fw/utils/OpenCommandRegistrarTest.java b/framework/src/test/java/org/onap/cli/fw/utils/OpenCommandRegistrarTest.java deleted file mode 100644 index 648746ca..00000000 --- a/framework/src/test/java/org/onap/cli/fw/utils/OpenCommandRegistrarTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * 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. - */ - -package org.onap.cli.fw.utils; - -import org.junit.Before; -import org.junit.Test; -import org.onap.cli.fw.OnapCommand; -import org.onap.cli.fw.OnapCommandRegistrar; -import org.onap.cli.fw.error.OnapCommandException; - - -public class OpenCommandRegistrarTest { - - @Before - public void setUp() throws Exception { - - } - - @Test - public void test() throws OnapCommandException { - OnapCommandRegistrar registrar = OnapCommandRegistrar.getRegistrar(); - OnapCommand cmd = registrar.get("sample-test"); - cmd.printVersion(); - registrar.listCommands(); - } - -} -- cgit 1.2.3-korg