|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.networknt.schema; |
| 17 | + |
| 18 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 19 | + |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | + |
| 22 | +class NotValidatorTest { |
| 23 | + @Test |
| 24 | + void walkValidationWithNullNodeShouldNotValidate() { |
| 25 | + String schemaContents = "{\r\n" |
| 26 | + + " \"type\": \"object\",\r\n" |
| 27 | + + " \"properties\": {\r\n" |
| 28 | + + " \"prop1\": {\r\n" |
| 29 | + + " \"not\": {\r\n" |
| 30 | + + " \"type\": \"string\"\r\n" |
| 31 | + + " }\r\n" |
| 32 | + + " }\r\n" |
| 33 | + + " },\r\n" |
| 34 | + + " \"additionalProperties\": false\r\n" |
| 35 | + + "}"; |
| 36 | + |
| 37 | + String jsonContents = "{}"; |
| 38 | + |
| 39 | + JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7); |
| 40 | + JsonSchema schema = factory.getSchema(schemaContents); |
| 41 | + ValidationResult result = schema.walk(jsonContents, InputFormat.JSON, true); |
| 42 | + assertEquals(true, result.getValidationMessages().isEmpty()); |
| 43 | + } |
| 44 | +} |
0 commit comments