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/01/15 17:18:45 UTC

[camel] branch camel-3.7.x updated (a4221cd -> 0225920)

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 a4221cd  CAMEL-16045: rest-dsl - xml or json binding should create new instance of data formats
     new 250fdf2  CAMEL-16032 [camel-main] autoconfiguration does not bind dataformat in the registry (#4887)
     new 0225920  CAMEL-16032 [camel-main] autoconfiguration does not bind dataformat in the registry

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:
 .../camel/impl/engine/AbstractCamelContext.java    | 26 +++++-----
 .../dataformat/DataFormatRegistrationTest.java     | 57 ++++++++++++++++++++++
 .../camel/model/dataformat/DummyDataformat.java}   | 55 +++++++++++----------
 .../org/apache/camel/support/CustomizersTest.java  | 15 ++----
 .../services/org/apache/camel/dataformat/dummy     |  1 +
 5 files changed, 105 insertions(+), 49 deletions(-)
 create mode 100644 core/camel-core/src/test/java/org/apache/camel/model/dataformat/DataFormatRegistrationTest.java
 copy core/{camel-core-model/src/main/java/org/apache/camel/model/dataformat/UniVocityHeader.java => camel-core/src/test/java/org/apache/camel/model/dataformat/DummyDataformat.java} (55%)
 create mode 100644 core/camel-core/src/test/resources/META-INF/services/org/apache/camel/dataformat/dummy


