Package uk.co.o2.json.sample

Source Code of uk.co.o2.json.sample.SampleSchemaTest

package uk.co.o2.json.sample;


import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import uk.co.o2.json.schema.ErrorMessage;
import uk.co.o2.json.schema.JsonSchema;
import uk.co.o2.json.schema.SchemaPassThroughCache;

import java.util.List;

import static org.junit.Assert.assertTrue;

public class SampleSchemaTest {

    private JsonFactory jsonFactory = new JsonFactory(new ObjectMapper());
    private SchemaPassThroughCache schemaFactory = new SchemaPassThroughCache(jsonFactory);

    @Test
    public void validateSchema_shouldWorkFromADifferentPackage() throws Exception {
        JsonSchema schema = schemaFactory.getSchema(getClass().getClassLoader().getResource("sample-json-schema.json"));
        JsonNode json = jsonFactory.createJsonParser(getClass().getClassLoader().getResource("valid-json-document.json")).readValueAsTree();

        List<ErrorMessage> errors = schema.validate(json);

        assertTrue(errors.isEmpty());
    }

}
TOP

Related Classes of uk.co.o2.json.sample.SampleSchemaTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.