Skip to content

Commit

Permalink
fixed 9 flaky tests in PropertySerializationTest.java: 'deserializeNo…
Browse files Browse the repository at this point in the history
…tReadOnlyStringProperty', 'deserializeIntegerMapProperty', 'serializeFloatProperty', 'deserializeDoubleProperty', 'serializeIntegerProperty', 'serializeLongProperty', 'deserializeLongProperty', 'deserializeFloatProperty', 'serializeIntegerMapProperty'
  • Loading branch information
xinying7 committed Nov 21, 2024
1 parent bc3fa15 commit 4bc815a
Showing 1 changed file with 55 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,45 +97,56 @@ public void serializeDoubleProperty() throws IOException {
String json2 = m.writeValueAsString(p);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);

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

@Test(description = "it should deserialize a DoubleProperty")
public void deserializeDoubleProperty() throws IOException {
final String json = "{\"type\":\"number\",\"format\":\"double\"}";
final Schema p = m.readValue(json, Schema.class);
final String json1 = "{\"type\":\"number\",\"format\":\"double\"}";
final Schema p = m.readValue(json1, Schema.class);
assertEquals(p.getType(), "number");
assertEquals(p.getFormat(), "double");
assertEquals(p.getClass(), NumberSchema.class);
assertEquals(m.writeValueAsString(p), json);
String json2 = m.writeValueAsString(p);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test(description = "it should serialize a FloatProperty")
public void serializeFloatProperty() throws IOException {
final NumberSchema p = new NumberSchema()
._default(new BigDecimal("1.2"));
p.format("float");
final String json = "{\"type\":\"number\",\"format\":\"float\",\"default\":1.2}";
assertEquals(m.writeValueAsString(p), json);
final String json1 = "{\"type\":\"number\",\"format\":\"float\",\"default\":1.2}";
String json2 = m.writeValueAsString(p);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test(description = "it should deserialize a FloatProperty")
public void deserializeFloatProperty() throws IOException {
final String json = "{\"type\":\"number\",\"format\":\"float\"}";
final Schema p = m.readValue(json, Schema.class);
final String json1 = "{\"type\":\"number\",\"format\":\"float\"}";
final Schema p = m.readValue(json1, Schema.class);
assertEquals(p.getType(), "number");
assertEquals(p.getFormat(), "float");
assertEquals(p.getClass(), NumberSchema.class);
assertEquals(m.writeValueAsString(p), json);
String json2 = m.writeValueAsString(p);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test(description = "it should serialize an IntegerProperty")
public void serializeIntegerProperty() throws IOException {
final IntegerSchema p = new IntegerSchema()
._default(32);
final String json = "{\"type\":\"integer\",\"format\":\"int32\",\"default\":32}";
assertEquals(m.writeValueAsString(p), json);
final String json1 = "{\"type\":\"integer\",\"format\":\"int32\",\"default\":32}";
String json2 = m.writeValueAsString(p);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test(description = "it should deserialize a IntegerProperty")
Expand All @@ -156,18 +167,24 @@ public void serializeLongProperty() throws IOException {
final IntegerSchema p = new IntegerSchema()
.format("int64")
._default(8675309);
final String json = "{\"type\":\"integer\",\"format\":\"int64\",\"default\":8675309}";
assertEquals(m.writeValueAsString(p), json);
final String json1 = "{\"type\":\"integer\",\"format\":\"int64\",\"default\":8675309}";
String json2 = m.writeValueAsString(p);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test(description = "it should deserialize a LongProperty")
public void deserializeLongProperty() throws IOException {
final String json = "{\"type\":\"integer\",\"format\":\"int64\"}";
final Schema p = m.readValue(json, Schema.class);
final String json1 = "{\"type\":\"integer\",\"format\":\"int64\"}";
final Schema p = m.readValue(json1, Schema.class);
assertEquals(p.getType(), "integer");
assertEquals(p.getFormat(), "int64");
assertEquals(p.getClass(), IntegerSchema.class);
assertEquals(m.writeValueAsString(p), json);
String json2 = m.writeValueAsString(p);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test(description = "it should serialize a string MapProperty")
Expand All @@ -189,17 +206,23 @@ public void deserializeStringMapProperty() throws IOException {
@Test(description = "it should serialize a integer MapProperty")
public void serializeIntegerMapProperty() throws IOException {
final Schema p = new MapSchema().additionalProperties(new IntegerSchema());
final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}";
assertEquals(m.writeValueAsString(p), json);
final String json1 = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}";
String json2 = m.writeValueAsString(p);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test(description = "it should deserialize a integer MapProperty")
public void deserializeIntegerMapProperty() throws IOException {
final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}";
final Schema p = m.readValue(json, Schema.class);
final String json1 = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}";
final Schema p = m.readValue(json1, Schema.class);
assertEquals(p.getType(), "object");
assertEquals(p.getClass(), MapSchema.class);
assertEquals(m.writeValueAsString(p), json);
String json2 = m.writeValueAsString(p);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test(description = "it should serialize a long MapProperty")
Expand Down Expand Up @@ -281,14 +304,17 @@ public void deserializeEnumStringProperty() throws IOException {

@Test(description = "it should deserialize an IntegerProperty with enums")
public void deserializeEnumIntegerProperty() throws IOException {
final String json = "{\"type\":\"integer\",\"format\":\"int32\",\"enum\":[1,2]}";
final Schema p = m.readValue(json, Schema.class);
final String json1 = "{\"type\":\"integer\",\"format\":\"int32\",\"enum\":[1,2]}";
final Schema p = m.readValue(json1, Schema.class);
assertEquals(p.getType(), "integer");
List<Number> _enum = ((IntegerSchema) p).getEnum();
assertNotNull(_enum);
assertEquals(_enum, Arrays.asList(1, 2));
assertEquals(p.getClass(), IntegerSchema.class);
assertEquals(m.writeValueAsString(p), json);
String json2 = m.writeValueAsString(p);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test(description = "it should serialize a string array property")
Expand Down Expand Up @@ -327,8 +353,11 @@ public void serializeReadOnlyStringProperty() throws IOException {
public void deserializeNotReadOnlyStringProperty() throws IOException {
final StringSchema p = new StringSchema();
p.setReadOnly(false);
final String json = "{\"type\":\"string\",\"readOnly\":false}";
assertEquals(m.writeValueAsString(p), json);
final String json1 = "{\"type\":\"string\",\"readOnly\":false}";
String json2 = m.writeValueAsString(p);
JSONObject jsonObj1 = new JSONObject(json1);
JSONObject jsonObj2 = new JSONObject(json2);
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
}

@Test(description = "it should serialize an object property with required set")
Expand Down

0 comments on commit 4bc815a

Please sign in to comment.