camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/5] git commit: check BarcodeFormat
Date Fri, 26 Sep 2014 15:50:49 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x efc285945 -> 720d8e4ff
  refs/heads/master b459854c4 -> 6a8cd4160


check BarcodeFormat

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

Branch: refs/heads/master
Commit: 9356e47994787f29b38aa47c2e01375dd7d137c8
Parents: b1e84ee
Author: Seiji Sogabe <s.sogabe@gmail.com>
Authored: Fri Sep 26 15:02:42 2014 +0900
Committer: Seiji Sogabe <s.sogabe@gmail.com>
Committed: Fri Sep 26 15:02:42 2014 +0900

----------------------------------------------------------------------
 .../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/9356e479/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/9356e479/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();


Mime
View raw message