You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2020/03/31 15:39:43 UTC

[camel-k-runtime] branch master updated: camel-knative: fix parsing of knative environment

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

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git


The following commit(s) were added to refs/heads/master by this push:
     new 4907025  camel-knative: fix parsing of knative environment
4907025 is described below

commit 4907025d1b3ef413eb4438fa6df16e87737fe857
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Tue Mar 31 17:17:27 2020 +0200

    camel-knative: fix parsing of knative environment
---
 camel-knative/camel-knative-api/pom.xml            | 12 +++++++
 .../component/knative/spi/KnativeEnvironment.java  |  4 +--
 .../knative/spi/KnativeEnvironmentTest.java        | 41 ++++++++++++++++++++++
 .../src/test/resources/log4j2-test.xml             | 38 ++++++++++++++++++++
 4 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/camel-knative/camel-knative-api/pom.xml b/camel-knative/camel-knative-api/pom.xml
index 86df59b..4ca5b01 100644
--- a/camel-knative/camel-knative-api/pom.xml
+++ b/camel-knative/camel-knative-api/pom.xml
@@ -59,6 +59,18 @@
             <artifactId>jackson-datatype-jdk8</artifactId>
         </dependency>
 
+        <!-- ****************************** -->
+        <!--                                -->
+        <!-- TESTS                          -->
+        <!--                                -->
+        <!-- ****************************** -->
+
+        <dependency>
+            <groupId>org.apache.camel.k</groupId>
+            <artifactId>camel-k-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
     <build>
diff --git a/camel-knative/camel-knative-api/src/main/java/org/apache/camel/component/knative/spi/KnativeEnvironment.java b/camel-knative/camel-knative-api/src/main/java/org/apache/camel/component/knative/spi/KnativeEnvironment.java
index d0547bf..ab3df47 100644
--- a/camel-knative/camel-knative-api/src/main/java/org/apache/camel/component/knative/spi/KnativeEnvironment.java
+++ b/camel-knative/camel-knative-api/src/main/java/org/apache/camel/component/knative/spi/KnativeEnvironment.java
@@ -232,13 +232,13 @@ public class KnativeEnvironment {
             @JsonProperty(value = "type", required = true) Knative.Type type,
             @JsonProperty(value = "name", required = true) String name,
             @JsonProperty(value = "host", required = false) String host,
-            @JsonProperty(value = "port", required = false) int port,
+            @JsonProperty(value = "port", required = false) Integer port,
             @JsonProperty(value = "metadata", required = false) Map<String, String> metadata) {
 
             super(
                 name,
                 host,
-                port,
+                port == null ? -1 : port,
                 KnativeSupport.mergeMaps(
                     metadata,
                     KnativeSupport.mapOf(
diff --git a/camel-knative/camel-knative-api/src/test/java/org/apache/camel/component/knative/spi/KnativeEnvironmentTest.java b/camel-knative/camel-knative-api/src/test/java/org/apache/camel/component/knative/spi/KnativeEnvironmentTest.java
new file mode 100644
index 0000000..93b898c
--- /dev/null
+++ b/camel-knative/camel-knative-api/src/test/java/org/apache/camel/component/knative/spi/KnativeEnvironmentTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.knative.spi;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class KnativeEnvironmentTest {
+
+    @Test
+    public void testKnativeEnvironmentDeserializationFromString() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+
+        KnativeEnvironment env = KnativeEnvironment.mandatoryLoadFromSerializedString(
+            context,
+            "{\"services\":[{\"type\":\"endpoint\",\"name\":\"knative3\",\"metadata\":{\"camel.endpoint.kind\":\"source\",\"knative.apiVersion\":\"serving.knative.dev/v1\",\"knative.kind\":\"Service\",\"service.path\":\"/\"}}]}"
+        );
+
+        assertThat(env.lookup(Knative.Type.endpoint, "knative3"))
+            .first()
+                .hasFieldOrPropertyWithValue("port", -1)
+                .hasFieldOrPropertyWithValue("host", null);
+    }
+}
diff --git a/camel-knative/camel-knative-api/src/test/resources/log4j2-test.xml b/camel-knative/camel-knative-api/src/test/resources/log4j2-test.xml
new file mode 100644
index 0000000..8c95e54
--- /dev/null
+++ b/camel-knative/camel-knative-api/src/test/resources/log4j2-test.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<Configuration status="INFO">
+  <Appenders>
+    <Console name="STDOUT" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c{1} - %msg%n"/>
+    </Console>
+    <Null name="NONE"/>
+  </Appenders>
+
+  <Loggers>
+    <Logger name="org.apache.camel.k" level="DEBUG"/>
+    <Logger name="org.apache.camel.component.knative" level="DEBUG"/>
+
+    <Root level="INFO">
+      <!--<AppenderRef ref="STDOUT"/>-->
+      <AppenderRef ref="NONE"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
\ No newline at end of file