Skip to content

Commit 19c41c5

Browse files
committed
fix: three nondeterministic tests
1 parent 38c6220 commit 19c41c5

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

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

Lines changed: 7 additions & 2 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

@@ -240,7 +243,7 @@ public void generateFromResponseSchemaWithAllOfComposedModel() {
240243
}
241244

242245
@Test
243-
public void generateFromResponseSchemaWithAllOfChildComposedModel() {
246+
public void generateFromResponseSchemaWithAllOfChildComposedModel() throws Exception {
244247
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/example_generator_test.yaml");
245248

246249
new InlineModelResolver().flatten(openAPI);
@@ -262,9 +265,11 @@ public void generateFromResponseSchemaWithAllOfChildComposedModel() {
262265
mediaTypeKeys
263266
);
264267

268+
ObjectMapper mapper = new ObjectMapper();
269+
265270
assertEquals(1, examples.size());
266271
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"));
272+
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")));
268273
assertEquals("200", examples.get(0).get("statusCode"));
269274
}
270275

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)