You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/02/03 12:12:29 UTC
[camel-k] 02/06: feat(test): binary data integration test
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit cfd2ffd536314a65821681b2874ad24574bb35e8
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Jan 29 15:26:47 2021 +0100
feat(test): binary data integration test
* Added integration test for #1946
---
e2e/resources/files/ResourcesBinary.java | 40 ++++++++++++++++++++++
e2e/resources/files/ResourcesText.java | 29 ++++++++++++++++
e2e/resources/files/resources-data.txt | 1 +
e2e/resources/files/resources-data.zip | Bin 0 -> 199 bytes
e2e/resources/resources_test.go | 57 +++++++++++++++++++++++++++++++
script/Makefile | 4 +++
6 files changed, 131 insertions(+)
diff --git a/e2e/resources/files/ResourcesBinary.java b/e2e/resources/files/ResourcesBinary.java
new file mode 100644
index 0000000..e1dbb55
--- /dev/null
+++ b/e2e/resources/files/ResourcesBinary.java
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+public class ResourcesBinary extends org.apache.camel.builder.RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("file:/etc/camel/resources/i-resource-000/?noop=true")
+ .unmarshal().zipFile()
+ .convertBodyTo(String.class)
+ .process(new ZipEntryProcessor());
+ }
+
+}
+
+class ZipEntryProcessor implements Processor {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ System.out.println(exchange.getIn().getBody().toString());
+ }
+
+}
\ No newline at end of file
diff --git a/e2e/resources/files/ResourcesText.java b/e2e/resources/files/ResourcesText.java
new file mode 100644
index 0000000..8ae314f
--- /dev/null
+++ b/e2e/resources/files/ResourcesText.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+public class ResourcesText extends org.apache.camel.builder.RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("file:/etc/camel/resources/i-resource-000/?noop=true")
+ .log("${body}");
+ }
+
+}
\ No newline at end of file
diff --git a/e2e/resources/files/resources-data.txt b/e2e/resources/files/resources-data.txt
new file mode 100644
index 0000000..dff7947
--- /dev/null
+++ b/e2e/resources/files/resources-data.txt
@@ -0,0 +1 @@
+the file body
\ No newline at end of file
diff --git a/e2e/resources/files/resources-data.zip b/e2e/resources/files/resources-data.zip
new file mode 100644
index 0000000..5c5b80b
Binary files /dev/null and b/e2e/resources/files/resources-data.zip differ
diff --git a/e2e/resources/resources_test.go b/e2e/resources/resources_test.go
new file mode 100644
index 0000000..7625e8e
--- /dev/null
+++ b/e2e/resources/resources_test.go
@@ -0,0 +1,57 @@
+// +build integration
+
+// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"
+
+/*
+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 resources
+
+import (
+ "testing"
+
+ . "github.com/apache/camel-k/e2e/support"
+ camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+ . "github.com/onsi/gomega"
+ v1 "k8s.io/api/core/v1"
+)
+
+func TestRunResourceExamples(t *testing.T) {
+
+ WithNewTestNamespace(t, func(ns string) {
+ Expect(Kamel("install", "-n", ns).Execute()).Should(BeNil())
+
+ t.Run("run java", func(t *testing.T) {
+ RegisterTestingT(t)
+ Expect(Kamel("run", "-n", ns, "./files/ResourcesText.java", "--resource", "./files/resources-data.txt").Execute()).Should(BeNil())
+ Eventually(IntegrationPodPhase(ns, "resources-text"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resources-text", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resources-text"), TestTimeoutShort).Should(ContainSubstring("the file body"))
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
+ })
+
+ t.Run("run java", func(t *testing.T) {
+ RegisterTestingT(t)
+ Expect(Kamel("run", "-n", ns, "./files/ResourcesBinary.java",
+ "--resource", "./files/resources-data.zip", "-d", "camel-zipfile").Execute()).Should(BeNil())
+ Eventually(IntegrationPodPhase(ns, "resources-binary"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resources-binary", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resources-binary"), TestTimeoutShort).Should(ContainSubstring("the file body"))
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
+ })
+ })
+}
diff --git a/script/Makefile b/script/Makefile
index dd94dd9..16893a9 100644
--- a/script/Makefile
+++ b/script/Makefile
@@ -161,6 +161,10 @@ test-local: build
STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" go test -timeout 60m -v ./e2e/local -tags=integration
#go test -timeout 60m -v ./e2e/local -tags=integration
+test-resources: build
+ STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" go test -timeout 60m -v ./e2e/resources -tags=integration
+ #go test -timeout 60m -v ./e2e/resources -tags=integration
+
build-kamel:
go build $(GOFLAGS) -o kamel ./cmd/kamel/*.go