-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
110 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 40 additions & 6 deletions
46
src/test/java/com/techatpark/sjson/schema/JsonSchemaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,50 @@ | ||
package com.techatpark.sjson.schema; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.networknt.schema.JsonSchema; | ||
import com.networknt.schema.JsonSchemaFactory; | ||
import com.networknt.schema.SpecVersion; | ||
import com.networknt.schema.ValidationMessage; | ||
import com.techatpark.sjson.util.TestUtil; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class JsonSchemaTest { | ||
|
||
@Test | ||
void read() { | ||
public final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
@ParameterizedTest | ||
@MethodSource("jsonSchemaFilesProvider") | ||
@Disabled | ||
void read(final File schemaFile) throws IOException { | ||
File dataFile = new File(new File(schemaFile.getParentFile().getParentFile(),"samples") | ||
,schemaFile.getName()); | ||
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V202012); | ||
JsonSchema jsonSchema = factory.getSchema(new FileInputStream(schemaFile)); | ||
JsonNode jsonNode = mapper.readTree(new FileReader(dataFile)); | ||
Set<ValidationMessage> expectedErrors = jsonSchema.validate(jsonNode); | ||
Set<ValidationMessage> actualErrors = jsonSchema.validate(jsonNode); | ||
Assertions.assertEquals(expectedErrors.size(), actualErrors.size()); | ||
} | ||
|
||
@Test | ||
void jsonText() { | ||
/** | ||
* Provides paths to JSON files for parameterized tests. | ||
* | ||
* @return Stream of paths to JSON files | ||
* @throws IOException if there is an issue listing files | ||
*/ | ||
private static Set<File> jsonSchemaFilesProvider() throws IOException { | ||
return TestUtil.getJSONSchemaFiles(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"id": 1, | ||
"name": "Lampshade", | ||
"price": 6 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,22 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/-/schema", | ||
"$id": "https://example.com/product.schema.json", | ||
"title": "Product", | ||
"description": "A product from Acme's catalog", | ||
"type": "object", | ||
"properties": { | ||
"productId": { | ||
"description": "The unique identifier for a product", | ||
"type": "integer" | ||
}, | ||
"productName": { | ||
"description": "Name of the product", | ||
"type": "string" | ||
}, | ||
"price": { | ||
"description": "The price of the product", | ||
"type": "number", | ||
"exclusiveMinimum": | ||
}, | ||
"tags": { | ||
"description": "Tags for the product", | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"minItems":, | ||
"uniqueItems": true | ||
}, | ||
"dimensions": { | ||
"type": "object", | ||
"properties": { | ||
"length": { | ||
"type": "number" | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "Product", | ||
"description": "A product from the catalog", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"description": "The unique identifier for a product", | ||
"type": "integer" | ||
}, | ||
"width": { | ||
"type": "number" | ||
"name": { | ||
"description": "Name of the product", | ||
"type": "string" | ||
}, | ||
"height": { | ||
"type": "number" | ||
"price": { | ||
"type": "number", | ||
"minimum": 0, | ||
"exclusiveMinimum": true | ||
} | ||
}, | ||
"required": [ | ||
"length", | ||
"width", | ||
"height" | ||
] | ||
}, | ||
"warehouseLocation": { | ||
"description": "Coordinates of the warehouse where the product is located.", | ||
"$ref": "https://example.com/geographical-location.schema.json" | ||
} | ||
}, | ||
"required": [ | ||
"productId", | ||
"productName", | ||
"price" | ||
] | ||
"required": ["id", "name", "price"] | ||
} |
This file was deleted.
Oops, something went wrong.