This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch camel-main
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
The following commit(s) were added to refs/heads/camel-main by this push:
new c77928a Set YamlDeserializationMode.FLOW on camel-context #707
c77928a is described below
commit c77928aa90349fc7409a2fb22c3715561e499ea4
Author: Luca Burgazzoli <[email protected]>
AuthorDate: Mon Jun 7 10:03:49 2021 +0200
Set YamlDeserializationMode.FLOW on camel-context #707
---
.../camel/k/listener/YamlConfigurerConfigurer.java | 49 ++++++++++++++++++
.../org.apache.camel.k.listener.YamlConfigurer | 2 +
.../apache/camel/k/listener/YamlConfigurer.java | 54 ++++++++++++++++++++
.../services/org.apache.camel.k.Runtime$Listener | 1 +
.../camel/k/listener/YamlConfigurerTest.java | 50 +++++++++++++++++++
.../org/apache/camel/k/quarkus/it/Application.java | 9 ++++
.../it/RuntimeYamlDeserializationClassicIT.java | 23 +++++++++
.../it/RuntimeYamlDeserializationClassicTest.java | 58 ++++++++++++++++++++++
.../it/RuntimeYamlDeserializationDefaultIT.java | 23 +++++++++
.../it/RuntimeYamlDeserializationDefaultTest.java | 55 ++++++++++++++++++++
.../it/RuntimeYamlDeserializationFlowIT.java | 23 +++++++++
.../it/RuntimeYamlDeserializationFlowTest.java | 58 ++++++++++++++++++++++
12 files changed, 405 insertions(+)
diff --git
a/camel-k-core/support/src/generated/java/org/apache/camel/k/listener/YamlConfigurerConfigurer.java
b/camel-k-core/support/src/generated/java/org/apache/camel/k/listener/YamlConfigurerConfigurer.java
new file mode 100644
index 0000000..39cade8
--- /dev/null
+++
b/camel-k-core/support/src/generated/java/org/apache/camel/k/listener/YamlConfigurerConfigurer.java
@@ -0,0 +1,49 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.k.listener;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.spi.ConfigurerStrategy;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.k.listener.YamlConfigurer;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class YamlConfigurerConfigurer extends
org.apache.camel.support.component.PropertyConfigurerSupport implements
GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+ @Override
+ public boolean configure(CamelContext camelContext, Object obj, String
name, Object value, boolean ignoreCase) {
+ org.apache.camel.k.listener.YamlConfigurer target =
(org.apache.camel.k.listener.YamlConfigurer) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "deserializationmode":
+ case "DeserializationMode":
target.setDeserializationMode(property(camelContext, java.lang.String.class,
value)); return true;
+ default: return false;
+ }
+ }
+
+ @Override
+ public Class<?> getOptionType(String name, boolean ignoreCase) {
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "deserializationmode":
+ case "DeserializationMode": return java.lang.String.class;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+ org.apache.camel.k.listener.YamlConfigurer target =
(org.apache.camel.k.listener.YamlConfigurer) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "deserializationmode":
+ case "DeserializationMode": return target.getDeserializationMode();
+ default: return null;
+ }
+ }
+}
+
diff --git
a/camel-k-core/support/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.k.listener.YamlConfigurer
b/camel-k-core/support/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.k.listener.YamlConfigurer
new file mode 100644
index 0000000..88860b3
--- /dev/null
+++
b/camel-k-core/support/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.k.listener.YamlConfigurer
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.k.listener.YamlConfigurerConfigurer
diff --git
a/camel-k-core/support/src/main/java/org/apache/camel/k/listener/YamlConfigurer.java
b/camel-k-core/support/src/main/java/org/apache/camel/k/listener/YamlConfigurer.java
new file mode 100644
index 0000000..a2f071c
--- /dev/null
+++
b/camel-k-core/support/src/main/java/org/apache/camel/k/listener/YamlConfigurer.java
@@ -0,0 +1,54 @@
+/*
+ * 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.listener;
+
+import org.apache.camel.k.Runtime;
+import org.apache.camel.k.support.PropertiesSupport;
+import org.apache.camel.spi.Configurer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Configurer
+public class YamlConfigurer extends AbstractPhaseListener {
+ public static final Logger LOGGER =
LoggerFactory.getLogger(YamlConfigurer.class);
+ public static final String CAMEL_K_YAML_PROPERTIES_PREFIX =
"camel.k.yaml.";
+
+ private String deserializationMode = "FLOW";
+
+ public YamlConfigurer() {
+ super(Runtime.Phase.ConfigureContext);
+ }
+
+ public String getDeserializationMode() {
+ return deserializationMode;
+ }
+
+ public void setDeserializationMode(String deserializationMode) {
+ this.deserializationMode = deserializationMode;
+ }
+
+ @Override
+ protected void accept(Runtime runtime) {
+ PropertiesSupport.bindProperties(
+ runtime.getCamelContext(),
+ this,
+ CAMEL_K_YAML_PROPERTIES_PREFIX,
+ true);
+
+
runtime.getCamelContext().getGlobalOptions().put("CamelYamlDslDeserializationMode",
getDeserializationMode());
+ }
+}
diff --git
a/camel-k-core/support/src/main/resources/META-INF/services/org.apache.camel.k.Runtime$Listener
b/camel-k-core/support/src/main/resources/META-INF/services/org.apache.camel.k.Runtime$Listener
index f0c50b7..4701174 100644
---
a/camel-k-core/support/src/main/resources/META-INF/services/org.apache.camel.k.Runtime$Listener
+++
b/camel-k-core/support/src/main/resources/META-INF/services/org.apache.camel.k.Runtime$Listener
@@ -16,5 +16,6 @@
#
org.apache.camel.k.listener.ContextConfigurer
+org.apache.camel.k.listener.YamlConfigurer
org.apache.camel.k.listener.SourcesConfigurer
org.apache.camel.k.listener.PropertiesConfigurer
diff --git
a/camel-k-core/support/src/test/java/org/apache/camel/k/listener/YamlConfigurerTest.java
b/camel-k-core/support/src/test/java/org/apache/camel/k/listener/YamlConfigurerTest.java
new file mode 100644
index 0000000..6336436
--- /dev/null
+++
b/camel-k-core/support/src/test/java/org/apache/camel/k/listener/YamlConfigurerTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.listener;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.k.Runtime;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.camel.util.PropertiesHelper.asProperties;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class YamlConfigurerTest {
+ @Test
+ public void yamlDeserializationModeShouldBeEnabledByDefault() {
+ CamelContext context = new DefaultCamelContext();
+
+ YamlConfigurer configuration = new YamlConfigurer();
+ configuration.accept(Runtime.on(context));
+
+
assertThat(context.getGlobalOptions()).containsEntry("CamelYamlDslDeserializationMode",
"FLOW");
+ }
+
+ @Test
+ public void yamlDeserializationModeShouldBeEnabledConfigurable() {
+ CamelContext context = new DefaultCamelContext();
+ context.getPropertiesComponent().setInitialProperties(asProperties(
+ "camel.k.yaml.deserialization-mode", "CLASSIC"
+ ));
+
+ YamlConfigurer configuration = new YamlConfigurer();
+ configuration.accept(Runtime.on(context));
+
+
assertThat(context.getGlobalOptions()).containsEntry("CamelYamlDslDeserializationMode",
"CLASSIC");
+ }
+}
diff --git
a/itests/camel-k-itests-runtime/src/main/java/org/apache/camel/k/quarkus/it/Application.java
b/itests/camel-k-itests-runtime/src/main/java/org/apache/camel/k/quarkus/it/Application.java
index cf4c855..2ad044a 100644
---
a/itests/camel-k-itests-runtime/src/main/java/org/apache/camel/k/quarkus/it/Application.java
+++
b/itests/camel-k-itests-runtime/src/main/java/org/apache/camel/k/quarkus/it/Application.java
@@ -46,6 +46,7 @@ public class Application {
@GET
@Path("/inspect")
@Produces(MediaType.APPLICATION_JSON)
+ @SuppressWarnings("unchecked")
public JsonObject inspect() {
return Json.createObjectBuilder()
.add(
@@ -57,6 +58,14 @@ public class Application {
.add(
"routes-collector",
instance(CamelMain.class).map(BaseMainSupport::getRoutesCollector).map(Object::getClass).map(Class::getName).orElse(""))
+ .add(
+ "global-options",
+ Json.createObjectBuilder(
+ (Map)instance(CamelMain.class)
+ .map(BaseMainSupport::getCamelContext)
+ .map(CamelContext::getGlobalOptions)
+ .orElseGet(Collections::emptyMap))
+ .build())
.build();
}
diff --git
a/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationClassicIT.java
b/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationClassicIT.java
new file mode 100644
index 0000000..cc187e5
--- /dev/null
+++
b/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationClassicIT.java
@@ -0,0 +1,23 @@
+/*
+ * 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.quarkus.it;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+public class RuntimeYamlDeserializationClassicIT extends
RuntimeYamlDeserializationClassicTest {
+}
\ No newline at end of file
diff --git
a/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationClassicTest.java
b/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationClassicTest.java
new file mode 100644
index 0000000..4b4e6a6
--- /dev/null
+++
b/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationClassicTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.quarkus.it;
+
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusTestProfile;
+import io.quarkus.test.junit.TestProfile;
+import io.restassured.path.json.JsonPath;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.apache.camel.util.CollectionHelper.mapOf;
+import static org.assertj.core.api.Assertions.assertThat;
+
+@TestProfile(RuntimeYamlDeserializationClassicTest.Profile.class)
+@QuarkusTest
+public class RuntimeYamlDeserializationClassicTest {
+ @Test
+ public void testContextCustomizerFromProperties() {
+ JsonPath p = given()
+ .accept(MediaType.APPLICATION_JSON)
+ .get("/test/inspect")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body()
+ .jsonPath();
+
+
assertThat(p.getMap("global-options")).containsEntry("CamelYamlDslDeserializationMode",
"CLASSIC");
+ }
+
+ public static class Profile implements QuarkusTestProfile {
+ @Override
+ public Map<String, String> getConfigOverrides() {
+ return mapOf(
+ "camel.k.yaml.deserialization-mode", "CLASSIC"
+ );
+ }
+ }
+}
diff --git
a/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationDefaultIT.java
b/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationDefaultIT.java
new file mode 100644
index 0000000..ebd1ae4
--- /dev/null
+++
b/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationDefaultIT.java
@@ -0,0 +1,23 @@
+/*
+ * 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.quarkus.it;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+public class RuntimeYamlDeserializationDefaultIT extends
RuntimeYamlDeserializationDefaultTest {
+}
\ No newline at end of file
diff --git
a/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationDefaultTest.java
b/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationDefaultTest.java
new file mode 100644
index 0000000..e593f31
--- /dev/null
+++
b/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationDefaultTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.quarkus.it;
+
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusTestProfile;
+import io.quarkus.test.junit.TestProfile;
+import io.restassured.path.json.JsonPath;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.assertj.core.api.Assertions.assertThat;
+
+@TestProfile(RuntimeYamlDeserializationDefaultTest.Profile.class)
+@QuarkusTest
+public class RuntimeYamlDeserializationDefaultTest {
+ @Test
+ public void testContextCustomizerFromProperties() {
+ JsonPath p = given()
+ .accept(MediaType.APPLICATION_JSON)
+ .get("/test/inspect")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body()
+ .jsonPath();
+
+
assertThat(p.getMap("global-options")).containsEntry("CamelYamlDslDeserializationMode",
"FLOW");
+ }
+
+ public static class Profile implements QuarkusTestProfile {
+ @Override
+ public Map<String, String> getConfigOverrides() {
+ return Map.of();
+ }
+ }
+}
diff --git
a/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationFlowIT.java
b/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationFlowIT.java
new file mode 100644
index 0000000..d83acc8
--- /dev/null
+++
b/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationFlowIT.java
@@ -0,0 +1,23 @@
+/*
+ * 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.quarkus.it;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+public class RuntimeYamlDeserializationFlowIT extends
RuntimeYamlDeserializationFlowTest {
+}
\ No newline at end of file
diff --git
a/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationFlowTest.java
b/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationFlowTest.java
new file mode 100644
index 0000000..d760cd6
--- /dev/null
+++
b/itests/camel-k-itests-runtime/src/test/java/org/apache/camel/k/quarkus/it/RuntimeYamlDeserializationFlowTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.quarkus.it;
+
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusTestProfile;
+import io.quarkus.test.junit.TestProfile;
+import io.restassured.path.json.JsonPath;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.apache.camel.util.CollectionHelper.mapOf;
+import static org.assertj.core.api.Assertions.assertThat;
+
+@TestProfile(RuntimeYamlDeserializationFlowTest.Profile.class)
+@QuarkusTest
+public class RuntimeYamlDeserializationFlowTest {
+ @Test
+ public void testContextCustomizerFromProperties() {
+ JsonPath p = given()
+ .accept(MediaType.APPLICATION_JSON)
+ .get("/test/inspect")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body()
+ .jsonPath();
+
+
assertThat(p.getMap("global-options")).containsEntry("CamelYamlDslDeserializationMode",
"FLOW");
+ }
+
+ public static class Profile implements QuarkusTestProfile {
+ @Override
+ public Map<String, String> getConfigOverrides() {
+ return mapOf(
+ "camel.k.yaml.deserialization-mode", "FLOW"
+ );
+ }
+ }
+}