Skip to content

Commit

Permalink
fixing flaky test testFormatOfBigDecimal
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
xinying7 committed Nov 23, 2024
1 parent e8bb595 commit 61c6313
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 60 deletions.
10 changes: 10 additions & 0 deletions modules/swagger-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230227</version>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import static io.swagger.v3.core.util.TestUtils.normalizeLineEnds;
import static org.testng.Assert.assertEquals;

import org.json.JSONObject;
import org.skyscreamer.jsonassert.JSONAssert;

public class NumericFormatTest {
@Test
public void testFormatOfInteger() {
Expand Down Expand Up @@ -41,8 +44,8 @@ public void testFormatOfDecimal() {
final Map<String, Schema> models = ModelConverters.getInstance().readAll(ModelWithDecimalFields.class);
assertEquals(models.size(), 1);

String json = Json.pretty(models);
assertEquals(normalizeLineEnds(json),
String json1 = Json.pretty(models);
String json2 =
"{\n" +
" \"ModelWithDecimalFields\" : {\n" +
" \"type\" : \"object\",\n" +
Expand All @@ -55,17 +58,21 @@ public void testFormatOfDecimal() {
" }\n" +
" }\n" +
" }\n" +
"}");
"}";
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);

JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

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

String json = Json.pretty(models);
String json1 = Json.pretty(models);

assertEquals(normalizeLineEnds(json),
String json2 =
"{\n" +
" \"ModelWithoutScientificFields\" : {\n" +
" \"type\" : \"object\",\n" +
Expand All @@ -79,7 +86,11 @@ public void testFormatOfBigDecimal() {
" }\n" +
" }\n" +
" }\n" +
"}");
"}";
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);

JSONAssert.assertEquals(jsonObj1, jsonObj2, true);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import io.swagger.v3.oas.models.servers.Server;
import org.testng.annotations.Test;
import org.yaml.snakeyaml.LoaderOptions;
import org.json.JSONObject;
import org.skyscreamer.jsonassert.JSONAssert;

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

String swaggerJson = Json.mapper().writeValueAsString(swagger);
assertEquals(swaggerJson, "{\"openapi\":\"3.0.1\",\"x-extension-with-properties\":{\"x-foo-bar\":\"foo bar\",\"x-bar-foo\":null}}");
String json2 = "{\"openapi\":\"3.0.1\",\"x-extension-with-properties\":{\"x-foo-bar\":\"foo bar\",\"x-bar-foo\":null}}";
JSONObject jsonObj1 = new JSONObject(swaggerJson);
JSONObject jsonObj2 = new JSONObject(json2);

JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import org.testng.annotations.Test;
import org.json.JSONObject;
import org.skyscreamer.jsonassert.JSONAssert;

import java.io.IOException;
import java.math.BigDecimal;
Expand Down Expand Up @@ -110,15 +112,22 @@ public void deserializeModel() throws IOException {
public void serializeArrayModel() throws IOException {
final ArraySchema model = new ArraySchema();
model.setItems(new Schema().$ref("Pet"));
assertEquals(m.writeValueAsString(model), "{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/Pet\"}}");
String json1 = m.writeValueAsString(model);
String json2 = "{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/Pet\"}}";
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test(description = "it should deserialize an array model")
public void deserializeArrayModel() throws IOException {
final String json = "{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Pet\"}}";
final Schema p = m.readValue(json, Schema.class);
final String json1 = "{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Pet\"}}";
final Schema p = m.readValue(json1, Schema.class);
String json2 = m.writeValueAsString(p);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
assertTrue(p instanceof ArraySchema);
assertEquals(m.writeValueAsString(p), json);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

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

0 comments on commit 61c6313

Please sign in to comment.