You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/05/26 06:52:42 UTC

[camel] branch camel-3.7.x updated (c28720f -> 52317aa)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch camel-3.7.x
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from c28720f  Regen
     new cbe9060  CAMEL-16658: camel-bean: AmbiguousMethodCallException when using Mockito mock as bean for camel-bean component. Thanks to Krzysztof Mackowiak for the patch.
     new 52317aa  CAMEL-16659: camel-core - Simple language parses minus sign (-) as a numeric value instead of a string value

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/camel/component/bean/BeanInfo.java  |  7 +++++
 ...elineTest.java => MockitoMockForClassTest.java} | 34 +++++++++-----------
 ...eTest.java => MockitoMockForInterfaceTest.java} | 36 +++++++++-------------
 ...pelineTest.java => MockitoSpyForClassTest.java} | 34 +++++++++-----------
 .../camel/language/simple/SimpleOperatorTest.java  | 16 ++++++++++
 .../org/apache/camel/support/ObjectHelper.java     | 14 ++++++---
 6 files changed, 75 insertions(+), 66 deletions(-)
 copy core/camel-core/src/test/java/org/apache/camel/component/bean/{BeanInPipelineTest.java => MockitoMockForClassTest.java} (70%)
 copy core/camel-core/src/test/java/org/apache/camel/component/bean/{BeanInPipelineTest.java => MockitoMockForInterfaceTest.java} (67%)
 copy core/camel-core/src/test/java/org/apache/camel/component/bean/{BeanInPipelineTest.java => MockitoSpyForClassTest.java} (70%)

[camel] 02/02: CAMEL-16659: camel-core - Simple language parses minus sign (-) as a numeric value instead of a string value

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.7.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 52317aac0548d1c2169e55c9e381c812fe69f9c2
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed May 26 07:32:45 2021 +0200

    CAMEL-16659: camel-core - Simple language parses minus sign (-) as a numeric value instead of a string value
