2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.dcae.vestest;
23 import static java.nio.file.Files.readAllBytes;
24 import static junit.framework.Assert.assertEquals;
26 import com.google.gson.JsonObject;
27 import com.google.gson.JsonParser;
28 import java.io.IOException;
29 import java.nio.file.Paths;
30 import org.junit.Test;
31 import org.onap.dcae.SchemaValidator;
33 public class TestJsonSchemaValidation {
36 public void shouldValidEventPassSchema_27_2() throws IOException {
38 SchemaValidator.validateAgainstSchema(
39 readJSONFromFile("src/test/resources/ves4_valid.json").toString(),
40 readJSONFromFile("etc/CommonEventFormat_27.2.json").toString());
41 assertEquals(result, "true");
45 public void shouldInvalidEventDoesNotPassSchema_27_2() throws IOException {
47 SchemaValidator.validateAgainstSchema(
48 readJSONFromFile("src/test/resources/ves4_invalid.json").toString(),
49 readJSONFromFile("etc/CommonEventFormat_27.2.json").toString());
50 assertEquals(result, "false");
54 public void shouldValidEventPassSchema_30_0_1() throws IOException {
56 SchemaValidator.validateAgainstSchema(
57 readJSONFromFile("src/test/resources/ves7_valid.json").toString(),
58 readJSONFromFile("etc/CommonEventFormat_30.0.1.json").toString());
59 assertEquals(result, "true");
63 public void shouldValidEventBatchPassSchema_30_0_1() throws IOException {
65 SchemaValidator.validateAgainstSchema(
66 readJSONFromFile("src/test/resources/ves7_batch_valid.json").toString(),
67 readJSONFromFile("etc/CommonEventFormat_30.0.1.json").toString());
68 assertEquals(result, "true");
72 public void shouldInvalidEventDoesNotPassSchema_30_0_1() throws IOException {
74 SchemaValidator.validateAgainstSchema(
75 readJSONFromFile("src/test/resources/ves7_invalid.json").toString(),
76 readJSONFromFile("etc/CommonEventFormat_30.0.1.json").toString());
77 assertEquals(result, "false");
80 private static JsonObject readJSONFromFile(String path) throws IOException {
81 return (JsonObject) new JsonParser().parse(new String(readAllBytes(Paths.get(path))));