[mule-scm] [mule][25312] branches/mule-3.3.x: Merged revisions 25310 via svnmerge from

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[mule-scm] [mule][25312] branches/mule-3.3.x: Merged revisions 25310 via svnmerge from

damian.bakarcic
[mule][25312] branches/mule-3.3.x: Merged revisions 25310 via svnmerge from

Diff

Property changes: branches/mule-3.3.x


Modified: svnmerge-integrated

+ /branches/mule-3.2.x:1-22786,22788-22794,22796-22822,22824-22832,22834-22855,22858-22905,22907,22909-22924,22926-22950,22952-22988,22990-22991,22993-23033,23035-23048,23050-23055,23057-23069,23071-23114,23116-23125,23127-23131,23133-23134,23136-23153,23155-23163,23165-23243,23245-23247,23249-23254,23256-23315,23317-23323,23325-23347,23349-23380,23382-23384,23386-23404,23406-23423,23425-23440,23442-23465,23467-23478,23480-23570,23572-23583,23585-23587,23589-23590,23592-23607,23609-23622,23625-23631,23634-23676,23678-23682,23684-23710,23712-23751,23753-23807,23809-23814,23816-23857,23859-23873,23875-23885,23887-23891,23893-23894,23896,23898-23958,23960-24069,24071-24086,24089-24120,24122-24136,24138-24251,24254-24284,24286-24425,24429,24434,24441,24467,24471,24477,24481,24483,24487,24500,24526,24530,24534,24539,24542,24545,24548,24571,24574,24578,24582,24587,24592,24596,24600,24603,24606,24613-24628,24635-24641,24650,24661,24666,24671,24674,24680-24681,246 84-24693,24695,24706,24712,24719-24721,24724,24740,24743,24752-24753,24756-24757,24763,24768,24785-24786,24796,24832,24835,24841-24842,24846,24852,24875,24892,24897,24910,24915,24930,24957,24962,24970,24983,24990,25015,25030,25043,25064,25068,25072,25075,25077,25096,25156,25158,25185,25196,25202,25208,25227,25233-25234,25236,25245,25298,25310

Modified: svn:mergeinfo

