You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/07/20 15:13:23 UTC
[camel] branch main updated: CAMEL-19554 - camel-snakeyaml: ensure tests have assertions.
This is an automated email from the ASF dual-hosted git repository.
orpiske 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 2eb7f940e52 CAMEL-19554 - camel-snakeyaml: ensure tests have assertions.
2eb7f940e52 is described below
commit 2eb7f940e52b6d6776ba500b958d6a23c37a6064
Author: Vaishnavi R <va...@gmail.com>
AuthorDate: Thu Jul 20 16:44:01 2023 +0530
CAMEL-19554 - camel-snakeyaml: ensure tests have assertions.
Updated the code.
Updated the code.
---
.../component/snakeyaml/SnakeYAMLDoSTest.java | 3 +-
.../component/snakeyaml/SnakeYAMLTestHelper.java | 5 +-
.../snakeyaml/SnakeYAMLTypeFilterHelper.java | 84 +++++++++++-----------
.../snakeyaml/SnakeYAMLUnmarshalTypeTest.java | 3 +-
4 files changed, 47 insertions(+), 48 deletions(-)
diff --git a/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLDoSTest.java b/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLDoSTest.java
index 386f16cb51b..757fbabdaec 100644
--- a/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLDoSTest.java
+++ b/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLDoSTest.java
@@ -30,6 +30,7 @@ import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -46,7 +47,7 @@ public class SnakeYAMLDoSTest extends CamelTestSupport {
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream("data.yaml")) {
ProducerTemplate template = context.createProducerTemplate();
- String result = template.requestBody("direct:back", is, String.class);
+ String result = assertDoesNotThrow(() -> template.requestBody("direct:back", is, String.class));
assertNotNull(result);
assertEquals("{name=Colm, location=Dublin}", result.trim());
diff --git a/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLTestHelper.java b/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLTestHelper.java
index e6bce9de244..20eef95edff 100644
--- a/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLTestHelper.java
+++ b/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLTestHelper.java
@@ -25,6 +25,7 @@ import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.component.snakeyaml.model.TestPojo;
import org.yaml.snakeyaml.nodes.Tag;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -79,11 +80,11 @@ public final class SnakeYAMLTestHelper {
mock.message(0).body().isEqualTo(body);
ProducerTemplate template = context.createProducerTemplate();
- String result = template.requestBody(directIn, body, String.class);
+ String result = assertDoesNotThrow(() -> template.requestBody(directIn, body, String.class));
assertNotNull(result);
assertEquals(expected, result.trim());
- template.sendBody(directBack, result);
+ assertDoesNotThrow(() -> template.sendBody(directBack, result));
mock.assertIsSatisfied();
}
diff --git a/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLTypeFilterHelper.java b/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLTypeFilterHelper.java
index 64e1ca23607..cb2b6e4e9c0 100644
--- a/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLTypeFilterHelper.java
+++ b/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLTypeFilterHelper.java
@@ -23,92 +23,88 @@ import org.apache.camel.component.snakeyaml.model.TestPojo;
import org.apache.camel.component.snakeyaml.model.UnsafePojo;
import org.yaml.snakeyaml.constructor.ConstructorException;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
public final class SnakeYAMLTypeFilterHelper {
private SnakeYAMLTypeFilterHelper() {
}
static void testSafeConstructor(ProducerTemplate template) {
- try {
- template.sendBody(
- "direct:safe-constructor",
- "!!org.apache.camel.component.snakeyaml.model.TestPojo {name: Camel}");
-
- fail("As SnakeYAML uses SafeConstructor, custom types should not be allowed");
- } catch (CamelExecutionException e) {
- assertTrue(e.getCause() instanceof ConstructorException);
- }
+
+ Exception ex = assertThrows(CamelExecutionException.class,
+ () -> template.sendBody(
+ "direct:safe-constructor",
+ "!!org.apache.camel.component.snakeyaml.model.TestPojo {name: Camel}"),
+ "As SnakeYAML uses SafeConstructor, custom types should not be allowed");
+
+ assertTrue(ex.getCause() instanceof ConstructorException);
}
static void testTypeConstructor(ProducerTemplate template) {
- Object result = template.requestBody(
+ Object result = assertDoesNotThrow(() -> template.requestBody(
"direct:type-constructor",
- "!!org.apache.camel.component.snakeyaml.model.TestPojo {name: Camel}");
+ "!!org.apache.camel.component.snakeyaml.model.TestPojo {name: Camel}"));
assertNotNull(result);
assertTrue(result instanceof TestPojo);
- try {
- template.sendBody(
- "direct:type-constructor",
- "!!org.apache.camel.component.snakeyaml.model.UnsafePojo {name: Camel}");
-
- fail("As SnakeYAML filters class is can unmarshall, UnsafePojo should not be allowed");
- } catch (CamelExecutionException e) {
- // Wrapped by SnakeYAML
- assertTrue(e.getCause() instanceof ConstructorException);
- // Thrown by SnakeYAMLDataFormat
- assertTrue(e.getCause().getCause() instanceof IllegalArgumentException);
- }
+ Exception ex = assertThrows(CamelExecutionException.class,
+ () -> template.sendBody(
+ "direct:type-constructor",
+ "!!org.apache.camel.component.snakeyaml.model.UnsafePojo {name: Camel}"),
+ "As SnakeYAML filters class is can unmarshall, UnsafePojo should not be allowed");
+
+ // Wrapped by SnakeYAML
+ assertTrue(ex.getCause() instanceof ConstructorException);
+ // Thrown by SnakeYAMLDataFormat
+ assertTrue(ex.getCause().getCause() instanceof IllegalArgumentException);
}
static void testTypeConstructorFromDefinition(ProducerTemplate template) {
Object result;
// TestPojo --> from definition type:
- result = template.requestBody(
+ result = assertDoesNotThrow(() -> template.requestBody(
"direct:type-constructor-strdef",
- "!!org.apache.camel.component.snakeyaml.model.TestPojo {name: Camel}");
+ "!!org.apache.camel.component.snakeyaml.model.TestPojo {name: Camel}"));
assertNotNull(result);
assertTrue(result instanceof TestPojo);
// RexPojo --> from definition rex:
- result = template.requestBody(
+ result = assertDoesNotThrow(() -> template.requestBody(
"direct:type-constructor-strdef",
- "!!org.apache.camel.component.snakeyaml.model.RexPojo {name: Camel}");
+ "!!org.apache.camel.component.snakeyaml.model.RexPojo {name: Camel}"));
assertNotNull(result);
assertTrue(result instanceof RexPojo);
- try {
- template.sendBody(
- "direct:type-constructor-strdef",
- "!!org.apache.camel.component.snakeyaml.model.UnsafePojo {name: Camel}");
-
- fail("As SnakeYAML filters class is can unmarshall, UnsafePojo should not be allowed");
- } catch (CamelExecutionException e) {
- // Wrapped by SnakeYAML
- assertTrue(e.getCause() instanceof ConstructorException);
- // Thrown by SnakeYAMLDataFormat
- assertTrue(e.getCause().getCause() instanceof IllegalArgumentException);
- }
+ Exception ex = assertThrows(CamelExecutionException.class,
+ () -> template.sendBody(
+ "direct:type-constructor-strdef",
+ "!!org.apache.camel.component.snakeyaml.model.UnsafePojo {name: Camel}"),
+ "As SnakeYAML filters class is can unmarshall, UnsafePojo should not be allowed");
+
+ // Wrapped by SnakeYAML
+ assertTrue(ex.getCause() instanceof ConstructorException);
+ // Thrown by SnakeYAMLDataFormat
+ assertTrue(ex.getCause().getCause() instanceof IllegalArgumentException);
}
static void testAllowAllConstructor(ProducerTemplate template) {
- Object testPojo = template.requestBody(
+ Object testPojo = assertDoesNotThrow(() -> template.requestBody(
"direct:all-constructor",
- "!!org.apache.camel.component.snakeyaml.model.TestPojo {name: Camel}");
+ "!!org.apache.camel.component.snakeyaml.model.TestPojo {name: Camel}"));
assertNotNull(testPojo);
assertTrue(testPojo instanceof TestPojo);
- Object unsafePojo = template.requestBody(
+ Object unsafePojo = assertDoesNotThrow(() -> template.requestBody(
"direct:all-constructor",
- "!!org.apache.camel.component.snakeyaml.model.UnsafePojo {name: Camel}");
+ "!!org.apache.camel.component.snakeyaml.model.UnsafePojo {name: Camel}"));
assertNotNull(unsafePojo);
assertTrue(unsafePojo instanceof UnsafePojo);
diff --git a/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLUnmarshalTypeTest.java b/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLUnmarshalTypeTest.java
index c06a50a80c9..78cba9f6c90 100644
--- a/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLUnmarshalTypeTest.java
+++ b/components/camel-snakeyaml/src/test/java/org/apache/camel/component/snakeyaml/SnakeYAMLUnmarshalTypeTest.java
@@ -21,13 +21,14 @@ import org.apache.camel.component.snakeyaml.model.TestPojo;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SnakeYAMLUnmarshalTypeTest extends CamelTestSupport {
@Test
public void testUnmarshal() {
- Object result = template.requestBody("direct:unmarshal", "name: Camel");
+ Object result = assertDoesNotThrow(() -> template.requestBody("direct:unmarshal", "name: Camel"));
assertNotNull(result);
assertTrue(result instanceof TestPojo);
}