Skip to content

Commit 61c6313

Browse files
author
xinying7
committed
fixing flaky test testFormatOfBigDecimal
fixing flaky test serializeDoubleProperty fix flaky test testFormatOfBigDecimal fix flaky test testExtensionObjectWithProperties fix flaky test serializeReadOnlyStringProperty fix flaky test serializeArrayModel fix flaky test deserializeArrayModel fix flaky test serializeArrayStringProperty fix flaky test deserializeArrayStringProperty fix flaky test serializeDateTimeProperty fix flaky test deserializeDateTimeProperty fix flaky test serializeObjectPropertyWithRequiredProperties fix flaky test serializeLongMapProperty fix flaky test deserializeLongMapProperty fixed flaky test deserializeIntegerProperty fixed 9 flaky tests in PropertySerializationTest.java: 'deserializeNotReadOnlyStringProperty', 'deserializeIntegerMapProperty', 'serializeFloatProperty', 'deserializeDoubleProperty', 'serializeIntegerProperty', 'serializeLongProperty', 'deserializeLongProperty', 'deserializeFloatProperty', 'serializeIntegerMapProperty'
1 parent e8bb595 commit 61c6313

File tree

5 files changed

+158
-60
lines changed

5 files changed

+158
-60
lines changed

modules/swagger-core/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@
5252
</plugins>
5353
</build>
5454
<dependencies>
55+
<dependency>
56+
<groupId>org.json</groupId>
57+
<artifactId>json</artifactId>
58+
<version>20230227</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.skyscreamer</groupId>
62+
<artifactId>jsonassert</artifactId>
63+
<version>1.5.0</version>
64+
</dependency>
5565
<dependency>
5666
<groupId>jakarta.xml.bind</groupId>
5767
<artifactId>jakarta.xml.bind-api</artifactId>

modules/swagger-core/src/test/java/io/swagger/v3/core/converting/NumericFormatTest.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
import static io.swagger.v3.core.util.TestUtils.normalizeLineEnds;
1515
import static org.testng.Assert.assertEquals;
1616

17+
import org.json.JSONObject;
18+
import org.skyscreamer.jsonassert.JSONAssert;
19+
1720
public class NumericFormatTest {
1821
@Test
1922
public void testFormatOfInteger() {
@@ -41,8 +44,8 @@ public void testFormatOfDecimal() {
4144
final Map<String, Schema> models = ModelConverters.getInstance().readAll(ModelWithDecimalFields.class);
4245
assertEquals(models.size(), 1);
4346

44-
String json = Json.pretty(models);
45-
assertEquals(normalizeLineEnds(json),
47+
String json1 = Json.pretty(models);
48+
String json2 =
4649
"{\n" +
4750
" \"ModelWithDecimalFields\" : {\n" +
4851
" \"type\" : \"object\",\n" +
@@ -55,17 +58,21 @@ public void testFormatOfDecimal() {
5558
" }\n" +
5659
" }\n" +
5760
" }\n" +
58-
"}");
61+
"}";
62+
JSONObject jsonObj1 = new JSONObject(json1);
63+
JSONObject jsonObj2 = new JSONObject(json2);
64+
65+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
5966
}
6067

6168
@Test
6269
public void testFormatOfBigDecimal() {
6370
final Map<String, Schema> models = ModelConverters.getInstance().readAll(ModelWithoutScientificFields.class);
6471
assertEquals(models.size(), 1);
6572

66-
String json = Json.pretty(models);
73+
String json1 = Json.pretty(models);
6774

68-
assertEquals(normalizeLineEnds(json),
75+
String json2 =
6976
"{\n" +
7077
" \"ModelWithoutScientificFields\" : {\n" +
7178
" \"type\" : \"object\",\n" +
@@ -79,7 +86,11 @@ public void testFormatOfBigDecimal() {
7986
" }\n" +
8087
" }\n" +
8188
" }\n" +
82-
"}");
89+
"}";
90+
JSONObject jsonObj1 = new JSONObject(json1);
91+
JSONObject jsonObj2 = new JSONObject(json2);
92+
93+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
8394

8495
}
8596

modules/swagger-core/src/test/java/io/swagger/v3/core/serialization/JsonSerializationTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import io.swagger.v3.oas.models.servers.Server;
1818
import org.testng.annotations.Test;
1919
import org.yaml.snakeyaml.LoaderOptions;
20+
import org.json.JSONObject;
21+
import org.skyscreamer.jsonassert.JSONAssert;
2022

2123
import java.util.HashMap;
2224
import java.util.Map;
@@ -68,7 +70,11 @@ public void testExtensionObjectWithProperties() throws Exception {
6870
swagger.addExtension("x-extension-with-properties", extensionObjectProps);
6971

7072
String swaggerJson = Json.mapper().writeValueAsString(swagger);
71-
assertEquals(swaggerJson, "{\"openapi\":\"3.0.1\",\"x-extension-with-properties\":{\"x-foo-bar\":\"foo bar\",\"x-bar-foo\":null}}");
73+
String json2 = "{\"openapi\":\"3.0.1\",\"x-extension-with-properties\":{\"x-foo-bar\":\"foo bar\",\"x-bar-foo\":null}}";
74+
JSONObject jsonObj1 = new JSONObject(swaggerJson);
75+
JSONObject jsonObj2 = new JSONObject(json2);
76+
77+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
7278
}
7379

7480
@Test

modules/swagger-core/src/test/java/io/swagger/v3/core/serialization/ModelSerializerTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import io.swagger.v3.oas.models.media.Schema;
1818
import io.swagger.v3.oas.models.media.StringSchema;
1919
import org.testng.annotations.Test;
20+
import org.json.JSONObject;
21+
import org.skyscreamer.jsonassert.JSONAssert;
2022

2123
import java.io.IOException;
2224
import java.math.BigDecimal;
@@ -110,15 +112,22 @@ public void deserializeModel() throws IOException {
110112
public void serializeArrayModel() throws IOException {
111113
final ArraySchema model = new ArraySchema();
112114
model.setItems(new Schema().$ref("Pet"));
113-
assertEquals(m.writeValueAsString(model), "{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/Pet\"}}");
115+
String json1 = m.writeValueAsString(model);
116+
String json2 = "{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/Pet\"}}";
117+
JSONObject jsonObj1 = new JSONObject(json1);
118+
JSONObject jsonObj2 = new JSONObject(json2);
119+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
114120
}
115121

116122
@Test(description = "it should deserialize an array model")
117123
public void deserializeArrayModel() throws IOException {
118-
final String json = "{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Pet\"}}";
119-
final Schema p = m.readValue(json, Schema.class);
124+
final String json1 = "{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Pet\"}}";
125+
final Schema p = m.readValue(json1, Schema.class);
126+
String json2 = m.writeValueAsString(p);
127+
JSONObject jsonObj1 = new JSONObject(json1);
128+
JSONObject jsonObj2 = new JSONObject(json2);
120129
assertTrue(p instanceof ArraySchema);
121-
assertEquals(m.writeValueAsString(p), json);
130+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
122131
}
123132

124133
@Test(description = "it should not create an xml object for $ref")

0 commit comments

Comments
 (0)