/branches/mule-3.2.x:23038,23057,23254,23267,23270-23272,23456,23460,23470,23472,23476,23480,23500,23508-23510,23518,23579,23594,23598,23602,23611,23620,23635,23637,23645,23649,23655,23657,23662,23665,23667,23669,23673-23675,23681,23686,23689,23691,23694,23696,23702,23707,23712,23714,23717,23719,23721-23722,23726,23731,23736,23738,23741,23747,23750,23754,23756,23762-23763,23775,23778-23780,23801,23819,23828,23834,23848,23865,23867,23869,23873,23876,23882-23883,23885,23896,23900,23908,23914,23937-23944,23951,24048-24050,24062,24073,24100,24117,24132-24133,24182-24187,24203,24208,24237-24244,24246,24250,24256,24264,24276-24279,24293-24296,24319,24350,24355,24358,24363,24371,24376,24378,24381,24384,24389-24391,24404-24408,24415,24424,24429,24434,24441,24467,24471,24477,24481,24483,24487,24500,24526,24530,24534,24539,24542,24548,24571,24574,24578,24582,24587,24592,24596,24600,24603,24606,24613-24614,24617-24618,24620,24625,24628,24635-24636,24641,24650,24661,2466 6,24680-24681,24684,24686,24693,24695,24706,24719-24721,24724,24740,24743,24752-24753,24756-24757,24763,24768,24785-24786,24796,24832,24835,24841-24842,24846,24852,24875,24892,24897,24910,24915,24930,24957,24962,24970,24983,24990,25015,25030,25043,25064,25068,25072,25075,25077,25096,25156,25158,25185,25196,25202,25208,25227,25233,25298 + /branches/mule-3.1.x:23002,23163,23454-23455,23459,23471,23475,23499,23506,23509,23516,23596,23610,23618,23628-23631,23634,23644,23647-23648,23653-23654,23659-23661,23672,23674,23679-23680,23684,23693,23700,23713,23734-23735,23749,23753,23761,23777,23800,23818,23859-23860,23864,23872,23884,23899,23907,23935,24072,24097,24118,24202,24318,24349,24354,24362,24370,24388,24414,24466,24470,24482,24486,24525,24529,24533,24537-24538,24547,24570,24577,24586,24595,24599,24619,24623-24624,24634,24665,24677-24679,24705,24739,24742,24749-24751,24851,24874,24891,24914,24956,24959,24969,24980,24988-24989,25042,25063,25095,25195,25198,25225,25232,25294 /branches/mule-3.2.x:23038,23057,23254,23267,23270-23272,23456,23460,23470,23472,23476,23480,23500,23508-23510,23518,23579,23594,23598,23602,23611,23620,23635,23637,23645,23649,23655,23657,23662,23665,23667,23669,23673-23675,23681,23686,23689,23691,23694,23696,23702,23707,23712,23714,23717,23719,23721-23722,23726,23731,23736,23738,23741,23747,23750,23754,23756,23762-23763,23775,23778-23780,23801,23819,23828,23834,23848,23865,23867,23869,23873,23876,23882-23883,23885,23896,23900,23908,23914,23937-23944,23951,24048-24050,24062,24073,24100,24117,24132-24133,24182-24187,24203,24208,24237-24244,24246,24250,24256,24264,24276-24279,24293-24296,24319,24350,24355,24358,24363,24371,24376,24378,24381,24384,24389-24391,24404-24408,24415,24424,24429,24434,24441,24467,24471,24477,24481,24483,24487,24500,24526,24530,24534,24539,24542,24548,24571,24574,24578,24582,24587,24592,24596,24600,24603,24606,24613-24614,24617-24618,24620,24625,24628,24635-24636,24641,24650,246 61,24666,24680-24681,24684,24686,24693,24695,24706,24719-24721,24724,24740,24743,24752-24753,24756-24757,24763,24768,24785-24786,24796,24832,24835,24841-24842,24846,24852,24875,24892,24897,24910,24915,24930,24957,24962,24970,24983,24990,25015,25030,25043,25064,25068,25072,25075,25077,25096,25156,25158,25185,25196,25202,25208,25227,25233,25298,25310

Modified: branches/mule-3.3.x/core/src/main/java/org/mule/transformer/compression/GZipCompressTransformer.java (25311 => 25312)


--- branches/mule-3.3.x/core/src/main/java/org/mule/transformer/compression/GZipCompressTransformer.java	2013-02-27 12:39:17 UTC (rev 25311)
+++ branches/mule-3.3.x/core/src/main/java/org/mule/transformer/compression/GZipCompressTransformer.java	2013-02-27 16:06:40 UTC (rev 25312)
@@ -12,7 +12,6 @@
 
 import org.mule.api.transformer.TransformerException;
 import org.mule.transformer.types.DataTypeFactory;
-import org.mule.util.IOUtils;
 import org.mule.util.SerializationUtils;
 import org.mule.util.compression.GZipCompression;
 
@@ -33,7 +32,8 @@
         this.registerSourceType(DataTypeFactory.create(Serializable.class));
         this.registerSourceType(DataTypeFactory.BYTE_ARRAY);
         this.registerSourceType(DataTypeFactory.INPUT_STREAM);
-        this.setReturnDataType(DataTypeFactory.BYTE_ARRAY);
+        // No type checking for the return type by default. It could either be a byte array or an input stream.
+        this.setReturnDataType(DataTypeFactory.OBJECT);
     }
 
     @Override
