You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metamodel.apache.org by ar...@apache.org on 2020/12/18 09:36:11 UTC
[metamodel] 02/05: MM-1229: JUnit test.
This is an automated email from the ASF dual-hosted git repository.
arjansh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/metamodel.git
commit b1ff67200d015f7af151ffa392b037e04ef36c2c
Author: jakub <j....@quadient.com>
AuthorDate: Thu Dec 17 14:35:33 2020 +0100
MM-1229: JUnit test.
---
.../fixedwidth/FixedWidthDataContext.java | 3 +++
.../fixedwidth/FixedWidthDataContextTest.java | 29 ++++++++++++++++++++--
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
index 60e33d1..51c6249 100644
--- a/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
+++ b/fixedwidth/src/main/java/org/apache/metamodel/fixedwidth/FixedWidthDataContext.java
@@ -19,8 +19,11 @@
package org.apache.metamodel.fixedwidth;
import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.List;
import org.apache.metamodel.MetaModelException;
diff --git a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java
index 713b48d..59c31ed 100644
--- a/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java
+++ b/fixedwidth/src/test/java/org/apache/metamodel/fixedwidth/FixedWidthDataContextTest.java
@@ -18,17 +18,22 @@
*/
package org.apache.metamodel.fixedwidth;
+import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Arrays;
-import junit.framework.TestCase;
-
import org.apache.metamodel.DataContext;
import org.apache.metamodel.data.DataSet;
import org.apache.metamodel.query.Query;
import org.apache.metamodel.schema.Schema;
import org.apache.metamodel.schema.Table;
import org.apache.metamodel.schema.naming.CustomColumnNamingStrategy;
+import org.apache.metamodel.util.UrlResource;
+
+import junit.framework.TestCase;
public class FixedWidthDataContextTest extends TestCase {
@@ -238,4 +243,24 @@ public class FixedWidthDataContextTest extends TestCase {
assertNotNull(table.getColumnByName(firstColumnName));
assertNotNull(table.getColumnByName(secondColumnName));
}
+
+ public void testUrlResource() throws MalformedURLException {
+ final URL url = new URL("http://localhost:8080/fixed-width.txt");
+ final DataContext dataContext = new FixedWidthDataContext(new ByteUrlResource(url),
+ new EbcdicConfiguration(FixedWidthConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", 4, false, true,
+ true));
+ assertNotNull(dataContext.getSchemaByName("localhost:8080"));
+ }
+
+ private static class ByteUrlResource extends UrlResource {
+ public ByteUrlResource(final URL url) {
+ super(url);
+ }
+
+ @Override
+ public InputStream read() {
+ // any InputStream that can not be cast to BufferedInputStream
+ return new ByteArrayInputStream("test-data".getBytes());
+ }
+ }
}