Skip to content

Commit 3b232f6

Browse files
authored
fix: five nondeterministic tests (#22513)
1 parent 8ad6fff commit 3b232f6

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

modules/openapi-generator/src/test/java/org/openapitools/codegen/ExampleGeneratorTest.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
import java.util.*;
88

9+
import com.fasterxml.jackson.databind.JsonNode;
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
912
import static org.testng.AssertJUnit.assertEquals;
1013
import static org.testng.AssertJUnit.assertNull;
1114

@@ -40,7 +43,7 @@ public void generateFromResponseSchemaWithPrimitiveType() {
4043
}
4144

4245
@Test
43-
public void generateFromResponseSchemaWithDateFormat() {
46+
public void generateFromResponseSchemaWithDateFormat() throws Exception {
4447
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/example_generator_test.yaml");
4548

4649
new InlineModelResolver().flatten(openAPI);
@@ -62,9 +65,11 @@ public void generateFromResponseSchemaWithDateFormat() {
6265
mediaTypeKeys
6366
);
6467

68+
ObjectMapper mapper = new ObjectMapper();
69+
6570
assertEquals(1, examples.size());
6671
assertEquals("application/json", examples.get(0).get("contentType"));
67-
assertEquals(String.format(Locale.ROOT, "{%n \"date_with_example\" : \"2024-01-01\",%n \"date_without_example\" : \"2000-01-23\"%n}"), examples.get(0).get("example"));
72+
assertEquals(mapper.readTree(String.format(Locale.ROOT, "{%n \"date_with_example\" : \"2024-01-01\",%n \"date_without_example\" : \"2000-01-23\"%n}")), mapper.readTree(examples.get(0).get("example")));
6873
assertEquals("200", examples.get(0).get("statusCode"));
6974
}
7075

@@ -211,7 +216,7 @@ public void generateFromResponseSchemaWithModel() {
211216
}
212217

213218
@Test
214-
public void generateFromResponseSchemaWithAllOfComposedModel() {
219+
public void generateFromResponseSchemaWithAllOfComposedModel() throws Exception{
215220
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/example_generator_test.yaml");
216221

217222
new InlineModelResolver().flatten(openAPI);
@@ -233,14 +238,16 @@ public void generateFromResponseSchemaWithAllOfComposedModel() {
233238
mediaTypeKeys
234239
);
235240

241+
ObjectMapper mapper = new ObjectMapper();
242+
236243
assertEquals(1, examples.size());
237244
assertEquals("application/json", examples.get(0).get("contentType"));
238-
assertEquals(String.format(Locale.ROOT, "{%n \"example_schema_property_composed\" : \"example schema property value composed\",%n \"example_schema_property\" : \"example schema property value\"%n}"), examples.get(0).get("example"));
245+
assertEquals(mapper.readTree(String.format(Locale.ROOT, "{%n \"example_schema_property_composed\" : \"example schema property value composed\",%n \"example_schema_property\" : \"example schema property value\"%n}")), mapper.readTree(examples.get(0).get("example")));
239246
assertEquals("200", examples.get(0).get("statusCode"));
240247
}
241248

242249
@Test
243-
public void generateFromResponseSchemaWithAllOfChildComposedModel() {
250+
public void generateFromResponseSchemaWithAllOfChildComposedModel() throws Exception {
244251
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/example_generator_test.yaml");
245252

246253
new InlineModelResolver().flatten(openAPI);
@@ -262,9 +269,11 @@ public void generateFromResponseSchemaWithAllOfChildComposedModel() {
262269
mediaTypeKeys
263270
);
264271

272+
ObjectMapper mapper = new ObjectMapper();
273+
265274
assertEquals(1, examples.size());
266275
assertEquals("application/json", examples.get(0).get("contentType"));
267-
assertEquals(String.format(Locale.ROOT, "{%n \"example_schema_property_composed\" : \"example schema property value composed\",%n \"example_schema_property_composed_parent\" : \"example schema property value composed parent\",%n \"example_schema_property\" : \"example schema property value\"%n}"), examples.get(0).get("example"));
276+
assertEquals(mapper.readTree(String.format(Locale.ROOT, "{%n \"example_schema_property_composed\" : \"example schema property value composed\",%n \"example_schema_property_composed_parent\" : \"example schema property value composed parent\",%n \"example_schema_property\" : \"example schema property value\"%n}")), mapper.readTree(examples.get(0).get("example")));
268277
assertEquals("200", examples.get(0).get("statusCode"));
269278
}
270279

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,29 +1251,33 @@ void testNotDuplicateOauth2FlowsScopes() {
12511251

12521252
final List<CodegenOperation> codegenOperations = paths.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
12531253
final CodegenOperation getWithBasicAuthAndOauth = getByOperationId(codegenOperations, "getWithBasicAuthAndOauth");
1254-
assertEquals(getWithBasicAuthAndOauth.authMethods.size(), 3);
1255-
assertEquals(getWithBasicAuthAndOauth.authMethods.get(0).name, "basic_auth");
1254+
List<CodegenSecurity> sortedAuthMethods = new ArrayList<>(getWithBasicAuthAndOauth.authMethods);
1255+
sortedAuthMethods.sort(Comparator.comparing(am -> am.name));
1256+
assertEquals(sortedAuthMethods.size(), 3);
1257+
assertEquals(sortedAuthMethods.get(0).name, "basic_auth");
12561258

1257-
final Map<String, Object> passwordFlowScope = getWithBasicAuthAndOauth.authMethods.get(1).scopes.get(0);
1259+
final Map<String, Object> passwordFlowScope = sortedAuthMethods.get(1).scopes.get(0);
12581260
assertEquals(passwordFlowScope.get("scope"), "something:create");
12591261
assertEquals(passwordFlowScope.get("description"), "create from password flow");
12601262

1261-
final Map<String, Object> clientCredentialsFlow = getWithBasicAuthAndOauth.authMethods.get(2).scopes.get(0);
1263+
final Map<String, Object> clientCredentialsFlow = sortedAuthMethods.get(2).scopes.get(0);
12621264
assertEquals(clientCredentialsFlow.get("scope"), "something:create");
12631265
assertEquals(clientCredentialsFlow.get("description"), "create from client credentials flow");
12641266

12651267
final CodegenOperation getWithOauthAuth = getByOperationId(codegenOperations, "getWithOauthAuth");
1266-
assertEquals(getWithOauthAuth.authMethods.size(), 2);
1268+
List<CodegenSecurity> sortedOauthAuthMethods = new ArrayList<>(getWithOauthAuth.authMethods);
1269+
sortedOauthAuthMethods.sort(Comparator.comparing(am -> am.name));
1270+
assertEquals(sortedOauthAuthMethods.size(), 2);
12671271

1268-
final Map<String, Object> passwordFlow = getWithOauthAuth.authMethods.get(0).scopes.get(0);
1272+
final Map<String, Object> passwordFlow = sortedOauthAuthMethods.get(0).scopes.get(0);
12691273
assertEquals(passwordFlow.get("scope"), "something:create");
12701274
assertEquals(passwordFlow.get("description"), "create from password flow");
12711275

1272-
final Map<String, Object> clientCredentialsCreateFlow = getWithOauthAuth.authMethods.get(1).scopes.get(0);
1276+
final Map<String, Object> clientCredentialsCreateFlow = sortedOauthAuthMethods.get(1).scopes.get(0);
12731277
assertEquals(clientCredentialsCreateFlow.get("scope"), "something:create");
12741278
assertEquals(clientCredentialsCreateFlow.get("description"), "create from client credentials flow");
12751279

1276-
final Map<String, Object> clientCredentialsProcessFlow = getWithOauthAuth.authMethods.get(1).scopes.get(1);
1280+
final Map<String, Object> clientCredentialsProcessFlow = sortedOauthAuthMethods.get(1).scopes.get(1);
12771281
assertEquals(clientCredentialsProcessFlow.get("scope"), "something:process");
12781282
assertEquals(clientCredentialsProcessFlow.get("description"), "process from client credentials flow");
12791283
}

modules/openapi-generator/src/test/java/org/openapitools/codegen/jetbrains/http/client/JetbrainsHttpClientClientCodegenTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -387,19 +387,19 @@ public void testBasicGenerationManyAuths() throws IOException {
387387
"Accept: application/json\n" +
388388
"Authorization: Bearer {{bearerToken}}");
389389

390-
TestUtils.assertFileContains(path, "### Get payment methods\n" +
391-
"## Get payment methods\n" +
392-
"GET https://checkout-test.adyen.com/v71/paymentMethods\n" +
393-
"Accept: application/json\n" +
394-
"Authorization: Basic: {{username-password}}\n" +
390+
TestUtils.assertFileContains(path, "### Get payment methods",
391+
"## Get payment methods",
392+
"GET https://checkout-test.adyen.com/v71/paymentMethods",
393+
"Accept: application/json",
394+
"Authorization: Basic: {{username-password}}",
395395
"Authorization: Bearer {{bearerToken}}");
396396

397-
TestUtils.assertFileContains(path, "### Make a payment\n" +
398-
"## Example with a merchant account that doesn&#39;t exist\n" +
399-
"POST https://checkout-test.adyen.com/v71/payments\n" +
400-
"Content-Type: application/json\n" +
401-
"Accept: application/json\n" +
402-
"Cookie: X-API-Key={{cookieKey}}\n" +
397+
TestUtils.assertFileContains(path, "### Make a payment",
398+
"## Example with a merchant account that doesn&#39;t exist",
399+
"POST https://checkout-test.adyen.com/v71/payments",
400+
"Content-Type: application/json",
401+
"Accept: application/json",
402+
"Cookie: X-API-Key={{cookieKey}}",
403403
"Authorization: Bearer {{bearerToken}}");
404404
}
405405

0 commit comments

Comments
 (0)