@@ -41,28 +41,23 @@
     {
         try
         {
-            byte[] data = null;
-            if (src instanceof byte[])
+            if (src instanceof InputStream)
             {
-                data = (byte[]) src;
+                return getStrategy().compressInputStream((InputStream) src);
             }
-            else if (src instanceof InputStream)
+            else
             {
-                InputStream input = (InputStream)src;
-                try
+                byte[] data;
+                if (src instanceof byte[])
                 {
-                    data = IOUtils.toByteArray(input);
+                    data = (byte[]) src;
                 }
-                finally
+                else
                 {
-                    input.close();
+                    data = SerializationUtils.serialize((Serializable) src);
                 }
+                return getStrategy().compressByteArray(data);
             }
-            else
-            {
-                data = SerializationUtils.serialize((Serializable) src);
-            }
-            return this.getStrategy().compressByteArray(data);
         }
         catch (IOException ioex)
         {

Modified: branches/mule-3.3.x/core/src/main/java/org/mule/transformer/compression/GZipUncompressTransformer.java (25311 => 25312)


--- branches/mule-3.3.x/core/src/main/java/org/mule/transformer/compression/GZipUncompressTransformer.java	2013-02-27 12:39:17 UTC (rev 25311)
+++ branches/mule-3.3.x/core/src/main/java/org/mule/transformer/compression/GZipUncompressTransformer.java	2013-02-27 16:06:40 UTC (rev 25312)
@@ -10,10 +10,10 @@
 
 package org.mule.transformer.compression;
 
+import org.mule.api.transformer.DataType;
 import org.mule.api.transformer.TransformerException;
 import org.mule.config.i18n.MessageFactory;
 import org.mule.transformer.types.DataTypeFactory;
-import org.mule.util.IOUtils;
 import org.mule.util.SerializationUtils;
 import org.mule.util.compression.GZipCompression;
 
@@ -31,47 +31,37 @@
         this.setStrategy(new GZipCompression());
         this.registerSourceType(DataTypeFactory.BYTE_ARRAY);
         this.registerSourceType(DataTypeFactory.INPUT_STREAM);
-        this.setReturnDataType(DataTypeFactory.BYTE_ARRAY);
+        // No type checking for the return type by default. It could either be a byte array or an input stream.
+        this.setReturnDataType(DataTypeFactory.OBJECT);
     }
 
     @Override
     public Object doTransform(Object src, String outputEncoding) throws TransformerException
     {
-        byte[] buffer;
-
         try
         {
-            byte[] input = null;
             if (src instanceof InputStream)
             {
-                InputStream inputStream = (InputStream) src;
-                try
+                return getStrategy().uncompressInputStream((InputStream) src);
+            }
+            else
+            {
+                byte[] buffer = getStrategy().uncompressByteArray((byte[]) src);
+                DataType<?> returnDataType = getReturnDataType();
+                if (!DataTypeFactory.OBJECT.equals(returnDataType) && !DataTypeFactory.BYTE_ARRAY.equals(getReturnDataType()))
                 {
-                    input = IOUtils.toByteArray(inputStream);
+                    return SerializationUtils.deserialize(buffer, muleContext);
                 }
-                finally
+                else
                 {
-                    inputStream.close();
+                    return buffer;
                 }
             }
-            else
-            {
-                input = (byte[]) src;
-            }
-
-            buffer = getStrategy().uncompressByteArray(input);
         }
         catch (IOException e)
         {
             throw new TransformerException(
                     MessageFactory.createStaticMessage("Failed to uncompress message."), this, e);
         }
-
-        if (!DataTypeFactory.BYTE_ARRAY.equals(getReturnDataType()))
-        {
-            return SerializationUtils.deserialize(buffer, muleContext);
-        }
-
-        return buffer;
     }
 }

Modified: branches/mule-3.3.x/core/src/main/java/org/mule/util/compression/CompressionStrategy.java (25311 => 25312)


--- branches/mule-3.3.x/core/src/main/java/org/mule/util/compression/CompressionStrategy.java	2013-02-27 12:39:17 UTC (rev 25311)
+++ branches/mule-3.3.x/core/src/main/java/org/mule/util/compression/CompressionStrategy.java	2013-02-27 16:06:40 UTC (rev 25312)
@@ -11,6 +11,7 @@
 package org.mule.util.compression;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 /**
  * <code>CompressionStrategy</code> is a base interface for Different compression
@@ -32,9 +33,48 @@
      */
     String SERVICE_ID = "META-INF/services/org.mule.util.compression.CompressionStrategy";
 
+    /**
+     * Compresses a byte array.
+     *
+     * @param bytes The byte array to compress.
+     * @return The compressed byte array.
+     * @throws IOException If an I/O error has occurred.
+     */
     byte[] compressByteArray(byte[] bytes) throws IOException;
 
