Skip to content

Commit 14794c6

Browse files
authored
Merge pull request #244 from msattel/feature/221
Feature/221
2 parents 9c1ef88 + cdfc710 commit 14794c6

File tree

10 files changed

+44
-36
lines changed

10 files changed

+44
-36
lines changed

pom.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</repository>
5959
</distributionManagement>
6060
<properties>
61-
<java.version>1.8</java.version>
61+
<java.version>1.6</java.version>
6262
<java.testversion>1.8</java.testversion>
6363
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6464
<version.jackson>2.10.0</version.jackson>
@@ -192,6 +192,8 @@
192192
<configuration>
193193
<source>${java.version}</source>
194194
<target>${java.version}</target>
195+
<testSource>${java.testversion}</testSource>
196+
<testTarget>${java.testversion}</testTarget>
195197
</configuration>
196198
<executions>
197199
<execution>
@@ -291,7 +293,7 @@
291293
<plugin>
292294
<groupId>org.jacoco</groupId>
293295
<artifactId>jacoco-maven-plugin</artifactId>
294-
<version>${version.jacoco}</version>
296+
<version>0.7.9</version>
295297
<executions>
296298
<!-- The Executions for merging -->
297299
<execution>

src/main/java/com/networknt/schema/ExclusiveMinimumValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ExclusiveMinimumValidator extends BaseJsonValidator implements Json
3434
*/
3535
private final ThresholdMixin typedMinimum;
3636

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

