METAMODEL-1114: Fixed
authorArjan Seijkens <Arjan.Seijkens@humaninference.com>
Tue, 6 Sep 2016 04:16:01 +0000 (21:16 -0700)
committerKasper Sørensen <i.am.kasper.sorensen@gmail.com>
Tue, 6 Sep 2016 04:16:01 +0000 (21:16 -0700)
Fixes #126

CHANGES.md
fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/EbcdicConfiguration.java
fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/EBCDICTest.java

index c8f288f..f44077e 100644 (file)
@@ -4,6 +4,7 @@
  * [METAMODEL-1109] - Fixed diacritics/encoding issue with Fixed Width reader.
  * [METAMODEL-1115] - Added support for passing your own PartnerConnection object to the Salesforce.com connector.
  * [METAMODEL-1113] - Fixed support for ColumnNamingStrategy in CSV connector.
+ * [METAMODEL-1114] - Added support for ColumnNamingStrategy in EBCDIC connector.
 
 ### Apache MetaModel 4.5.4
 
index 389a4f8..e4bff94 100644 (file)
@@ -18,6 +18,8 @@
  */
 package org.apache.metamodel.fixedwidth;
 
+import org.apache.metamodel.schema.naming.ColumnNamingStrategy;
+
 /**
  * Special fixed-width configuration for EBCDIC files. 
  */
@@ -35,7 +37,12 @@ public final class EbcdicConfiguration extends FixedWidthConfiguration {
 
     public EbcdicConfiguration(int columnNameLineNumber, String encoding, int[] valueWidths,
             boolean failOnInconsistentLineWidth, boolean skipEbcdicHeader, boolean eolPresent) {
-        super(columnNameLineNumber, null, encoding, valueWidths, failOnInconsistentLineWidth);
+        this(columnNameLineNumber, null, encoding, valueWidths, failOnInconsistentLineWidth, skipEbcdicHeader, eolPresent);
+    }
+
+    public EbcdicConfiguration(int columnNameLineNumber, ColumnNamingStrategy columnNamingStrategy, String encoding,
+            int[] valueWidths, boolean failOnInconsistentLineWidth, boolean skipEbcdicHeader, boolean eolPresent) {
+        super(columnNameLineNumber, columnNamingStrategy, encoding, valueWidths, failOnInconsistentLineWidth);
         _skipEbcdicHeader = skipEbcdicHeader;
         _eolPresent = eolPresent;
     }
index ea19960..2b5c8be 100644 (file)
@@ -20,12 +20,15 @@ package org.apache.metamodel.fixedwidth;
 
 import java.io.File;
 
+import org.apache.metamodel.DataContext;
 import org.apache.metamodel.data.DataSet;
 import org.apache.metamodel.schema.Schema;
 import org.apache.metamodel.schema.Table;
+import org.apache.metamodel.schema.naming.CustomColumnNamingStrategy;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 public class EBCDICTest {
     private static final int[] COLUMN_WIDTHS = new int[] { 2, 7, 10, 10 };
@@ -74,4 +77,19 @@ public class EBCDICTest {
             }
         }
     }
+
+    @Test
+    public void testCustomColumnNames() throws Exception {
+        final String[] columnNames = {"first", "second", "third", "fourth"};
+        final FixedWidthConfiguration configuration = new EbcdicConfiguration(
+                FixedWidthConfiguration.NO_COLUMN_NAME_LINE, new CustomColumnNamingStrategy(columnNames), ENCODING,
+                COLUMN_WIDTHS, false, true, false);
+        final DataContext dataContext = new FixedWidthDataContext(new File(
+                "src/test/resources/fixed-width-2-7-10-10.ebc"), configuration);
+        final Table table = dataContext.getDefaultSchema().getTable(0);
+
+        for (int i = 0; i < columnNames.length; i++) {
+            assertNotNull(table.getColumnByName(columnNames[i]));
+        }
+    }
 }