You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2020/06/24 20:12:30 UTC
[camel] 01/13: [CAMEL-11807] Upgrade camel-exec to junit5
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7a859abb9872a968ed78334698c3ec6f23e7f0a7
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Wed Jun 24 13:24:30 2020 +0200
[CAMEL-11807] Upgrade camel-exec to junit5
---
components/camel-exec/pom.xml | 6 ++--
.../camel/component/exec/ExecDefaultExecutor.java | 2 +-
.../exec/impl/DefaultExecCommandExecutor.java | 2 +-
.../component/exec/DefaultExecBindingTest.java | 15 +++++----
.../camel/component/exec/ExecEndpointTest.java | 35 +++++++++++---------
.../camel/component/exec/ExecJava8IssueTest.java | 16 +++++----
.../exec/ExecJavaProcessRecipientListTest.java | 17 ++++++----
.../camel/component/exec/ExecJavaProcessTest.java | 24 ++++++++------
.../camel/component/exec/ExecOutFileTest.java | 19 ++++++-----
.../camel/component/exec/ExecProducerTest.java | 13 ++++----
.../camel/component/exec/ExecScriptTest.java | 27 ++++++++-------
.../exec/impl/ExecDocumentationExamplesTest.java | 38 +++++++++++++---------
.../component/exec/impl/ExecParseUtilsTest.java | 19 ++++++-----
13 files changed, 133 insertions(+), 100 deletions(-)
diff --git a/components/camel-exec/pom.xml b/components/camel-exec/pom.xml
index 24cfc08..dc175d9 100644
--- a/components/camel-exec/pom.xml
+++ b/components/camel-exec/pom.xml
@@ -53,7 +53,7 @@
<!-- test scope -->
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-test-spring</artifactId>
+ <artifactId>camel-test-spring-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -62,8 +62,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecDefaultExecutor.java b/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecDefaultExecutor.java
index e731588..bc6ab8b4 100644
--- a/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecDefaultExecutor.java
+++ b/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecDefaultExecutor.java
@@ -41,7 +41,7 @@ public class ExecDefaultExecutor extends DefaultExecutor {
try {
return process.exitValue();
} catch (IllegalThreadStateException e) {
- // ignore the process is alive
+ // Disabled the process is alive
}
}
return 0;
diff --git a/components/camel-exec/src/main/java/org/apache/camel/component/exec/impl/DefaultExecCommandExecutor.java b/components/camel-exec/src/main/java/org/apache/camel/component/exec/impl/DefaultExecCommandExecutor.java
index d84ff2a..0254d04 100644
--- a/components/camel-exec/src/main/java/org/apache/camel/component/exec/impl/DefaultExecCommandExecutor.java
+++ b/components/camel-exec/src/main/java/org/apache/camel/component/exec/impl/DefaultExecCommandExecutor.java
@@ -94,7 +94,7 @@ public class DefaultExecCommandExecutor implements ExecCommandExecutor {
exitValue = ((ExecDefaultExecutor) executor).getExitValue();
}
- // workaround to ignore if the stream was already closes due some race condition in commons-exec
+ // workaround to Disabled if the stream was already closes due some race condition in commons-exec
String msg = ioe.getMessage();
if (msg != null && "stream closed".equals(msg.toLowerCase(Locale.ENGLISH))) {
LOG.debug("Ignoring Stream closed IOException", ioe);
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/DefaultExecBindingTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/DefaultExecBindingTest.java
index 45a6a51..fdc9671 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/DefaultExecBindingTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/DefaultExecBindingTest.java
@@ -23,25 +23,26 @@ import java.util.List;
import org.apache.camel.Component;
import org.apache.camel.Exchange;
import org.apache.camel.component.exec.impl.DefaultExecBinding;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Assert;
-import org.junit.Test;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class DefaultExecBindingTest extends CamelTestSupport {
@Test
public void testReadInput() throws Exception {
ExecCommand command = readInput("exec:test", Collections.EMPTY_LIST);
- Assert.assertEquals("Get a wrong args.", Collections.EMPTY_LIST, command.getArgs());
+ assertEquals(Collections.EMPTY_LIST, command.getArgs(), "Get a wrong args.");
List<String> args = Arrays.asList("arg1", "arg2");
command = readInput("exec:test", args);
- assertEquals("Get a wrong args.", args, command.getArgs());
+ assertEquals(args, command.getArgs(), "Get a wrong args.");
command = readInput("exec:test", "arg1 arg2");
- assertEquals("Get a wrong args.", args, command.getArgs());
+ assertEquals(args, command.getArgs(), "Get a wrong args.");
command = readInput("exec:test?args=arg1 arg2", null);
- assertEquals("Get a wrong args.", args, command.getArgs());
+ assertEquals(args, command.getArgs(), "Get a wrong args.");
}
private ExecCommand readInput(String execEndpointUri, Object args) throws Exception {
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecEndpointTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecEndpointTest.java
index d8199a8..008aa5e 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecEndpointTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecEndpointTest.java
@@ -18,26 +18,31 @@ package org.apache.camel.component.exec;
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
+import org.apache.camel.test.spring.junit5.CamelSpringTest;
import org.apache.camel.util.UnsafeUriCharactersEncoder;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static org.apache.camel.component.exec.ExecEndpoint.NO_TIMEOUT;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test the configuration of {@link ExecEndpoint}
*/
+@CamelSpringTest
@ContextConfiguration
-public class ExecEndpointTest extends AbstractJUnit4SpringContextTests {
+public class ExecEndpointTest {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ExecEndpointTest.class);
@Autowired
private CamelContext camelContext;
@@ -50,7 +55,7 @@ public class ExecEndpointTest extends AbstractJUnit4SpringContextTests {
private Component component;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
component = camelContext.getComponent("exec");
}
@@ -58,14 +63,14 @@ public class ExecEndpointTest extends AbstractJUnit4SpringContextTests {
@Test
@DirtiesContext
public void testValidComponentDescriptor() {
- assertNotNull("The Camel Exec component can not be resolved", component);
+ assertNotNull(component, "The Camel Exec component can not be resolved");
}
@Test
@DirtiesContext
public void testCreateEndpointDefaultConf() throws Exception {
ExecEndpoint e = createExecEndpoint("exec:test");
- assertTrue("The Camel Exec component must create instances of " + ExecEndpoint.class.getSimpleName(), e instanceof ExecEndpoint);
+ assertTrue(e instanceof ExecEndpoint, "The Camel Exec component must create instances of " + ExecEndpoint.class.getSimpleName());
assertNull(e.getArgs());
assertNull(e.getWorkingDir());
assertNull(e.getOutFile());
@@ -86,14 +91,14 @@ public class ExecEndpointTest extends AbstractJUnit4SpringContextTests {
@DirtiesContext
public void testCreateEndpointCustomBinding() throws Exception {
ExecEndpoint e = createExecEndpoint("exec:test?binding=#customBinding");
- assertSame("Expected is the custom customBinding reference from the application context", customBinding, e.getBinding());
+ assertSame(customBinding, e.getBinding(), "Expected is the custom customBinding reference from the application context");
}
@Test
@DirtiesContext
public void testCreateEndpointCustomCommandExecutor() throws Exception {
ExecEndpoint e = createExecEndpoint("exec:test?commandExecutor=#customExecutor");
- assertSame("Expected is the custom customExecutor reference from the application context", customExecutor, e.getCommandExecutor());
+ assertSame(customExecutor, e.getCommandExecutor(), "Expected is the custom customExecutor reference from the application context");
}
@Test
@@ -208,7 +213,7 @@ public class ExecEndpointTest extends AbstractJUnit4SpringContextTests {
}
private ExecEndpoint createExecEndpoint(String uri) throws Exception {
- logger.debug("Using Exec endpoint URI " + uri);
+ LOGGER.debug("Using Exec endpoint URI " + uri);
return (ExecEndpoint)component.createEndpoint(uri);
}
}
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJava8IssueTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJava8IssueTest.java
index eecd183..593bcb6 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJava8IssueTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJava8IssueTest.java
@@ -29,22 +29,24 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.commons.exec.OS;
import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Test to duplicate issues with Camel's exec command in Java 8 on Unix
* This issue appears to be caused by a race condition, so this test does not always fail
*/
-public class ExecJava8IssueTest extends Assert {
+public class ExecJava8IssueTest {
private File tempDir;
private final String tempDirName = name();
private final String tempFileName = name();
- @Before
+ @BeforeEach
public void setUp() {
tempDir = new File("target", tempDirName);
if (!(tempDir.mkdir())) {
@@ -52,7 +54,7 @@ public class ExecJava8IssueTest extends Assert {
}
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
FileUtils.deleteDirectory(tempDir);
}
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessRecipientListTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessRecipientListTest.java
index d1caa98..163a3f2 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessRecipientListTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessRecipientListTest.java
@@ -28,9 +28,9 @@ import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.test.junit5.CamelTestSupport;
import org.apache.commons.io.IOUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_ARGS;
import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_EXECUTABLE;
@@ -48,6 +48,9 @@ import static org.apache.camel.component.exec.ExecutableJavaProgram.READ_INPUT_L
import static org.apache.camel.component.exec.ExecutableJavaProgram.SLEEP_WITH_TIMEOUT;
import static org.apache.camel.component.exec.ExecutableJavaProgram.THREADS;
import static org.apache.commons.io.IOUtils.LINE_SEPARATOR;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Tests the functionality of the {@link org.apache.camel.component.exec.ExecComponent}, executing<br>
@@ -145,8 +148,8 @@ public class ExecJavaProcessRecipientListTest extends CamelTestSupport {
ExecResult body = e.getIn().getBody(ExecResult.class);
output.assertIsSatisfied();
- assertNull("the test executable must not print anything in stdout", body.getStdout());
- assertNotNull("the test executable must print in stderr", body.getStderr());
+ assertNull(body.getStdout(), "the test executable must not print anything in stdout");
+ assertNotNull(body.getStderr(), "the test executable must print in stderr");
// the converter must fall back to the stderr, because stdout is null
String stderr = e.getIn().getBody(String.class);
assertEquals(PRINT_IN_STDERR, stderr);
@@ -162,11 +165,11 @@ public class ExecJavaProcessRecipientListTest extends CamelTestSupport {
ExecResult body = e.getIn().getBody(ExecResult.class);
output.assertIsSatisfied();
- assertNull("the test executable must not print anything in stdout", body.getStdout());
- assertNotNull("the test executable must print in stderr", body.getStderr());
+ assertNull(body.getStdout(), "the test executable must not print anything in stdout");
+ assertNotNull(body.getStderr(), "the test executable must print in stderr");
// the converter must fall back to the stderr, because stdout is null
String out = e.getIn().getBody(String.class);
- assertEquals("Should be empty", "", out);
+ assertEquals("", out, "Should be empty");
}
@Test
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
index 059453c..fd096a2 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
@@ -33,9 +33,9 @@ import org.apache.camel.component.exec.impl.ProvokeExceptionExecCommandExecutor;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.converter.IOConverter;
import org.apache.camel.reifier.RouteReifier;
-import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.test.junit5.CamelTestSupport;
import org.apache.commons.io.IOUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_ARGS;
import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_EXECUTABLE;
@@ -55,6 +55,10 @@ import static org.apache.camel.component.exec.ExecutableJavaProgram.READ_INPUT_L
import static org.apache.camel.component.exec.ExecutableJavaProgram.SLEEP_WITH_TIMEOUT;
import static org.apache.camel.component.exec.ExecutableJavaProgram.THREADS;
import static org.apache.commons.io.IOUtils.LINE_SEPARATOR;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests the functionality of the {@link ExecComponent}, executing<br>
@@ -164,8 +168,8 @@ public class ExecJavaProcessTest extends CamelTestSupport {
ExecResult body = e.getIn().getBody(ExecResult.class);
output.assertIsSatisfied();
- assertNull("the test executable must not print anything in stdout", body.getStdout());
- assertNotNull("the test executable must print in stderr", body.getStderr());
+ assertNull(body.getStdout(), "the test executable must not print anything in stdout");
+ assertNotNull(body.getStderr(), "the test executable must print in stderr");
// the converter must fall back to the stderr, because stdout is null
String stderr = e.getIn().getBody(String.class);
assertEquals(PRINT_IN_STDERR, stderr);
@@ -183,11 +187,11 @@ public class ExecJavaProcessTest extends CamelTestSupport {
ExecResult body = e.getIn().getBody(ExecResult.class);
output.assertIsSatisfied();
- assertNull("the test executable must not print anything in stdout", body.getStdout());
- assertNotNull("the test executable must print in stderr", body.getStderr());
+ assertNull(body.getStdout(), "the test executable must not print anything in stdout");
+ assertNotNull(body.getStderr(), "the test executable must print in stderr");
// the converter must fall back to the stderr, because stdout is null
String out = e.getIn().getBody(String.class);
- assertEquals("Should be empty", "", out);
+ assertEquals("", out, "Should be empty");
}
@Test
@@ -318,7 +322,7 @@ public class ExecJavaProcessTest extends CamelTestSupport {
assertNotNull(result);
String out = IOConverter.toString(result.getStdout(), exchange);
- assertTrue(out, out.contains("1Hello World"));
+ assertTrue(out.contains("1Hello World"), out);
}
/**
@@ -351,8 +355,8 @@ public class ExecJavaProcessTest extends CamelTestSupport {
assertNotNull(result);
String out = IOConverter.toString(result.getStdout(), exchange);
- assertTrue(out, out.contains("1Hello"));
- assertTrue(out, out.contains("2World"));
+ assertTrue(out.contains("1Hello"), out);
+ assertTrue(out.contains("2World"), out);
}
/**
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java
index 1f2ce43..fcd40c4 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java
@@ -27,22 +27,23 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
+import org.apache.camel.test.spring.junit5.CamelSpringTest;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_OUT_FILE;
import static org.apache.commons.io.IOUtils.LINE_SEPARATOR;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+@CamelSpringTest
@ContextConfiguration(locations = {"exec-mock-executor-context.xml"})
-public class ExecOutFileTest extends AbstractJUnit4SpringContextTests {
+public class ExecOutFileTest {
private static final String FILE_CONTENT = buildFileContent();
@@ -51,13 +52,13 @@ public class ExecOutFileTest extends AbstractJUnit4SpringContextTests {
@Produce("direct:input")
private ProducerTemplate producerTemplate;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
FILE.createNewFile();
FileUtils.writeStringToFile(FILE, FILE_CONTENT, Charset.defaultCharset());
}
- @After
+ @AfterEach
public void tearDown() {
FileUtils.deleteQuietly(FILE);
}
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java
index 9cc1f0e..7011eea 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java
@@ -27,27 +27,28 @@ import org.apache.camel.Processor;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.exec.impl.ExecCommandExecutorMock;
+import org.apache.camel.test.spring.junit5.CamelSpringTest;
import org.apache.commons.io.IOUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_ARGS;
import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_EXECUTABLE;
import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_TIMEOUT;
import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_WORKING_DIR;
import static org.apache.commons.io.IOUtils.LINE_SEPARATOR;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Test the functionality of {@link ExecProducer}
*/
+@CamelSpringTest
@ContextConfiguration(locations = {"exec-mock-executor-context.xml"})
-public class ExecProducerTest extends AbstractJUnit4SpringContextTests {
+public class ExecProducerTest {
@Produce("direct:input")
private ProducerTemplate producerTemplate;
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecScriptTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecScriptTest.java
index c6c9711..8760dce 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecScriptTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecScriptTest.java
@@ -22,12 +22,14 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
+import org.apache.camel.test.spring.junit5.CamelSpringTest;
import org.apache.commons.exec.OS;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_ARGS;
import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_EXECUTABLE;
@@ -36,21 +38,24 @@ import static org.apache.camel.component.exec.ExecBinding.EXEC_STDERR;
import static org.apache.camel.component.exec.ExecEndpoint.NO_TIMEOUT;
import static org.apache.camel.component.exec.ExecTestUtils.getClasspathResourceFileOrNull;
import static org.apache.camel.component.exec.ExecutableJavaProgram.PRINT_IN_STDOUT;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test executing a OS script. Use only manually, see the TODO
*/
+@CamelSpringTest
@ContextConfiguration
-public class ExecScriptTest extends AbstractJUnit4SpringContextTests {
+public class ExecScriptTest {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ExecScriptTest.class);
@Produce("direct:input")
private ProducerTemplate producerTemplate;
/**
- * TODO <b>the test is ignored for now to prevent accidental build
+ * TODO <b>the test is Disabledd for now to prevent accidental build
* failures.</b> Java 1.5 does not offer a method to check if a file is
* executable there is only a canRead method, which is not enough to
* guarantee that the script can be executed. <br>
@@ -59,7 +64,7 @@ public class ExecScriptTest extends AbstractJUnit4SpringContextTests {
*/
@Test
@DirtiesContext
- @Ignore
+ @Disabled
public void testExecuteScript() throws Exception {
File scriptFile = getExecScriptFileOrNull("exec-test-script");
if (scriptFile != null) {
@@ -75,7 +80,7 @@ public class ExecScriptTest extends AbstractJUnit4SpringContextTests {
}
} else {
String os = System.getProperty("os.name");
- logger.warn("Executing batch scripts is not tested on " + os);
+ LOGGER.warn("Executing batch scripts is not tested on " + os);
}
}
@@ -122,7 +127,7 @@ public class ExecScriptTest extends AbstractJUnit4SpringContextTests {
File resourceFile = getClasspathResourceFileOrNull(resource);
// TODO use canExecute here (available since java 1.6)
if (resourceFile != null && !resourceFile.canRead()) {
- logger.warn("The resource " + resourceFile.getAbsolutePath() + " is not readable!");
+ LOGGER.warn("The resource " + resourceFile.getAbsolutePath() + " is not readable!");
// it is not readable, do not try to execute it
return null;
}
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecDocumentationExamplesTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecDocumentationExamplesTest.java
index 8f728f5..f6bfb62 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecDocumentationExamplesTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecDocumentationExamplesTest.java
@@ -26,16 +26,22 @@ import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.exec.ExecResult;
-import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.test.junit5.CamelTestSupport;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import static org.apache.camel.component.exec.ExecTestUtils.buildJavaExecutablePath;
+import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
- * The tests are ignored by default, because they are OS-specific. On demand
+ * The tests are Disabledd by default, because they are OS-specific. On demand
* they can be run manually to validate the documentation examples for that OS.
*/
@@ -48,6 +54,8 @@ public class ExecDocumentationExamplesTest extends CamelTestSupport {
private static final String ANT_BUILD_FILE_CONTENT = buildAntFileContent();
private static final String TEST_MSG = "Hello Camel Exec!";
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ExecDocumentationExamplesTest.class);
@Produce("direct:javaVersion")
protected ProducerTemplate templateJavaVersion;
@@ -65,7 +73,7 @@ public class ExecDocumentationExamplesTest extends CamelTestSupport {
protected ProducerTemplate templateWordCount;
@Test
- @Ignore
+ @Disabled
public void testExecLinuxWordCount() throws Exception {
// use type conversion here
ExecResult body = templateWordCount.requestBody((Object)"test", ExecResult.class);
@@ -77,7 +85,7 @@ public class ExecDocumentationExamplesTest extends CamelTestSupport {
* The test assumes, that java is in the system path
*/
@Test
- @Ignore
+ @Disabled
public void testJavaVersion() throws Exception {
ExecResult body = templateJavaVersion.requestBody((Object)"test", ExecResult.class);
InputStream out = body.getStdout();
@@ -86,12 +94,12 @@ public class ExecDocumentationExamplesTest extends CamelTestSupport {
assertNull(out);
assertNotNull(err);
String outString = IOUtils.toString(err, Charset.defaultCharset());
- log.info("Received stdout: " + outString);
+ LOGGER.info("Received stdout: " + outString);
assertTrue(outString.contains("java version"));
}
@Test
- @Ignore
+ @Disabled
public void testWinJavaVersionWorkingDir() throws Exception {
ExecResult body = templateJavaVersionWorkingDir.requestBody((Object)"test", ExecResult.class);
InputStream out = body.getStdout();
@@ -100,7 +108,7 @@ public class ExecDocumentationExamplesTest extends CamelTestSupport {
assertNull(out);
assertNotNull(err);
String outerr = IOUtils.toString(err, Charset.defaultCharset());
- log.info("Received stderr: " + outerr);
+ LOGGER.info("Received stderr: " + outerr);
assertTrue(outerr.contains("java version"));
}
@@ -108,16 +116,16 @@ public class ExecDocumentationExamplesTest extends CamelTestSupport {
* The test assumes that Apache ant is installed
*/
@Test
- @Ignore
+ @Disabled
public void testExecWinAnt() throws Exception {
File f = new File(ANT_BUILD_FILE_NAME);
f.createNewFile();
FileUtils.writeStringToFile(f, ANT_BUILD_FILE_CONTENT, Charset.defaultCharset());
- assertTrue("You must create a sample build file!", f.exists());
+ assertTrue(f.exists(), "You must create a sample build file!");
ExecResult body = templateExecAnt.requestBody((Object)"test", ExecResult.class);
String stdout = IOUtils.toString(body.getStdout(), Charset.defaultCharset());
assertNull(body.getStderr());
- assertTrue("The ant script should print" + TEST_MSG, stdout.contains(TEST_MSG));
+ assertTrue(stdout.contains(TEST_MSG), "The ant script should print" + TEST_MSG);
f.delete();
}
@@ -125,16 +133,16 @@ public class ExecDocumentationExamplesTest extends CamelTestSupport {
* The test assumes that Apache ant is installed
*/
@Test
- @Ignore
+ @Disabled
public void testExecWinAntWithOutFile() throws Exception {
File f = new File(ANT_BUILD_FILE_NAME);
f.createNewFile();
FileUtils.writeStringToFile(f, ANT_BUILD_FILE_CONTENT, Charset.defaultCharset());
- assertTrue("You must create a sample build file!", f.exists());
+ assertTrue(f.exists(), "You must create a sample build file!");
// use type conversion here
InputStream body = templateExecAntWithOutFile.requestBody((Object)"test", InputStream.class);
String bodyString = IOUtils.toString(body, Charset.defaultCharset());
- assertTrue("The ant script should print" + TEST_MSG, bodyString.contains(TEST_MSG));
+ assertTrue(bodyString.contains(TEST_MSG), "The ant script should print" + TEST_MSG);
f.delete();
}
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecParseUtilsTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecParseUtilsTest.java
index 7cb1c82..6b8b100 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecParseUtilsTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecParseUtilsTest.java
@@ -18,14 +18,15 @@ package org.apache.camel.component.exec.impl;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static org.apache.camel.component.exec.impl.ExecParseUtils.isDoubleQuoted;
import static org.apache.camel.component.exec.impl.ExecParseUtils.isSingleQuoted;
import static org.apache.camel.component.exec.impl.ExecParseUtils.splitToWhiteSpaceSeparatedTokens;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests for {@link ExecParseUtils}
@@ -126,13 +127,15 @@ public class ExecParseUtilsTest {
assertEquals("\"arg1\"", args.get(1));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testWhiteSpaceSeparatedArgsNotClosed() {
- splitToWhiteSpaceSeparatedTokens("arg 0 \" arg1 \"arg 2\"");
+ assertThrows(IllegalArgumentException.class,
+ () -> splitToWhiteSpaceSeparatedTokens("arg 0 \" arg1 \"arg 2\""));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testInvalidQuotes() {
- splitToWhiteSpaceSeparatedTokens("\"\"arg 0 \" arg1 \"arg 2\"");
+ assertThrows(IllegalArgumentException.class,
+ () -> splitToWhiteSpaceSeparatedTokens("\"\"arg 0 \" arg1 \"arg 2\""));
}
}