[camel] 01/02: CAMEL-16032 [camel-main] autoconfiguration does not bind dataformat in the registry (#4887)

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 250fdf24890f4c7e053f84d0a52aa9ad6700ab75
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 15 16:28:24 2021 +0100

    CAMEL-16032 [camel-main] autoconfiguration does not bind dataformat in the registry (#4887)
    
    This reverts commit d145296dcfb875590407dbff4c7cc5f3ed3e7aee.
---
 .../camel/impl/engine/AbstractCamelContext.java    | 26 ++++-----
 .../dataformat/DataFormatRegistrationTest.java     | 57 ++++++++++++++++++++
 .../camel/model/dataformat/DummyDataformat.java    | 63 ++++++++++++++++++++++
 .../services/org/apache/camel/dataformat/dummy     |  1 +
 4 files changed, 134 insertions(+), 13 deletions(-)

diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index b5d7364..c4488fe 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -29,6 +29,7 @@ import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Properties;
 import java.util.Set;
 import java.util.TreeMap;
@@ -3781,25 +3782,24 @@ public abstract class AbstractCamelContext extends BaseService
 
     @Override
     public DataFormat resolveDataFormat(String name) {
-        final DataFormat answer = dataformats.computeIfAbsent(name, new Function<String, DataFormat>() {
-            @Override
-            public DataFormat apply(String s) {
-                DataFormat df = ResolverHelper.lookupDataFormatInRegistryWithFallback(getCamelContextReference(), name);
+        final DataFormat answer = dataformats.computeIfAbsent(name, s -> {
+            DataFormat df = Optional
+                    .ofNullable(ResolverHelper.lookupDataFormatInRegistryWithFallback(getCamelContextReference(), name))
+                    .orElseGet(() -> getDataFormatResolver().createDataFormat(name, getCamelContextReference()));
 
-                if (df != null) {
-                    // inject CamelContext if aware
-                    CamelContextAware.trySetCamelContext(df, getCamelContextReference());
+            if (df != null) {
+                // inject CamelContext if aware
+                CamelContextAware.trySetCamelContext(df, getCamelContextReference());
 
-                    for (LifecycleStrategy strategy : lifecycleStrategies) {
-                        strategy.onDataFormatCreated(name, df);
-                    }
+                for (LifecycleStrategy strategy : lifecycleStrategies) {
+                    strategy.onDataFormatCreated(name, df);
                 }
-
-                return df;
             }
+
+            return df;
         });
 
-        return answer != null ? answer : createDataFormat(name);
+        return answer;
     }
 
     @Override
diff --git a/core/camel-core/src/test/java/org/apache/camel/model/dataformat/DataFormatRegistrationTest.java b/core/camel-core/src/test/java/org/apache/camel/model/dataformat/DataFormatRegistrationTest.java
new file mode 100644
index 0000000..8cafddd
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/model/dataformat/DataFormatRegistrationTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.model.dataformat;
+
+import java.lang.reflect.Field;
+import java.util.Map;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.impl.engine.AbstractCamelContext;
+import org.apache.camel.spi.DataFormat;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+//CAMEL-16032
+public class DataFormatRegistrationTest extends ContextTestSupport {
+
+    @Test
+    public void shouldRegisterDataformatInCacheTest() throws Exception {
+        DummyDataformat df = (DummyDataformat) context.resolveDataFormat("dummy");
+        df.setName("DUMMMY");
+        df.setVersion("2.3.6");
+        Field field = AbstractCamelContext.class.getDeclaredField("dataformats");
+        field.setAccessible(true);
+        Map<String, DataFormat> dataformats = (Map) field.get(context);
+        assertThat(dataformats).containsKey("dummy");
+
+        DummyDataformat df2 = (DummyDataformat) context.resolveDataFormat("dummy");
+        dataformats = (Map) field.get(context);
+        assertThat(dataformats).containsKey("dummy");
+        assertThat(df2.getName()).isEqualTo(df.getName()).isEqualTo("DUMMMY");
+        assertThat(df2.getVersion()).isEqualTo(df.getVersion()).isEqualTo("2.3.6");
+    }
+
+    @Test
+    public void missingDataformatTest() throws Exception {
+        DataFormat df = context.resolveDataFormat("nonExistent");
+        Field field = AbstractCamelContext.class.getDeclaredField("dataformats");
+        field.setAccessible(true);
+        Map<String, DataFormat> dataformats = (Map) field.get(context);
+        assertThat(dataformats).isEmpty();
+    }
+}
diff --git a/core/camel-core/src/test/java/org/apache/camel/model/dataformat/DummyDataformat.java b/core/camel-core/src/test/java/org/apache/camel/model/dataformat/DummyDataformat.java
new file mode 100644
index 0000000..a736d23
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/model/dataformat/DummyDataformat.java
@@ -0,0 +1,63 @@
+/*
+ * 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.model.dataformat;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.DataFormatName;
+import org.apache.camel.support.service.ServiceSupport;
+
+public class DummyDataformat extends ServiceSupport implements DataFormat, DataFormatName {
+
+    private String name;
+
+    private String version;
+
+    @Override
+    public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
+
+    }
+
+    @Override
+    public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
+        return null;
+    }
+
+    @Override
+    public String getDataFormatName() {
+        return "dummy";
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+}
diff --git a/core/camel-core/src/test/resources/META-INF/services/org/apache/camel/dataformat/dummy b/core/camel-core/src/test/resources/META-INF/services/org/apache/camel/dataformat/dummy
new file mode 100644
index 0000000..3a22a41
--- /dev/null
+++ b/core/camel-core/src/test/resources/META-INF/services/org/apache/camel/dataformat/dummy
@@ -0,0 +1 @@
+class=org.apache.camel.model.dataformat.DummyDataformat
\ No newline at end of file


[camel] 02/02: CAMEL-16032 [camel-main] autoconfiguration does not bind dataformat in the registry

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 0225920e5d54a3aa024d30b629073ba75ca1cde8
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 15 18:12:57 2021 +0100

    CAMEL-16032 [camel-main] autoconfiguration does not bind dataformat in the registry
---
 .../java/org/apache/camel/support/CustomizersTest.java    | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/support/CustomizersTest.java b/core/camel-core/src/test/java/org/apache/camel/support/CustomizersTest.java
index 2bfd53e..b43d34b 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/CustomizersTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/CustomizersTest.java
@@ -39,12 +39,7 @@ import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
 
 import static org.apache.camel.util.CollectionHelper.propertiesOf;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
 
 public class CustomizersTest {
 
@@ -231,8 +226,8 @@ public class CustomizersTest {
                 "my-df-customizer",
                 DataFormatCustomizer.forType(MyDataFormat.class, target -> target.setId(counter.incrementAndGet())));
 
-        DataFormat df1 = context.resolveDataFormat("my-df");
-        DataFormat df2 = context.resolveDataFormat("my-df");
+        DataFormat df1 = context.createDataFormat("my-df");
+        DataFormat df2 = context.createDataFormat("my-df");
 
         assertNotEquals(df1, df2);
 
@@ -257,8 +252,8 @@ public class CustomizersTest {
                 "my-df-customizer",
                 DataFormatCustomizer.forType(MyDataFormat.class, target -> target.setId(counter.incrementAndGet())));
 
-        DataFormat df1 = context.resolveDataFormat("my-df");
-        DataFormat df2 = context.resolveDataFormat("my-df");
+        DataFormat df1 = context.createDataFormat("my-df");
+        DataFormat df2 = context.createDataFormat("my-df");
 
         assertNotEquals(df1, df2);