This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
The following commit(s) were added to refs/heads/main by this push:
new a01f9413 Ref #414: Add camel-barcode integration test (#415)
a01f9413 is described below
commit a01f94132fb3be859694e5f5a4334300d53d4386
Author: François de Parscau <[email protected]>
AuthorDate: Tue Jul 9 18:48:48 2024 +0200
Ref #414: Add camel-barcode integration test (#415)
---
tests/features/camel-barcode/pom.xml | 40 ++++++++++
.../camel/test/CamelBarcodeRouteSupplier.java | 88 ++++++++++++++++++++++
.../karaf/camel/itest/CamelBarcodeITest.java | 55 ++++++++++++++
tests/features/pom.xml | 1 +
4 files changed, 184 insertions(+)
diff --git a/tests/features/camel-barcode/pom.xml
b/tests/features/camel-barcode/pom.xml
new file mode 100644
index 00000000..885d5243
--- /dev/null
+++ b/tests/features/camel-barcode/pom.xml
@@ -0,0 +1,40 @@
+<?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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.karaf</groupId>
+ <artifactId>camel-karaf-features-test</artifactId>
+ <version>4.6.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-barcode-test</artifactId>
+ <name>Apache Camel :: Karaf :: Tests :: Features :: Barcode</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-barcode</artifactId>
+ <version>${camel-version}</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
diff --git
a/tests/features/camel-barcode/src/main/java/org/apache/karaf/camel/test/CamelBarcodeRouteSupplier.java
b/tests/features/camel-barcode/src/main/java/org/apache/karaf/camel/test/CamelBarcodeRouteSupplier.java
new file mode 100644
index 00000000..a87153e8
--- /dev/null
+++
b/tests/features/camel-barcode/src/main/java/org/apache/karaf/camel/test/CamelBarcodeRouteSupplier.java
@@ -0,0 +1,88 @@
+/*
+ * 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.karaf.camel.test;
+
+import static org.apache.camel.builder.Builder.constant;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Path;
+import java.util.function.Function;
+
+import javax.imageio.ImageIO;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.dataformat.barcode.BarcodeDataFormat;
+import org.apache.camel.dataformat.barcode.BarcodeImageType;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.spi.DataFormat;
+import
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.BinaryBitmap;
+import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
+import com.google.zxing.client.j2se.MatrixToImageWriter;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.common.HybridBinarizer;
+
+@Component(
+ name = "karaf-camel-barcode-test",
+ immediate = true,
+ service = CamelBarcodeRouteSupplier.class
+)
+public class CamelBarcodeRouteSupplier extends
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+ @Override
+ protected Function<RouteBuilder, RouteDefinition> consumerRoute() {
+
+ try (DataFormat code1 = new BarcodeDataFormat(200, 200,
BarcodeImageType.PNG, BarcodeFormat.CODE_39)) {
+ return builder -> builder.from("timer://testTimer?repeatCount=1")
+ .setBody(constant("OK"))
+ .marshal(code1)
+ .process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws
Exception {
+ InputStream bis =
exchange.getIn().getBody(InputStream.class);
+ BinaryBitmap bitmap =
+ new BinaryBitmap(new HybridBinarizer(new
BufferedImageLuminanceSource(ImageIO.read(bis))));
+ BitMatrix blackMatrix = bitmap.getBlackMatrix();
+ blackMatrix.rotate180();
+ File file =
Path.of(System.getProperty("barcode.image")).toFile();
+ try (FileOutputStream outputStream = new
FileOutputStream(file)) {
+ MatrixToImageWriter.writeToStream(blackMatrix,
"png", outputStream);
+ }
+ exchange.getIn().setBody(file);
+ }
+ })
+ .unmarshal(code1)
+ .log("unmarshalled ${body}");
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ @Override
+ protected boolean producerEnabled() {
+ return false;
+ }
+}
+
diff --git
a/tests/features/camel-barcode/src/test/java/org/apache/karaf/camel/itest/CamelBarcodeITest.java
b/tests/features/camel-barcode/src/test/java/org/apache/karaf/camel/itest/CamelBarcodeITest.java
new file mode 100644
index 00000000..359cbf03
--- /dev/null
+++
b/tests/features/camel-barcode/src/test/java/org/apache/karaf/camel/itest/CamelBarcodeITest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed 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.karaf.camel.itest;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.apache.karaf.camel.itests.CamelKarafTestHint;
+import org.apache.karaf.camel.itests.PaxExamWithExternalResource;
+import org.apache.karaf.camel.itests.TemporaryFile;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+@CamelKarafTestHint(externalResourceProvider =
CamelBarcodeITest.ExternalResourceProviders.class)
+@RunWith(PaxExamWithExternalResource.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelBarcodeITest extends
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+ public static final String IMAGE_PROPERTY = "barcode.image";
+
+ @Override
+ public void configureMock(MockEndpoint mock) {
+ mock.expectedBodiesReceived("OK");
+ }
+
+ @Test
+ public void testResultMock() throws Exception {
+ assertMockEndpointsSatisfied();
+ assertTrue(Files.size(Path.of(System.getProperty(IMAGE_PROPERTY))) >
0);
+ }
+
+ public static final class ExternalResourceProviders {
+ public static TemporaryFile createTempFile() throws IOException {
+ return new TemporaryFile(IMAGE_PROPERTY, "barcode", "png");
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index 3f75f60d..2122114a 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -50,6 +50,7 @@
<module>camel-aws2-sqs</module>
<module>camel-aws2-sts</module>
<module>camel-azure-storage-blob</module>
+ <module>camel-barcode</module>
<module>camel-core</module>
<module>camel-ehcache</module>
<module>camel-elasticsearch</module>