Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed 35 different flaky tests with ID category #4783

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -8,6 +8,8 @@
import io.swagger.v3.oas.models.media.ByteArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.Test;
import org.json.JSONObject;
import org.skyscreamer.jsonassert.JSONAssert;

import java.util.Map;

Expand Down Expand Up @@ -42,14 +44,18 @@ public void testByteProperty() {
Schema model = new Schema()
.addProperties("byteProperty", new ByteArraySchema());

assertEquals(Json.pretty(model), "{" + NEWLINE +
String json1 = "{" + NEWLINE +
" \"properties\" : {" + NEWLINE +
" \"byteProperty\" : {" + NEWLINE +
" \"type\" : \"string\"," + NEWLINE +
" \"format\" : \"byte\"" + NEWLINE +
" }" + NEWLINE +
" }" + NEWLINE +
"}");
"}";
String json2 = Json.pretty(model);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test
Expand All @@ -73,7 +79,7 @@ public void testByteArray() {
Schema model = new Schema()
.addProperties("byteArray", new ArraySchema().items(new BinarySchema()));

assertEquals(Json.pretty(model), "{" + NEWLINE +
String json1 = "{" + NEWLINE +
" \"properties\" : {" + NEWLINE +
" \"byteArray\" : {" + NEWLINE +
" \"type\" : \"array\"," + NEWLINE +
Expand All @@ -83,7 +89,11 @@ public void testByteArray() {
" }" + NEWLINE +
" }" + NEWLINE +
" }" + NEWLINE +
"}");
"}";
String json2 = Json.pretty(model);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test
Expand All @@ -92,7 +102,7 @@ public void testReadOnlyByteArray() {
.addProperties("byteArray",
new ArraySchema().items(new BinarySchema()).readOnly(true));

assertEquals(Json.pretty(model), "{" + NEWLINE +
String json1 = "{" + NEWLINE +
" \"properties\" : {" + NEWLINE +
" \"byteArray\" : {" + NEWLINE +
" \"type\" : \"array\"," + NEWLINE +
Expand All @@ -103,7 +113,11 @@ public void testReadOnlyByteArray() {
" }" + NEWLINE +
" }" + NEWLINE +
" }" + NEWLINE +
"}");
"}";
String json2 = Json.pretty(model);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

class ByteConverterModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,23 @@ public void serializeParameterizedType() {

final Schema employee = (Schema) schemas.get("employee").getProperties().get("employee");
final Map<String, Schema> props = employee.getProperties();
final Iterator<String> et = props.keySet().iterator();

final Schema id = props.get(et.next());
final Schema id = props.get("id");
assertTrue(id instanceof IntegerSchema);

final Schema firstName = props.get(et.next());
final Schema firstName = props.get("firstName");
assertTrue(firstName instanceof StringSchema);

final Schema lastName = props.get(et.next());
final Schema lastName = props.get("lastName");
assertTrue(lastName instanceof StringSchema);

final Schema department = props.get(et.next());
final Schema department = props.get("department");
assertNotNull(department.get$ref());

final Schema manager = props.get(et.next());
final Schema manager = props.get("manager");
assertNotNull(manager.get$ref());

final Schema team = props.get(et.next());
final Schema team = props.get("team");
assertTrue(team instanceof ArraySchema);

final ArraySchema ap = (ArraySchema) team;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
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() {
final Map<String, Schema> models = ModelConverters.getInstance().readAll(ModelWithIntegerFields.class);
assertEquals(models.size(), 1);

String json = Json.pretty(models);
assertEquals(normalizeLineEnds(json),
String json1 = Json.pretty(models);
String json2 =
"{\n" +
" \"ModelWithIntegerFields\" : {\n" +
" \"type\" : \"object\",\n" +
Expand All @@ -33,16 +36,20 @@ public void testFormatOfInteger() {
" }\n" +
" }\n" +
" }\n" +
"}");
"}";
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);

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

@Test
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 +62,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 +90,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 @@ -33,6 +33,9 @@
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

public class JsonDeserializationTest {
private final ObjectMapper m = Json.mapper();

Expand Down Expand Up @@ -490,40 +493,60 @@ public void testNullExampleAndValues() throws Exception {

assertNull(oas.getComponents().getSchemas().get("UserStatus").getExample());
assertTrue(oas.getComponents().getSchemas().get("UserStatus").getExampleSetFlag());
assertEquals(Yaml.pretty(oas), yamlNull);

// Use Jackson's YAML mapper to parse both expected and actual YAML into maps
ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
Map<String, Object> expectedMap = yamlMapper.readValue(yamlNull, Map.class);
Map<String, Object> actualMap = yamlMapper.readValue(Yaml.pretty(oas), Map.class);
assertEquals(expectedMap, actualMap);

oas = Yaml.mapper().readValue(yamlMissing, OpenAPI.class);
Yaml.prettyPrint(oas);
assertNull(oas.getComponents().getSchemas().get("UserStatus").getExample());
assertFalse(oas.getComponents().getSchemas().get("UserStatus").getExampleSetFlag());
assertEquals(Yaml.pretty(oas), yamlMissing);

Map<String, Object> expectedMap2 = yamlMapper.readValue(yamlMissing, Map.class);
Map<String, Object> actualMap2 = yamlMapper.readValue(Yaml.pretty(oas), Map.class);
assertEquals(expectedMap2, actualMap2);

oas = Yaml.mapper().readValue(yamlNotNull, OpenAPI.class);
Yaml.prettyPrint(oas);
assertNotNull(oas.getComponents().getSchemas().get("UserStatus").getExample());
assertTrue(oas.getComponents().getSchemas().get("UserStatus").getExampleSetFlag());
assertEquals(Yaml.pretty(oas), yamlNotNull);

Map<String, Object> expectedMap3 = yamlMapper.readValue(yamlNotNull, Map.class);
Map<String, Object> actualMap3 = yamlMapper.readValue(Yaml.pretty(oas), Map.class);
assertEquals(expectedMap3, actualMap3);

oas = Yaml.mapper().readValue(yamlValueNull, OpenAPI.class);
Yaml.prettyPrint(oas);
Example ex = oas.getComponents().getExamples().get("UserStatus");
assertNull(ex.getValue());
assertTrue(ex.getValueSetFlag());
assertEquals(Yaml.pretty(oas), yamlValueNull);

Map<String, Object> expectedMap4 = yamlMapper.readValue(yamlValueNull, Map.class);
Map<String, Object> actualMap4 = yamlMapper.readValue(Yaml.pretty(oas), Map.class);
assertEquals(expectedMap4, actualMap4);

oas = Yaml.mapper().readValue(yamlValueMissing, OpenAPI.class);
Yaml.prettyPrint(oas);
ex = oas.getComponents().getExamples().get("UserStatus");
assertNull(ex.getValue());
assertFalse(ex.getValueSetFlag());
assertEquals(Yaml.pretty(oas), yamlValueMissing);

Map<String, Object> expectedMap5 = yamlMapper.readValue(yamlValueMissing, Map.class);
Map<String, Object> actualMap5 = yamlMapper.readValue(Yaml.pretty(oas), Map.class);
assertEquals(expectedMap5, actualMap5);

oas = Yaml.mapper().readValue(yamlValueNotNull, OpenAPI.class);
Yaml.prettyPrint(oas);
ex = oas.getComponents().getExamples().get("UserStatus");
assertNotNull(ex.getValue());
assertTrue(ex.getValueSetFlag());
assertEquals(Yaml.pretty(oas), yamlValueNotNull);

Map<String, Object> expectedMap6 = yamlMapper.readValue(yamlValueNotNull, Map.class);
Map<String, Object> actualMap6 = yamlMapper.readValue(Yaml.pretty(oas), Map.class);
assertEquals(expectedMap6, actualMap6);
}

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

import static io.swagger.v3.core.util.TestUtils.normalizeLineEnds;
import static org.testng.Assert.assertEquals;
Expand Down Expand Up @@ -167,13 +169,17 @@ public void testBooleanAdditionalPropertiesSerialization() throws Exception {
Schema responseSchema = response.getContent().get("*/*").getSchema();

Schema schema = new ObjectSchema().additionalProperties(true);
assertEquals(normalizeLineEnds(Json.pretty(schema)), "{\n" +
String json1 = "{\n" +
" \"type\" : \"object\",\n" +
" \"additionalProperties\" : true\n" +
"}");
"}";
String json2 = normalizeLineEnds(Json.pretty(schema));
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);

schema = new ObjectSchema().additionalProperties(responseSchema);
assertEquals(normalizeLineEnds(Json.pretty(schema)), "{\n" +
String json3 = "{\n" +
" \"type\" : \"object\",\n" +
" \"additionalProperties\" : {\n" +
" \"type\" : \"object\",\n" +
Expand All @@ -183,7 +189,11 @@ public void testBooleanAdditionalPropertiesSerialization() throws Exception {
" },\n" +
" \"x-foo\" : \"vendor x\"\n" +
" }\n" +
"}");
"}";
String json4 = normalizeLineEnds(Json.pretty(schema));
JSONObject jsonObj3 = new JSONObject(json3);
JSONObject jsonObj4 = new JSONObject(json4);
JSONAssert.assertEquals(jsonObj3, jsonObj4, true);
}

@Test(description = "vendor extensions should be included with object type")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
import io.swagger.v3.core.resolving.resources.User2169;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
import java.util.Map;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

public class JsonPropertyTest {

@Test(description = "test ticket 2169")
Expand Down Expand Up @@ -128,9 +136,9 @@ public void testTicket2169() {
}

@Test(description = "test ticket 2845")
public void testTicket2845() {
public void testTicket2845() throws Exception {

SerializationMatchers.assertEqualsToYaml(ModelConverters.getInstance().readAll(Ticket2845Holder.class), "Ticket2845Child:\n" +
String expectedYaml = "Ticket2845Child:\n" +
" type: object\n" +
" properties:\n" +
" bar:\n" +
Expand All @@ -141,7 +149,15 @@ public void testTicket2845() {
" type: object\n" +
" properties:\n" +
" child:\n" +
" $ref: '#/components/schemas/Ticket2845Child'");
" $ref: '#/components/schemas/Ticket2845Child'";

String actualYaml = new ObjectMapper(new YAMLFactory())
.writeValueAsString(ModelConverters.getInstance().readAll(Ticket2845Holder.class));

Set<String> expectedSet = new HashSet<>(Arrays.asList(expectedYaml.split("\n")));
Set<String> actualSet = new HashSet<>(Arrays.asList(actualYaml.split("\n")));
expectedSet.remove(null);
assertEquals(expectedSet, actualSet);

/*
TODO: Test demonstrating annotation not being resolved when class is used/refernces elsewhere with different annotations
Expand All @@ -150,9 +166,7 @@ and referenced (in the same or different class) with no or different @JsonIgnor
The possible solutions are either resolve into different unrelated schemas or resolve inline
(see https://github.com/swagger-api/swagger-core/issues/3366 and other related tickets)
*/
SerializationMatchers.assertEqualsToYaml(
ModelConverters.getInstance().readAll(Ticket2845HolderNoAnnotationNotWorking.class),
"Ticket2845Child:\n" +
String expectedYaml2 = "Ticket2845Child:\n" +
" type: object\n" +
" properties:\n" +
" foo:\n" +
Expand All @@ -167,7 +181,14 @@ and referenced (in the same or different class) with no or different @JsonIgnor
" child:\n" +
" $ref: '#/components/schemas/Ticket2845Child'\n" +
" childNoAnnotation:\n" +
" $ref: '#/components/schemas/Ticket2845Child'");
" $ref: '#/components/schemas/Ticket2845Child'";

String actualYaml2 = new ObjectMapper(new YAMLFactory())
.writeValueAsString(ModelConverters.getInstance().readAll(Ticket2845HolderNoAnnotationNotWorking.class));
Set<String> expectedSet2 = new HashSet<>(Arrays.asList(expectedYaml2.split("\n")));
Set<String> actualSet2 = new HashSet<>(Arrays.asList(actualYaml2.split("\n")));
expectedSet2.remove(null);
assertEquals(expectedSet2, actualSet2);
}

static class Ticket2845Parent {
Expand Down
Loading