+    /**
+     * Compresses an {@link InputStream}.
+     *
+     * @param is The {@link InputStream} to compress.
+     * @return The compressed {@link InputStream}.
+     * @throws IOException If an I/O error has occurred.
+     */
+    InputStream compressInputStream(InputStream is) throws IOException;
+
+    /**
+     * Uncompresses a compressed byte array.
+     *
+     * @param bytes The byte array to uncompress.
+     * @return The uncompressed byte array.
+     * @throws IOException If an I/O error has occurred.
+     */
     byte[] uncompressByteArray(byte[] bytes) throws IOException;
 
+    /**
+     * Uncompresses a compressed {@link InputStream}.
+     *
+     * @param is The compressed {@link InputStream}.
+     * @return The uncompressed {@link InputStream}.
+     * @throws IOException If an I/O error has occurred.
+     */
+    InputStream uncompressInputStream(InputStream is) throws IOException;
+
+    /**
+     * Checks whether a byte array has been compressed or not.
+     *
+     * @param bytes The byte array.
+     * @return True if the byte array is compressed, false otherwise.
+     * @throws IOException If an I/O error has occurred.
+     */
     boolean isCompressed(byte[] bytes) throws IOException;
 }

Copied: branches/mule-3.3.x/core/src/main/java/org/mule/util/compression/GZIPCompressorInputStream.java (from rev 25310, branches/mule-3.2.x/core/src/main/java/org/mule/util/compression/GZIPCompressorInputStream.java) (0 => 25312)


