Skip to content

Commit d998053

Browse files
Atharva JoshiAtharva Joshi
authored andcommitted
integration test
Signed-off-by: Atharva Joshi <[email protected]>
1 parent 2f2102f commit d998053

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

server/src/main/java/io/pravega/schemaregistry/rules/jsoncompatibility/JsonCompatibilityChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private boolean canReadChecker(SchemaInfo toValidate, List<SchemaInfo> toValidat
6060
return null;
6161
}).collect(
6262
Collectors.toList());
63-
return toCheckAgainst.stream().map(x -> checkNodeType(toCheck, x)).anyMatch(x -> x != null);
63+
return !toCheckAgainst.stream().map(x -> checkNodeType(toCheck, x)).anyMatch(x -> x != null);
6464
}
6565

6666
protected BreakingChanges checkNodeType(JsonNode toCheck, JsonNode toCheckAgainst) {

server/src/test/java/io/pravega/schemaregistry/rules/jsoncompatibility/JsonCompatibilityCheckerTest.java

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ public void testCanRead() {
5454
SchemaInfo schemaInfo1 = new SchemaInfo("toValidate", SerializationFormat.Json, ByteBuffer.wrap(y.getBytes()),
5555
ImmutableMap.of());
5656
toValidateAgainst.add(schemaInfo1);
57-
//Assert.assertTrue(jsonCompatibilityChecker.canRead(toValidate, toValidateAgainst));
58-
System.out.println(jsonCompatibilityChecker.canBeRead(toValidate, toValidateAgainst));
57+
Assert.assertTrue(jsonCompatibilityChecker.canRead(toValidate, toValidateAgainst));
5958
}
6059

6160
@Test
62-
public void testPrintNodes() {
61+
public void testDependencies() {
6362
JsonCompatibilityChecker jsonCompatibilityChecker = new JsonCompatibilityChecker();
6463
String x = "{\n" +
6564
"\"type\": \"object\",\n" +
@@ -90,38 +89,44 @@ public void testPrintNodes() {
9089
"\"billing_address\": { \"type\": \"string\" }\n" +
9190
"},\n" +
9291
"\"required\": [\"billing_address\"]\n" +
92+
"},\n" +
93+
"\"name\": {\n" +
94+
"\"properties\": {\n" +
95+
"\"salutation\": { \"type\": \"string\" }\n" +
96+
"},\n" +
97+
"\"required\": [\"salutation\"]\n" +
9398
"}\n" +
9499
"}\n" +
95100
"}\n";
101+
SchemaInfo toValidate = new SchemaInfo("toValidate", SerializationFormat.Json, ByteBuffer.wrap(x.getBytes()),
102+
ImmutableMap.of());
103+
SchemaInfo schemaInfo1 = new SchemaInfo("toValidate", SerializationFormat.Json, ByteBuffer.wrap(y.getBytes()),
104+
ImmutableMap.of());
105+
List<SchemaInfo> toValidateAgainst = new ArrayList<>();
106+
toValidateAgainst.add(toValidate);
107+
Assert.assertTrue(jsonCompatibilityChecker.canRead(toValidate, toValidateAgainst));
108+
toValidateAgainst.add(schemaInfo1);
109+
Assert.assertTrue(jsonCompatibilityChecker.canRead(toValidate, toValidateAgainst));
96110
String z = "{\n" +
97111
"\"type\": \"object\",\n" +
98112
"\"properties\": {\n" +
99-
"\"first_name\": { \"type\": \"string\" },\n" +
100-
"\"last_name\": { \"type\": \"string\" },\n" +
101-
"\"birthday\": { \"type\": \"string\", \"format\": \"date\" },\n" +
102-
"\"address\": {\n" +
103-
"\"type\": \"object\",\n" +
113+
"\"name\": { \"type\": \"string\" },\n" +
114+
"\"credit_card\": { \"type\": \"number\" }\n" +
115+
"},\n" +
116+
"\"required\": [\"name\"],\n" +
117+
"\"dependencies\": {\n" +
118+
"\"credit_card\": {\n" +
104119
"\"properties\": {\n" +
105-
"\"street_address\": { \"type\": \"string\" },\n" +
106-
"\"city\": { \"type\": \"string\" },\n" +
107-
"\"state\": { \"type\": \"string\" },\n" +
108-
"\"country\": { \"type\" : \"string\" }\n" +
120+
"\"billing_address\": { \"type\": \"number\" }\n" +
109121
"},\n" +
110-
"\"required\": [\"city\"]\n" +
122+
"\"required\": [\"billing_address\"]\n" +
123+
"}\n" +
111124
"}\n" +
112-
"},\n" +
113-
"\"required\": [\"first_name\"]\n" +
114125
"}\n";
115-
SchemaInfo toValidate = new SchemaInfo("toValidate", SerializationFormat.Json, ByteBuffer.wrap(x.getBytes()),
116-
ImmutableMap.of());
117-
SchemaInfo schemaInfo1 = new SchemaInfo("toValidate", SerializationFormat.Json, ByteBuffer.wrap(y.getBytes()),
118-
ImmutableMap.of());
119126
SchemaInfo schemaInfo11 = new SchemaInfo("toValidateAgainst", SerializationFormat.Json,
120127
ByteBuffer.wrap(z.getBytes()), ImmutableMap.of());
121-
List<SchemaInfo> toValidateAgainst = new ArrayList<>();
122-
toValidateAgainst.add(schemaInfo1);
123128
toValidateAgainst.add(schemaInfo11);
124-
jsonCompatibilityChecker.canBeRead(toValidate, toValidateAgainst);
129+
Assert.assertFalse(jsonCompatibilityChecker.canBeRead(toValidate, toValidateAgainst));
125130
}
126131

127132
@Test
@@ -149,7 +154,8 @@ public void testBasicProperties() throws IOException {
149154
SchemaInfo toValidateAgainst = new SchemaInfo("toValidateAgainst", SerializationFormat.Json,
150155
ByteBuffer.wrap(x2.getBytes()), ImmutableMap.of());
151156
List<SchemaInfo> toValidateAgainstList = new ArrayList<>();
152-
157+
toValidateAgainstList.add(toValidateAgainst);
158+
Assert.assertTrue(jsonCompatibilityChecker.canRead(toValidate, toValidateAgainstList));
153159
//different properties
154160
x2 = "{\n" +
155161
"\"type\": \"object\",\n" +
@@ -161,7 +167,8 @@ public void testBasicProperties() throws IOException {
161167
"}\n";
162168
SchemaInfo toValidateAgainst1 = new SchemaInfo("toValidateAgainst", SerializationFormat.Json,
163169
ByteBuffer.wrap(x2.getBytes()), ImmutableMap.of());
164-
170+
toValidateAgainstList.add(toValidateAgainst1);
171+
Assert.assertFalse(jsonCompatibilityChecker.canRead(toValidate, toValidateAgainstList));
165172
//different property values
166173
x2 = "{\n" +
167174
"\"type\": \"object\",\n" +
@@ -173,10 +180,8 @@ public void testBasicProperties() throws IOException {
173180
"}\n";
174181
SchemaInfo toValidateAgainst2 = new SchemaInfo("toValidateAgainst", SerializationFormat.Json,
175182
ByteBuffer.wrap(x2.getBytes()), ImmutableMap.of());
176-
toValidateAgainstList.add(toValidateAgainst);
177-
toValidateAgainstList.add(toValidateAgainst1);
178183
toValidateAgainstList.add(toValidateAgainst2);
179-
Assert.assertFalse(jsonCompatibilityChecker.canBeRead(toValidate, toValidateAgainstList));
184+
Assert.assertFalse(jsonCompatibilityChecker.canRead(toValidate, toValidateAgainstList));
180185
}
181186

182187
@Test
@@ -199,6 +204,7 @@ public void testRequired() throws IOException {
199204
ByteBuffer.wrap(x1.getBytes()), ImmutableMap.of());
200205
List<SchemaInfo> toValidateAgainstList = new ArrayList<>();
201206
toValidateAgainstList.add(toValidateAgainst);
207+
Assert.assertTrue(jsonCompatibilityChecker.canRead(toValidate, toValidateAgainstList));
202208
//remove required array element
203209
String x2 = "{\n" +
204210
"\"type\": \"object\",\n" +
@@ -208,12 +214,12 @@ public void testRequired() throws IOException {
208214
"\"address\": { \"type\": \"string\" },\n" +
209215
"\"telephone\": { \"type\": \"string\" }\n" +
210216
"},\n" +
211-
"\"required\": [\"email\"]\n" +
217+
"\"required\": [\"name\", \"email\", \"address\"]\n" +
212218
"}\n";
213219
SchemaInfo toValidateAgainst1 = new SchemaInfo("toValidateAgainst", SerializationFormat.Json,
214220
ByteBuffer.wrap(x2.getBytes()), ImmutableMap.of());
215221
toValidateAgainstList.add(toValidateAgainst1);
216-
Assert.assertFalse(jsonCompatibilityChecker.canBeRead(toValidate, toValidateAgainstList));
222+
Assert.assertTrue(jsonCompatibilityChecker.canRead(toValidate, toValidateAgainstList));
217223
x2 = "{\n" +
218224
"\"type\": \"object\",\n" +
219225
"\"properties\": {\n" +
@@ -222,11 +228,13 @@ public void testRequired() throws IOException {
222228
"\"address\": { \"type\": \"string\" },\n" +
223229
"\"telephone\": { \"type\": \"string\" }\n" +
224230
"},\n" +
225-
"\"required\": [\"email\", \"email\", \"address\"]\n" +
231+
"\"required\": [\"address\"]\n" +
226232
"}\n";
227233
SchemaInfo toValidateAgainst2 = new SchemaInfo("toValidateAgainst", SerializationFormat.Json,
228234
ByteBuffer.wrap(x2.getBytes()), ImmutableMap.of());
229-
235+
toValidateAgainstList.clear();
236+
toValidateAgainstList.add(toValidateAgainst2);
237+
Assert.assertFalse(jsonCompatibilityChecker.canBeRead(toValidate, toValidateAgainstList));
230238
}
231239
}
232240

0 commit comments

Comments
 (0)