---
 .../apache/camel/language/simple/SimpleOperatorTest.java | 16 ++++++++++++++++
 .../main/java/org/apache/camel/support/ObjectHelper.java | 14 ++++++++++----
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
index 849a04b..ed4de94 100644
--- a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
@@ -169,6 +169,10 @@ public class SimpleOperatorTest extends LanguageTestSupport {
         assertPredicate("${in.header.foo} == 'def'", false);
         assertPredicate("${in.header.foo} == '1'", false);
 
+        // special with just minus sign
+        assertPredicate("${in.header.foo} == '-'", false);
+        assertPredicate("${in.header.bar} == '-'", false);
+
         // no type converter needed from this point forward
         context.getTypeConverterRegistry().getStatistics().setStatisticsEnabled(true);
         context.getTypeConverterRegistry().getStatistics().reset();
@@ -207,6 +211,10 @@ public class SimpleOperatorTest extends LanguageTestSupport {
         assertPredicate("${in.header.bar} =~ '444'", false);
         assertPredicate("${in.header.bar} =~ 444", false);
         assertPredicate("${in.header.bar} =~ '1'", false);
+
+        // special with just minus sign
+        assertPredicate("${in.header.foo} =~ '-'", false);
+        assertPredicate("${in.header.bar} =~ '-'", false);
     }
 
     @Test
@@ -222,6 +230,10 @@ public class SimpleOperatorTest extends LanguageTestSupport {
         assertPredicate("${in.header.bar} != '444'", true);
         assertPredicate("${in.header.bar} != 444", true);
         assertPredicate("${in.header.bar} != '1'", true);
+
+        // special with just minus sign
+        assertPredicate("${in.header.foo} != '-'", true);
+        assertPredicate("${in.header.bar} != '-'", true);
     }
 
     @Test
@@ -326,6 +338,10 @@ public class SimpleOperatorTest extends LanguageTestSupport {
         assertPredicate("${in.header.bar} >= '123'", true);
         assertPredicate("${in.header.bar} >= 123", true);
         assertPredicate("${in.header.bar} >= '200'", false);
+
+        // special with just minus sign
+        assertPredicate("${in.header.foo} >= '-'", true);
+        assertPredicate("${in.header.bar} >= '-'", true);
     }
 
     @Test
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
index 64f613f..6cc8cea 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ObjectHelper.java
@@ -119,8 +119,8 @@ public final class ObjectHelper {
                 Long rightNum = (Long) rightValue;
                 return leftNum.compareTo(rightNum) == 0;
             }
-        } else if ((rightValue instanceof String) &&
-                (leftValue instanceof Integer || leftValue instanceof Long)) {
+        } else if (rightValue instanceof String &&
+                ((leftValue instanceof Integer || leftValue instanceof Long) && isNumber((String) rightValue))) {
             if (leftValue instanceof Integer) {
                 Integer leftNum = (Integer) leftValue;
                 Integer rightNum = Integer.valueOf((String) rightValue);
@@ -219,8 +219,8 @@ public final class ObjectHelper {
                 Long rightNum = (Long) rightValue;
                 return leftNum.compareTo(rightNum);
             }
-        } else if ((rightValue instanceof String) &&
-                (leftValue instanceof Integer || leftValue instanceof Long)) {
+        } else if (rightValue instanceof String &&
+                ((leftValue instanceof Integer || leftValue instanceof Long) && isNumber((String) rightValue))) {
             if (leftValue instanceof Integer) {
                 Integer leftNum = (Integer) leftValue;
                 Integer rightNum = Integer.valueOf((String) rightValue);
@@ -295,6 +295,9 @@ public final class ObjectHelper {
         if (text == null || text.isEmpty()) {
             return false;
         }
+        if (text.equals("-")) {
+            return false;
+        }
         for (int i = 0; i < text.length(); i++) {
             char ch = text.charAt(i);
             if (i == 0 && ch == '-') {
@@ -313,6 +316,9 @@ public final class ObjectHelper {
         if (text == null || text.isEmpty()) {
             return false;
         }
+        if (text.equals("-")) {
+            return false;
+        }
         boolean dots = false;
         for (int i = 0; i < text.length(); i++) {
             char ch = text.charAt(i);

[camel] 01/02: CAMEL-16658: camel-bean: AmbiguousMethodCallException when using Mockito mock as bean for camel-bean component. Thanks to Krzysztof Mackowiak for the patch.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.7.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit cbe9060958a903eb4ae38170ed74ac9256f0122e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed May 26 06:52:42 2021 +0200

    CAMEL-16658: camel-bean: AmbiguousMethodCallException when using Mockito mock as bean for camel-bean component. Thanks to Krzysztof Mackowiak for the patch.
---
 .../org/apache/camel/component/bean/BeanInfo.java  |  7 +++
 .../component/bean/MockitoMockForClassTest.java    | 62 ++++++++++++++++++++++
 .../bean/MockitoMockForInterfaceTest.java          | 60 +++++++++++++++++++++
 .../component/bean/MockitoSpyForClassTest.java     | 62 ++++++++++++++++++++++
 4 files changed, 191 insertions(+)

diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
index b61f37c..d54ef3b 100644
--- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
+++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
@@ -64,6 +64,8 @@ import static org.apache.camel.component.bean.ParameterMappingStrategyHelper.cre
 public class BeanInfo {
     private static final Logger LOG = LoggerFactory.getLogger(BeanInfo.class);
     private static final String CGLIB_CLASS_SEPARATOR = "$$";
+    private static final String CGLIB_METHOD_MARKER = "CGLIB$";
+    private static final String BYTE_BUDDY_METHOD_MARKER = "$accessor$";
     private static final String[] EXCLUDED_METHOD_NAMES = new String[] {
             "clone", "equals", "finalize", "getClass", "hashCode", "notify", "notifyAll", "wait", // java.lang.Object
             "getInvocationHandler", "getProxyClass", "isProxyClass", "newProxyInstance" // java.lang.Proxy
@@ -918,6 +920,11 @@ public class BeanInfo {
             return false;
         }
 
+        // must not be a method added by Mockito (CGLIB or Byte Buddy)
+        if (name.contains(CGLIB_METHOD_MARKER) || name.contains(BYTE_BUDDY_METHOD_MARKER)) {
+            return false;
+        }
+
         return true;
     }
 
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/bean/MockitoMockForClassTest.java b/core/camel-core/src/test/java/org/apache/camel/component/bean/MockitoMockForClassTest.java
new file mode 100644
index 0000000..b1c6a57
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/component/bean/MockitoMockForClassTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.Registry;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.when;
+
+public class MockitoMockForClassTest extends ContextTestSupport {
+
+    @Test
+    public void testCallingMock() throws Exception {
+        Object response = template.requestBody("direct:start", "anything");
+        assertEquals("mocked answer", response);
+    }
+
+    @Override
+    protected Registry createRegistry() throws Exception {
+        MyService mockService = Mockito.mock(MyService.class);
+        when(mockService.doSomething(any())).thenReturn("mocked answer");
+
+        Registry answer = super.createRegistry();
+        answer.bind("myService", mockService);
+        return answer;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:start").bean("bean:myService");
+            }
+        };
+    }
+
+    public class MyService {
+        public String doSomething(String body) {
+            return "real answer";
+        }
+    }
+
+}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/bean/MockitoMockForInterfaceTest.java b/core/camel-core/src/test/java/org/apache/camel/component/bean/MockitoMockForInterfaceTest.java
new file mode 100644
index 0000000..464774c
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/component/bean/MockitoMockForInterfaceTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.Registry;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.when;
+
+public class MockitoMockForInterfaceTest extends ContextTestSupport {
+
+    @Test
+    public void testCallingMock() throws Exception {
+        Object response = template.requestBody("direct:start", "anything");
+        assertEquals("mocked answer", response);
+    }
+
+    @Override
+    protected Registry createRegistry() throws Exception {
+        MyService mockService = Mockito.mock(MyService.class);
+        when(mockService.doSomething(any())).thenReturn("mocked answer");
+
+        Registry answer = super.createRegistry();
+        answer.bind("myService", mockService);
+        return answer;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:start").bean("bean:myService");
+            }
+        };
+    }
+
+    public interface MyService {
+        String doSomething(String body);
+    }
+
+}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/bean/MockitoSpyForClassTest.java b/core/camel-core/src/test/java/org/apache/camel/component/bean/MockitoSpyForClassTest.java
new file mode 100644
index 0000000..4918782
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/component/bean/MockitoSpyForClassTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.Registry;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.when;
+
+public class MockitoSpyForClassTest extends ContextTestSupport {
+
+    @Test
+    public void testCallingSpy() throws Exception {
+        Object response = template.requestBody("direct:start", "anything");
+        assertEquals("mocked answer", response);
+    }
+
+    @Override
+    protected Registry createRegistry() throws Exception {
+        MyService mockService = Mockito.spy(new MyService());
+        when(mockService.doSomething(any())).thenReturn("mocked answer");
+
+        Registry answer = super.createRegistry();
+        answer.bind("myService", mockService);
+        return answer;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:start").bean("bean:myService");
+            }
+        };
+    }
+
+    public class MyService {
+        public String doSomething(String body) {
+            return "real answer";
+        }
+    }
+
+}