This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 10321393eff Fix Flaky Tests Caused by JSON permutations (#8875)
10321393eff is described below
commit 10321393effee154ed22fc4896fa51c01501b98c
Author: Bharati Kulkarni <[email protected]>
AuthorDate: Fri Dec 9 03:38:35 2022 -0600
Fix Flaky Tests Caused by JSON permutations (#8875)
* Fix Flaky Tests
* Removed Unused Import
* Indentation Fixed
---
.../apache/camel/component/gson/GsonFieldNamePolicyTest.java | 6 ++++--
.../apache/camel/component/gson/GsonMarshalExclusionTest.java | 11 ++++++++---
.../camel/component/gson/SpringGsonFieldNamePolicyTest.java | 6 ++++--
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git
a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonFieldNamePolicyTest.java
b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonFieldNamePolicyTest.java
index 23c616f05c5..b9355522b8c 100644
---
a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonFieldNamePolicyTest.java
+++
b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonFieldNamePolicyTest.java
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class GsonFieldNamePolicyTest extends CamelTestSupport {
@@ -44,9 +45,10 @@ public class GsonFieldNamePolicyTest extends
CamelTestSupport {
pojo.setFirstName("Donald");
pojo.setLastName("Duck");
- String expected =
"{\"id\":123,\"first_name\":\"Donald\",\"last_name\":\"Duck\"}";
String json = template.requestBody("direct:inPojo", pojo,
String.class);
- assertEquals(expected, json);
+ assertTrue(json.contains("\"id\":123"));
+ assertTrue(json.contains("\"first_name\":\"Donald\""));
+ assertTrue(json.contains("\"last_name\":\"Duck\""));
}
@Override
diff --git
a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java
b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java
index 53d56546d35..417302ddad0 100644
---
a/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java
+++
b/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java
@@ -27,7 +27,8 @@ import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class GsonMarshalExclusionTest extends CamelTestSupport {
@@ -43,7 +44,9 @@ public class GsonMarshalExclusionTest extends
CamelTestSupport {
Object marshalled = template.requestBody("direct:inPojoExcludeWeight",
in);
String marshalledAsString =
context.getTypeConverter().convertTo(String.class, marshalled);
- assertEquals("{\"age\":30,\"height\":190}", marshalledAsString);
+ assertTrue(marshalledAsString.contains("\"height\":190"));
+ assertTrue(marshalledAsString.contains("\"age\":30"));
+ assertFalse(marshalledAsString.contains("\"weight\":70"));
template.sendBody("direct:backPojoExcludeWeight", marshalled);
@@ -62,7 +65,9 @@ public class GsonMarshalExclusionTest extends
CamelTestSupport {
Object marshalled = template.requestBody("direct:inPojoExcludeAge",
in);
String marshalledAsString =
context.getTypeConverter().convertTo(String.class, marshalled);
- assertEquals("{\"height\":190,\"weight\":70}", marshalledAsString);
+ assertTrue(marshalledAsString.contains("\"height\":190"));
+ assertTrue(marshalledAsString.contains("\"weight\":70"));
+ assertFalse(marshalledAsString.contains("\"age\":30"));
template.sendBody("direct:backPojoExcludeAge", marshalled);
diff --git
a/components/camel-gson/src/test/java/org/apache/camel/component/gson/SpringGsonFieldNamePolicyTest.java
b/components/camel-gson/src/test/java/org/apache/camel/component/gson/SpringGsonFieldNamePolicyTest.java
index 5931bb9c24c..c689adfb853 100644
---
a/components/camel-gson/src/test/java/org/apache/camel/component/gson/SpringGsonFieldNamePolicyTest.java
+++
b/components/camel-gson/src/test/java/org/apache/camel/component/gson/SpringGsonFieldNamePolicyTest.java
@@ -23,6 +23,7 @@ import
org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class SpringGsonFieldNamePolicyTest extends CamelSpringTestSupport {
@@ -49,8 +50,9 @@ public class SpringGsonFieldNamePolicyTest extends
CamelSpringTestSupport {
pojo.setFirstName("Donald");
pojo.setLastName("Duck");
- String expected =
"{\"id\":123,\"first_name\":\"Donald\",\"last_name\":\"Duck\"}";
String json = template.requestBody("direct:inPojo", pojo,
String.class);
- assertEquals(expected, json);
+ assertTrue(json.contains("\"id\":123"));
+ assertTrue(json.contains("\"first_name\":\"Donald\""));
+ assertTrue(json.contains("\"last_name\":\"Duck\""));
}
}