Skip to content

Commit

Permalink
Merge pull request #244 from msattel/feature/221
Browse files Browse the repository at this point in the history
Feature/221
  • Loading branch information
stevehu authored Feb 12, 2020
2 parents 9c1ef88 + cdfc710 commit 14794c6
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 36 deletions.
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</repository>
</distributionManagement>
<properties>
<java.version>1.8</java.version>
<java.version>1.6</java.version>
<java.testversion>1.8</java.testversion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.jackson>2.10.0</version.jackson>
Expand Down Expand Up @@ -192,6 +192,8 @@
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<testSource>${java.testversion}</testSource>
<testTarget>${java.testversion}</testTarget>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -291,7 +293,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${version.jacoco}</version>
<version>0.7.9</version>
<executions>
<!-- The Executions for merging -->
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ExclusiveMinimumValidator extends BaseJsonValidator implements Json
*/
private final ThresholdMixin typedMinimum;

public ExclusiveMinimumValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) {
public ExclusiveMinimumValidator(String schemaPath, final JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) {
super(schemaPath, schemaNode, parentSchema, ValidatorTypeCode.EXCLUSIVE_MINIMUM, validationContext);

if (!schemaNode.isNumber()) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/networknt/schema/JsonMetaSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static class V4 {
private static String URI = "http://json-schema.org/draft-04/schema#";
private static final String ID = "id";

public static final List<Format> BUILTIN_FORMATS = new ArrayList<>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
public static final List<Format> BUILTIN_FORMATS = new ArrayList<Format>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
static {
// add version specific formats here.
//BUILTIN_FORMATS.add(pattern("phone", "^\\+(?:[0-9] ?){6,14}[0-9]$"));
Expand Down Expand Up @@ -98,7 +98,7 @@ private static class V6 {
// Draft 6 uses "$id"
private static final String ID = "$id";

public static final List<Format> BUILTIN_FORMATS = new ArrayList<>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
public static final List<Format> BUILTIN_FORMATS = new ArrayList<Format>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
static {
// add version specific formats here.
//BUILTIN_FORMATS.add(pattern("phone", "^\\+(?:[0-9] ?){6,14}[0-9]$"));
Expand Down Expand Up @@ -126,7 +126,7 @@ private static class V7 {
private static String URI = "http://json-schema.org/draft-07/schema#";
private static final String ID = "$id";

public static final List<Format> BUILTIN_FORMATS = new ArrayList<>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
public static final List<Format> BUILTIN_FORMATS = new ArrayList<Format>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
static {
// add version specific formats here.
//BUILTIN_FORMATS.add(pattern("phone", "^\\+(?:[0-9] ?){6,14}[0-9]$"));
Expand Down Expand Up @@ -154,7 +154,7 @@ private static class V201909 {
private static String URI = "https://json-schema.org/draft/2019-09/schema";
private static final String ID = "$id";

public static final List<Format> BUILTIN_FORMATS = new ArrayList<>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
public static final List<Format> BUILTIN_FORMATS = new ArrayList<Format>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
static {
// add version specific formats here.
//BUILTIN_FORMATS.add(pattern("phone", "^\\+(?:[0-9] ?){6,14}[0-9]$"));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/JsonSchemaFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public JsonSchema getSchema(final URI schemaUri, final SchemaValidatorsConfig co

final URI mappedUri;
try {
mappedUri = this.uriFactory.create(map.getOrDefault(schemaUri.toString(), schemaUri.toString()));
mappedUri = this.uriFactory.create(map.get(schemaUri.toString())!=null ? map.get(schemaUri.toString()) : schemaUri.toString());
} catch (IllegalArgumentException e) {
logger.error("Failed to create URI.", e);
throw new JsonSchemaException(e);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/MinimumValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MinimumValidator extends BaseJsonValidator implements JsonValidator
*/
private final ThresholdMixin typedMinimum;

public MinimumValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) {
public MinimumValidator(String schemaPath, final JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) {
super(schemaPath, schemaNode, parentSchema, ValidatorTypeCode.MINIMUM, validationContext);

if (!schemaNode.isNumber()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/ValidationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ValidationContext {
private final JsonMetaSchema metaSchema;
private final JsonSchemaFactory jsonSchemaFactory;
private SchemaValidatorsConfig config;
private final Map<String, JsonSchemaRef> refParsingInProgress = new HashMap<>();
private final Map<String, JsonSchemaRef> refParsingInProgress = new HashMap<String, JsonSchemaRef>();

public ValidationContext(URIFactory uriFactory, JsonMetaSchema metaSchema, JsonSchemaFactory jsonSchemaFactory, SchemaValidatorsConfig config) {
if (uriFactory == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public URI create(final String uri)
{
try {
return new URL(null, uri, STREAM_HANDLER).toURI();
} catch (MalformedURLException | URISyntaxException e) {
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Unable to create URI.", e);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Unable to create URI.", e);
}
}
Expand All @@ -58,7 +60,9 @@ public URI create(final URI baseURI, final String segment)
{
try {
return new URL(convert(baseURI), segment, STREAM_HANDLER).toURI();
} catch (MalformedURLException | URISyntaxException e) {
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Unable to create URI.", e);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Unable to create URI.", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @author <a href="mailto:[email protected]">Kenneth Waldenstrom</a>
*/
class ClasspathURLStreamHandler extends URLStreamHandler {
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(new HashSet<>(
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(new HashSet<String>(
Arrays.asList("classpath", "resource")));

@Override
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/networknt/schema/uri/URLFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public final class URLFactory implements URIFactory {
// These supported schemes are defined in {@link #URL(String, String, int, String)}.
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(new HashSet<>(
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(new HashSet<String>(
Arrays.asList("http", "https", "ftp", "file", "jar")));

/**
Expand All @@ -42,7 +42,9 @@ public URI create(final String uri)
{
try {
return new URL(uri).toURI();
} catch (MalformedURLException | URISyntaxException e) {
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Unable to create URI.", e);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Unable to create URI.", e);
}
}
Expand All @@ -57,7 +59,9 @@ public URI create(final URI baseURI, final String segment)
{
try {
return new URL(baseURI.toURL(), segment).toURI();
} catch (MalformedURLException | URISyntaxException e) {
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Unable to create URI.", e);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Unable to create URI.", e);
}
}
Expand Down
38 changes: 18 additions & 20 deletions src/test/java/com/networknt/schema/MaximumValidatorPerfTest.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
package com.networknt.schema;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.DecimalNode;
import com.fasterxml.jackson.databind.node.DoubleNode;
import com.fasterxml.jackson.databind.node.TextNode;
import org.junit.Ignore;
import org.junit.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.assertTrue;

@Ignore
public class MaximumValidatorPerfTest {
Expand All @@ -29,13 +21,13 @@ public void testTime() throws InvocationTargetException, IllegalAccessException
long start = System.currentTimeMillis();
executeTests(testMethods, 200000);
long end = System.currentTimeMillis();
System.out.println("time to execute all tests using:" + (end - start) +"ms");
System.out.println("time to execute all tests using:" + (end - start) + "ms");
}

public void executeTests(List<Method> methods, int executeTimes) throws InvocationTargetException, IllegalAccessException {

for(int i = 0; i < executeTimes; i++) {
for(Method testMethod : methods) {
for (int i = 0; i < executeTimes; i++) {
for (Method testMethod : methods) {
testMethod.invoke(test);
}
}
Expand All @@ -45,24 +37,30 @@ public void executeTests(List<Method> methods, int executeTimes) throws Invocati
public List<Method> getTestMethods(String[] methodNames) {
Method[] methods = test.getClass().getMethods();
List<Method> testMethods = new ArrayList<Method>();
if(methodNames.length > 0) {
for(String name : methodNames) {
testMethods.addAll(Arrays.stream(methods).filter(m -> m.getName().equals(name)).collect(Collectors.toList()));
if (methodNames.length > 0) {
for (String name : methodNames) {
Collection<Method> listOfMethodNames = new ArrayList<Method>();
for (Method testMethod : methods) {
if (testMethod.getName().equals(name)) {
listOfMethodNames.add(testMethod);
}
}
testMethods.addAll(listOfMethodNames);
}
return testMethods;
}
for (Method m : methods) {
Annotation[] annotations = m.getDeclaredAnnotations();
boolean isTestMethod = false;
for(Annotation annotation : annotations) {
if(annotation.annotationType() == Test.class) {
for (Annotation annotation : annotations) {
if (annotation.annotationType() == Test.class) {
isTestMethod = true;
}
}
if(isTestMethod) {
if (isTestMethod) {
//filter out incompatible test cases.
if(!m.getName().equals("doubleValueCoarsing") && !m.getName().equals("negativeDoubleOverflowTest"))
testMethods.add(m);
if (!m.getName().equals("doubleValueCoarsing") && !m.getName().equals("negativeDoubleOverflowTest"))
testMethods.add(m);
}
}
return testMethods;
Expand Down

0 comments on commit 14794c6

Please sign in to comment.