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 2014/09/26 17:50:52 UTC

[4/5] git commit: check BarcodeFormat

check BarcodeFormat


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f8b18d69
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f8b18d69
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f8b18d69

Branch: refs/heads/camel-2.14.x
Commit: f8b18d69c68f2ca4d1f3af1e113d0d826693fb1a
Parents: efc2859
Author: Seiji Sogabe <s....@gmail.com>
Authored: Fri Sep 26 15:02:42 2014 +0900
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 26 17:50:32 2014 +0200

----------------------------------------------------------------------
 .../barcode/BarcodeDataFormatCamelTest.java     |  8 +++---
 .../dataformat/barcode/BarcodeTestBase.java     | 30 ++++++++++++++++++--
 2 files changed, 31 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f8b18d69/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java
----------------------------------------------------------------------
diff --git a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java
index d747fbb..b5a5d6b 100644
--- a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java
+++ b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java
@@ -69,7 +69,7 @@ public class BarcodeDataFormatCamelTest extends BarcodeTestBase {
         template.sendBody("direct:code1", MSG);
 
         assertMockEndpointsSatisfied(5, TimeUnit.SECONDS);
-        this.checkImage(image, 100, 100, BarcodeImageType.PNG.toString());
+        this.checkImage(image, 100, 100, BarcodeImageType.PNG.toString(), BarcodeFormat.QR_CODE);
     }
     
     /**
@@ -85,7 +85,7 @@ public class BarcodeDataFormatCamelTest extends BarcodeTestBase {
         template.sendBody("direct:code2", MSG);
 
         assertMockEndpointsSatisfied(5, TimeUnit.SECONDS);
-        this.checkImage(image, 200, 200, BarcodeImageType.PNG.toString());
+        this.checkImage(image, 200, 200, BarcodeImageType.PNG.toString(), BarcodeFormat.QR_CODE);
     }
     
     /**
@@ -101,7 +101,7 @@ public class BarcodeDataFormatCamelTest extends BarcodeTestBase {
         template.sendBody("direct:code3", MSG);
 
         assertMockEndpointsSatisfied(5, TimeUnit.SECONDS);
-        this.checkImage(image, 100, 100, "JPEG");
+        this.checkImage(image, 100, 100, "JPEG", BarcodeFormat.QR_CODE);
     }
     
     /**
@@ -117,7 +117,7 @@ public class BarcodeDataFormatCamelTest extends BarcodeTestBase {
         template.sendBody("direct:code4", MSG);
 
         assertMockEndpointsSatisfied(60, TimeUnit.SECONDS);
-        this.checkImage(image, "JPEG");
+        this.checkImage(image, "JPEG", BarcodeFormat.PDF_417);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/f8b18d69/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeTestBase.java
----------------------------------------------------------------------
diff --git a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeTestBase.java b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeTestBase.java
index 201dcfa..251dc9d 100644
--- a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeTestBase.java
+++ b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeTestBase.java
@@ -16,6 +16,14 @@
  */
 package org.apache.camel.dataformat.barcode;
 
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.BinaryBitmap;
+import com.google.zxing.MultiFormatReader;
+import com.google.zxing.Reader;
+import com.google.zxing.ReaderException;
+import com.google.zxing.Result;
+import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
+import com.google.zxing.common.HybridBinarizer;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
@@ -43,7 +51,7 @@ public class BarcodeTestBase extends CamelTestSupport {
     @EndpointInject(uri = "mock:image")
     MockEndpoint image;
 
-    protected void checkImage(MockEndpoint mock, int height, int width, String type) throws IOException {
+    protected void checkImage(MockEndpoint mock, int height, int width, String type, BarcodeFormat format) throws IOException {
         Exchange ex = mock.getReceivedExchanges().get(0);
         File in = ex.getIn().getBody(File.class);
 
@@ -52,16 +60,32 @@ public class BarcodeTestBase extends CamelTestSupport {
         assertTrue(height >= i.getHeight());
         assertTrue(width >= i.getWidth());
         this.checkType(in, type);
+        this.checkFormat(in, format);
         in.delete();
     }
-    
-    protected void checkImage(MockEndpoint mock, String type) throws IOException {
+
+    protected void checkImage(MockEndpoint mock, String type, BarcodeFormat format) throws IOException {
         Exchange ex = mock.getReceivedExchanges().get(0);
         File in = ex.getIn().getBody(File.class);
         this.checkType(in, type);
+        this.checkFormat(in, format);
         in.delete();
     }
     
+    private void checkFormat(File file, BarcodeFormat format) throws IOException {
+        Reader reader = new MultiFormatReader();
+        BinaryBitmap bitmap = new BinaryBitmap((new HybridBinarizer(
+                new BufferedImageLuminanceSource(ImageIO.read(file)))));
+        Result result;
+        try {
+            result = reader.decode(bitmap);
+        } catch (ReaderException ex) {
+            throw new IOException(ex);
+        }
+        
+        assertEquals(format, result.getBarcodeFormat());
+    }
+    
     private void checkType(File file, String type) throws IOException {
         ImageInputStream iis = ImageIO.createImageInputStream(file);
         ImageReader reader = ImageIO.getImageReaders(iis).next();