summaryrefslogtreecommitdiffstats
path: root/framework/src/test/java
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2017-08-18 12:13:23 +0530
committersubhash kumar singh <subhash.kumar.singh@huawei.com>2017-08-18 07:06:13 +0000
commit8d3d394a5effe4127e8480c812de82d81fe5e5ae (patch)
treed828a563715b6d92f0cae94e6da709d64d1f7d54 /framework/src/test/java
parent7fcf1e84c6e2a1b8bfbeaff52b8baa9bc8d418d6 (diff)
Move schema validation to load schema
Move schema validation to load schema. Issue-Id: CLI-25 Change-Id: I8fdb8450f6f95b7170c10b0ec5883162a4cf406a Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
Diffstat (limited to 'framework/src/test/java')
-rw-r--r--framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java4
-rw-r--r--framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java18
-rw-r--r--framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java144
-rw-r--r--framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java24
4 files changed, 110 insertions, 80 deletions
diff --git a/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java b/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java
index 57847254..12ff2085 100644
--- a/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java
+++ b/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java
@@ -38,7 +38,7 @@ public class TestCommandValidate {
@Test
public void testNoAuthArgumentTrue() throws OnapCommandException {
- OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true, false);
OnapCommandParameter noAuthParam = cmd.getParameters().stream().filter(p -> p.getName().equalsIgnoreCase("no-auth")).findFirst().get();
noAuthParam.setValue(true);
@@ -49,7 +49,7 @@ public class TestCommandValidate {
@Test(expected = OnapCommandParameterMissing.class)
public void testNoAuthArgFalse() throws OnapCommandException {
- OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true, false);
cmd.validate();
}
}
diff --git a/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java b/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java
index da37f6f4..20ca10f7 100644
--- a/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java
+++ b/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java
@@ -39,7 +39,7 @@ public class TestDefaultParameterSection {
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true, false);
List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
assertTrue(parameters.contains("onap-username"));
assertTrue(parameters.contains("onap-password"));
@@ -53,7 +53,7 @@ public class TestDefaultParameterSection {
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "sample-test-exclude-param.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-exclude-param.yaml", true, false);
List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
assertTrue(parameters.contains("onap-username"));
assertTrue(parameters.contains("onap-password"));
@@ -70,7 +70,7 @@ public class TestDefaultParameterSection {
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "sample-test-include-exclude.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-include-exclude.yaml", true, false);
List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
assertTrue(parameters.contains("onap-username"));
@@ -85,7 +85,7 @@ public class TestDefaultParameterSection {
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "onap-test-schema.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "onap-test-schema.yaml", true, false);
List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
assertFalse(parameters.contains("onap-username"));
@@ -103,7 +103,7 @@ public class TestDefaultParameterSection {
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-default-parameter.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-default-parameter.yaml", true, false);
}
@Test(expected = OnapCommandInvalidDefaultParameter.class)
@@ -113,7 +113,7 @@ public class TestDefaultParameterSection {
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-default-params-not-exist.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-default-params-not-exist.yaml", true, false);
}
@Test(expected = OnapCommandInvalidSchema.class)
@@ -123,7 +123,7 @@ public class TestDefaultParameterSection {
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "sample-test-import-def-param-false.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-import-def-param-false.yaml", true, false);
}
@Test(expected = OnapCommandInvalidDefaultParameter.class)
@@ -133,7 +133,7 @@ public class TestDefaultParameterSection {
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-include-noauth.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-include-noauth.yaml", true, false);
}
@Test(expected = OnapCommandInvalidDefaultParameter.class)
@@ -143,6 +143,6 @@ public class TestDefaultParameterSection {
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-exclude-noauth.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-exclude-noauth.yaml", true, false);
}
}
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 4c48683b..a8df9979 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
@@ -17,87 +17,117 @@
package org.onap.cli.fw.schema;
import org.junit.Test;
+import org.onap.cli.fw.OnapCommand;
+import org.onap.cli.fw.cmd.OnapHttpCommand;
+import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
-import org.yaml.snakeyaml.scanner.ScannerException;
+import org.onap.cli.fw.utils.OnapCommandUtils;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashSet;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
public class ValidateSchemaTest {
@Test(expected = OnapCommandInvalidSchema.class)
- public void invalidateTest1() throws OnapCommandInvalidSchema {
- new SchemaValidator(new File("fdsfds"));
- new SchemaValidator(new File("fdsfds.yaml"));
+ public void invalidateTest1() throws OnapCommandException {
+
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ OnapCommandUtils.loadSchema(cmd, "fdsfds.yaml", true, true);
}
@Test(expected = OnapCommandInvalidSchema.class)
- public void invalidateTest2() throws OnapCommandInvalidSchema {
- new SchemaValidator(new File("fdsfds"));
+ public void invalidateTest2() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ OnapCommandUtils.loadSchema(cmd, "fdsfds", true, true);
}
@Test(expected = OnapCommandInvalidSchema.class)
- public void invalidateTest4() throws OnapCommandInvalidSchema {
- new SchemaValidator(
- new File(ValidateSchemaTest.class.getClassLoader().getResource("onap.properties").getFile()));
+ public void invalidateTest4() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ OnapCommandUtils.loadSchema(cmd,
+ ValidateSchemaTest.class.getClassLoader().getResource("onap.properties").getFile(),
+ true, true);
}
@Test(expected = OnapCommandInvalidSchema.class)
- public void invalidateTest5() throws OnapCommandInvalidSchema {
- new SchemaValidator(new File(
- ValidateSchemaTest.class.getClassLoader().getResource("schema-invalid-file-null.yaml").getFile()));
+ public void invalidateTest5() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ OnapCommandUtils.loadSchema(cmd, "schema-invalid-file-null.yaml", true, true);
}
@Test
- public void invalidate1Test5() throws OnapCommandInvalidSchema {
- new SchemaValidator("schema-validate-pass.yaml");
+ public void invalidate1Test5() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ OnapCommandUtils.loadSchema(cmd, "schema-validate-pass.yaml", true, true);
+
}
- @Test(expected = ScannerException.class)
- public void invalidateTest3() throws OnapCommandInvalidSchema {
- new SchemaValidator(
- new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-invalid-file.yaml").getFile()));
+ @Test(expected = OnapCommandInvalidSchema.class)
+ public void invalidateTest3() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ OnapCommandUtils.loadSchema(cmd, "schema-invalid-file.yaml", true, true);
}
@Test
- public void validateTest() throws OnapCommandInvalidSchema {
- new SchemaValidator(
- new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-http.yaml").getFile()))
- .validate();
-
- new SchemaValidator(
- new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-basic.yaml").getFile()))
- .validate();
- new SchemaValidator(new File(ValidateSchemaTest.class.getClassLoader()
- .getResource("schema-validate-invalidschematype.yaml").getFile())).validate();
- new SchemaValidator(
- new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-invalid.yaml").getFile()))
- .validate();
- new SchemaValidator(
- new File(ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-pass.yaml").getFile()))
- .validate();
+ public void validateTest() throws OnapCommandException {
- }
+ OnapCommand cmd1 = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ List<String> errorList1 = OnapCommandUtils.loadSchema(cmd1, "schema-validate-http.yaml", true, true);
+ assertTrue(errorList1.size() > 0);
+
+ OnapCommand cmd2 = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ List<String> errorList2 = OnapCommandUtils.loadSchema(cmd2, "schema-validate-basic.yaml", true, true);
+ assertTrue(errorList2.size() > 0);
+
+ OnapCommand cmd3 = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ List<String> errorList3 = OnapCommandUtils.loadSchema(cmd2, "schema-validate-invalidschematype.yaml", true, true);
+ assertTrue(errorList3.size() > 0);
+
+ OnapCommand cmd4 = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ List<String> errorList4 = OnapCommandUtils.loadSchema(cmd2, "schema-validate-invalid.yaml", true, true);
+
+ OnapHttpCommand onapHttpCommand = new OnapHttpCommand();
+ errorList4.addAll(OnapCommandUtils.loadHTTPSchemaSection(onapHttpCommand,
+ "schema-validate-invalid.yaml", true));
+ assertTrue(errorList4.size() > 0);
+
+ OnapCommand cmd5 = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ List<String> errorList5 = OnapCommandUtils.loadSchema(cmd5, "schema-validate-pass.yaml", true, true);
+ assertTrue(errorList5.size() == 0);
- @Test
- public void schemaValidateInterfaceTest() throws OnapCommandInvalidSchema {
- SchemaValidate.attributeNameExist("name", "section");
- SchemaValidate.emptyValue("section", "attribute");
- SchemaValidate.defaultYamlSchema("section");
- SchemaValidate.emptySection("section");
- SchemaValidate.invalidAttributeScope("name", new ArrayList<String>());
- SchemaValidate.invalidAttrType("name", "section", new ArrayList<String>());
- SchemaValidate.invalidBooleanValueMessage("section", "attribute", "value");
- SchemaValidate.invalidRequestParam("subSection", "attribute");
- SchemaValidate.invalidSections(new HashSet<String>(), new ArrayList<String>(), new ArrayList<String>());
- SchemaValidate.attributeScopeEmpty("fsdf");
- SchemaValidate.invalidType("section", "attribute", new ArrayList<String>());
- SchemaValidate.longOptionExist("name");
- SchemaValidate.shortOptionExist("name");
- SchemaValidate.optionExist("option", "attrValue", "name");
- SchemaValidate.optionDefaultExist("option", "attrValue", "name", new HashSet<String>());
- SchemaValidate.nameExist("name", "section");
- SchemaValidate.mandatoryAttrEmpty("param", "section");
}
}
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 d01e2e77..064576d8 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
@@ -69,7 +69,7 @@ import java.util.Set;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OnapCommandUtilsTest {
- @Test(expected = OnapCommandSchemaNotFound.class)
+ @Test(expected = OnapCommandInvalidSchema.class)
public void onapCommandUtilsInputStreamNullTest() throws OnapCommandException {
OnapCommandUtils.validateSchemaVersion("sample-test1-schema-http1.yaml", "1.0");
}
@@ -144,32 +144,32 @@ public class OnapCommandUtilsTest {
@Test
public void loadOnapCommandSchemaWithOutDefaultTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", false);
+ OnapCommandUtils.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();
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-name.yaml", false);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-name.yaml", false, false);
}
@Test(expected = OnapCommandParameterOptionConflict.class)
public void loadOnapCommandSchemaWithDuplicateShortOptionTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-shortoption.yaml", false);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-shortoption.yaml", false, false);
}
@Test(expected = OnapCommandParameterOptionConflict.class)
public void loadOnapCommandSchemaWithDuplicateLongOptionTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-longoption.yaml", false);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-longoption.yaml", false, false);
}
@Test
public void loadOnapCommandSchemaWithDefaultTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", true, false);
assertTrue("sample-test".equals(cmd.getName()) && cmd.getParameters().size() > 9);
for (OnapCommandParameter com : cmd.getParameters()) {
@@ -185,7 +185,7 @@ public class OnapCommandUtilsTest {
@Test
public void loadOnapCommandSchemaAuthRequiredTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema-auth-required.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-schema-auth-required.yaml", true, false);
assertTrue("sample-test".equals(cmd.getName()));
Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters());
@@ -219,7 +219,7 @@ public class OnapCommandUtilsTest {
OnapHttpCommand cmd = new OnapHttpCommandSample();
cmd.setName("sample-test-http");
try {
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml");
+ OnapCommandUtils.loadHTTPSchemaSection(cmd, "sample-test-schema.yaml", false);
} catch (OnapCommandParameterNameConflict | OnapCommandParameterOptionConflict
| OnapCommandInvalidParameterType | OnapCommandInvalidPrintDirection
| OnapCommandInvalidResultAttributeScope | OnapCommandSchemaNotFound | OnapCommandInvalidSchema
@@ -233,7 +233,7 @@ public class OnapCommandUtilsTest {
OnapHttpCommand cmd = new OnapHttpCommandSample();
cmd.setName("sample-create-http");
try {
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema-http.yaml");
+ OnapCommandUtils.loadHTTPSchemaSection(cmd, "sample-test-schema-http.yaml", true);
assertTrue(cmd.getSuccessStatusCodes().size() == 2);
} catch (OnapCommandParameterNameConflict | OnapCommandParameterOptionConflict
| OnapCommandInvalidParameterType | OnapCommandInvalidPrintDirection
@@ -246,7 +246,7 @@ public class OnapCommandUtilsTest {
@Test
public void helpCommandTest() throws IOException, OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", true, false);
String actualResult = OnapCommandUtils.help(cmd);
@@ -392,7 +392,7 @@ public class OnapCommandUtilsTest {
public void zendExceptionTest2() throws OnapCommandException {
mockExternalResources();
- OnapCommandUtils.loadSchema(new OnapHttpCommandSample(), "schemaName", false);
+ OnapCommandUtils.loadSchema(new OnapHttpCommandSample(), "schemaName", false, false);
}
@Test(expected = OnapCommandException.class)
@@ -428,7 +428,7 @@ public class OnapCommandUtilsTest {
mockPrintMethodException();
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", true);
+ OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", true, false);
OnapCommandUtils.help(cmd);