summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java
diff options
context:
space:
mode:
authorsiddharth0905 <siddharth.singh4@amdocs.com>2018-08-21 17:55:30 +0530
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-09-13 11:00:08 +0000
commitc58f445fcef56a6440f3b21d54b390700623c48c (patch)
tree9540ba4f1c7c2ec92c07ce2abcd04d02e06033cc /openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java
parent7678396a1df3122d80d838c958d857f03e2aefbb (diff)
Test coverage
Increase test coverage Change-Id: I43e3149d0d4b07dc8e260f3d5fac025197882f3a Issue-ID: SDC-1673 Signed-off-by: siddharth0905 <siddharth.singh4@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java84
1 files changed, 45 insertions, 39 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java
index 9b21f632cc..e57cdc2a80 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -28,50 +28,56 @@ import org.testng.annotations.Test;
public class JsonSchemaDataGeneratorTest {
- public static final String SCHEMA_WITHOUT_DEFAULTS =
- readFromFile("jsonUtil/json_schema/aSchema.json");
+ private static final String SCHEMA_WITHOUT_DEFAULTS =
+ readFromFile("jsonUtil/json_schema/aSchema.json");
- public static final String SCHEMA_WITH_REFS_AND_DEFAULTS =
- readFromFile("jsonUtil/json_schema/schemaWithRefsAndDefaults.json");
+ private static final String SCHEMA_WITH_REFS_AND_DEFAULTS =
+ readFromFile("jsonUtil/json_schema/schemaWithRefsAndDefaults.json");
- public static final String SCHEMA_WITH_INVALID_DEFAULT =
- readFromFile("jsonUtil/json_schema/schemaWithInvalidDefault.json");
+ private static final String SCHEMA_WITH_INVALID_DEFAULT =
+ readFromFile("jsonUtil/json_schema/schemaWithInvalidDefault.json");
- public static final String SCHEMA_NIC =
- readFromFile("jsonUtil/json_schema/nicSchema.json");
+ private static final String SCHEMA_NIC =
+ readFromFile("jsonUtil/json_schema/nicSchema.json");
- @Test
- public void testSchemaWithoutDefaults() {
- testGenerate(SCHEMA_WITHOUT_DEFAULTS, new JSONObject());
- }
+ @Test
+ public void testSchemaWithoutDefaults() {
+ testGenerate(SCHEMA_WITHOUT_DEFAULTS, new JSONObject());
+ }
- @Test
- public void testSchemaWithRefsAndDefaults() {
- testGenerate(SCHEMA_WITH_REFS_AND_DEFAULTS,
- new JSONObject(
- "{\"cityOfBirth\":\"Tel Aviv\",\"address\":{\"city\":\"Tel Aviv\"},\"phoneNumber\":[{\"code\":1,\"location\":\"Home\"},{\"code\":2,\"location\":\"Office\"}]}"));
- }
+ @Test
+ public void testSchemaWithRefsAndDefaults() {
+ testGenerate(SCHEMA_WITH_REFS_AND_DEFAULTS,
+ new JSONObject("{\"cityOfBirth\":\"Tel Aviv\",\"address\":{\"city\":\"Tel Aviv\"},"
+ + "\"houseNumber\":1,\"pincode\":111111,"
+ + "\"phoneNumber\":[{\"code\":1,\"location\":\"Home\"},{\"code\":2,\"location\":\"Office\"}]}"));
+ }
- @Test(expectedExceptions = JSONException.class)
- public void testSchemaWithInvalidDefault() {
- testGenerate(SCHEMA_WITH_INVALID_DEFAULT, null);
- }
+ @Test(expectedExceptions = JSONException.class)
+ public void testSchemaWithInvalidDefault() {
+ testGenerate(SCHEMA_WITH_INVALID_DEFAULT, null);
+ }
- @Test
- public void testNicQuestionnaireSchema() {
- testGenerate(SCHEMA_NIC,
- new JSONObject("{\"ipConfiguration\":{\"ipv4Required\":true,\"ipv6Required\":false}}"));
- }
+ @Test
+ public void testNicQuestionnaireSchema() {
+ testGenerate(SCHEMA_NIC,
+ new JSONObject("{\"ipConfiguration\":{\"ipv4Required\":true,\"ipv6Required\":false}}"));
+ }
- private void testGenerate(String schema, JSONObject expectedData) {
- JsonSchemaDataGenerator jsonSchemaDataGenerator = new JsonSchemaDataGenerator(schema);
- String data = jsonSchemaDataGenerator.generateData();
- System.out.println(data);
- JSONObject dataJson = new JSONObject(data);
- Assert.assertTrue(expectedData.similar(dataJson));
- }
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testConstructorException() {
+ Assert.assertNull(new JsonSchemaDataGenerator(null));
+ }
- private static String readFromFile(String filename) {
- return FileUtils.readViaInputStream(filename, stream -> new String(FileUtils.toByteArray(stream)));
- }
+ private void testGenerate(String schema, JSONObject expectedData) {
+ JsonSchemaDataGenerator jsonSchemaDataGenerator = new JsonSchemaDataGenerator(schema);
+ jsonSchemaDataGenerator.setIncludeDefaults(true);
+ String data = jsonSchemaDataGenerator.generateData();
+ JSONObject dataJson = new JSONObject(data);
+ Assert.assertTrue(expectedData.similar(dataJson));
+ }
+
+ private static String readFromFile(String filename) {
+ return FileUtils.readViaInputStream(filename, stream -> new String(FileUtils.toByteArray(stream)));
+ }
}