Skip to content

Commit cab2df5

Browse files
Atharva JoshiAtharva Joshi
Atharva Joshi
authored and
Atharva Joshi
committed
subschema test 2
Signed-off-by: Atharva Joshi <[email protected]>
1 parent 5e73209 commit cab2df5

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import static io.pravega.schemaregistry.rules.jsoncompatibility.BreakingChangesStore.*;
77

88
public class SubSchemaComparator {
9-
JsonCompatibilityChecker jsonCompatibilityChecker = new JsonCompatibilityChecker();
9+
JsonCompatibilityChecker jsonCompatibilityChecker;
1010

1111
public void setJsonCompatibilityChecker() {
1212
this.jsonCompatibilityChecker = new JsonCompatibilityChecker();

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

+1-17
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,10 @@ public void testEqualCase() {
3333
"}\n" +
3434
"}\n" +
3535
"}\n";
36-
String y = "{\n" +
37-
"\"type\": \"object\",\n" +
38-
"\"properties\": {\n" +
39-
"\"name\": { \"type\": \"string\" },\n" +
40-
"\"credit_card\": { \"type\": \"number\" }\n" +
41-
"},\n" +
42-
"\"required\": [\"name\"],\n" +
43-
"\"dependencies\": {\n" +
44-
"\"credit_card\": {\n" +
45-
"\"properties\": {\n" +
46-
"\"billing_address\": { \"type\": \"string\" }\n" +
47-
"},\n" +
48-
"\"required\": [\"billing_address\"]\n" +
49-
"}\n" +
50-
"}\n" +
51-
"}\n";
5236
SchemaInfo toValidate = new SchemaInfo("toValidate", SerializationFormat.Json, ByteBuffer.wrap(x.getBytes()),
5337
ImmutableMap.of());
5438
List<SchemaInfo> toValidateAgainst = new ArrayList<>();
55-
SchemaInfo schemaInfo1 = new SchemaInfo("toValidate", SerializationFormat.Json, ByteBuffer.wrap(y.getBytes()),
39+
SchemaInfo schemaInfo1 = new SchemaInfo("toValidate", SerializationFormat.Json, ByteBuffer.wrap(x.getBytes()),
5640
ImmutableMap.of());
5741
toValidateAgainst.add(schemaInfo1);
5842
Assert.assertTrue(jsonCompatibilityChecker.canRead(toValidate, toValidateAgainst));

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

+32-2
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,43 @@ public void testArrayComparisionOnlyAddition() throws IOException {
125125

126126
@Test
127127
public void testHasSubSchema() throws IOException {
128-
String x1 = "{\n" +
128+
String x = "{\n" +
129129
"\"anyOf\": [\n" +
130130
"{ \"type\": \"string\" },\n" +
131131
"{ \"type\": \"number\" }\n" +
132132
"]\n" +
133133
"}\n";
134-
JsonNode node = objectMapper.readTree(ByteBuffer.wrap(x1.getBytes()).array());
134+
JsonNode node = objectMapper.readTree(ByteBuffer.wrap(x.getBytes()).array());
135+
Assert.assertTrue(jsonCompatibilityCheckerUtils.hasSubSchema(node));
136+
x = "{\n" +
137+
"\"oneOf\": [\n" +
138+
"{ \"type\": \"string\" },\n" +
139+
"{ \"type\": \"number\" }\n" +
140+
"]\n" +
141+
"}\n";
142+
node = objectMapper.readTree(ByteBuffer.wrap(x.getBytes()).array());
143+
Assert.assertTrue(jsonCompatibilityCheckerUtils.hasSubSchema(node));
144+
x = "{\n" +
145+
"\"allOf\": [\n" +
146+
"{ \"type\": \"string\" },\n" +
147+
"{ \"type\": \"number\" }\n" +
148+
"]\n" +
149+
"}\n";
150+
node = objectMapper.readTree(ByteBuffer.wrap(x.getBytes()).array());
135151
Assert.assertTrue(jsonCompatibilityCheckerUtils.hasSubSchema(node));
152+
x = "{\n" +
153+
"\"type\": \"object\",\n" +
154+
"\"properties\": {\n" +
155+
"\"name\": { \"type\": \"string\" },\n" +
156+
"\"credit_card\": { \"type\": \"number\" },\n" +
157+
"\"billing_address\": { \"type\": \"string\" }\n" +
158+
"},\n" +
159+
"\"required\": [\"name\"],\n" +
160+
"\"dependencies\": {\n" +
161+
"\"credit_card\": [\"billing_address\"]\n" +
162+
"}\n" +
163+
"}\n";
164+
node = objectMapper.readTree(ByteBuffer.wrap(x.getBytes()).array());
165+
Assert.assertFalse(jsonCompatibilityCheckerUtils.hasSubSchema(node));
136166
}
137167
}

0 commit comments

Comments
 (0)