From 4bc815ad5483a0984a7449e9d88f71d733e8abf1 Mon Sep 17 00:00:00 2001 From: xinying7 Date: Thu, 21 Nov 2024 02:19:40 -0600 Subject: [PATCH] fixed 9 flaky tests in PropertySerializationTest.java: 'deserializeNotReadOnlyStringProperty', 'deserializeIntegerMapProperty', 'serializeFloatProperty', 'deserializeDoubleProperty', 'serializeIntegerProperty', 'serializeLongProperty', 'deserializeLongProperty', 'deserializeFloatProperty', 'serializeIntegerMapProperty' --- .../properties/PropertySerializationTest.java | 81 +++++++++++++------ 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/modules/swagger-core/src/test/java/io/swagger/v3/core/serialization/properties/PropertySerializationTest.java b/modules/swagger-core/src/test/java/io/swagger/v3/core/serialization/properties/PropertySerializationTest.java index 96e7dd0d27..70c195ea1e 100644 --- a/modules/swagger-core/src/test/java/io/swagger/v3/core/serialization/properties/PropertySerializationTest.java +++ b/modules/swagger-core/src/test/java/io/swagger/v3/core/serialization/properties/PropertySerializationTest.java @@ -97,18 +97,20 @@ public void serializeDoubleProperty() throws IOException { String json2 = m.writeValueAsString(p); JSONObject jsonObj1 = new JSONObject(json1); JSONObject jsonObj2 = new JSONObject(json2); - JSONAssert.assertEquals(jsonObj1, jsonObj2, true); } @Test(description = "it should deserialize a DoubleProperty") public void deserializeDoubleProperty() throws IOException { - final String json = "{\"type\":\"number\",\"format\":\"double\"}"; - final Schema p = m.readValue(json, Schema.class); + final String json1 = "{\"type\":\"number\",\"format\":\"double\"}"; + final Schema p = m.readValue(json1, Schema.class); assertEquals(p.getType(), "number"); assertEquals(p.getFormat(), "double"); assertEquals(p.getClass(), NumberSchema.class); - assertEquals(m.writeValueAsString(p), json); + String json2 = m.writeValueAsString(p); + JSONObject jsonObj1 = new JSONObject(json1); + JSONObject jsonObj2 = new JSONObject(json2); + JSONAssert.assertEquals(jsonObj1, jsonObj2, true); } @Test(description = "it should serialize a FloatProperty") @@ -116,26 +118,35 @@ public void serializeFloatProperty() throws IOException { final NumberSchema p = new NumberSchema() ._default(new BigDecimal("1.2")); p.format("float"); - final String json = "{\"type\":\"number\",\"format\":\"float\",\"default\":1.2}"; - assertEquals(m.writeValueAsString(p), json); + final String json1 = "{\"type\":\"number\",\"format\":\"float\",\"default\":1.2}"; + String json2 = m.writeValueAsString(p); + JSONObject jsonObj1 = new JSONObject(json1); + JSONObject jsonObj2 = new JSONObject(json2); + JSONAssert.assertEquals(jsonObj1, jsonObj2, true); } @Test(description = "it should deserialize a FloatProperty") public void deserializeFloatProperty() throws IOException { - final String json = "{\"type\":\"number\",\"format\":\"float\"}"; - final Schema p = m.readValue(json, Schema.class); + final String json1 = "{\"type\":\"number\",\"format\":\"float\"}"; + final Schema p = m.readValue(json1, Schema.class); assertEquals(p.getType(), "number"); assertEquals(p.getFormat(), "float"); assertEquals(p.getClass(), NumberSchema.class); - assertEquals(m.writeValueAsString(p), json); + String json2 = m.writeValueAsString(p); + JSONObject jsonObj1 = new JSONObject(json1); + JSONObject jsonObj2 = new JSONObject(json2); + JSONAssert.assertEquals(jsonObj1, jsonObj2, true); } @Test(description = "it should serialize an IntegerProperty") public void serializeIntegerProperty() throws IOException { final IntegerSchema p = new IntegerSchema() ._default(32); - final String json = "{\"type\":\"integer\",\"format\":\"int32\",\"default\":32}"; - assertEquals(m.writeValueAsString(p), json); + final String json1 = "{\"type\":\"integer\",\"format\":\"int32\",\"default\":32}"; + String json2 = m.writeValueAsString(p); + JSONObject jsonObj1 = new JSONObject(json1); + JSONObject jsonObj2 = new JSONObject(json2); + JSONAssert.assertEquals(jsonObj1, jsonObj2, true); } @Test(description = "it should deserialize a IntegerProperty") @@ -156,18 +167,24 @@ public void serializeLongProperty() throws IOException { final IntegerSchema p = new IntegerSchema() .format("int64") ._default(8675309); - final String json = "{\"type\":\"integer\",\"format\":\"int64\",\"default\":8675309}"; - assertEquals(m.writeValueAsString(p), json); + final String json1 = "{\"type\":\"integer\",\"format\":\"int64\",\"default\":8675309}"; + String json2 = m.writeValueAsString(p); + JSONObject jsonObj1 = new JSONObject(json1); + JSONObject jsonObj2 = new JSONObject(json2); + JSONAssert.assertEquals(jsonObj1, jsonObj2, true); } @Test(description = "it should deserialize a LongProperty") public void deserializeLongProperty() throws IOException { - final String json = "{\"type\":\"integer\",\"format\":\"int64\"}"; - final Schema p = m.readValue(json, Schema.class); + final String json1 = "{\"type\":\"integer\",\"format\":\"int64\"}"; + final Schema p = m.readValue(json1, Schema.class); assertEquals(p.getType(), "integer"); assertEquals(p.getFormat(), "int64"); assertEquals(p.getClass(), IntegerSchema.class); - assertEquals(m.writeValueAsString(p), json); + String json2 = m.writeValueAsString(p); + JSONObject jsonObj1 = new JSONObject(json1); + JSONObject jsonObj2 = new JSONObject(json2); + JSONAssert.assertEquals(jsonObj1, jsonObj2, true); } @Test(description = "it should serialize a string MapProperty") @@ -189,17 +206,23 @@ public void deserializeStringMapProperty() throws IOException { @Test(description = "it should serialize a integer MapProperty") public void serializeIntegerMapProperty() throws IOException { final Schema p = new MapSchema().additionalProperties(new IntegerSchema()); - final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}"; - assertEquals(m.writeValueAsString(p), json); + final String json1 = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}"; + String json2 = m.writeValueAsString(p); + JSONObject jsonObj1 = new JSONObject(json1); + JSONObject jsonObj2 = new JSONObject(json2); + JSONAssert.assertEquals(jsonObj1, jsonObj2, true); } @Test(description = "it should deserialize a integer MapProperty") public void deserializeIntegerMapProperty() throws IOException { - final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}"; - final Schema p = m.readValue(json, Schema.class); + final String json1 = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}"; + final Schema p = m.readValue(json1, Schema.class); assertEquals(p.getType(), "object"); assertEquals(p.getClass(), MapSchema.class); - assertEquals(m.writeValueAsString(p), json); + String json2 = m.writeValueAsString(p); + JSONObject jsonObj1 = new JSONObject(json1); + JSONObject jsonObj2 = new JSONObject(json2); + JSONAssert.assertEquals(jsonObj1, jsonObj2, true); } @Test(description = "it should serialize a long MapProperty") @@ -281,14 +304,17 @@ public void deserializeEnumStringProperty() throws IOException { @Test(description = "it should deserialize an IntegerProperty with enums") public void deserializeEnumIntegerProperty() throws IOException { - final String json = "{\"type\":\"integer\",\"format\":\"int32\",\"enum\":[1,2]}"; - final Schema p = m.readValue(json, Schema.class); + final String json1 = "{\"type\":\"integer\",\"format\":\"int32\",\"enum\":[1,2]}"; + final Schema p = m.readValue(json1, Schema.class); assertEquals(p.getType(), "integer"); List _enum = ((IntegerSchema) p).getEnum(); assertNotNull(_enum); assertEquals(_enum, Arrays.asList(1, 2)); assertEquals(p.getClass(), IntegerSchema.class); - assertEquals(m.writeValueAsString(p), json); + String json2 = m.writeValueAsString(p); + JSONObject jsonObj1 = new JSONObject(json1); + JSONObject jsonObj2 = new JSONObject(json2); + JSONAssert.assertEquals(jsonObj1, jsonObj2, true); } @Test(description = "it should serialize a string array property") @@ -327,8 +353,11 @@ public void serializeReadOnlyStringProperty() throws IOException { public void deserializeNotReadOnlyStringProperty() throws IOException { final StringSchema p = new StringSchema(); p.setReadOnly(false); - final String json = "{\"type\":\"string\",\"readOnly\":false}"; - assertEquals(m.writeValueAsString(p), json); + final String json1 = "{\"type\":\"string\",\"readOnly\":false}"; + String json2 = m.writeValueAsString(p); + JSONObject jsonObj1 = new JSONObject(json1); + JSONObject jsonObj2 = new JSONObject(json2); + JSONAssert.assertEquals(jsonObj1, jsonObj2, true); } @Test(description = "it should serialize an object property with required set")