diff --git a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/JSONSchemaTest.java b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/JSONSchemaTest.java index c303ce9293329..d17bbf0b8a0f0 100644 --- a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/JSONSchemaTest.java +++ b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/JSONSchemaTest.java @@ -33,8 +33,10 @@ import org.apache.pulsar.client.impl.schema.SchemaTestUtils.NestedBar; import org.apache.pulsar.client.impl.schema.SchemaTestUtils.NestedBarList; import org.apache.pulsar.common.schema.SchemaType; +import org.skyscreamer.jsonassert.JSONAssert; import org.testng.Assert; import org.testng.annotations.Test; +import org.json.JSONException; import static org.apache.pulsar.client.impl.schema.SchemaTestUtils.FOO_FIELDS; import static org.apache.pulsar.client.impl.schema.SchemaTestUtils.SCHEMA_JSON_NOT_ALLOW_NULL; @@ -44,13 +46,16 @@ @Slf4j public class JSONSchemaTest { + public static void assertJSONEqual(String s1, String s2) throws JSONException{ + JSONAssert.assertEquals(s1, s2, false); + } @Test - public void testNotAllowNullSchema() { + public void testNotAllowNullSchema() throws JSONException { JSONSchema jsonSchema = JSONSchema.of(SchemaDefinition.builder().withPojo(Foo.class).withAlwaysAllowNull(false).build()); Assert.assertEquals(jsonSchema.getSchemaInfo().getType(), SchemaType.JSON); Schema.Parser parser = new Schema.Parser(); String schemaJson = new String(jsonSchema.getSchemaInfo().getSchema()); - Assert.assertEquals(schemaJson, SCHEMA_JSON_NOT_ALLOW_NULL); + assertJSONEqual(schemaJson, SCHEMA_JSON_NOT_ALLOW_NULL); Schema schema = parser.parse(schemaJson); for (String fieldName : FOO_FIELDS) { @@ -67,13 +72,13 @@ public void testNotAllowNullSchema() { } @Test - public void testAllowNullSchema() { + public void testAllowNullSchema() throws JSONException { JSONSchema jsonSchema = JSONSchema.of(SchemaDefinition.builder().withPojo(Foo.class).build()); Assert.assertEquals(jsonSchema.getSchemaInfo().getType(), SchemaType.JSON); Schema.Parser parser = new Schema.Parser(); parser.setValidateDefaults(false); String schemaJson = new String(jsonSchema.getSchemaInfo().getSchema()); - Assert.assertEquals(schemaJson, SCHEMA_JSON_ALLOW_NULL); + assertJSONEqual(schemaJson, SCHEMA_JSON_ALLOW_NULL); Schema schema = parser.parse(schemaJson); for (String fieldName : FOO_FIELDS) { diff --git a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaInfoTest.java b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaInfoTest.java index 99a1724a83ab2..994f01386c4bf 100644 --- a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaInfoTest.java +++ b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaInfoTest.java @@ -38,6 +38,7 @@ import org.apache.pulsar.common.schema.KeyValueEncodingType; import org.apache.pulsar.common.schema.SchemaInfo; import org.apache.pulsar.common.schema.SchemaType; +import org.json.JSONException; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -209,18 +210,18 @@ public void testKeyValueSchemaInfoBackwardCompatibility() { } @Test - public void testKeyValueSchemaInfoToString() { + public void testKeyValueSchemaInfoToString() throws JSONException { String havePrimitiveType = DefaultImplementation .convertKeyValueSchemaInfoDataToString(KeyValueSchemaInfo .decodeKeyValueSchemaInfo(Schema.KeyValue(Schema.AVRO(Foo.class), Schema.STRING) .getSchemaInfo())); - assertEquals(havePrimitiveType, KEY_VALUE_SCHEMA_INFO_INCLUDE_PRIMITIVE); + JSONSchemaTest.assertJSONEqual(havePrimitiveType, KEY_VALUE_SCHEMA_INFO_INCLUDE_PRIMITIVE); String notHavePrimitiveType = DefaultImplementation .convertKeyValueSchemaInfoDataToString(KeyValueSchemaInfo .decodeKeyValueSchemaInfo(Schema.KeyValue(Schema.AVRO(Foo.class), Schema.AVRO(Foo.class)).getSchemaInfo())); - assertEquals(notHavePrimitiveType, KEY_VALUE_SCHEMA_INFO_NOT_INCLUDE_PRIMITIVE); + JSONSchemaTest.assertJSONEqual(notHavePrimitiveType, KEY_VALUE_SCHEMA_INFO_NOT_INCLUDE_PRIMITIVE); } }