--- branches/mule-3.3.x/core/src/main/java/org/mule/util/compression/GZIPCompressorInputStream.java	                        (rev 0)
+++ branches/mule-3.3.x/core/src/main/java/org/mule/util/compression/GZIPCompressorInputStream.java	2013-02-27 16:06:40 UTC (rev 25312)
@@ -0,0 +1,177 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+
+package org.mule.util.compression;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.CRC32;
+import java.util.zip.CheckedInputStream;
+import java.util.zip.Deflater;
+import java.util.zip.DeflaterInputStream;
+
+/**
+ * Implements an input stream for compressing input data in the GZIP compression format.
+ */
+public class GZIPCompressorInputStream extends DeflaterInputStream
+{
+    // GZIP header magic number.
+    private final static int GZIP_MAGIC = 0x8b1f;
+
+    // Writes GZIP member header.
+    private final static byte[] HEADER = {
+        (byte) GZIP_MAGIC,                // Magic number (short)
+        (byte)(GZIP_MAGIC >> 8),          // Magic number (short)
+        Deflater.DEFLATED,                // Compression method (CM)
+        0,                                // Flags (FLG)
+        0,                                // Modification time MTIME (int)
+        0,                                // Modification time MTIME (int)
+        0,                                // Modification time MTIME (int)
+        0,                                // Modification time MTIME (int)
+        0,                                // Extra flags (XFLG)
+        0                                 // Operating system (OS)
+    };
+
+    // Trailer length in bytes.
+    private final static int TRAILER_LENGTH = 8;
+
+    // If true, the GZIP trailer has been written.
+    private boolean trailerWritten = false;
+
+    // Internal buffer for GZIP header and trailer.
+    private Buffer buffer;
+
+    /**
+     * Helper inner class containing the length and position of the internal buffer.
+     */
+    private class Buffer
+    {
+        public byte[] data;
+        public int position;
+        public int length;
+
+        /**
+         * Creates a new buffer initializing it with the GZIP header content.
+         */
+        public Buffer()
+        {
+            data = new byte[Math.max(HEADER.length, TRAILER_LENGTH)];
+            System.arraycopy(HEADER, 0, data, 0, HEADER.length);
+            position = 0;
+            length = HEADER.length;
+        }
+
+        /**
+         * Returns the amount of bytes that are left to be read from the buffer.
+         *
+         * @return The byte counts to be read.
+         */
+        int getByteCountRemainder()
+        {
+            return length - position;
+        }
+    }
+
+    /**
+     * Creates a new {@link GZIPCompressorInputStream} from an uncompressed {@link InputStream}.
+     *
+     * @param in The uncompressed {@link InputStream}.
+     */
+    public GZIPCompressorInputStream(InputStream in)
+    {
+        super(new CheckedInputStream(in, new CRC32()), new Deflater(Deflater.DEFAULT_COMPRESSION, true));
+        buffer = new Buffer();
+    }
+
+    public int read(byte b[], int off, int len) throws IOException
+    {
+        // Check if there are bytes left to be read from the internal buffer. This is used to provide the header
+        // or trailer, and always takes precedence.
+        int count;
+        if (buffer.getByteCountRemainder() > 0)
+        {
+            // Write data from the internal buffer into b.
+            count = Math.min(len, buffer.getByteCountRemainder());
+            System.arraycopy(buffer.data, buffer.position, b, off, count);
+
+            // Advance the internal buffer position as "count" bytes have already been read.
+            buffer.position += count;
+            return count;
+        }
+
+        // Attempt to read compressed input data.
+        count = super.read(b, off, len);
+        if (count > 0)
+        {
+            return count;
+        }
+
+        /* If the stream has reached completion, write out the GZIP trailer and re-attempt
+         * the read */
+        if (count <= 0 && !trailerWritten)
+        {
+            buffer.position = 0;
+            buffer.length = writeTrailer(buffer.data, buffer.position);
+            trailerWritten = true;
+            return read(b, off, len);
+        }
+        else
+        {
+            return count;
+        }
+    }
+
+    /**
+     * Writes GZIP member trailer to a byte array, starting at a given offset.
+     *
+     * @param buf The buffer to write the trailer to.
+     * @param offset The offset from which to start writing.
+     * @return The amount of bytes that were written.
+     * @throws IOException If an I/O error is produced.
+     */
+    private int writeTrailer(byte[] buf, int offset) throws IOException
+    {
+        int count = writeInt((int) ((CheckedInputStream) this.in).getChecksum().getValue(), buf, offset); // CRC-32 of uncompr. data
+        count += writeInt(def.getTotalIn(), buf, offset + 4); // Number of uncompr. bytes
+        return count;
+    }
+
+    /**
+     * Writes integer in Intel byte order to a byte array, starting at a given offset.
+     *
+     * @param i The integer to write.
+     * @param buf The buffer to write the integer to.
+     * @param offset The offset from which to start writing.
+     * @return The amount of bytes written.
+     * @throws IOException If an I/O error is produced.
+     */
+    private int writeInt(int i, byte[] buf, int offset) throws IOException
+    {
+        int count = writeShort(i & 0xffff, buf, offset);
+        count += writeShort((i >> 16) & 0xffff, buf, offset + 2);
+        return count;
+    }
+
+    /**
+     * Writes short integer in Intel byte order to a byte array, starting at a given offset.
+     *
+     * @param s The short to write.
+     * @param buf The buffer to write the integer to.
+     * @param offset The offset from which to start writing.
+     * @return The amount of bytes written.
+     * @throws IOException If an I/O error is produced.
+     */
+    private int writeShort(int s, byte[] buf, int offset) throws IOException
+    {
+        buf[offset] = (byte)(s & 0xff);
+        buf[offset + 1] = (byte)((s >> 8) & 0xff);
+        return 2;
+    }
+}

Modified: branches/mule-3.3.x/core/src/main/java/org/mule/util/compression/GZipCompression.java (25311 => 25312)


--- branches/mule-3.3.x/core/src/main/java/org/mule/util/compression/GZipCompression.java	2013-02-27 12:39:17 UTC (rev 25311)
+++ branches/mule-3.3.x/core/src/main/java/org/mule/util/compression/GZipCompression.java	2013-02-27 16:06:40 UTC (rev 25312)
@@ -12,6 +12,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
 
@@ -115,6 +116,11 @@
         }
     }
 
