1 package org.openecomp.core.utilities.json;
4 import org.openecomp.core.utilities.file.FileUtils;
5 import org.testng.Assert;
6 import org.testng.annotations.Test;
10 public class JsonUtilTest {
13 public void testValidJsonValidate() throws Exception {
15 new String(FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json/a.json")));
16 String jsonSchema = new String(
17 FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json_schema/aSchema.json")));
19 List<String> validationErrors = JsonUtil.validate(json, jsonSchema);
20 Assert.assertNull(validationErrors);
24 public void testInValidJsonValidate() throws Exception {
25 String json = new String(
26 FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json/a_invalid.json")));
27 String jsonSchema = new String(
28 FileUtils.toByteArray(FileUtils.getFileInputStream("jsonUtil/json_schema/aSchema.json")));
30 List<String> validationErrors = JsonUtil.validate(json, jsonSchema);
31 Assert.assertNotNull(validationErrors);
32 Assert.assertEquals(validationErrors.size(), 3);
33 Assert.assertEquals(validationErrors.get(0),
34 "#/cityOfBirth: Paris is not a valid value. Possible values: New York,Tel Aviv,London");
35 Assert.assertEquals(validationErrors.get(1),
36 "#/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");
37 Assert.assertEquals(validationErrors.get(2),
38 "#/phoneNumber/0/code: expected type: Number, found: String");