hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shiv...@apache.org
Subject [01/15] incubator-hawq git commit: HAWQ-45. PXF Package Namespace change
Date Wed, 28 Oct 2015 22:09:51 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/HAWQ-45 [created] 1c7ab9eb8


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/BridgeOutputBuilderTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/BridgeOutputBuilderTest.java b/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/BridgeOutputBuilderTest.java
deleted file mode 100644
index fc29815..0000000
--- a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/BridgeOutputBuilderTest.java
+++ /dev/null
@@ -1,219 +0,0 @@
-package com.pivotal.pxf.service;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
-import java.sql.Date;
-import java.sql.Timestamp;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Test;
-
-import com.pivotal.pxf.api.BadRecordException;
-import com.pivotal.pxf.api.OneField;
-import com.pivotal.pxf.api.io.DataType;
-import com.pivotal.pxf.service.io.GPDBWritable;
-import com.pivotal.pxf.service.utilities.ProtocolData;
-
-public class BridgeOutputBuilderTest {
-
-    private static final int UN_SUPPORTED_TYPE = -1;
-    private GPDBWritable output = null;
-
-    @Test
-    public void testFillGPDBWritable() throws Exception {
-        Map<String, String> parameters = new HashMap<String, String>();
-        parameters.put("X-GP-ATTRS", "14");
-
-        addColumn(parameters, 0, DataType.INTEGER,   "col0");
-        addColumn(parameters, 1, DataType.FLOAT8,    "col1");
-        addColumn(parameters, 2, DataType.REAL,      "col2");
-        addColumn(parameters, 3, DataType.BIGINT,    "col3");
-        addColumn(parameters, 4, DataType.SMALLINT,  "col4");
-        addColumn(parameters, 5, DataType.BOOLEAN,   "col5");
-        addColumn(parameters, 6, DataType.BYTEA,     "col6");
-        addColumn(parameters, 7, DataType.VARCHAR,   "col7");
-        addColumn(parameters, 8, DataType.BPCHAR,    "col8");
-        addColumn(parameters, 9, DataType.CHAR,      "col9");
-        addColumn(parameters, 10, DataType.TEXT,     "col10");
-        addColumn(parameters, 11, DataType.NUMERIC,  "col11");
-        addColumn(parameters, 12, DataType.TIMESTAMP,"col12");
-        addColumn(parameters, 13, DataType.DATE,     "col13");
-
-
-        BridgeOutputBuilder builder = makeBuilder(parameters);
-        output = builder.makeGPDBWritableOutput();
-
-        List<OneField> recFields = Arrays.asList(new OneField(DataType.INTEGER.getOID(), 0),
-                new OneField(DataType.FLOAT8.getOID(), (double) 0),
-                new OneField(DataType.REAL.getOID(), (float) 0),
-                new OneField(DataType.BIGINT.getOID(), (long) 0),
-                new OneField(DataType.SMALLINT.getOID(), (short) 0),
-                new OneField(DataType.BOOLEAN.getOID(), true),
-                new OneField(DataType.BYTEA.getOID(), new byte[]{0}),
-                new OneField(DataType.VARCHAR.getOID(), "value"),
-                new OneField(DataType.BPCHAR.getOID(), "value"),
-                new OneField(DataType.CHAR.getOID(), "value"),
-                new OneField(DataType.TEXT.getOID(), "value"),
-                new OneField(DataType.NUMERIC.getOID(), "0"),
-                new OneField(DataType.TIMESTAMP.getOID(), new Timestamp(0)),
-                new OneField(DataType.DATE.getOID(), new Date(1)));
-        builder.fillGPDBWritable(recFields);
-
-        assertEquals(output.getInt(0), Integer.valueOf(0));
-        assertEquals(output.getDouble(1), Double.valueOf(0));
-        assertEquals(output.getFloat(2), Float.valueOf(0));
-        assertEquals(output.getLong(3), Long.valueOf(0));
-        assertEquals(output.getShort(4), Short.valueOf((short) 0));
-        assertEquals(output.getBoolean(5), true);
-        assertArrayEquals(output.getBytes(6), new byte[]{0});
-        assertEquals(output.getString(7), "value\0");
-        assertEquals(output.getString(8), "value\0");
-        assertEquals(output.getString(9), "value\0");
-        assertEquals(output.getString(10), "value\0");
-        assertEquals(output.getString(11), "0\0");
-        assertEquals(Timestamp.valueOf(output.getString(12)), new Timestamp(0));
-        assertEquals(Date.valueOf(output.getString(13).trim()).toString(), new Date(1).toString());
-    }
-
-    @Test
-    public void testFillOneGPDBWritableField() throws Exception {
-        Map<String, String> parameters = new HashMap<String, String>();
-        parameters.put("X-GP-ATTRS", "1");    	
-        addColumn(parameters, 0, DataType.INTEGER, "col0");    	
-        BridgeOutputBuilder builder = makeBuilder(parameters);
-        output = builder.makeGPDBWritableOutput();
-
-        OneField unSupportedField = new OneField(UN_SUPPORTED_TYPE, new Byte((byte) 0));
-        try {
-            builder.fillOneGPDBWritableField(unSupportedField, 0);
-            fail("Unsupported data type should throw exception");
-        } catch (UnsupportedOperationException e) {
-            assertEquals(e.getMessage(), "Byte is not supported for HAWQ conversion");
-        }
-    }
-
-    @Test
-    public void testRecordSmallerThanSchema() throws Exception {
-        Map<String, String> parameters = new HashMap<String, String>();
-        parameters.put("X-GP-ATTRS", "4");
-
-        addColumn(parameters, 0, DataType.INTEGER, "col0");
-        addColumn(parameters, 1, DataType.INTEGER, "col1");
-        addColumn(parameters, 2, DataType.INTEGER, "col2");
-        addColumn(parameters, 3, DataType.INTEGER, "col3");
-
-        BridgeOutputBuilder builder = makeBuilder(parameters);
-        output = builder.makeGPDBWritableOutput();
-
-        /* all four fields */
-        List<OneField> complete = Arrays.asList(
-                new OneField(DataType.INTEGER.getOID(), 10),
-                new OneField(DataType.INTEGER.getOID(), 20),
-                new OneField(DataType.INTEGER.getOID(), 30),
-                new OneField(DataType.INTEGER.getOID(), 40));
-        builder.fillGPDBWritable(complete);
-        assertEquals(output.getColType().length, 4);
-        assertEquals(output.getInt(0), Integer.valueOf(10));
-        assertEquals(output.getInt(1), Integer.valueOf(20));
-        assertEquals(output.getInt(2), Integer.valueOf(30));
-        assertEquals(output.getInt(3), Integer.valueOf(40));
-
-        /* two fields instead of four */
-        List<OneField> incomplete = Arrays.asList(
-        		new OneField(DataType.INTEGER.getOID(), 10),
-    			new OneField(DataType.INTEGER.getOID(), 20));
-        try {
-            builder.fillGPDBWritable(incomplete);
-            fail("testRecordBiggerThanSchema should have failed on - Record has 2 fields but the schema size is 4");
-        } catch (BadRecordException e) {
-            assertEquals(e.getMessage(), "Record has 2 fields but the schema size is 4");
-        }
-    }
-
-    @Test
-    public void testRecordBiggerThanSchema() throws Exception {
-        Map<String, String> parameters = new HashMap<String, String>();
-        parameters.put("X-GP-ATTRS", "4");
-
-        addColumn(parameters, 0, DataType.INTEGER, "col0");
-        addColumn(parameters, 1, DataType.INTEGER, "col1");
-        addColumn(parameters, 2, DataType.INTEGER, "col2");
-        addColumn(parameters, 3, DataType.INTEGER, "col3");
-
-        BridgeOutputBuilder builder = makeBuilder(parameters);
-        output = builder.makeGPDBWritableOutput();
-
-        /* five fields instead of four */
-        List<OneField> complete = Arrays.asList(
-                new OneField(DataType.INTEGER.getOID(), 10),
-                new OneField(DataType.INTEGER.getOID(), 20),
-                new OneField(DataType.INTEGER.getOID(), 30),
-                new OneField(DataType.INTEGER.getOID(), 40),
-                new OneField(DataType.INTEGER.getOID(), 50));
-        try {
-            builder.fillGPDBWritable(complete);
-            fail("testRecordBiggerThanSchema should have failed on - Record has 5 fields but the schema size is 4");
-        } catch (BadRecordException e) {
-            assertEquals(e.getMessage(), "Record has 5 fields but the schema size is 4");
-        }
-    }
-
-    @Test
-    public void testFieldTypeMismatch() throws Exception {
-        Map<String, String> parameters = new HashMap<String, String>();
-        parameters.put("X-GP-ATTRS", "4");
-
-        addColumn(parameters, 0, DataType.INTEGER, "col0");
-        addColumn(parameters, 1, DataType.INTEGER, "col1");
-        addColumn(parameters, 2, DataType.INTEGER, "col2");
-        addColumn(parameters, 3, DataType.INTEGER, "col3");
-
-        BridgeOutputBuilder builder = makeBuilder(parameters);
-        output = builder.makeGPDBWritableOutput();
-
-        /* last field is REAL while schema requires INT */
-        List<OneField> complete = Arrays.asList(
-                new OneField(DataType.INTEGER.getOID(), 10),
-                new OneField(DataType.INTEGER.getOID(), 20),
-                new OneField(DataType.INTEGER.getOID(), 30),
-                new OneField(DataType.REAL.getOID(), 40.0));
-        try {
-            builder.fillGPDBWritable(complete);
-            fail("testFieldTypeMismatch should have failed on - For field 3 schema requires type INTEGER but input record has type REAL");
-        } catch (BadRecordException e) {
-            assertEquals(e.getMessage(), "For field col3 schema requires type INTEGER but input record has type REAL");
-        }
-    }   
-
-    private void addColumn(Map<String, String> parameters, int idx, DataType dataType, String name) {
-        parameters.put("X-GP-ATTR-NAME" + idx, name);
-        parameters.put("X-GP-ATTR-TYPECODE" + idx, Integer.toString(dataType.getOID()));
-        parameters.put("X-GP-ATTR-TYPENAME" + idx, dataType.toString());
-    }
-
-    private BridgeOutputBuilder makeBuilder(Map<String, String> parameters) throws Exception {
-
-        parameters.put("X-GP-ALIGNMENT", "8");
-        parameters.put("X-GP-SEGMENT-ID", "-44");
-        parameters.put("X-GP-SEGMENT-COUNT", "2");
-        parameters.put("X-GP-HAS-FILTER", "0");
-        parameters.put("X-GP-FORMAT", "TEXT");
-        parameters.put("X-GP-URL-HOST", "my://bags");
-        parameters.put("X-GP-URL-PORT", "-8020");
-        parameters.put("X-GP-ACCESSOR", "are");
-        parameters.put("X-GP-RESOLVER", "packed");
-        parameters.put("X-GP-DATA-DIR", "i'm/ready/to/go");
-        parameters.put("X-GP-FRAGMENT-METADATA", "U29tZXRoaW5nIGluIHRoZSB3YXk=");
-        parameters.put("X-GP-I'M-STANDING-HERE", "outside-your-door");
-
-        ProtocolData protocolData = new ProtocolData(parameters);
-        BridgeOutputBuilder builder = new BridgeOutputBuilder(protocolData);
-        return builder;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/MetadataResponseFormatterTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/MetadataResponseFormatterTest.java b/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/MetadataResponseFormatterTest.java
deleted file mode 100644
index a2cd09f..0000000
--- a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/MetadataResponseFormatterTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package com.pivotal.pxf.service;
-
-import static org.junit.Assert.*;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-
-import com.pivotal.pxf.api.Metadata;
-
-public class MetadataResponseFormatterTest {
-
-    String result = null;
-
-    @Test
-    public void formatResponseString() throws Exception {
-        List<Metadata.Field> fields = new ArrayList<Metadata.Field>();
-        Metadata.Table tableName = new Metadata.Table("default", "table1");
-        Metadata metadata = new Metadata(tableName, fields);
-        fields.add(new Metadata.Field("field1", "int"));
-        fields.add(new Metadata.Field("field2", "text"));
-
-        result = MetadataResponseFormatter.formatResponseString(metadata);
-        String expected = "{\"PXFMetadata\":[{"
-                + "\"table\":{\"dbName\":\"default\",\"tableName\":\"table1\"},"
-                + "\"fields\":[{\"name\":\"field1\",\"type\":\"int\"},{\"name\":\"field2\",\"type\":\"text\"}]}]}";
-
-        assertEquals(expected, result);
-    }
-
-    @Test
-    public void formatResponseStringWithNullModifier() throws Exception {
-        List<Metadata.Field> fields = new ArrayList<Metadata.Field>();
-        Metadata.Table tableName = new Metadata.Table("default", "table1");
-        Metadata metadata = new Metadata(tableName, fields);
-        fields.add(new Metadata.Field("field1", "int", null));
-        fields.add(new Metadata.Field("field2", "text", new String[] {}));
-
-        result = MetadataResponseFormatter.formatResponseString(metadata);
-        String expected = "{\"PXFMetadata\":[{"
-                + "\"table\":{\"dbName\":\"default\",\"tableName\":\"table1\"},"
-                + "\"fields\":[{\"name\":\"field1\",\"type\":\"int\"},{\"name\":\"field2\",\"type\":\"text\"}]}]}";
-
-        assertEquals(expected, result);
-    }
-
-    @Test
-    public void formatResponseStringWithModifiers() throws Exception {
-        List<Metadata.Field> fields = new ArrayList<Metadata.Field>();
-        Metadata.Table tableName = new Metadata.Table("default", "table1");
-        Metadata metadata = new Metadata(tableName, fields);
-        fields.add(new Metadata.Field("field1", "int"));
-        fields.add(new Metadata.Field("field2", "numeric",
-                new String[] {"1349", "1789"}));
-        fields.add(new Metadata.Field("field3", "char",
-                new String[] {"50"}));
-
-        result = MetadataResponseFormatter.formatResponseString(metadata);
-        String expected = "{\"PXFMetadata\":[{"
-                + "\"table\":{\"dbName\":\"default\",\"tableName\":\"table1\"},"
-                + "\"fields\":["
-                + "{\"name\":\"field1\",\"type\":\"int\"},"
-                + "{\"name\":\"field2\",\"type\":\"numeric\",\"modifiers\":[\"1349\",\"1789\"]},"
-                + "{\"name\":\"field3\",\"type\":\"char\",\"modifiers\":[\"50\"]}"
-                + "]}]}";
-
-        assertEquals(expected, result);
-    }
-
-    @Test
-    public void formatResponseStringNull() throws Exception {
-        Metadata metadata = null;
-
-        try {
-            result = MetadataResponseFormatter.formatResponseString(metadata);
-            fail("formatting should fail because metadata is null");
-        } catch (IllegalArgumentException e) {
-            assertEquals("metadata object is null - cannot serialize", e.getMessage());
-        }
-    }
-
-    @Test
-    public void formatResponseStringNoFields() throws Exception {
-        Metadata.Table tableName = new Metadata.Table("default", "table1");
-        Metadata metadata = new Metadata(tableName, null);
-
-        try {
-            result = MetadataResponseFormatter.formatResponseString(metadata);
-            fail("formatting should fail because fields field is null");
-        } catch (IllegalArgumentException e) {
-            assertEquals("metadata contains no fields - cannot serialize", e.getMessage());
-        }
-
-        ArrayList<Metadata.Field> fields = new ArrayList<Metadata.Field>();
-        metadata = new Metadata(tableName, fields);
-
-        try {
-            result = MetadataResponseFormatter.formatResponseString(metadata);
-            fail("formatting should fail because there are no fields");
-        } catch (IllegalArgumentException e) {
-            assertEquals("metadata contains no fields - cannot serialize", e.getMessage());
-        }
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/io/GPDBWritableTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/io/GPDBWritableTest.java b/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/io/GPDBWritableTest.java
deleted file mode 100644
index f84d088..0000000
--- a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/io/GPDBWritableTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package com.pivotal.pxf.service.io;
-
-import org.apache.commons.logging.Log;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.mockito.stubbing.OngoingStubbing;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
-
-import java.io.DataInput;
-import java.io.EOFException;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor("GPDBWritable")
-@PrepareForTest({GPDBWritable.class})
-public class GPDBWritableTest {
-
-    DataInput inputStream;
-    OngoingStubbing<Integer> ongoing;
-    Log Log;
-
-    @Before
-    public void SetupStaticLog() {
-        Log = mock(Log.class);
-        Whitebox.setInternalState(GPDBWritable.class, Log);
-    }
-
-    /*
-     * Test the readFields method: empty stream
-	 */
-    @Test
-    public void testReadFieldsEmpty() throws Exception {
-
-        GPDBWritable gpdbWritable = buildGPDBWritable();
-
-        int[] empty = new int[0];
-        buildStream(empty, true);
-
-        gpdbWritable.readFields(inputStream);
-
-        verifyLog("Reached end of stream (EOFException)");
-        assertTrue(gpdbWritable.isEmpty());
-    }
-
-    /*
-     * Test the readFields method: first int -1
-     */
-    @Test
-    public void testReadFieldsFirstIntMinusOne() throws Exception {
-
-        GPDBWritable gpdbWritable = buildGPDBWritable();
-
-        int[] firstInt = new int[]{-1};
-        buildStream(firstInt, false);
-
-        gpdbWritable.readFields(inputStream);
-
-        verifyLog("Reached end of stream (returned -1)");
-        assertTrue(gpdbWritable.isEmpty());
-    }
-
-    /*
-     * Test the readFields method: first int ok (negative and positive numbers)
-     */
-    @Test
-    public void testReadFieldsFirstIntOK() throws Exception {
-        GPDBWritable gpdbWritable = buildGPDBWritable();
-
-        int[] firstInt = new int[]{-2};
-        buildStream(firstInt, true);
-        when(inputStream.readShort()).thenThrow(new EOFException());
-
-        try {
-            gpdbWritable.readFields(inputStream);
-        } catch (EOFException e) {
-            assertTrue(true);
-        } catch (Exception e) {
-            assertTrue(false);
-        }
-
-        assertFalse(gpdbWritable.isEmpty()); // len < 0
-
-        firstInt = new int[]{8};
-        buildStream(firstInt, true);
-        when(inputStream.readShort()).thenThrow(new EOFException());
-
-        try {
-            gpdbWritable.readFields(inputStream);
-        } catch (EOFException e) {
-            assertTrue(true);
-        } catch (Exception e) {
-            assertTrue(false);
-        }
-        assertFalse(gpdbWritable.isEmpty()); // len > 0
-    }
-
-
-    /*
-     * helpers functions
-     */
-    private GPDBWritable buildGPDBWritable()
-            throws Exception {
-        return new GPDBWritable();
-    }
-
-    // add data to stream, end with EOFException on demand.
-    private DataInput buildStream(int[] data, boolean throwException) throws Exception {
-        inputStream = mock(DataInput.class);
-        ongoing = when(inputStream.readInt());
-        for (int b : data) {
-            ongoing = ongoing.thenReturn(b);
-        }
-
-        if (throwException) {
-            ongoing.thenThrow(new EOFException());
-        }
-        return inputStream;
-    }
-
-    private void verifyLog(String msg) {
-        Mockito.verify(Log).debug(msg);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/rest/RestResourceTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/rest/RestResourceTest.java b/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/rest/RestResourceTest.java
deleted file mode 100644
index 2debf34..0000000
--- a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/rest/RestResourceTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package com.pivotal.pxf.service.rest;
-
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-
-import org.apache.commons.codec.CharEncoding;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-
-import javax.ws.rs.core.MultivaluedMap;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-
-@PrepareForTest({RestResource.class})
-public class RestResourceTest {
-
-    RestResource restResource;
-    MultivaluedMap<String, String> multivaluedMap;
-
-    @Test
-    public void testConvertToCaseInsensitiveMap() throws Exception {
-        List<String> multiCaseKeys = Arrays.asList("X-GP-SHLOMO", "x-gp-shlomo", "X-Gp-ShLoMo");
-        String value = "\\\"The king";
-        String replacedValue = "\"The king";
-
-        for (String key : multiCaseKeys) {
-            multivaluedMap.put(key, Collections.singletonList(value));
-        }
-
-        assertEquals("All keys should have existed", multivaluedMap.keySet().size(), multiCaseKeys.size());
-
-        Map<String, String> caseInsensitiveMap = restResource.convertToCaseInsensitiveMap(multivaluedMap);
-
-        assertEquals("Only one key should have exist", caseInsensitiveMap.keySet().size(), 1);
-
-        for (String key : multiCaseKeys) {
-            assertEquals("All keys should have returned the same value", caseInsensitiveMap.get(key), replacedValue);
-        }
-    }
-
-    @Test
-    public void testConvertToCaseInsensitiveMapUtf8() throws Exception {
-        byte[] bytes = {
-                (byte) 0x61, (byte) 0x32, (byte) 0x63, (byte) 0x5c, (byte) 0x22,
-                (byte) 0x55, (byte) 0x54, (byte) 0x46, (byte) 0x38, (byte) 0x5f,
-                (byte) 0xe8, (byte) 0xa8, (byte) 0x88, (byte) 0xe7, (byte) 0xae,
-                (byte) 0x97, (byte) 0xe6, (byte) 0xa9, (byte) 0x9f, (byte) 0xe7,
-                (byte) 0x94, (byte) 0xa8, (byte) 0xe8, (byte) 0xaa, (byte) 0x9e,
-                (byte) 0x5f, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x30,
-                (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x5c,
-                (byte) 0x22, (byte) 0x6f, (byte) 0x35
-        };
-        String value = new String(bytes, CharEncoding.ISO_8859_1);
-
-        multivaluedMap.put("one", Collections.singletonList(value));
-
-        Map<String, String> caseInsensitiveMap = restResource.convertToCaseInsensitiveMap(multivaluedMap);
-
-        assertEquals("Only one key should have exist", caseInsensitiveMap.keySet().size(), 1);
-
-        assertEquals("Value should be converted to UTF-8",
-                caseInsensitiveMap.get("one"), "a2c\"UTF8_計算機用語_00000000\"o5");
-    }
-
-    @Before
-    public void before() throws Exception {
-        restResource = mock(RestResource.class, Mockito.CALLS_REAL_METHODS);
-        multivaluedMap = new MultivaluedMapImpl();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/utilities/ProtocolDataTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/utilities/ProtocolDataTest.java b/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/utilities/ProtocolDataTest.java
deleted file mode 100644
index ae82225..0000000
--- a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/utilities/ProtocolDataTest.java
+++ /dev/null
@@ -1,233 +0,0 @@
-package com.pivotal.pxf.service.utilities;
-
-import com.pivotal.pxf.api.OutputFormat;
-import com.pivotal.pxf.service.utilities.ProtocolData;
-import com.pivotal.pxf.api.utilities.ProfileConfException;
-
-import static com.pivotal.pxf.api.utilities.ProfileConfException.MessageFormat.NO_PROFILE_DEF;
-
-import com.pivotal.pxf.api.utilities.ProfilesConf;
-
-import org.junit.Before;
-import org.junit.After;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TreeMap;
-
-import org.apache.hadoop.security.UserGroupInformation;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({UserGroupInformation.class, ProfilesConf.class})
-public class ProtocolDataTest {
-    Map<String, String> parameters;
-
-    @Test
-    public void protocolDataCreated() throws Exception {
-        ProtocolData protocolData = new ProtocolData(parameters);
-
-        assertEquals(System.getProperty("greenplum.alignment"), "all");
-        assertEquals(protocolData.getTotalSegments(), 2);
-        assertEquals(protocolData.getSegmentId(), -44);
-        assertEquals(protocolData.outputFormat(), OutputFormat.TEXT);
-        assertEquals(protocolData.serverName(), "my://bags");
-        assertEquals(protocolData.serverPort(), -8020);
-        assertFalse(protocolData.hasFilter());
-        assertNull(protocolData.getFilterString());
-        assertEquals(protocolData.getColumns(), 0);
-        assertEquals(protocolData.getDataFragment(), -1);
-        assertNull(protocolData.getRecordkeyColumn());
-        assertEquals(protocolData.getAccessor(), "are");
-        assertEquals(protocolData.getResolver(), "packed");
-        assertEquals(protocolData.getDataSource(), "i'm/ready/to/go");
-        assertEquals(protocolData.getUserProperty("i'm-standing-here"), "outside-your-door");
-        assertEquals(protocolData.getParametersMap(), parameters);
-        assertNull(protocolData.getLogin());
-        assertNull(protocolData.getSecret());
-    }
-
-    @Test
-    public void ProtocolDataCopied() throws Exception {
-        ProtocolData protocolData = new ProtocolData(parameters);
-        ProtocolData copy = new ProtocolData(protocolData);
-        assertEquals(copy.getParametersMap(), protocolData.getParametersMap());
-    }
-
-    @Test
-    public void profileWithDuplicateProperty() throws Exception {
-        PowerMockito.mockStatic(ProfilesConf.class);
-
-        Map<String, String> mockedProfiles = new HashMap<>();
-        mockedProfiles.put("wHEn you trY yOUR bESt", "but you dont succeed");
-        mockedProfiles.put("when YOU get WHAT you WANT", "but not what you need");
-        mockedProfiles.put("when you feel so tired", "but you cant sleep");
-
-        when(ProfilesConf.getProfilePluginsMap("a profile")).thenReturn(mockedProfiles);
-
-        parameters.put("x-gp-profile", "a profile");
-        parameters.put("when you try your best", "and you do succeed");
-        parameters.put("WHEN you GET what YOU want", "and what you need");
-
-        try {
-            new ProtocolData(parameters);
-            fail("Duplicate property should throw IllegalArgumentException");
-        } catch (IllegalArgumentException iae) {
-            assertEquals("Profile 'a profile' already defines: [when YOU get WHAT you WANT, wHEn you trY yOUR bESt]",
-                    iae.getMessage());
-        }
-    }
-
-    @Test
-    public void definedProfile() throws Exception {
-        parameters.put("X-GP-PROFILE", "HIVE");
-        parameters.remove("X-GP-ACCESSOR");
-        parameters.remove("X-GP-RESOLVER");
-        ProtocolData protocolData = new ProtocolData(parameters);
-        assertEquals(protocolData.getFragmenter(), "com.pivotal.pxf.plugins.hive.HiveDataFragmenter");
-        assertEquals(protocolData.getAccessor(), "com.pivotal.pxf.plugins.hive.HiveAccessor");
-        assertEquals(protocolData.getResolver(), "com.pivotal.pxf.plugins.hive.HiveResolver");
-    }
-
-    @Test
-    public void undefinedProfile() throws Exception {
-        parameters.put("X-GP-PROFILE", "THIS_PROFILE_NEVER_EXISTED!");
-        try {
-            new ProtocolData(parameters);
-            fail("Undefined profile should throw ProfileConfException");
-        } catch (ProfileConfException pce) {
-            assertEquals(pce.getMsgFormat(), NO_PROFILE_DEF);
-        }
-    }
-
-    @Test
-    public void threadSafeTrue() throws Exception {
-        parameters.put("X-GP-THREAD-SAFE", "TRUE");
-        ProtocolData protocolData = new ProtocolData(parameters);
-        assertEquals(protocolData.isThreadSafe(), true);
-
-        parameters.put("X-GP-THREAD-SAFE", "true");
-        protocolData = new ProtocolData(parameters);
-        assertEquals(protocolData.isThreadSafe(), true);
-    }
-
-    @Test
-    public void threadSafeFalse() throws Exception {
-        parameters.put("X-GP-THREAD-SAFE", "False");
-        ProtocolData protocolData = new ProtocolData(parameters);
-        assertEquals(protocolData.isThreadSafe(), false);
-
-        parameters.put("X-GP-THREAD-SAFE", "falSE");
-        protocolData = new ProtocolData(parameters);
-        assertEquals(protocolData.isThreadSafe(), false);
-    }
-
-    @Test
-    public void threadSafeMaybe() throws Exception {
-        parameters.put("X-GP-THREAD-SAFE", "maybe");
-        try {
-            new ProtocolData(parameters);
-            fail("illegal THREAD-SAFE value should throw IllegalArgumentException");
-        } catch (IllegalArgumentException e) {
-            assertEquals(e.getMessage(),
-                    "Illegal boolean value 'maybe'. Usage: [TRUE|FALSE]");
-        }
-    }
-
-    @Test
-    public void threadSafeDefault() throws Exception {
-        parameters.remove("X-GP-THREAD-SAFE");
-        ProtocolData protocolData = new ProtocolData(parameters);
-        assertEquals(protocolData.isThreadSafe(), true);
-    }
-
-    @Test
-    public void getFragmentMetadata() throws Exception {
-        ProtocolData protocolData = new ProtocolData(parameters);
-        byte[] location = protocolData.getFragmentMetadata();
-        assertEquals(new String(location), "Something in the way");
-    }
-
-    @Test
-    public void getFragmentMetadataNull() throws Exception {
-        parameters.remove("X-GP-FRAGMENT-METADATA");
-        ProtocolData ProtocolData = new ProtocolData(parameters);
-        assertNull(ProtocolData.getFragmentMetadata());
-    }
-
-    @Test
-    public void getFragmentMetadataNotBase64() throws Exception {
-        String badValue = "so b@d";
-        parameters.put("X-GP-FRAGMENT-METADATA", badValue);
-        try {
-            new ProtocolData(parameters);
-            fail("should fail with bad fragment metadata");
-        } catch (Exception e) {
-            assertEquals(e.getMessage(), "Fragment metadata information must be Base64 encoded." +
-                    "(Bad value: " + badValue + ")");
-        }
-    }
-
-    @Test
-    public void nullTokenThrows() throws Exception {
-        when(UserGroupInformation.isSecurityEnabled()).thenReturn(true);
-
-        try {
-            new ProtocolData(parameters);
-            fail("null X-GP-TOKEN should throw");
-        } catch (IllegalArgumentException e) {
-            assertEquals(e.getMessage(),
-                    "Internal server error. Property \"TOKEN\" has no value in current request");
-        }
-    }
-
-    @Test
-    public void filterUtf8() throws Exception {
-        parameters.remove("X-GP-HAS-FILTER");
-        parameters.put("X-GP-HAS-FILTER", "1");
-        parameters.put("X-GP-FILTER", "UTF8_計算機用語_00000000");
-        ProtocolData protocolData = new ProtocolData(parameters);
-        assertTrue(protocolData.hasFilter());
-        assertEquals("UTF8_計算機用語_00000000", protocolData.getFilterString());
-    }
-
-    /*
-     * setUp function called before each test
-     */
-    @Before
-    public void setUp() {
-        parameters = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
-
-        parameters.put("X-GP-ALIGNMENT", "all");
-        parameters.put("X-GP-SEGMENT-ID", "-44");
-        parameters.put("X-GP-SEGMENT-COUNT", "2");
-        parameters.put("X-GP-HAS-FILTER", "0");
-        parameters.put("X-GP-FORMAT", "TEXT");
-        parameters.put("X-GP-URL-HOST", "my://bags");
-        parameters.put("X-GP-URL-PORT", "-8020");
-        parameters.put("X-GP-ATTRS", "-1");
-        parameters.put("X-GP-ACCESSOR", "are");
-        parameters.put("X-GP-RESOLVER", "packed");
-        parameters.put("X-GP-DATA-DIR", "i'm/ready/to/go");
-        parameters.put("X-GP-FRAGMENT-METADATA", "U29tZXRoaW5nIGluIHRoZSB3YXk=");
-        parameters.put("X-GP-I'M-STANDING-HERE", "outside-your-door");
-
-        PowerMockito.mockStatic(UserGroupInformation.class);
-    }
-
-    /*
-     * tearDown function called after each test
-     */
-    @After
-    public void tearDown() {
-        // Cleanup the system property ProtocolData sets
-        System.clearProperty("greenplum.alignment");
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/utilities/SecuredHDFSTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/utilities/SecuredHDFSTest.java b/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/utilities/SecuredHDFSTest.java
deleted file mode 100644
index 340091b..0000000
--- a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/utilities/SecuredHDFSTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package com.pivotal.pxf.service.utilities;
-
-import org.apache.hadoop.security.UserGroupInformation;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import javax.servlet.ServletContext;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({UserGroupInformation.class})
-public class SecuredHDFSTest {
-    Map<String, String> parameters;
-    ProtocolData mockProtocolData;
-    ServletContext mockContext;
-
-    @Test
-    public void invalidTokenThrows() {
-        when(UserGroupInformation.isSecurityEnabled()).thenReturn(true);
-        when(mockProtocolData.getToken()).thenReturn("This is odd");
-
-        try {
-            SecuredHDFS.verifyToken(mockProtocolData, mockContext);
-            fail("invalid X-GP-TOKEN should throw");
-        } catch (SecurityException e) {
-            assertEquals("Failed to verify delegation token java.io.EOFException", e.getMessage());
-        }
-    }
-
-    /*
-     * setUp function called before each test
-	 */
-    @Before
-    public void setUp() {
-        parameters = new HashMap<>();
-
-        parameters.put("X-GP-ALIGNMENT", "all");
-        parameters.put("X-GP-SEGMENT-ID", "-44");
-        parameters.put("X-GP-SEGMENT-COUNT", "2");
-        parameters.put("X-GP-HAS-FILTER", "0");
-        parameters.put("X-GP-FORMAT", "TEXT");
-        parameters.put("X-GP-URL-HOST", "my://bags");
-        parameters.put("X-GP-URL-PORT", "-8020");
-        parameters.put("X-GP-ATTRS", "-1");
-        parameters.put("X-GP-ACCESSOR", "are");
-        parameters.put("X-GP-RESOLVER", "packed");
-        parameters.put("X-GP-DATA-DIR", "i'm/ready/to/go");
-        parameters.put("X-GP-FRAGMENT-METADATA", "U29tZXRoaW5nIGluIHRoZSB3YXk=");
-        parameters.put("X-GP-I'M-STANDING-HERE", "outside-your-door");
-
-        mockProtocolData = mock(ProtocolData.class);        
-        mockContext = mock(ServletContext.class);
-
-        PowerMockito.mockStatic(UserGroupInformation.class);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/utilities/UtilitiesTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/utilities/UtilitiesTest.java b/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/utilities/UtilitiesTest.java
deleted file mode 100644
index 9b7bd40..0000000
--- a/pxf/pxf-service/src/test/java/com/pivotal/pxf/service/utilities/UtilitiesTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.pivotal.pxf.service.utilities;
-
-import org.apache.hadoop.security.UserGroupInformation;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({UserGroupInformation.class})
-public class UtilitiesTest {
-    @Test
-    public void byteArrayToOctalStringNull() throws Exception {
-        StringBuilder sb = null;
-        byte[] bytes = "nofink".getBytes();
-
-        Utilities.byteArrayToOctalString(bytes, sb);
-
-        assertNull(sb);
-
-        sb = new StringBuilder();
-        bytes = null;
-
-        Utilities.byteArrayToOctalString(bytes, sb);
-
-        assertEquals(0, sb.length());
-    }
-
-    @Test
-    public void byteArrayToOctalString() throws Exception {
-        String orig = "Have Narisha";
-        String octal = "Rash Rash Rash!";
-        String expected = orig + "\\\\122\\\\141\\\\163\\\\150\\\\040"
-                + "\\\\122\\\\141\\\\163\\\\150\\\\040"
-                + "\\\\122\\\\141\\\\163\\\\150\\\\041";
-        StringBuilder sb = new StringBuilder();
-        sb.append(orig);
-
-        Utilities.byteArrayToOctalString(octal.getBytes(), sb);
-
-        assertEquals(orig.length() + (octal.length() * 5), sb.length());
-        assertEquals(expected, sb.toString());
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/BridgeOutputBuilderTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/BridgeOutputBuilderTest.java b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/BridgeOutputBuilderTest.java
new file mode 100644
index 0000000..137622d
--- /dev/null
+++ b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/BridgeOutputBuilderTest.java
@@ -0,0 +1,219 @@
+package org.apache.hawq.pxf.service;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+
+import org.apache.hawq.pxf.api.BadRecordException;
+import org.apache.hawq.pxf.api.OneField;
+import org.apache.hawq.pxf.api.io.DataType;
+import org.apache.hawq.pxf.service.io.GPDBWritable;
+import org.apache.hawq.pxf.service.utilities.ProtocolData;
+
+public class BridgeOutputBuilderTest {
+
+    private static final int UN_SUPPORTED_TYPE = -1;
+    private GPDBWritable output = null;
+
+    @Test
+    public void testFillGPDBWritable() throws Exception {
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put("X-GP-ATTRS", "14");
+
+        addColumn(parameters, 0, DataType.INTEGER,   "col0");
+        addColumn(parameters, 1, DataType.FLOAT8,    "col1");
+        addColumn(parameters, 2, DataType.REAL,      "col2");
+        addColumn(parameters, 3, DataType.BIGINT,    "col3");
+        addColumn(parameters, 4, DataType.SMALLINT,  "col4");
+        addColumn(parameters, 5, DataType.BOOLEAN,   "col5");
+        addColumn(parameters, 6, DataType.BYTEA,     "col6");
+        addColumn(parameters, 7, DataType.VARCHAR,   "col7");
+        addColumn(parameters, 8, DataType.BPCHAR,    "col8");
+        addColumn(parameters, 9, DataType.CHAR,      "col9");
+        addColumn(parameters, 10, DataType.TEXT,     "col10");
+        addColumn(parameters, 11, DataType.NUMERIC,  "col11");
+        addColumn(parameters, 12, DataType.TIMESTAMP,"col12");
+        addColumn(parameters, 13, DataType.DATE,     "col13");
+
+
+        BridgeOutputBuilder builder = makeBuilder(parameters);
+        output = builder.makeGPDBWritableOutput();
+
+        List<OneField> recFields = Arrays.asList(new OneField(DataType.INTEGER.getOID(), 0),
+                new OneField(DataType.FLOAT8.getOID(), (double) 0),
+                new OneField(DataType.REAL.getOID(), (float) 0),
+                new OneField(DataType.BIGINT.getOID(), (long) 0),
+                new OneField(DataType.SMALLINT.getOID(), (short) 0),
+                new OneField(DataType.BOOLEAN.getOID(), true),
+                new OneField(DataType.BYTEA.getOID(), new byte[]{0}),
+                new OneField(DataType.VARCHAR.getOID(), "value"),
+                new OneField(DataType.BPCHAR.getOID(), "value"),
+                new OneField(DataType.CHAR.getOID(), "value"),
+                new OneField(DataType.TEXT.getOID(), "value"),
+                new OneField(DataType.NUMERIC.getOID(), "0"),
+                new OneField(DataType.TIMESTAMP.getOID(), new Timestamp(0)),
+                new OneField(DataType.DATE.getOID(), new Date(1)));
+        builder.fillGPDBWritable(recFields);
+
+        assertEquals(output.getInt(0), Integer.valueOf(0));
+        assertEquals(output.getDouble(1), Double.valueOf(0));
+        assertEquals(output.getFloat(2), Float.valueOf(0));
+        assertEquals(output.getLong(3), Long.valueOf(0));
+        assertEquals(output.getShort(4), Short.valueOf((short) 0));
+        assertEquals(output.getBoolean(5), true);
+        assertArrayEquals(output.getBytes(6), new byte[]{0});
+        assertEquals(output.getString(7), "value\0");
+        assertEquals(output.getString(8), "value\0");
+        assertEquals(output.getString(9), "value\0");
+        assertEquals(output.getString(10), "value\0");
+        assertEquals(output.getString(11), "0\0");
+        assertEquals(Timestamp.valueOf(output.getString(12)), new Timestamp(0));
+        assertEquals(Date.valueOf(output.getString(13).trim()).toString(), new Date(1).toString());
+    }
+
+    @Test
+    public void testFillOneGPDBWritableField() throws Exception {
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put("X-GP-ATTRS", "1");    	
+        addColumn(parameters, 0, DataType.INTEGER, "col0");    	
+        BridgeOutputBuilder builder = makeBuilder(parameters);
+        output = builder.makeGPDBWritableOutput();
+
+        OneField unSupportedField = new OneField(UN_SUPPORTED_TYPE, new Byte((byte) 0));
+        try {
+            builder.fillOneGPDBWritableField(unSupportedField, 0);
+            fail("Unsupported data type should throw exception");
+        } catch (UnsupportedOperationException e) {
+            assertEquals(e.getMessage(), "Byte is not supported for HAWQ conversion");
+        }
+    }
+
+    @Test
+    public void testRecordSmallerThanSchema() throws Exception {
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put("X-GP-ATTRS", "4");
+
+        addColumn(parameters, 0, DataType.INTEGER, "col0");
+        addColumn(parameters, 1, DataType.INTEGER, "col1");
+        addColumn(parameters, 2, DataType.INTEGER, "col2");
+        addColumn(parameters, 3, DataType.INTEGER, "col3");
+
+        BridgeOutputBuilder builder = makeBuilder(parameters);
+        output = builder.makeGPDBWritableOutput();
+
+        /* all four fields */
+        List<OneField> complete = Arrays.asList(
+                new OneField(DataType.INTEGER.getOID(), 10),
+                new OneField(DataType.INTEGER.getOID(), 20),
+                new OneField(DataType.INTEGER.getOID(), 30),
+                new OneField(DataType.INTEGER.getOID(), 40));
+        builder.fillGPDBWritable(complete);
+        assertEquals(output.getColType().length, 4);
+        assertEquals(output.getInt(0), Integer.valueOf(10));
+        assertEquals(output.getInt(1), Integer.valueOf(20));
+        assertEquals(output.getInt(2), Integer.valueOf(30));
+        assertEquals(output.getInt(3), Integer.valueOf(40));
+
+        /* two fields instead of four */
+        List<OneField> incomplete = Arrays.asList(
+        		new OneField(DataType.INTEGER.getOID(), 10),
+    			new OneField(DataType.INTEGER.getOID(), 20));
+        try {
+            builder.fillGPDBWritable(incomplete);
+            fail("testRecordBiggerThanSchema should have failed on - Record has 2 fields but the schema size is 4");
+        } catch (BadRecordException e) {
+            assertEquals(e.getMessage(), "Record has 2 fields but the schema size is 4");
+        }
+    }
+
+    @Test
+    public void testRecordBiggerThanSchema() throws Exception {
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put("X-GP-ATTRS", "4");
+
+        addColumn(parameters, 0, DataType.INTEGER, "col0");
+        addColumn(parameters, 1, DataType.INTEGER, "col1");
+        addColumn(parameters, 2, DataType.INTEGER, "col2");
+        addColumn(parameters, 3, DataType.INTEGER, "col3");
+
+        BridgeOutputBuilder builder = makeBuilder(parameters);
+        output = builder.makeGPDBWritableOutput();
+
+        /* five fields instead of four */
+        List<OneField> complete = Arrays.asList(
+                new OneField(DataType.INTEGER.getOID(), 10),
+                new OneField(DataType.INTEGER.getOID(), 20),
+                new OneField(DataType.INTEGER.getOID(), 30),
+                new OneField(DataType.INTEGER.getOID(), 40),
+                new OneField(DataType.INTEGER.getOID(), 50));
+        try {
+            builder.fillGPDBWritable(complete);
+            fail("testRecordBiggerThanSchema should have failed on - Record has 5 fields but the schema size is 4");
+        } catch (BadRecordException e) {
+            assertEquals(e.getMessage(), "Record has 5 fields but the schema size is 4");
+        }
+    }
+
+    @Test
+    public void testFieldTypeMismatch() throws Exception {
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put("X-GP-ATTRS", "4");
+
+        addColumn(parameters, 0, DataType.INTEGER, "col0");
+        addColumn(parameters, 1, DataType.INTEGER, "col1");
+        addColumn(parameters, 2, DataType.INTEGER, "col2");
+        addColumn(parameters, 3, DataType.INTEGER, "col3");
+
+        BridgeOutputBuilder builder = makeBuilder(parameters);
+        output = builder.makeGPDBWritableOutput();
+
+        /* last field is REAL while schema requires INT */
+        List<OneField> complete = Arrays.asList(
+                new OneField(DataType.INTEGER.getOID(), 10),
+                new OneField(DataType.INTEGER.getOID(), 20),
+                new OneField(DataType.INTEGER.getOID(), 30),
+                new OneField(DataType.REAL.getOID(), 40.0));
+        try {
+            builder.fillGPDBWritable(complete);
+            fail("testFieldTypeMismatch should have failed on - For field 3 schema requires type INTEGER but input record has type REAL");
+        } catch (BadRecordException e) {
+            assertEquals(e.getMessage(), "For field col3 schema requires type INTEGER but input record has type REAL");
+        }
+    }   
+
+    private void addColumn(Map<String, String> parameters, int idx, DataType dataType, String name) {
+        parameters.put("X-GP-ATTR-NAME" + idx, name);
+        parameters.put("X-GP-ATTR-TYPECODE" + idx, Integer.toString(dataType.getOID()));
+        parameters.put("X-GP-ATTR-TYPENAME" + idx, dataType.toString());
+    }
+
+    private BridgeOutputBuilder makeBuilder(Map<String, String> parameters) throws Exception {
+
+        parameters.put("X-GP-ALIGNMENT", "8");
+        parameters.put("X-GP-SEGMENT-ID", "-44");
+        parameters.put("X-GP-SEGMENT-COUNT", "2");
+        parameters.put("X-GP-HAS-FILTER", "0");
+        parameters.put("X-GP-FORMAT", "TEXT");
+        parameters.put("X-GP-URL-HOST", "my://bags");
+        parameters.put("X-GP-URL-PORT", "-8020");
+        parameters.put("X-GP-ACCESSOR", "are");
+        parameters.put("X-GP-RESOLVER", "packed");
+        parameters.put("X-GP-DATA-DIR", "i'm/ready/to/go");
+        parameters.put("X-GP-FRAGMENT-METADATA", "U29tZXRoaW5nIGluIHRoZSB3YXk=");
+        parameters.put("X-GP-I'M-STANDING-HERE", "outside-your-door");
+
+        ProtocolData protocolData = new ProtocolData(parameters);
+        BridgeOutputBuilder builder = new BridgeOutputBuilder(protocolData);
+        return builder;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/MetadataResponseFormatterTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/MetadataResponseFormatterTest.java b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/MetadataResponseFormatterTest.java
new file mode 100644
index 0000000..1e43d1e
--- /dev/null
+++ b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/MetadataResponseFormatterTest.java
@@ -0,0 +1,106 @@
+package org.apache.hawq.pxf.service;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+import org.apache.hawq.pxf.api.Metadata;
+
+public class MetadataResponseFormatterTest {
+
+    String result = null;
+
+    @Test
+    public void formatResponseString() throws Exception {
+        List<Metadata.Field> fields = new ArrayList<Metadata.Field>();
+        Metadata.Table tableName = new Metadata.Table("default", "table1");
+        Metadata metadata = new Metadata(tableName, fields);
+        fields.add(new Metadata.Field("field1", "int"));
+        fields.add(new Metadata.Field("field2", "text"));
+
+        result = MetadataResponseFormatter.formatResponseString(metadata);
+        String expected = "{\"PXFMetadata\":[{"
+                + "\"table\":{\"dbName\":\"default\",\"tableName\":\"table1\"},"
+                + "\"fields\":[{\"name\":\"field1\",\"type\":\"int\"},{\"name\":\"field2\",\"type\":\"text\"}]}]}";
+
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void formatResponseStringWithNullModifier() throws Exception {
+        List<Metadata.Field> fields = new ArrayList<Metadata.Field>();
+        Metadata.Table tableName = new Metadata.Table("default", "table1");
+        Metadata metadata = new Metadata(tableName, fields);
+        fields.add(new Metadata.Field("field1", "int", null));
+        fields.add(new Metadata.Field("field2", "text", new String[] {}));
+
+        result = MetadataResponseFormatter.formatResponseString(metadata);
+        String expected = "{\"PXFMetadata\":[{"
+                + "\"table\":{\"dbName\":\"default\",\"tableName\":\"table1\"},"
+                + "\"fields\":[{\"name\":\"field1\",\"type\":\"int\"},{\"name\":\"field2\",\"type\":\"text\"}]}]}";
+
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void formatResponseStringWithModifiers() throws Exception {
+        List<Metadata.Field> fields = new ArrayList<Metadata.Field>();
+        Metadata.Table tableName = new Metadata.Table("default", "table1");
+        Metadata metadata = new Metadata(tableName, fields);
+        fields.add(new Metadata.Field("field1", "int"));
+        fields.add(new Metadata.Field("field2", "numeric",
+                new String[] {"1349", "1789"}));
+        fields.add(new Metadata.Field("field3", "char",
+                new String[] {"50"}));
+
+        result = MetadataResponseFormatter.formatResponseString(metadata);
+        String expected = "{\"PXFMetadata\":[{"
+                + "\"table\":{\"dbName\":\"default\",\"tableName\":\"table1\"},"
+                + "\"fields\":["
+                + "{\"name\":\"field1\",\"type\":\"int\"},"
+                + "{\"name\":\"field2\",\"type\":\"numeric\",\"modifiers\":[\"1349\",\"1789\"]},"
+                + "{\"name\":\"field3\",\"type\":\"char\",\"modifiers\":[\"50\"]}"
+                + "]}]}";
+
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void formatResponseStringNull() throws Exception {
+        Metadata metadata = null;
+
+        try {
+            result = MetadataResponseFormatter.formatResponseString(metadata);
+            fail("formatting should fail because metadata is null");
+        } catch (IllegalArgumentException e) {
+            assertEquals("metadata object is null - cannot serialize", e.getMessage());
+        }
+    }
+
+    @Test
+    public void formatResponseStringNoFields() throws Exception {
+        Metadata.Table tableName = new Metadata.Table("default", "table1");
+        Metadata metadata = new Metadata(tableName, null);
+
+        try {
+            result = MetadataResponseFormatter.formatResponseString(metadata);
+            fail("formatting should fail because fields field is null");
+        } catch (IllegalArgumentException e) {
+            assertEquals("metadata contains no fields - cannot serialize", e.getMessage());
+        }
+
+        ArrayList<Metadata.Field> fields = new ArrayList<Metadata.Field>();
+        metadata = new Metadata(tableName, fields);
+
+        try {
+            result = MetadataResponseFormatter.formatResponseString(metadata);
+            fail("formatting should fail because there are no fields");
+        } catch (IllegalArgumentException e) {
+            assertEquals("metadata contains no fields - cannot serialize", e.getMessage());
+        }
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java
new file mode 100644
index 0000000..45a0163
--- /dev/null
+++ b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java
@@ -0,0 +1,132 @@
+package org.apache.hawq.pxf.service.io;
+
+import org.apache.commons.logging.Log;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.stubbing.OngoingStubbing;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+
+import java.io.DataInput;
+import java.io.EOFException;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(PowerMockRunner.class)
+@SuppressStaticInitializationFor("GPDBWritable")
+@PrepareForTest({GPDBWritable.class})
+public class GPDBWritableTest {
+
+    DataInput inputStream;
+    OngoingStubbing<Integer> ongoing;
+    Log Log;
+
+    @Before
+    public void SetupStaticLog() {
+        Log = mock(Log.class);
+        Whitebox.setInternalState(GPDBWritable.class, Log);
+    }
+
+    /*
+     * Test the readFields method: empty stream
+	 */
+    @Test
+    public void testReadFieldsEmpty() throws Exception {
+
+        GPDBWritable gpdbWritable = buildGPDBWritable();
+
+        int[] empty = new int[0];
+        buildStream(empty, true);
+
+        gpdbWritable.readFields(inputStream);
+
+        verifyLog("Reached end of stream (EOFException)");
+        assertTrue(gpdbWritable.isEmpty());
+    }
+
+    /*
+     * Test the readFields method: first int -1
+     */
+    @Test
+    public void testReadFieldsFirstIntMinusOne() throws Exception {
+
+        GPDBWritable gpdbWritable = buildGPDBWritable();
+
+        int[] firstInt = new int[]{-1};
+        buildStream(firstInt, false);
+
+        gpdbWritable.readFields(inputStream);
+
+        verifyLog("Reached end of stream (returned -1)");
+        assertTrue(gpdbWritable.isEmpty());
+    }
+
+    /*
+     * Test the readFields method: first int ok (negative and positive numbers)
+     */
+    @Test
+    public void testReadFieldsFirstIntOK() throws Exception {
+        GPDBWritable gpdbWritable = buildGPDBWritable();
+
+        int[] firstInt = new int[]{-2};
+        buildStream(firstInt, true);
+        when(inputStream.readShort()).thenThrow(new EOFException());
+
+        try {
+            gpdbWritable.readFields(inputStream);
+        } catch (EOFException e) {
+            assertTrue(true);
+        } catch (Exception e) {
+            assertTrue(false);
+        }
+
+        assertFalse(gpdbWritable.isEmpty()); // len < 0
+
+        firstInt = new int[]{8};
+        buildStream(firstInt, true);
+        when(inputStream.readShort()).thenThrow(new EOFException());
+
+        try {
+            gpdbWritable.readFields(inputStream);
+        } catch (EOFException e) {
+            assertTrue(true);
+        } catch (Exception e) {
+            assertTrue(false);
+        }
+        assertFalse(gpdbWritable.isEmpty()); // len > 0
+    }
+
+
+    /*
+     * helpers functions
+     */
+    private GPDBWritable buildGPDBWritable()
+            throws Exception {
+        return new GPDBWritable();
+    }
+
+    // add data to stream, end with EOFException on demand.
+    private DataInput buildStream(int[] data, boolean throwException) throws Exception {
+        inputStream = mock(DataInput.class);
+        ongoing = when(inputStream.readInt());
+        for (int b : data) {
+            ongoing = ongoing.thenReturn(b);
+        }
+
+        if (throwException) {
+            ongoing.thenThrow(new EOFException());
+        }
+        return inputStream;
+    }
+
+    private void verifyLog(String msg) {
+        Mockito.verify(Log).debug(msg);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/rest/RestResourceTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/rest/RestResourceTest.java b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/rest/RestResourceTest.java
new file mode 100644
index 0000000..6cacbec
--- /dev/null
+++ b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/rest/RestResourceTest.java
@@ -0,0 +1,77 @@
+package org.apache.hawq.pxf.service.rest;
+
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+
+import org.apache.commons.codec.CharEncoding;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+
+@PrepareForTest({RestResource.class})
+public class RestResourceTest {
+
+    RestResource restResource;
+    MultivaluedMap<String, String> multivaluedMap;
+
+    @Test
+    public void testConvertToCaseInsensitiveMap() throws Exception {
+        List<String> multiCaseKeys = Arrays.asList("X-GP-SHLOMO", "x-gp-shlomo", "X-Gp-ShLoMo");
+        String value = "\\\"The king";
+        String replacedValue = "\"The king";
+
+        for (String key : multiCaseKeys) {
+            multivaluedMap.put(key, Collections.singletonList(value));
+        }
+
+        assertEquals("All keys should have existed", multivaluedMap.keySet().size(), multiCaseKeys.size());
+
+        Map<String, String> caseInsensitiveMap = restResource.convertToCaseInsensitiveMap(multivaluedMap);
+
+        assertEquals("Only one key should have exist", caseInsensitiveMap.keySet().size(), 1);
+
+        for (String key : multiCaseKeys) {
+            assertEquals("All keys should have returned the same value", caseInsensitiveMap.get(key), replacedValue);
+        }
+    }
+
+    @Test
+    public void testConvertToCaseInsensitiveMapUtf8() throws Exception {
+        byte[] bytes = {
+                (byte) 0x61, (byte) 0x32, (byte) 0x63, (byte) 0x5c, (byte) 0x22,
+                (byte) 0x55, (byte) 0x54, (byte) 0x46, (byte) 0x38, (byte) 0x5f,
+                (byte) 0xe8, (byte) 0xa8, (byte) 0x88, (byte) 0xe7, (byte) 0xae,
+                (byte) 0x97, (byte) 0xe6, (byte) 0xa9, (byte) 0x9f, (byte) 0xe7,
+                (byte) 0x94, (byte) 0xa8, (byte) 0xe8, (byte) 0xaa, (byte) 0x9e,
+                (byte) 0x5f, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x30,
+                (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x5c,
+                (byte) 0x22, (byte) 0x6f, (byte) 0x35
+        };
+        String value = new String(bytes, CharEncoding.ISO_8859_1);
+
+        multivaluedMap.put("one", Collections.singletonList(value));
+
+        Map<String, String> caseInsensitiveMap = restResource.convertToCaseInsensitiveMap(multivaluedMap);
+
+        assertEquals("Only one key should have exist", caseInsensitiveMap.keySet().size(), 1);
+
+        assertEquals("Value should be converted to UTF-8",
+                caseInsensitiveMap.get("one"), "a2c\"UTF8_計算機用語_00000000\"o5");
+    }
+
+    @Before
+    public void before() throws Exception {
+        restResource = mock(RestResource.class, Mockito.CALLS_REAL_METHODS);
+        multivaluedMap = new MultivaluedMapImpl();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/ProtocolDataTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/ProtocolDataTest.java b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/ProtocolDataTest.java
new file mode 100644
index 0000000..194f148
--- /dev/null
+++ b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/ProtocolDataTest.java
@@ -0,0 +1,232 @@
+package org.apache.hawq.pxf.service.utilities;
+
+import org.apache.hawq.pxf.api.OutputFormat;
+import org.apache.hawq.pxf.api.utilities.ProfileConfException;
+
+import static org.apache.hawq.pxf.api.utilities.ProfileConfException.MessageFormat.NO_PROFILE_DEF;
+
+import org.apache.hawq.pxf.api.utilities.ProfilesConf;
+
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.hadoop.security.UserGroupInformation;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({UserGroupInformation.class, ProfilesConf.class})
+public class ProtocolDataTest {
+    Map<String, String> parameters;
+
+    @Test
+    public void protocolDataCreated() throws Exception {
+        ProtocolData protocolData = new ProtocolData(parameters);
+
+        assertEquals(System.getProperty("greenplum.alignment"), "all");
+        assertEquals(protocolData.getTotalSegments(), 2);
+        assertEquals(protocolData.getSegmentId(), -44);
+        assertEquals(protocolData.outputFormat(), OutputFormat.TEXT);
+        assertEquals(protocolData.serverName(), "my://bags");
+        assertEquals(protocolData.serverPort(), -8020);
+        assertFalse(protocolData.hasFilter());
+        assertNull(protocolData.getFilterString());
+        assertEquals(protocolData.getColumns(), 0);
+        assertEquals(protocolData.getDataFragment(), -1);
+        assertNull(protocolData.getRecordkeyColumn());
+        assertEquals(protocolData.getAccessor(), "are");
+        assertEquals(protocolData.getResolver(), "packed");
+        assertEquals(protocolData.getDataSource(), "i'm/ready/to/go");
+        assertEquals(protocolData.getUserProperty("i'm-standing-here"), "outside-your-door");
+        assertEquals(protocolData.getParametersMap(), parameters);
+        assertNull(protocolData.getLogin());
+        assertNull(protocolData.getSecret());
+    }
+
+    @Test
+    public void ProtocolDataCopied() throws Exception {
+        ProtocolData protocolData = new ProtocolData(parameters);
+        ProtocolData copy = new ProtocolData(protocolData);
+        assertEquals(copy.getParametersMap(), protocolData.getParametersMap());
+    }
+
+    @Test
+    public void profileWithDuplicateProperty() throws Exception {
+        PowerMockito.mockStatic(ProfilesConf.class);
+
+        Map<String, String> mockedProfiles = new HashMap<>();
+        mockedProfiles.put("wHEn you trY yOUR bESt", "but you dont succeed");
+        mockedProfiles.put("when YOU get WHAT you WANT", "but not what you need");
+        mockedProfiles.put("when you feel so tired", "but you cant sleep");
+
+        when(ProfilesConf.getProfilePluginsMap("a profile")).thenReturn(mockedProfiles);
+
+        parameters.put("x-gp-profile", "a profile");
+        parameters.put("when you try your best", "and you do succeed");
+        parameters.put("WHEN you GET what YOU want", "and what you need");
+
+        try {
+            new ProtocolData(parameters);
+            fail("Duplicate property should throw IllegalArgumentException");
+        } catch (IllegalArgumentException iae) {
+            assertEquals("Profile 'a profile' already defines: [when YOU get WHAT you WANT, wHEn you trY yOUR bESt]",
+                    iae.getMessage());
+        }
+    }
+
+    @Test
+    public void definedProfile() throws Exception {
+        parameters.put("X-GP-PROFILE", "HIVE");
+        parameters.remove("X-GP-ACCESSOR");
+        parameters.remove("X-GP-RESOLVER");
+        ProtocolData protocolData = new ProtocolData(parameters);
+        assertEquals(protocolData.getFragmenter(), "org.apache.hawq.pxf.plugins.hive.HiveDataFragmenter");
+        assertEquals(protocolData.getAccessor(), "org.apache.hawq.pxf.plugins.hive.HiveAccessor");
+        assertEquals(protocolData.getResolver(), "org.apache.hawq.pxf.plugins.hive.HiveResolver");
+    }
+
+    @Test
+    public void undefinedProfile() throws Exception {
+        parameters.put("X-GP-PROFILE", "THIS_PROFILE_NEVER_EXISTED!");
+        try {
+            new ProtocolData(parameters);
+            fail("Undefined profile should throw ProfileConfException");
+        } catch (ProfileConfException pce) {
+            assertEquals(pce.getMsgFormat(), NO_PROFILE_DEF);
+        }
+    }
+
+    @Test
+    public void threadSafeTrue() throws Exception {
+        parameters.put("X-GP-THREAD-SAFE", "TRUE");
+        ProtocolData protocolData = new ProtocolData(parameters);
+        assertEquals(protocolData.isThreadSafe(), true);
+
+        parameters.put("X-GP-THREAD-SAFE", "true");
+        protocolData = new ProtocolData(parameters);
+        assertEquals(protocolData.isThreadSafe(), true);
+    }
+
+    @Test
+    public void threadSafeFalse() throws Exception {
+        parameters.put("X-GP-THREAD-SAFE", "False");
+        ProtocolData protocolData = new ProtocolData(parameters);
+        assertEquals(protocolData.isThreadSafe(), false);
+
+        parameters.put("X-GP-THREAD-SAFE", "falSE");
+        protocolData = new ProtocolData(parameters);
+        assertEquals(protocolData.isThreadSafe(), false);
+    }
+
+    @Test
+    public void threadSafeMaybe() throws Exception {
+        parameters.put("X-GP-THREAD-SAFE", "maybe");
+        try {
+            new ProtocolData(parameters);
+            fail("illegal THREAD-SAFE value should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            assertEquals(e.getMessage(),
+                    "Illegal boolean value 'maybe'. Usage: [TRUE|FALSE]");
+        }
+    }
+
+    @Test
+    public void threadSafeDefault() throws Exception {
+        parameters.remove("X-GP-THREAD-SAFE");
+        ProtocolData protocolData = new ProtocolData(parameters);
+        assertEquals(protocolData.isThreadSafe(), true);
+    }
+
+    @Test
+    public void getFragmentMetadata() throws Exception {
+        ProtocolData protocolData = new ProtocolData(parameters);
+        byte[] location = protocolData.getFragmentMetadata();
+        assertEquals(new String(location), "Something in the way");
+    }
+
+    @Test
+    public void getFragmentMetadataNull() throws Exception {
+        parameters.remove("X-GP-FRAGMENT-METADATA");
+        ProtocolData ProtocolData = new ProtocolData(parameters);
+        assertNull(ProtocolData.getFragmentMetadata());
+    }
+
+    @Test
+    public void getFragmentMetadataNotBase64() throws Exception {
+        String badValue = "so b@d";
+        parameters.put("X-GP-FRAGMENT-METADATA", badValue);
+        try {
+            new ProtocolData(parameters);
+            fail("should fail with bad fragment metadata");
+        } catch (Exception e) {
+            assertEquals(e.getMessage(), "Fragment metadata information must be Base64 encoded." +
+                    "(Bad value: " + badValue + ")");
+        }
+    }
+
+    @Test
+    public void nullTokenThrows() throws Exception {
+        when(UserGroupInformation.isSecurityEnabled()).thenReturn(true);
+
+        try {
+            new ProtocolData(parameters);
+            fail("null X-GP-TOKEN should throw");
+        } catch (IllegalArgumentException e) {
+            assertEquals(e.getMessage(),
+                    "Internal server error. Property \"TOKEN\" has no value in current request");
+        }
+    }
+
+    @Test
+    public void filterUtf8() throws Exception {
+        parameters.remove("X-GP-HAS-FILTER");
+        parameters.put("X-GP-HAS-FILTER", "1");
+        parameters.put("X-GP-FILTER", "UTF8_計算機用語_00000000");
+        ProtocolData protocolData = new ProtocolData(parameters);
+        assertTrue(protocolData.hasFilter());
+        assertEquals("UTF8_計算機用語_00000000", protocolData.getFilterString());
+    }
+
+    /*
+     * setUp function called before each test
+     */
+    @Before
+    public void setUp() {
+        parameters = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
+
+        parameters.put("X-GP-ALIGNMENT", "all");
+        parameters.put("X-GP-SEGMENT-ID", "-44");
+        parameters.put("X-GP-SEGMENT-COUNT", "2");
+        parameters.put("X-GP-HAS-FILTER", "0");
+        parameters.put("X-GP-FORMAT", "TEXT");
+        parameters.put("X-GP-URL-HOST", "my://bags");
+        parameters.put("X-GP-URL-PORT", "-8020");
+        parameters.put("X-GP-ATTRS", "-1");
+        parameters.put("X-GP-ACCESSOR", "are");
+        parameters.put("X-GP-RESOLVER", "packed");
+        parameters.put("X-GP-DATA-DIR", "i'm/ready/to/go");
+        parameters.put("X-GP-FRAGMENT-METADATA", "U29tZXRoaW5nIGluIHRoZSB3YXk=");
+        parameters.put("X-GP-I'M-STANDING-HERE", "outside-your-door");
+
+        PowerMockito.mockStatic(UserGroupInformation.class);
+    }
+
+    /*
+     * tearDown function called after each test
+     */
+    @After
+    public void tearDown() {
+        // Cleanup the system property ProtocolData sets
+        System.clearProperty("greenplum.alignment");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/SecuredHDFSTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/SecuredHDFSTest.java b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/SecuredHDFSTest.java
new file mode 100644
index 0000000..2bc8612
--- /dev/null
+++ b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/SecuredHDFSTest.java
@@ -0,0 +1,66 @@
+package org.apache.hawq.pxf.service.utilities;
+
+import org.apache.hadoop.security.UserGroupInformation;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.servlet.ServletContext;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({UserGroupInformation.class})
+public class SecuredHDFSTest {
+    Map<String, String> parameters;
+    ProtocolData mockProtocolData;
+    ServletContext mockContext;
+
+    @Test
+    public void invalidTokenThrows() {
+        when(UserGroupInformation.isSecurityEnabled()).thenReturn(true);
+        when(mockProtocolData.getToken()).thenReturn("This is odd");
+
+        try {
+            SecuredHDFS.verifyToken(mockProtocolData, mockContext);
+            fail("invalid X-GP-TOKEN should throw");
+        } catch (SecurityException e) {
+            assertEquals("Failed to verify delegation token java.io.EOFException", e.getMessage());
+        }
+    }
+
+    /*
+     * setUp function called before each test
+	 */
+    @Before
+    public void setUp() {
+        parameters = new HashMap<>();
+
+        parameters.put("X-GP-ALIGNMENT", "all");
+        parameters.put("X-GP-SEGMENT-ID", "-44");
+        parameters.put("X-GP-SEGMENT-COUNT", "2");
+        parameters.put("X-GP-HAS-FILTER", "0");
+        parameters.put("X-GP-FORMAT", "TEXT");
+        parameters.put("X-GP-URL-HOST", "my://bags");
+        parameters.put("X-GP-URL-PORT", "-8020");
+        parameters.put("X-GP-ATTRS", "-1");
+        parameters.put("X-GP-ACCESSOR", "are");
+        parameters.put("X-GP-RESOLVER", "packed");
+        parameters.put("X-GP-DATA-DIR", "i'm/ready/to/go");
+        parameters.put("X-GP-FRAGMENT-METADATA", "U29tZXRoaW5nIGluIHRoZSB3YXk=");
+        parameters.put("X-GP-I'M-STANDING-HERE", "outside-your-door");
+
+        mockProtocolData = mock(ProtocolData.class);        
+        mockContext = mock(ServletContext.class);
+
+        PowerMockito.mockStatic(UserGroupInformation.class);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/1c7ab9eb/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/UtilitiesTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/UtilitiesTest.java b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/UtilitiesTest.java
new file mode 100644
index 0000000..8b1c9b6
--- /dev/null
+++ b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/UtilitiesTest.java
@@ -0,0 +1,48 @@
+package org.apache.hawq.pxf.service.utilities;
+
+import org.apache.hadoop.security.UserGroupInformation;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({UserGroupInformation.class})
+public class UtilitiesTest {
+    @Test
+    public void byteArrayToOctalStringNull() throws Exception {
+        StringBuilder sb = null;
+        byte[] bytes = "nofink".getBytes();
+
+        Utilities.byteArrayToOctalString(bytes, sb);
+
+        assertNull(sb);
+
+        sb = new StringBuilder();
+        bytes = null;
+
+        Utilities.byteArrayToOctalString(bytes, sb);
+
+        assertEquals(0, sb.length());
+    }
+
+    @Test
+    public void byteArrayToOctalString() throws Exception {
+        String orig = "Have Narisha";
+        String octal = "Rash Rash Rash!";
+        String expected = orig + "\\\\122\\\\141\\\\163\\\\150\\\\040"
+                + "\\\\122\\\\141\\\\163\\\\150\\\\040"
+                + "\\\\122\\\\141\\\\163\\\\150\\\\041";
+        StringBuilder sb = new StringBuilder();
+        sb.append(orig);
+
+        Utilities.byteArrayToOctalString(octal.getBytes(), sb);
+
+        assertEquals(orig.length() + (octal.length() * 5), sb.length());
+        assertEquals(expected, sb.toString());
+    }
+}


Mime
View raw message