2
2
3
3
import org .junit .Test ;
4
4
5
+ import static org .everit .json .schema .TestSupport .buildWithLocation ;
6
+
5
7
public class ConditionalSchemaTest {
6
8
7
9
private static final StringSchema MAX_LENGTH_STRING_SCHEMA = StringSchema .builder ().maxLength (4 ).build ();
@@ -46,9 +48,15 @@ public void onlyElseSuccess() {
46
48
47
49
// if-then
48
50
49
- @ Test ( expected = ValidationException . class )
51
+ @ Test
50
52
public void ifSubschemaSuccessThenSubschemaFailure () {
51
- ConditionalSchema .builder ().ifSchema (MAX_LENGTH_STRING_SCHEMA ).thenSchema (PATTERN_STRING_SCHEMA ).build ().validate ("bar" );
53
+ ConditionalSchema subject = buildWithLocation (ConditionalSchema .builder ().ifSchema (MAX_LENGTH_STRING_SCHEMA ).thenSchema (PATTERN_STRING_SCHEMA ));
54
+ TestSupport .failureOf (subject )
55
+ .expectedKeyword ("then" )
56
+ .expectedPointer ("#" )
57
+ .expectedViolatedSchema (subject )
58
+ .input ("bar" )
59
+ .expect ();
52
60
}
53
61
54
62
@ Test
@@ -73,9 +81,15 @@ public void ifSubschemaSuccessElseSubschemaFailure() {
73
81
ConditionalSchema .builder ().ifSchema (MAX_LENGTH_STRING_SCHEMA ).elseSchema (PATTERN_STRING_SCHEMA ).build ().validate ("bar" );
74
82
}
75
83
76
- @ Test ( expected = ValidationException . class )
84
+ @ Test
77
85
public void ifSubschemaFailureElseSubschemaFailure () {
78
- ConditionalSchema .builder ().ifSchema (PATTERN_STRING_SCHEMA ).elseSchema (MAX_LENGTH_STRING_SCHEMA ).build ().validate ("barbar" );
86
+ ConditionalSchema subject = buildWithLocation (ConditionalSchema .builder ().ifSchema (PATTERN_STRING_SCHEMA ).elseSchema (MAX_LENGTH_STRING_SCHEMA ));
87
+ TestSupport .failureOf (subject )
88
+ .expectedKeyword ("else" )
89
+ .expectedPointer ("#" )
90
+ .expectedViolatedSchema (subject )
91
+ .input ("barbar" )
92
+ .expect ();
79
93
}
80
94
81
95
@ Test
@@ -122,34 +136,58 @@ public void ifSubschemaSuccessThenSubschemaSuccessElseSubSchemaFailure() {
122
136
ConditionalSchema .builder ().ifSchema (PATTERN_STRING_SCHEMA ).thenSchema (MAX_LENGTH_STRING_SCHEMA ).elseSchema (MIN_LENGTH_STRING_SCHEMA ).build ().validate ("foo" );
123
137
}
124
138
125
- @ Test ( expected = ValidationException . class )
139
+ @ Test
126
140
public void ifSubschemaSuccessThenSubschemaFailureElseSubSchemaSuccess () {
127
- ConditionalSchema .builder ().ifSchema (PATTERN_STRING_SCHEMA ).thenSchema (MAX_LENGTH_STRING_SCHEMA ).elseSchema (MIN_LENGTH_STRING_SCHEMA ).build ().validate ("foobar" );
141
+ ConditionalSchema subject = buildWithLocation (ConditionalSchema .builder ().ifSchema (PATTERN_STRING_SCHEMA ).thenSchema (MAX_LENGTH_STRING_SCHEMA ).elseSchema (MIN_LENGTH_STRING_SCHEMA ));
142
+ TestSupport .failureOf (subject )
143
+ .expectedKeyword ("then" )
144
+ .expectedPointer ("#" )
145
+ .expectedViolatedSchema (subject )
146
+ .input ("foobar" )
147
+ .expect ();
128
148
}
129
149
130
- @ Test ( expected = ValidationException . class )
150
+ @ Test
131
151
public void ifSubschemaSuccessThenSubschemaFailureElseSubSchemaFailure () {
132
- ConditionalSchema .builder ().ifSchema (PATTERN_STRING_SCHEMA ).thenSchema (MAX_LENGTH_STRING_SCHEMA ).elseSchema (MIN_LENGTH_STRING_SCHEMA ).build ().validate ("foooo" );
152
+ ConditionalSchema subject = buildWithLocation (ConditionalSchema .builder ().ifSchema (PATTERN_STRING_SCHEMA ).thenSchema (MAX_LENGTH_STRING_SCHEMA ).elseSchema (MIN_LENGTH_STRING_SCHEMA ));
153
+ TestSupport .failureOf (subject )
154
+ .expectedKeyword ("then" )
155
+ .expectedPointer ("#" )
156
+ .expectedViolatedSchema (subject )
157
+ .input ("foooo" )
158
+ .expect ();
133
159
}
134
160
135
161
@ Test
136
162
public void ifSubschemaFailureThenSubschemaSuccessElseSubSchemaSuccess () {
137
163
ConditionalSchema .builder ().ifSchema (MAX_LENGTH_STRING_SCHEMA ).thenSchema (PATTERN_STRING_SCHEMA ).elseSchema (MIN_LENGTH_STRING_SCHEMA ).build ().validate ("foobar" );
138
164
}
139
165
140
- @ Test ( expected = ValidationException . class )
166
+ @ Test
141
167
public void ifSubschemaFailureThenSubschemaSuccessElseSubSchemaFailure () {
142
- ConditionalSchema .builder ().ifSchema (PATTERN_STRING_SCHEMA ).thenSchema (MAX_LENGTH_STRING_SCHEMA ).elseSchema (MIN_LENGTH_STRING_SCHEMA ).build ().validate ("bar" );
168
+ ConditionalSchema subject = buildWithLocation (ConditionalSchema .builder ().ifSchema (PATTERN_STRING_SCHEMA ).thenSchema (MAX_LENGTH_STRING_SCHEMA ).elseSchema (MIN_LENGTH_STRING_SCHEMA ));
169
+ TestSupport .failureOf (subject )
170
+ .expectedKeyword ("else" )
171
+ .expectedPointer ("#" )
172
+ .expectedViolatedSchema (subject )
173
+ .input ("bar" )
174
+ .expect ();
143
175
}
144
176
145
177
@ Test
146
178
public void ifSubschemaFailureThenSubschemaFailureElseSubSchemaSuccess () {
147
179
ConditionalSchema .builder ().ifSchema (PATTERN_STRING_SCHEMA ).thenSchema (MIN_LENGTH_STRING_SCHEMA ).elseSchema (MAX_LENGTH_STRING_SCHEMA ).build ().validate ("bar" );
148
180
}
149
181
150
- @ Test ( expected = ValidationException . class )
182
+ @ Test
151
183
public void ifSubschemaFailureThenSubschemaFailureElseSubSchemaFailure () {
152
- ConditionalSchema .builder ().ifSchema (PATTERN_STRING_SCHEMA ).thenSchema (MIN_LENGTH_STRING_SCHEMA ).elseSchema (MAX_LENGTH_STRING_SCHEMA ).build ().validate ("barbarbar" );
184
+ ConditionalSchema subject = buildWithLocation (ConditionalSchema .builder ().ifSchema (PATTERN_STRING_SCHEMA ).thenSchema (MIN_LENGTH_STRING_SCHEMA ).elseSchema (MAX_LENGTH_STRING_SCHEMA ));
185
+ TestSupport .failureOf (subject )
186
+ .expectedKeyword ("else" )
187
+ .expectedPointer ("#" )
188
+ .expectedViolatedSchema (subject )
189
+ .input ("barbarbar" )
190
+ .expect ();
153
191
}
154
192
155
193
}
0 commit comments