• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020, 2021 Oracle and/or its affiliates.
3  */
4 package com.networknt.schema;
5 
6 import org.junit.jupiter.api.Assertions;
7 import org.junit.jupiter.api.Test;
8 import org.junit.jupiter.api.function.Executable;
9 
10 public class Issue406Test {
11     protected static final String INVALID_$REF_SCHEMA = "{\"$ref\":\"urn:unresolved\"}";
12     protected static final String CIRCULAR_$REF_SCHEMA = "{\"$ref\":\"#/nestedSchema\","
13             + "\"nestedSchema\":{\"$ref\":\"#/nestedSchema\"}}";
14 
15     @Test
testPreloadingNotHappening()16     public void testPreloadingNotHappening() {
17         final JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
18         final JsonSchema schema = factory.getSchema(INVALID_$REF_SCHEMA);
19         // not breaking - pass
20         Assertions.assertNotNull(schema);
21     }
22 
23     @Test
testPreloadingHappening()24     public void testPreloadingHappening() {
25         final JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
26         final JsonSchema schema = factory.getSchema(INVALID_$REF_SCHEMA);
27         Assertions.assertThrows(JsonSchemaException.class,
28                             new Executable() {
29                                 @Override
30                                 public void execute() {
31                                     schema.initializeValidators();
32                                 }
33                             },
34                             "#/$ref: Reference urn:unresolved cannot be resolved");
35     }
36 
37     @Test
testPreloadingHappeningForCircularDependency()38     public void testPreloadingHappeningForCircularDependency() {
39         final JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
40         final JsonSchema schema = factory.getSchema(CIRCULAR_$REF_SCHEMA);
41         schema.initializeValidators();
42     }
43 }
44