Skip to content

Commit f56c7ff

Browse files
authored
Merge pull request #144 from NanaOkada/fix-flaky
Fix 4 flaky tests in TestGenerateJsonSchema
2 parents 69d682d + 14e2c5b commit f56c7ff

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import com.fasterxml.jackson.annotation.JsonFilter;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
56
import com.fasterxml.jackson.databind.JavaType;
7+
import com.fasterxml.jackson.databind.MapperFeature;
68
import com.fasterxml.jackson.databind.ObjectMapper;
79
import com.fasterxml.jackson.databind.ser.FilterProvider;
810
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
@@ -19,6 +21,7 @@
1921
public class TestGenerateJsonSchema
2022
extends SchemaTestBase
2123
{
24+
@JsonPropertyOrder({"property1", "property2", "property3", "property4", "property5"})
2225
public static class SimpleBean
2326
{
2427
private int property1;
@@ -272,17 +275,19 @@ public void testSimpleMap() throws Exception {
272275
}
273276

274277
public void testSinglePropertyDependency() throws Exception {
275-
JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER);
278+
ObjectMapper mapper = new ObjectMapper();
279+
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
280+
JsonSchemaGenerator generator = new JsonSchemaGenerator(mapper);
276281
JsonSchema jsonSchema = generator.generateSchema(SimpleBean.class);
277282
((ObjectSchema) jsonSchema).addSimpleDependency("property1", "property2");
278283

279-
Map<String, Object> result = writeAndMap(MAPPER, jsonSchema);
284+
Map<String, Object> result = writeAndMap(mapper, jsonSchema);
280285
assertNotNull(result);
281-
282-
String schemaString = MAPPER.writeValueAsString(jsonSchema);
286+
287+
String schemaString = mapper.writeValueAsString(jsonSchema);
283288
assertEquals("{\"type\":\"object\"," +
284-
"\"id\":\"urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\"," +
285289
"\"dependencies\":{\"property1\":[\"property2\"]}," +
290+
"\"id\":\"urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\"," +
286291
"\"properties\":{\"property1\":{\"type\":\"integer\"}" +
287292
",\"property2\":{\"type\":\"string\"}," +
288293
"\"property3\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}," +
@@ -291,20 +296,22 @@ public void testSinglePropertyDependency() throws Exception {
291296
}
292297

293298
public void testMultiplePropertyDependencies() throws Exception {
294-
JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER);
299+
ObjectMapper mapper = new ObjectMapper();
300+
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
301+
JsonSchemaGenerator generator = new JsonSchemaGenerator(mapper);
295302
JsonSchema jsonSchema = generator.generateSchema(SimpleBean.class);
296303
((ObjectSchema) jsonSchema).addSimpleDependency("property1", "property2");
297304
((ObjectSchema) jsonSchema).addSimpleDependency("property1", "property3");
298305
((ObjectSchema) jsonSchema).addSimpleDependency("property1", "property2");
299306
((ObjectSchema) jsonSchema).addSimpleDependency("property2", "property3");
300307

301-
Map<String, Object> result = writeAndMap(MAPPER, jsonSchema);
308+
Map<String, Object> result = writeAndMap(mapper, jsonSchema);
302309
assertNotNull(result);
303310

304-
String schemaString = MAPPER.writeValueAsString(jsonSchema);
311+
String schemaString = mapper.writeValueAsString(jsonSchema);
305312
assertEquals("{\"type\":\"object\"," +
306-
"\"id\":\"urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\"," +
307313
"\"dependencies\":{\"property1\":[\"property2\",\"property3\"],\"property2\":[\"property3\"]}," +
314+
"\"id\":\"urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\"," +
308315
"\"properties\":{\"property1\":{\"type\":\"integer\"}" +
309316
",\"property2\":{\"type\":\"string\"}," +
310317
"\"property3\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}," +
@@ -313,7 +320,9 @@ public void testMultiplePropertyDependencies() throws Exception {
313320
}
314321

315322
public void testSchemaPropertyDependency() throws Exception {
316-
JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER);
323+
ObjectMapper mapper = new ObjectMapper();
324+
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
325+
JsonSchemaGenerator generator = new JsonSchemaGenerator(mapper);
317326

318327
// Given this dependency schema
319328
JsonSchema schemaPropertyDependency = generator.generateSchema(DependencySchema.class);
@@ -322,14 +331,14 @@ public void testSchemaPropertyDependency() throws Exception {
322331
JsonSchema simpleBeanSchema = generator.generateSchema(SimpleBean.class);
323332
((ObjectSchema) simpleBeanSchema).addSchemaDependency("property1", schemaPropertyDependency);
324333

325-
Map<String, Object> result = writeAndMap(MAPPER, simpleBeanSchema);
334+
Map<String, Object> result = writeAndMap(mapper, simpleBeanSchema);
326335
assertNotNull(result);
327336

328337
// Test the generated value.
329-
String schemaString = MAPPER.writeValueAsString(simpleBeanSchema);
338+
String schemaString = mapper.writeValueAsString(simpleBeanSchema);
330339
assertEquals("{\"type\":\"object\"," +
331-
"\"id\":\"urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\"," +
332340
"\"dependencies\":{\"property1\":{\"id\":\"urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:DependencySchema\",\"properties\":{\"property2\":{\"type\":\"string\",\"required\":true}}}}," +
341+
"\"id\":\"urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\"," +
333342
"\"properties\":{\"property1\":{\"type\":\"integer\"}" +
334343
",\"property2\":{\"type\":\"string\"}," +
335344
"\"property3\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}," +
@@ -338,7 +347,9 @@ public void testSchemaPropertyDependency() throws Exception {
338347
}
339348

340349
public void testSchemaPropertyDependencies() throws Exception {
341-
JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER);
350+
ObjectMapper mapper = new ObjectMapper();
351+
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
352+
JsonSchemaGenerator generator = new JsonSchemaGenerator(mapper);
342353

343354
// Given this dependency schema
344355
JsonSchema schemaPropertyDependency = generator.generateSchema(DependencySchema.class);
@@ -348,18 +359,18 @@ public void testSchemaPropertyDependencies() throws Exception {
348359
((ObjectSchema) simpleBeanSchema).addSchemaDependency("property1", schemaPropertyDependency);
349360
((ObjectSchema) simpleBeanSchema).addSchemaDependency("property3", schemaPropertyDependency);
350361

351-
Map<String, Object> result = writeAndMap(MAPPER, simpleBeanSchema);
362+
Map<String, Object> result = writeAndMap(mapper, simpleBeanSchema);
352363
assertNotNull(result);
353364

354365
// Test the generated value.
355-
String schemaString = MAPPER.writeValueAsString(simpleBeanSchema);
366+
String schemaString = mapper.writeValueAsString(simpleBeanSchema);
356367
assertEquals(
357368
"{" +
358369
"\"type\":\"object\"," +
359-
"\"id\":\"urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\"," +
360370
"\"dependencies\":{" +
361371
"\"property1\":{\"id\":\"urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:DependencySchema\",\"properties\":{\"property2\":{\"type\":\"string\",\"required\":true}}}," +
362372
"\"property3\":{\"id\":\"urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:DependencySchema\",\"properties\":{\"property2\":{\"type\":\"string\",\"required\":true}}}}," +
373+
"\"id\":\"urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\"," +
363374
"\"properties\":{" +
364375
"\"property1\":{\"type\":\"integer\"}" +
365376
",\"property2\":{\"type\":\"string\"}," +

0 commit comments

Comments
 (0)