4040
if (!schemaNode.isNumber()) {

src/main/java/com/networknt/schema/JsonMetaSchema.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static class V4 {
6969
private static String URI = "http://json-schema.org/draft-04/schema#";
7070
private static final String ID = "id";
7171

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

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

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

157-
public static final List<Format> BUILTIN_FORMATS = new ArrayList<>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
157+
public static final List<Format> BUILTIN_FORMATS = new ArrayList<Format>(JsonMetaSchema.COMMON_BUILTIN_FORMATS);
158158
static {
159159
// add version specific formats here.
160160
//BUILTIN_FORMATS.add(pattern("phone", "^\\+(?:[0-9] ?){6,14}[0-9]$"));

src/main/java/com/networknt/schema/JsonSchemaFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public JsonSchema getSchema(final URI schemaUri, final SchemaValidatorsConfig co
313313

314314
final URI mappedUri;
315315
try {
316-
mappedUri = this.uriFactory.create(map.getOrDefault(schemaUri.toString(), schemaUri.toString()));
316+
mappedUri = this.uriFactory.create(map.get(schemaUri.toString())!=null ? map.get(schemaUri.toString()) : schemaUri.toString());
317317
} catch (IllegalArgumentException e) {
318318
logger.error("Failed to create URI.", e);
319319
throw new JsonSchemaException(e);

src/main/java/com/networknt/schema/MinimumValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class MinimumValidator extends BaseJsonValidator implements JsonValidator
3737
*/
3838
private final ThresholdMixin typedMinimum;
3939

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

4343
if (!schemaNode.isNumber()) {

src/main/java/com/networknt/schema/ValidationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ValidationContext {
2727
private final JsonMetaSchema metaSchema;
2828
private final JsonSchemaFactory jsonSchemaFactory;
2929
private SchemaValidatorsConfig config;
30-
private final Map<String, JsonSchemaRef> refParsingInProgress = new HashMap<>();
30+
private final Map<String, JsonSchemaRef> refParsingInProgress = new HashMap<String, JsonSchemaRef>();
3131

3232
public ValidationContext(URIFactory uriFactory, JsonMetaSchema metaSchema, JsonSchemaFactory jsonSchemaFactory, SchemaValidatorsConfig config) {
3333
if (uriFactory == null) {

src/main/java/com/networknt/schema/uri/ClasspathURLFactory.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public URI create(final String uri)
4545
{
4646
try {
4747
return new URL(null, uri, STREAM_HANDLER).toURI();
48-
} catch (MalformedURLException | URISyntaxException e) {
48+
} catch (MalformedURLException e) {
49+
throw new IllegalArgumentException("Unable to create URI.", e);
50+
} catch (URISyntaxException e) {
4951
throw new IllegalArgumentException("Unable to create URI.", e);
5052
}
5153
}
@@ -58,7 +60,9 @@ public URI create(final URI baseURI, final String segment)
5860
{
5961
try {
6062
return new URL(convert(baseURI), segment, STREAM_HANDLER).toURI();
61-
} catch (MalformedURLException | URISyntaxException e) {
63+
} catch (MalformedURLException e) {
64+
throw new IllegalArgumentException("Unable to create URI.", e);
65+
} catch (URISyntaxException e) {
6266
throw new IllegalArgumentException("Unable to create URI.", e);
6367
}
6468
}

src/main/java/com/networknt/schema/uri/ClasspathURLStreamHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* @author <a href="mailto:[email protected]">Kenneth Waldenstrom</a>
3333
*/
3434
class ClasspathURLStreamHandler extends URLStreamHandler {
35-
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(new HashSet<>(
35+
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(new HashSet<String>(
3636
Arrays.asList("classpath", "resource")));
3737

3838
@Override

src/main/java/com/networknt/schema/uri/URLFactory.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
public final class URLFactory implements URIFactory {
3232
// These supported schemes are defined in {@link #URL(String, String, int, String)}.
33-
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(new HashSet<>(
33+
public static final Set<String> SUPPORTED_SCHEMES = Collections.unmodifiableSet(new HashSet<String>(
3434
Arrays.asList("http", "https", "ftp", "file", "jar")));
3535

3636
/**
@@ -42,7 +42,9 @@ public URI create(final String uri)
4242
{
4343
try {
4444
return new URL(uri).toURI();
45-
} catch (MalformedURLException | URISyntaxException e) {
45+
} catch (MalformedURLException e) {
46+
throw new IllegalArgumentException("Unable to create URI.", e);
47+
} catch (URISyntaxException e) {
4648
throw new IllegalArgumentException("Unable to create URI.", e);
4749
}
4850
}
@@ -57,7 +59,9 @@ public URI create(final URI baseURI, final String segment)
5759
{
5860
try {
5961
return new URL(baseURI.toURL(), segment).toURI();
60-
} catch (MalformedURLException | URISyntaxException e) {
62+
} catch (MalformedURLException e) {
63+
throw new IllegalArgumentException("Unable to create URI.", e);
64+
} catch (URISyntaxException e) {
6165
throw new IllegalArgumentException("Unable to create URI.", e);
6266
}
6367
}

src/test/java/com/networknt/schema/MaximumValidatorPerfTest.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
package com.networknt.schema;
22

3-
import com.fasterxml.jackson.databind.JsonNode;
4-
import com.fasterxml.jackson.databind.node.DecimalNode;
5-
import com.fasterxml.jackson.databind.node.DoubleNode;
6-
import com.fasterxml.jackson.databind.node.TextNode;
73
import org.junit.Ignore;
84
import org.junit.Test;
95

106
import java.lang.annotation.Annotation;
117
import java.lang.reflect.InvocationTargetException;
128
import java.lang.reflect.Method;
13-
import java.math.BigDecimal;
149
import java.util.ArrayList;
15-
import java.util.Arrays;
10+
import java.util.Collection;
1611
import java.util.List;
17-
import java.util.stream.Collectors;
18-
19-
import static org.junit.Assert.assertTrue;
2012

2113
@Ignore
2214
public class MaximumValidatorPerfTest {
@@ -29,13 +21,13 @@ public void testTime() throws InvocationTargetException, IllegalAccessException
2921
long start = System.currentTimeMillis();
3022
executeTests(testMethods, 200000);
3123
long end = System.currentTimeMillis();
32-
System.out.println("time to execute all tests using:" + (end - start) +"ms");
24+
System.out.println("time to execute all tests using:" + (end - start) + "ms");
3325
}
3426

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

37-
for(int i = 0; i < executeTimes; i++) {
38-
for(Method testMethod : methods) {
29+
for (int i = 0; i < executeTimes; i++) {
30+
for (Method testMethod : methods) {
3931
testMethod.invoke(test);
4032
}
4133
}
@@ -45,24 +37,30 @@ public void executeTests(List<Method> methods, int executeTimes) throws Invocati
4537
public List<Method> getTestMethods(String[] methodNames) {
4638
Method[] methods = test.getClass().getMethods();
4739
List<Method> testMethods = new ArrayList<Method>();
48-
if(methodNames.length > 0) {
49-
for(String name : methodNames) {
50-
testMethods.addAll(Arrays.stream(methods).filter(m -> m.getName().equals(name)).collect(Collectors.toList()));
40+
if (methodNames.length > 0) {
41+
for (String name : methodNames) {
42+
Collection<Method> listOfMethodNames = new ArrayList<Method>();
43+
for (Method testMethod : methods) {
44+
if (testMethod.getName().equals(name)) {
45+
listOfMethodNames.add(testMethod);
46+
}
47+
}
48+
testMethods.addAll(listOfMethodNames);
5149
}
5250
return testMethods;
5351
}
5452
for (Method m : methods) {
5553
Annotation[] annotations = m.getDeclaredAnnotations();
5654
boolean isTestMethod = false;
57-
for(Annotation annotation : annotations) {
58-
if(annotation.annotationType() == Test.class) {
55+
for (Annotation annotation : annotations) {
56+
if (annotation.annotationType() == Test.class) {
5957
isTestMethod = true;
6058
}
6159
}
62-
if(isTestMethod) {
60+
if (isTestMethod) {
6361
//filter out incompatible test cases.
64-
if(!m.getName().equals("doubleValueCoarsing") && !m.getName().equals("negativeDoubleOverflowTest"))
65-
testMethods.add(m);
62+
if (!m.getName().equals("doubleValueCoarsing") && !m.getName().equals("negativeDoubleOverflowTest"))
63+
testMethods.add(m);
6664
}
6765
}
6866
return testMethods;

0 commit comments

Comments
 (0)