summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-02-19 12:35:04 +0200
committerMichael Lando <ml636r@att.com>2017-02-19 12:35:04 +0200
commitf5f13c4f6b6fe3b4d98e349dfd7db59339803436 (patch)
tree72caffc93fab394ffa3b761505775331f1c559b9 /openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test
parent451a3400b76511393c62a444f588a4ed15f4a549 (diff)
push addional code
Change-Id: Ia427bb3460cda3a896f8faced2de69eaf3807b74 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java50
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonUtilTest.java40
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json/a.json12
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json/a_invalid.json13
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/aSchema.json60
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/nicSchema.json118
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/schemaWithInvalidDefault.json67
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/schemaWithRefsAndDefaults.json71
8 files changed, 431 insertions, 0 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
new file mode 100644
index 0000000000..83c87737d2
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonSchemaDataGeneratorTest.java
@@ -0,0 +1,50 @@
+package org.openecomp.core.utilities.json;
+
+import org.openecomp.core.utilities.file.FileUtils;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class JsonSchemaDataGeneratorTest {
+
+ public static final String SCHEMA_WITHOUT_DEFAULTS = new String(
+ FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json_schema/aSchema.json")));
+ public static final String SCHEMA_WITH_REFS_AND_DEFAULTS = new String(FileUtils.toByteArray(
+ FileUtils.getFileInputStream("jsonUtil/json_schema/schemaWithRefsAndDefaults.json")));
+ public static final String SCHEMA_WITH_INVALID_DEFAULT = new String(FileUtils.toByteArray(
+ FileUtils.getFileInputStream("jsonUtil/json_schema/schemaWithInvalidDefault.json")));
+ public static final String SCHEMA_NIC = new String(
+ FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json_schema/nicSchema.json")));
+
+ @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(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}}"));
+ }
+
+ 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));
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonUtilTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonUtilTest.java
new file mode 100644
index 0000000000..e232f72f38
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/json/JsonUtilTest.java
@@ -0,0 +1,40 @@
+package org.openecomp.core.utilities.json;
+
+
+import org.openecomp.core.utilities.file.FileUtils;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+public class JsonUtilTest {
+
+ @Test
+ public void testValidJsonValidate() throws Exception {
+ String json =
+ new String(FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json/a.json")));
+ String jsonSchema = new String(
+ FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json_schema/aSchema.json")));
+
+ List<String> validationErrors = JsonUtil.validate(json, jsonSchema);
+ Assert.assertNull(validationErrors);
+ }
+
+ @Test
+ public void testInValidJsonValidate() throws Exception {
+ String json = new String(
+ FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json/a_invalid.json")));
+ String jsonSchema = new String(
+ FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json_schema/aSchema.json")));
+
+ List<String> validationErrors = JsonUtil.validate(json, jsonSchema);
+ Assert.assertNotNull(validationErrors);
+ Assert.assertEquals(validationErrors.size(), 3);
+ Assert.assertEquals(validationErrors.get(0),
+ "#/cityOfBirth: Paris is not a valid value. Possible values: New York,Tel Aviv,London");
+ Assert.assertEquals(validationErrors.get(1),
+ "#/address: {\"streetAddress\":\"21 2nd Street\",\"city\":\"Paris\"} is not a valid value. {\"streetAddress\":\"21 2nd Street\",\"city\":\"New York\"} is the only possible value for this field");
+ Assert.assertEquals(validationErrors.get(2),
+ "#/phoneNumber/0/code: expected type: Number, found: String");
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json/a.json b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json/a.json
new file mode 100644
index 0000000000..a3320d5fc7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json/a.json
@@ -0,0 +1,12 @@
+{
+ "address": {
+ "streetAddress": "21 2nd Street",
+ "city": "New York"
+ },
+ "phoneNumber": [
+ {
+ "location": "home",
+ "code": 44
+ }
+ ]
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json/a_invalid.json b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json/a_invalid.json
new file mode 100644
index 0000000000..8a02522ea9
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json/a_invalid.json
@@ -0,0 +1,13 @@
+{
+ "address": {
+ "streetAddress": "21 2nd Street",
+ "city": "Paris"
+ },
+ "phoneNumber": [
+ {
+ "location": "home",
+ "code": "test"
+ }
+ ],
+ "cityOfBirth": "Paris"
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/aSchema.json b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/aSchema.json
new file mode 100644
index 0000000000..a77e38df87
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/aSchema.json
@@ -0,0 +1,60 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "type": "object",
+ "definitions": {
+ "city": {
+ "type": "string",
+ "enum": [
+ "Tel Aviv",
+ "New York",
+ "London"
+ ]
+ }
+ },
+ "properties": {
+ "address": {
+ "type": "object",
+ "properties": {
+ "streetAddress": {
+ "type": "string"
+ },
+ "city": {
+ "$ref": "#/definitions/city"
+ }
+ },
+ "enum": [
+ {
+ "streetAddress": "21 2nd Street",
+ "city": "New York"
+ }
+ ],
+ "required": [
+ "streetAddress",
+ "city"
+ ]
+ },
+ "phoneNumber": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type": "string"
+ },
+ "code": {
+ "type": "integer"
+ }
+ },
+ "required": [
+ "location",
+ "code"
+ ]
+ }
+ },
+ "cityOfBirth" : { "$ref" : "#/definitions/city"}
+ },
+ "required": [
+ "address",
+ "phoneNumber"
+ ]
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/nicSchema.json b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/nicSchema.json
new file mode 100644
index 0000000000..d96de6aa31
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/nicSchema.json
@@ -0,0 +1,118 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "type": "object",
+ "properties": {
+ "protocols": {
+ "type": "object",
+ "properties": {
+ "protocols": {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "enum": [
+ "TCP",
+ "UDP",
+ "SCTP",
+ "IPsec"
+ ]
+ },
+ "minItems": 1
+ },
+ "protocolWithHighestTrafficProfile": {
+ "$ref": "#/properties/protocols/properties/protocols/items"
+ }
+ },
+ "additionalProperties": false
+ },
+ "ipConfiguration": {
+ "type": "object",
+ "properties": {
+ "ipv4Required": {
+ "type": "boolean",
+ "default": true
+ },
+ "ipv6Required": {
+ "type": "boolean",
+ "default": false
+ }
+ },
+ "additionalProperties": false
+ },
+ "network": {
+ "type": "object",
+ "properties": {
+ "networkDescription": {
+ "type": "string",
+ "pattern": "[A-Za-z]+",
+ "maxLength": 300
+ }
+ },
+ "additionalProperties": false
+ },
+ "sizing": {
+ "type": "object",
+ "definitions": {
+ "peakAndAvg": {
+ "type": "object",
+ "properties": {
+ "peak": {
+ "type": "number"
+ },
+ "avg": {
+ "type": "number"
+ }
+ },
+ "additionalProperties": false
+ },
+ "packetsAndBytes": {
+ "type": "object",
+ "properties": {
+ "packets": {
+ "$ref": "#/properties/sizing/definitions/peakAndAvg"
+ },
+ "bytes": {
+ "$ref": "#/properties/sizing/definitions/peakAndAvg"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "properties": {
+ "describeQualityOfService": {
+ "type": "string"
+ },
+ "inflowTrafficPerSecond": {
+ "$ref": "#/properties/sizing/definitions/packetsAndBytes"
+ },
+ "outflowTrafficPerSecond": {
+ "$ref": "#/properties/sizing/definitions/packetsAndBytes"
+ },
+ "flowLength": {
+ "$ref": "#/properties/sizing/definitions/packetsAndBytes"
+ },
+ "acceptableJitter": {
+ "type": "object",
+ "properties": {
+ "mean": {
+ "type": "number"
+ },
+ "max": {
+ "type": "number"
+ },
+ "variable": {
+ "type": "number"
+ }
+ },
+ "additionalProperties": false
+ },
+ "acceptablePacketLoss": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 100
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/schemaWithInvalidDefault.json b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/schemaWithInvalidDefault.json
new file mode 100644
index 0000000000..100d17f48e
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/schemaWithInvalidDefault.json
@@ -0,0 +1,67 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "definitions": {
+ "city": {
+ "type": "string",
+ "enum": [
+ "Tel Aviv",
+ "New York",
+ "London"
+ ],
+ "default": "Tel Aviv"
+ }
+ },
+ "type": "object",
+ "properties": {
+ "address": {
+ "type": "object",
+ "properties": {
+ "streetAddress": {
+ "type": "string",
+ "default" : 7
+ },
+ "city": {
+ "$ref": "#/definitions/city"
+ }
+ },
+ "required": [
+ "streetAddress",
+ "city"
+ ]
+ },
+ "phoneNumber": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type": "string"
+ },
+ "code": {
+ "type": "integer",
+ "default": 777
+ }
+ },
+ "required": [
+ "location",
+ "code"
+ ]
+ },
+ "default": [
+ {
+ "location": "Home",
+ "code": 1
+ },
+ {
+ "location": "Office",
+ "code": 2
+ }
+ ]
+ },
+ "cityOfBirth" : { "$ref" : "#/definitions/city"}
+ },
+ "required": [
+ "address",
+ "phoneNumber"
+ ]
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/schemaWithRefsAndDefaults.json b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/schemaWithRefsAndDefaults.json
new file mode 100644
index 0000000000..de027b9d56
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/resources/jsonUtil/json_schema/schemaWithRefsAndDefaults.json
@@ -0,0 +1,71 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "definitions": {
+ "city": {
+ "type": "string",
+ "enum": [
+ "Tel Aviv",
+ "New York",
+ "London"
+ ],
+ "default": "Tel Aviv"
+ },
+ "zipCode" : {
+ "type" : "integer"
+ }
+ },
+ "type": "object",
+ "properties": {
+ "address": {
+ "type": "object",
+ "properties": {
+ "streetAddress": {
+ "type": "string"
+ },
+ "city": {
+ "$ref": "#/definitions/city"
+ },
+ "cityZipCode" : {"$ref" : "#/definitions/zipCode"}
+ },
+ "required": [
+ "streetAddress",
+ "city"
+ ]
+ },
+ "phoneNumber": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type": "string"
+ },
+ "locationZipCode" : {"$ref" : "#/definitions/zipCode"},
+ "code": {
+ "type": "integer",
+ "default": 777
+ }
+ },
+ "required": [
+ "location",
+ "code"
+ ]
+ },
+ "default": [
+ {
+ "location": "Home",
+ "code": 1
+ },
+ {
+ "location": "Office",
+ "code": 2
+ }
+ ]
+ },
+ "cityOfBirth" : { "$ref" : "#/definitions/city"}
+ },
+ "required": [
+ "address",
+ "phoneNumber"
+ ]
+} \ No newline at end of file