+    public InputStream compressInputStream(InputStream is) throws IOException
+    {
+        return new GZIPCompressorInputStream(is);
+    }
+
     /**
      * Used for uncompressing a byte array into a uncompressed byte array using GZIP
      * 
@@ -185,4 +191,9 @@
         }
     }
 
+    public InputStream uncompressInputStream(InputStream is) throws IOException
+    {
+        return new GZIPInputStream(is);
+    }
+
 }

Modified: branches/mule-3.3.x/core/src/test/java/org/mule/transformer/compression/GZipTransformerStreamTestCase.java (25311 => 25312)


--- branches/mule-3.3.x/core/src/test/java/org/mule/transformer/compression/GZipTransformerStreamTestCase.java	2013-02-27 12:39:17 UTC (rev 25311)
+++ branches/mule-3.3.x/core/src/test/java/org/mule/transformer/compression/GZipTransformerStreamTestCase.java	2013-02-27 16:06:40 UTC (rev 25312)
@@ -10,7 +10,11 @@
 
 package org.mule.transformer.compression;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import org.mule.api.transformer.TransformerException;
+import org.mule.util.IOUtils;
 import org.mule.util.SerializationUtils;
 
 import java.io.ByteArrayInputStream;
@@ -19,23 +23,24 @@
 
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
 public class GZipTransformerStreamTestCase extends GZipTransformerTestCase
 {
     
     @Test
     public void testStreamingCompression() throws TransformerException
     {
-        GZipCompressTransformer transformer = new GZipCompressTransformer();
+        GZipCompressTransformer transformer = (GZipCompressTransformer) super.getTransformer();
         
-        InputStream input = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
+        InputStream uncompressedInputStream = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
 
-        byte[] expected = (byte[]) this.getResultData();
-        byte[] result = (byte[]) transformer.transform(input);
-        
-        assertTrue(Arrays.equals(expected, result));
+        // Compress input data.
+        InputStream compressedInputStream = (InputStream) transformer.transform(uncompressedInputStream);
+
+        byte[] compressedBytes = (byte[]) getResultData();
+        assertTrue(Arrays.equals(compressedBytes, IOUtils.toByteArray(compressedInputStream)));
+
+        IOUtils.closeQuietly(uncompressedInputStream);
+        IOUtils.closeQuietly(compressedInputStream);
     }
 
     @Test
@@ -43,12 +48,37 @@
     {
         GZipUncompressTransformer transformer = new GZipUncompressTransformer();
         transformer.setMuleContext(muleContext);
-        
-        InputStream input = new ByteArrayInputStream((byte[]) this.getResultData());
-        byte[] resultBytes = (byte[]) transformer.transform(input);
-        assertEquals(TEST_DATA, SerializationUtils.deserialize(resultBytes));
+
+        InputStream compressedInputStream = new ByteArrayInputStream((byte[]) getResultData());
+
+        // Decompress the input data.
+        InputStream decompressedInputStream = (InputStream) transformer.transform(compressedInputStream);
+
+        assertEquals(TEST_DATA, SerializationUtils.deserialize(IOUtils.toByteArray(decompressedInputStream)));
+
+        IOUtils.closeQuietly(compressedInputStream);
+        IOUtils.closeQuietly(decompressedInputStream);
     }
 
+    @Test
+    public void testStreamingCompressionDecompression() throws TransformerException
+    {
+        GZipCompressTransformer compressTransformer = (GZipCompressTransformer) super.getTransformer();
+        GZipUncompressTransformer decompressTransformer = new GZipUncompressTransformer();
+        decompressTransformer.setMuleContext(muleContext);
+
+        InputStream input = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
+
+        // Compress the input data.
+        InputStream compressedInputStream = (InputStream) compressTransformer.transform(input);
+        // Decompress the input data.
+        InputStream decompressedInputStream = (InputStream) decompressTransformer.transform(compressedInputStream);
+
+        assertEquals(SerializationUtils.deserialize(IOUtils.toByteArray(decompressedInputStream)), TEST_DATA);
+
+        IOUtils.closeQuietly(compressedInputStream);
+        IOUtils.closeQuietly(decompressedInputStream);
+    }
 }
 
 

Copied: branches/mule-3.3.x/tests/integration/src/test/java/org/mule/test/transformers/GZipTransformerFunctionalTestCase.java (from rev 25310, branches/mule-3.2.x/tests/integration/src/test/java/org/mule/test/transformers/GZipTransformerFunctionalTestCase.java) (0 => 25312)


--- branches/mule-3.3.x/tests/integration/src/test/java/org/mule/test/transformers/GZipTransformerFunctionalTestCase.java	                        (rev 0)
+++ branches/mule-3.3.x/tests/integration/src/test/java/org/mule/test/transformers/GZipTransformerFunctionalTestCase.java	2013-02-27 16:06:40 UTC (rev 25312)
@@ -0,0 +1,81 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+
+package org.mule.test.transformers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.mule.api.MuleMessage;
+import org.mule.module.client.MuleClient;
+import org.mule.tck.junit4.FunctionalTestCase;
+import org.mule.util.IOUtils;
+import org.mule.util.SerializationUtils;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.junit.Test;
+
+/**
+ * Functional test case for the GZipCompressTransformer and GZipUncompressTransformer.
+ */
+public class GZipTransformerFunctionalTestCase extends FunctionalTestCase
+{
+    private static final String TEST_DATA = "the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog";
+
+    @Override
+    protected String getConfigResources()
+    {
+        return "org/mule/test/transformers/gzip-transformer-functional-test.xml";
+    }
+
+    @Test
+    public void testCompressDecompressByteArray() throws Exception
+    {
+        byte[] testDataByteArray = SerializationUtils.serialize(TEST_DATA);
+        MuleClient client = new MuleClient(muleContext);
+
+        // Compress input.
+        MuleMessage compressedResponse = client.send("vm://compressInput", testDataByteArray, null);
+        assertNotNull(compressedResponse);
+        assertTrue(compressedResponse.getPayload() instanceof byte[]);
+
+        // Decompress response.
+        MuleMessage uncompressedResponse = client.send("vm://decompressInput", compressedResponse.getPayload(), null);
+        assertNotNull(uncompressedResponse);
+        assertTrue(uncompressedResponse.getPayload() instanceof byte[]);
+
+        String uncompressedStr = (String) SerializationUtils.deserialize((byte[]) uncompressedResponse.getPayload());
+        assertEquals(TEST_DATA, uncompressedStr);
+    }
+
+    @Test
+    public void testCompressDecompressInputStream() throws Exception
+    {
+        ByteArrayInputStream bis = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
+        MuleClient client = new MuleClient(muleContext);
+
+        // Compress input.
+        MuleMessage compressedResponse = client.send("vm://compressInput", bis, null);
+        assertNotNull(compressedResponse);
+        assertTrue(compressedResponse.getPayload() instanceof InputStream);
+
+        // Decompress response.
+        MuleMessage uncompressedResponse = client.send("vm://decompressInput", compressedResponse.getPayload(), null);
+        assertNotNull(uncompressedResponse);
+        assertTrue(uncompressedResponse.getPayload() instanceof InputStream);
+
+        byte[] uncompressedByteArray = IOUtils.toByteArray((InputStream) uncompressedResponse.getPayload());
+        String uncompressedStr = (String) SerializationUtils.deserialize(uncompressedByteArray);
+        assertEquals(TEST_DATA, uncompressedStr);
+    }
+}

Copied: branches/mule-3.3.x/tests/integration/src/test/resources/org/mule/test/transformers/gzip-transformer-functional-test.xml (from rev 25310, branches/mule-3.2.x/tests/integration/src/test/resources/org/mule/test/transformers/gzip-transformer-functional-test.xml) (0 => 25312)


--- branches/mule-3.3.x/tests/integration/src/test/resources/org/mule/test/transformers/gzip-transformer-functional-test.xml	                        (rev 0)
+++ branches/mule-3.3.x/tests/integration/src/test/resources/org/mule/test/transformers/gzip-transformer-functional-test.xml	2013-02-27 16:06:40 UTC (rev 25312)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
+      xsi:schemaLocation="
+          http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
+          http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd">
+
+    <flow name="compressInput">
+        <vm:inbound-endpoint path="compressInput" exchange-pattern="request-response"/>
+        <gzip-compress-transformer/>
+    </flow>
+
+    <flow name="decompressInput">
+        <vm:inbound-endpoint path="decompressInput" exchange-pattern="request-response"/>
+        <gzip-uncompress-transformer/>
+    </flow>
+
+</mule>

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email