diff options
author | Kanagaraj Manickam <kanagaraj.manickam@huawei.com> | 2020-08-06 03:27:35 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-08-06 03:27:35 +0000 |
commit | 29e3d400b200b0567caa6c5768d51ebc2ce2a891 (patch) | |
tree | 898d66b059c384909a2bda622e45d1036cca45d6 /framework/src/test | |
parent | 85d106fbd8da63243157c4d79b45c13c9c2d7a2f (diff) | |
parent | 2bdd4f82bb6d2d7928044228bf0893cf6aa5921d (diff) |
Merge "Code improvement - Pending sonar issues"
Diffstat (limited to 'framework/src/test')
9 files changed, 36 insertions, 9 deletions
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 60aa5e7d..94b5e15b 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 @@ -34,6 +34,9 @@ import org.onap.cli.fw.input.OnapCommandParameterType; import org.onap.cli.fw.output.OnapCommandResultAttribute; import org.onap.cli.fw.registrar.OnapCommandRegistrar; +import org.onap.cli.fw.output.OnapCommandResult; +import static org.junit.Assert.assertNotNull; + public class OnapCommandSampleTest { @Test public void sampleTestVersion() { @@ -52,6 +55,8 @@ public class OnapCommandSampleTest { OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test"); sample.setParameters(parameters); sample.execute(); + OnapCommandResult onapCommandResult = sample.execute(); + assertEquals("open-cli::test",onapCommandResult.getOutput()); } catch (OnapCommandException e) { } } @@ -70,6 +75,8 @@ public class OnapCommandSampleTest { OnapCommandSample sample = new OnapCommandSample(); sample.setParameters(parameters); sample.execute(); + OnapCommandResult onapCommandResult = sample.execute(); + assertNotNull(onapCommandResult); } catch (OnapCommandException e) { } } 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 5b5c6fac..0e067e5b 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 @@ -22,6 +22,8 @@ import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.registrar.OnapCommandRegistrar; import org.onap.cli.fw.schema.ValidateSchemaTest; +import org.onap.cli.fw.output.OnapCommandResult; +import static org.junit.Assert.assertNotNull; public class OnapSchemaValidateCommandTest { @@ -32,6 +34,8 @@ public class OnapSchemaValidateCommandTest { cmd.getParametersMap().get("schema-location").setValue("schema-validate-pass.yaml"); cmd.getParametersMap().get("internal-schema").setValue("true"); cmd.execute(); + OnapCommandResult onapCommandResult = cmd.execute(); + assertNotNull(onapCommandResult.getOutput()); } @Ignore @@ -42,5 +46,7 @@ public class OnapSchemaValidateCommandTest { ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-pass.yaml").getFile()); cmd.getParametersMap().get("internal-schema").setValue("true"); cmd.execute(); + OnapCommandResult onapCommandResult = cmd.execute(); + assertNotNull(onapCommandResult); } } diff --git a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java index c2f3bd6e..66be4489 100644 --- a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java +++ b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java @@ -19,11 +19,14 @@ package org.onap.cli.fw.input; import org.junit.Test; import org.onap.cli.fw.store.OnapCommandProfileStore; +import static org.junit.Assert.assertNotNull; + public class OnapCommandParameterCacheTest { @Test public void test() { OnapCommandProfileStore cache = OnapCommandProfileStore.getInstance(); + assertNotNull(cache); } diff --git a/framework/src/test/java/org/onap/cli/fw/input/cache/OnapCommandParameterCacheTest.java b/framework/src/test/java/org/onap/cli/fw/input/cache/OnapCommandParameterCacheTest.java index 76844d72..70c89d88 100644 --- a/framework/src/test/java/org/onap/cli/fw/input/cache/OnapCommandParameterCacheTest.java +++ b/framework/src/test/java/org/onap/cli/fw/input/cache/OnapCommandParameterCacheTest.java @@ -16,19 +16,22 @@ package org.onap.cli.fw.input.cache; -import static org.junit.Assert.assertTrue; - import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.junit.Test; +import static org.junit.Assert.assertNotNull; + public class OnapCommandParameterCacheTest { @Test public void paramTypeGetTest() throws IOException { FileUtils.forceMkdir(new File("data")); FileUtils.touch(new File("data" + File.separator + "test-profile.json")); + File test_profile = new File("data" + File.separator + "test-profile.json"); + FileUtils.touch(test_profile); + assertNotNull(test_profile.lastModified()); //assertTrue(OnapCommandProfileStore.getInstance().getProfiles().contains("test")); // FileUtils.cleanDirectory(new File("data")); } 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 83a46088..f46fc911 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 @@ -108,6 +108,7 @@ public class OnapCommandResultTest { // Will be handled after the json print is implemented String result = res.print(); + assertEquals("[{\"param\":{\"id\":\"0001\",\"value\":\"result\"}}]",result); // String expRes = "+--------+\n|param |\n+--------+\n|value // |\n+--------+\n"; // assertEquals(expRes,result); 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 index 3b8876cf..ad5b0b88 100644 --- a/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java +++ b/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java @@ -19,6 +19,7 @@ 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.assertFalse; import static org.junit.Assert.fail; import java.io.File; @@ -62,8 +63,8 @@ public class OnapCommandRegistrarTest { @Test public void oclipCommandNotFoundTest() throws OnapCommandException { + registerar = OnapCommandRegistrar.getRegistrar(); try { - registerar = OnapCommandRegistrar.getRegistrar(); registerar.get("Test1"); fail("This should have thrown an exception"); } catch (OnapCommandNotFound e) { @@ -87,7 +88,7 @@ public class OnapCommandRegistrarTest { @Test public void listTest() { - registerar.listCommands(); + assertFalse(registerar.listCommands().isEmpty()); } @Test @@ -95,7 +96,7 @@ public class OnapCommandRegistrarTest { OnapCommandRegistrar registrar = OnapCommandRegistrar.getRegistrar(); OnapCommand cmd = registrar.get("sample-test"); cmd.printVersion(); - registrar.listCommands(); + assertFalse(registerar.listCommands().isEmpty()); } @Test public void getTestSuiteTest() 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 507490c6..00c311fc 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 @@ -29,6 +29,8 @@ import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandInvalidSchema; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + public class ValidateSchemaTest { @Test(expected = OnapCommandInvalidSchema.class) @@ -49,7 +51,7 @@ public class ValidateSchemaTest { @Override protected void run() throws OnapCommandException {} }; - cmd.initializeSchema("test-command-to-valdiate-merge.yaml", true); + assertTrue(cmd.initializeSchema("test-command-to-valdiate-merge.yaml", true).isEmpty()); } @Test(expected = OnapCommandInvalidSchema.class) @@ -79,6 +81,7 @@ public class ValidateSchemaTest { protected void run() throws OnapCommandException {} }; OnapCommandSchemaLoader.loadSchema(cmd, "schema-invalid-file-null.yaml", true, true); + fail("OnapCommandInvalidSchema exception occurs"); } @Test @@ -88,7 +91,8 @@ public class ValidateSchemaTest { protected void run() throws OnapCommandException {} }; OnapCommandSchemaLoader.loadSchema(cmd, "schema-validate-pass.yaml", true, true); - + List<String> list = OnapCommandSchemaLoader.loadSchema(cmd, "schema-validate-pass.yaml", true, true); + assertTrue(list.isEmpty()); } @Test(expected = OnapCommandInvalidSchema.class) diff --git a/framework/src/test/java/org/onap/cli/fw/store/OnapCommandProfileStoreTest.java b/framework/src/test/java/org/onap/cli/fw/store/OnapCommandProfileStoreTest.java index c2f2fe17..18657c7d 100644 --- a/framework/src/test/java/org/onap/cli/fw/store/OnapCommandProfileStoreTest.java +++ b/framework/src/test/java/org/onap/cli/fw/store/OnapCommandProfileStoreTest.java @@ -72,6 +72,7 @@ public class OnapCommandProfileStoreTest { @Test public void addTest() { onapCommandProfileStore.add("abc", "abc", "abc"); + assertNotNull(onapCommandProfileStore. getParams("abc")); } @Test 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 e5fa45b7..5ce32782 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 @@ -420,7 +420,7 @@ public class OnapCommandUtilsTest { String actualResult = OnapCommandHelperUtils.help(cmd); String expectedHelp = FileUtil.loadResource("sample-cmd-test-help.txt"); - + assertNotNull(actualResult); //mrkanag compare the result } @@ -482,7 +482,7 @@ public class OnapCommandUtilsTest { OnapCommandSampleInfo cmd = new OnapCommandSampleInfo(); OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-info.yaml", true, false); OnapCommandInfo info = cmd.getInfo(); - assert info != null; + assertNotNull(info); } @OnapCommandSchema(schema = "sample-test-info.yaml") @@ -507,6 +507,7 @@ public class OnapCommandUtilsTest { System.out.println(pr.getOutput()); System.out.println(pr.getError()); System.out.println(pr.getExitCode()); + assertEquals(0, pr.getExitCode()); pr = new ProcessRunner(new String [] {"dir", "c:"}, null); pr.run(); |