Skip to content

Commit 53c6646

Browse files
committed
running acceptance tests in early-failing mode
Now both `V6TestSuiteTest` and `TestSuiteTest` to run the testsuites both in collecting mode and early-failing mode, so now both classes have 2 `@Test` methods. Also an easy fix of different `ValidationFailureReporter#inContextOf()` behavior in collecting and early-failing mode (throwing vs collecting exceptions).
1 parent 9222b16 commit 53c6646

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

core/src/main/java/org/everit/json/schema/EarlyFailingFailureReporter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ public EarlyFailingFailureReporter(Schema schema) {
1313
@Override public void validationFinished() {
1414

1515
}
16+
17+
@Override ValidationException inContextOfSchema(Schema schema, Runnable task) {
18+
try {
19+
return super.inContextOfSchema(schema, task);
20+
} catch (ValidationException e) {
21+
return e;
22+
}
23+
}
1624
}

tests/src/test/java/org/everit/json/schema/TestCase.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ static List<Object[]> loadAsParamsFromPackage(String packageName) {
5757

5858
final boolean expectedToBeValid;
5959

60+
private Schema schema;
61+
6062
private TestCase(JSONObject input, JSONObject schemaTest, String fileName) {
6163
schemaDescription = "[" + fileName + "]/" + schemaTest.getString("description");
6264
schemaJson = schemaTest.get("schema");
@@ -65,28 +67,36 @@ private TestCase(JSONObject input, JSONObject schemaTest, String fileName) {
6567
inputData = input.get("data");
6668
}
6769

68-
private void testInEarlyFailureMode(Schema schema) {
69-
// validator = new ValidatorBuilder().failEarly().build();
70-
// validator = new ValidatorBuilder().failEarly().loadDefaultValues().build();
71-
// validator.performValidation(schema, inputData);
70+
public void runTestInEarlyFailureMode() {
71+
testWithValidator(Validator.builder().failEarly().build(), schema);
7272
}
7373

74-
public void runTest(SchemaLoader.SchemaLoaderBuilder loaderBuilder) {
74+
private void testWithValidator(Validator validator, Schema schema) {
7575
try {
76-
SchemaLoader loader = loaderBuilder.schemaJson(schemaJson).build();
77-
Schema schema = loader.load().build();
78-
schema.validate(inputData);
76+
validator.performValidation(schema, inputData);
7977
if (!expectedToBeValid) {
8078
throw new AssertionError("false success for " + inputDescription);
8179
}
8280
} catch (ValidationException e) {
8381
if (expectedToBeValid) {
8482
throw new AssertionError("false failure for " + inputDescription, e);
8583
}
84+
}
85+
}
86+
87+
public void loadSchema(SchemaLoader.SchemaLoaderBuilder loaderBuilder) {
88+
try {
89+
SchemaLoader loader = loaderBuilder.schemaJson(schemaJson).build();
90+
this.schema = loader.load().build();
8691
} catch (SchemaException e) {
8792
throw new AssertionError("schema loading failure for " + schemaDescription, e);
8893
} catch (JSONException e) {
8994
throw new AssertionError("schema loading error for " + schemaDescription, e);
9095
}
9196
}
97+
98+
public void runTestInCollectingMode() {
99+
testWithValidator(Validator.builder().build(), schema);
100+
}
101+
92102
}

tests/src/test/java/org/everit/json/schema/TestSuiteTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package org.everit.json.schema;
22

3+
import java.util.List;
4+
35
import org.everit.json.schema.loader.SchemaLoader;
4-
import org.json.JSONException;
56
import org.junit.AfterClass;
67
import org.junit.BeforeClass;
78
import org.junit.Test;
89
import org.junit.runner.RunWith;
910
import org.junit.runners.Parameterized;
1011
import org.junit.runners.Parameterized.Parameters;
1112

12-
import java.util.List;
13-
1413
@RunWith(Parameterized.class)
1514
public class TestSuiteTest {
1615

@@ -35,10 +34,17 @@ public static void stopJetty() throws Exception {
3534

3635
public TestSuiteTest(TestCase testcase, String descr) {
3736
this.tc = testcase;
37+
tc.loadSchema(SchemaLoader.builder());
3838
}
3939

4040
@Test
41-
public void test() {
42-
tc.runTest(SchemaLoader.builder());
41+
public void testInCollectingMode() {
42+
tc.runTestInCollectingMode();
4343
}
44+
45+
@Test
46+
public void testInEarlyFailingMode() {
47+
tc.runTestInEarlyFailureMode();
48+
}
49+
4450
}

tests/src/test/java/org/everit/json/schema/V6TestSuiteTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@ public static void stopJetty() throws Exception {
3636

3737
public V6TestSuiteTest(TestCase testcase, String descr) {
3838
this.tc = testcase;
39+
tc.loadSchema(SchemaLoader.builder().draftV6Support());
3940
}
4041

4142
@Test
42-
public void test() {
43-
tc.runTest(SchemaLoader.builder().draftV6Support());
43+
public void testInCollectingMode() {
44+
tc.runTestInCollectingMode();
45+
}
46+
47+
@Test
48+
public void testInEarlyFailingMode() {
49+
tc.runTestInEarlyFailureMode();
4450
}
4551

4652
}

0 commit comments

Comments
 (0)