You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2018/10/26 08:38:09 UTC
[camel-k] 02/03: chore(test) : switch to junit 5
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 25227daafe823f6b3b3d54a3fb550347a8b45df7
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Sat Oct 20 15:24:18 2018 +0200
chore(test) : switch to junit 5
---
runtime/groovy/pom.xml | 14 ++++++++---
.../k/groovy/dsl/ComponentConfiguration.groovy | 16 +++++--------
.../k/groovy/dsl/ComponentsConfiguration.groovy | 20 ++++++++--------
.../org/apache/camel/k/groovy/helper/Runner.groovy | 28 ----------------------
runtime/groovy/src/test/resources/log4j2-test.xml | 6 ++---
runtime/jvm/pom.xml | 13 +++++++---
.../org/apache/camel/k/jvm/PropertiesTest.java | 2 +-
.../org/apache/camel/k/jvm/RoutesLoadersTest.java | 22 ++++++++++-------
runtime/jvm/src/test/resources/log4j2-test.xml | 6 ++---
9 files changed, 56 insertions(+), 71 deletions(-)
diff --git a/runtime/groovy/pom.xml b/runtime/groovy/pom.xml
index 59c7db5..681bab2 100644
--- a/runtime/groovy/pom.xml
+++ b/runtime/groovy/pom.xml
@@ -70,13 +70,21 @@
</exclusion>
</exclusions>
</dependency>
+
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <version>${junit-jupiter.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
diff --git a/runtime/groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/ComponentConfiguration.groovy b/runtime/groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/ComponentConfiguration.groovy
index 33aea0b..2454e72 100644
--- a/runtime/groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/ComponentConfiguration.groovy
+++ b/runtime/groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/ComponentConfiguration.groovy
@@ -16,11 +16,8 @@
*/
package org.apache.camel.k.groovy.dsl
-
import org.apache.camel.util.IntrospectionSupport
-import java.lang.reflect.Array
-
class ComponentConfiguration {
private final org.apache.camel.Component component
@@ -28,15 +25,14 @@ class ComponentConfiguration {
this.component = component
}
- def methodMissing(String name, args) {
+ def methodMissing(String name, arguments) {
final Object value
+ final Object[] args = arguments as Object[]
if (args == null) {
value = null
- } else if (!args.getClass().isArray()) {
- value = args
- } else if (Array.getLength(args) == 1) {
- value = Array.get(args, 0)
+ } else if (args.length == 1) {
+ value = args[0]
} else {
throw new IllegalArgumentException("Unable to set property \"" + name + "\" on component \"" + name + "\"")
}
@@ -52,13 +48,13 @@ class ComponentConfiguration {
}
if (!IntrospectionSupport.setProperty(component, name, value, true)) {
- throw new MissingMethodException("Missing method \"" + name + "\" on component: \"" + this.component.class.name + "\"")
+ throw new MissingMethodException(name, this.component.class, args as Object[])
}
}
def propertyMissing(String name, value) {
if (!IntrospectionSupport.setProperty(component, name, value, true)) {
- throw new MissingMethodException("Missing method \"" + name + "\" on component: \"" + this.component.class.name + "\"")
+ throw new MissingMethodException(name, this.component.class, value)
}
}
diff --git a/runtime/groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/ComponentsConfiguration.groovy b/runtime/groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/ComponentsConfiguration.groovy
index 7bf0f93..3c6cca6 100644
--- a/runtime/groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/ComponentsConfiguration.groovy
+++ b/runtime/groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/ComponentsConfiguration.groovy
@@ -19,8 +19,6 @@ package org.apache.camel.k.groovy.dsl
import org.apache.camel.CamelContext
import org.apache.camel.Component
-import java.lang.reflect.Array
-
class ComponentsConfiguration {
private final CamelContext context
@@ -60,18 +58,20 @@ class ComponentsConfiguration {
throw new IllegalArgumentException("Type mismatch, expected: " + type + ", got: " + component.class)
}
- def methodMissing(String name, args) {
- if (args != null && args.getClass().isArray()) {
- if (Array.getLength(args) == 1) {
- def clos = Array.get(args, 0)
+ def methodMissing(String name, arguments) {
+ final Object[] args = arguments as Object[]
+
+ if (args != null) {
+ if (args.length == 1) {
+ def clos = args[0]
if (clos instanceof Closure) {
return component(name, clos)
}
}
- if (Array.getLength(args) == 2) {
- def type = Array.get(args, 0)
- def clos = Array.get(args, 1)
+ if (args.length == 2) {
+ def type = args[0]
+ def clos = args[1]
if (type instanceof Class && Component.class.isAssignableFrom(type) && clos instanceof Closure) {
return component(name,type, clos)
@@ -79,6 +79,6 @@ class ComponentsConfiguration {
}
}
- throw new MissingMethodException("Missing method: \"$name\", args: $args")
+ throw new MissingMethodException(name, this, args)
}
}
diff --git a/runtime/groovy/src/test/groovy/org/apache/camel/k/groovy/helper/Runner.groovy b/runtime/groovy/src/test/groovy/org/apache/camel/k/groovy/helper/Runner.groovy
deleted file mode 100644
index 8376c29..0000000
--- a/runtime/groovy/src/test/groovy/org/apache/camel/k/groovy/helper/Runner.groovy
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License") you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.k.groovy.helper
-
-import org.apache.camel.k.jvm.Runtime
-
-class Runner {
- static void main(args) {
- def runtime = new Runtime()
- runtime.setDuration(5)
- runtime.load('classpath:routes-with-component-configuration.groovy', null)
- runtime.run()
- }
-}
diff --git a/runtime/groovy/src/test/resources/log4j2-test.xml b/runtime/groovy/src/test/resources/log4j2-test.xml
index 9d4c35b..84d2957 100644
--- a/runtime/groovy/src/test/resources/log4j2-test.xml
+++ b/runtime/groovy/src/test/resources/log4j2-test.xml
@@ -4,16 +4,14 @@
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c{1} - %msg%n"/>
</Console>
- <File name="FILE" fileName="target/camel-k-runtime-groovy-test.log">
- <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c{1} - %msg%n"/>
- </File>
+ <Null name="NONE"/>
</Appenders>
<Loggers>
<Root level="INFO">
<!--<AppenderRef ref="STDOUT"/>-->
- <AppenderRef ref="FILE"/>
+ <AppenderRef ref="NONE"/>
</Root>
</Loggers>
diff --git a/runtime/jvm/pom.xml b/runtime/jvm/pom.xml
index bab10eb..cf87fb1 100644
--- a/runtime/jvm/pom.xml
+++ b/runtime/jvm/pom.xml
@@ -84,12 +84,19 @@
<!-- ****************************** -->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <version>${junit-jupiter.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
diff --git a/runtime/jvm/src/test/java/org/apache/camel/k/jvm/PropertiesTest.java b/runtime/jvm/src/test/java/org/apache/camel/k/jvm/PropertiesTest.java
index ddca7a7..ffb727e 100644
--- a/runtime/jvm/src/test/java/org/apache/camel/k/jvm/PropertiesTest.java
+++ b/runtime/jvm/src/test/java/org/apache/camel/k/jvm/PropertiesTest.java
@@ -22,7 +22,7 @@ import org.apache.camel.CamelContext;
import org.apache.camel.component.seda.SedaComponent;
import org.apache.camel.main.MainListenerSupport;
import org.apache.camel.main.MainSupport;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
diff --git a/runtime/jvm/src/test/java/org/apache/camel/k/jvm/RoutesLoadersTest.java b/runtime/jvm/src/test/java/org/apache/camel/k/jvm/RoutesLoadersTest.java
index c58f2a4..328aaf3 100644
--- a/runtime/jvm/src/test/java/org/apache/camel/k/jvm/RoutesLoadersTest.java
+++ b/runtime/jvm/src/test/java/org/apache/camel/k/jvm/RoutesLoadersTest.java
@@ -21,9 +21,10 @@ import java.util.List;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ToDefinition;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
public class RoutesLoadersTest {
@@ -112,22 +113,27 @@ public class RoutesLoadersTest {
assertThat(routes.get(0).getOutputs().get(0)).isInstanceOf(ToDefinition.class);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testResourceWithoutScheme() {
- RoutesLoaders.loaderFor("routes.js", null);
+ assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
+ () -> RoutesLoaders.loaderFor("routes.js", null)
+ );
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testResourceWithIllegalScheme() {
- RoutesLoaders.loaderFor("http:routes.js", null);
+ assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
+ () -> RoutesLoaders.loaderFor("http:routes.js", null)
+ );
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testUnsupportedLanguage() {
- RoutesLoaders.loaderFor(" test", null);
+ assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
+ () -> RoutesLoaders.loaderFor(" test", null)
+ );
}
-
public static class MyRoutes extends RouteBuilder {
@Override
public void configure() throws Exception {
diff --git a/runtime/jvm/src/test/resources/log4j2-test.xml b/runtime/jvm/src/test/resources/log4j2-test.xml
index 619c63a..9af8521 100644
--- a/runtime/jvm/src/test/resources/log4j2-test.xml
+++ b/runtime/jvm/src/test/resources/log4j2-test.xml
@@ -4,15 +4,13 @@
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c{1} - %msg%n"/>
</Console>
- <File name="FILE" fileName="target/camel-k-runtime-jmv-test.log">
- <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c{1} - %msg%n"/>
- </File>
+ <Null name="NONE"/>
</Appenders>
<Loggers>
<Root level="INFO">
<!--<AppenderRef ref="STDOUT"/>-->
- <AppenderRef ref="FILE"/>
+ <AppenderRef ref="NONE"/>
</Root>
</Loggers>