Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/BasicFunctionalityTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/BasicFunctionalityTest.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/BasicFunctionalityTest.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/BasicFunctionalityTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,48 @@
+package com.pgac.flatfile;
+
+import com.pgac.flatfile.EntityArray;
+import com.pgac.flatfile.EntityMap;
+
+/**
+ *
+ */
+public class BasicFunctionalityTest extends EntityParserTestBase {
+
+ public void testBasicFunctionality() throws Exception {
+ EntityMap test1 = (EntityMap) entityFactory.getEntity("basic");
+ assertEquals(1, test1.getChild("foo").length());
+ assertEquals(2, test1.getChild("bar").length());
+ assertEquals(3, test1.getChild("baz").length());
+ EntityArray simpleArray = (EntityArray) test1.getChild("simpleArray");
+ int sz = simpleArray.size();
+ assertEquals(3, sz);
+ for (int i = 0; i < sz; i++) {
+ assertEquals(1, simpleArray.getChild(i).length());
+ }
+ EntityMap complex = (EntityMap) test1.getChild("complex");
+ assertEquals(3, complex.getChildMap().size());
+ assertEquals(1, complex.getChild("foo").length());
+ assertEquals(2, complex.getChild("bar").length());
+ assertEquals(3, complex.getChild("baz").length());
+
+ EntityArray complexArray = (EntityArray)
test1.getChild("complexArray");
+ sz = complexArray.size();
+ assertEquals(3, sz);
+ for (int i = 0; i < sz; i++) {
+ EntityMap child = (EntityMap) complexArray.getChild(i);
+ assertEquals(6, child.length());
+ assertEquals(1, child.getChild("foo").length());
+ assertEquals(2, child.getChild("bar").length());
+ assertEquals(3, child.getChild("baz").length());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.pgac.fixedlength.EntityParserTestBase#getSource()
+ */
+ protected String getSource() {
+ return "basic.test";
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/BasicFunctionalityTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DefaultOptionsTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DefaultOptionsTest.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DefaultOptionsTest.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DefaultOptionsTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,25 @@
+package com.pgac.flatfile;
+
+/**
+ *
+ */
+public class DefaultOptionsTest extends EntityParserTestBase {
+
+ public void test1() {
+ assertValue("@@@foo", entityFactory.getEntity("field1"));
+ assertValue("foo@@@", entityFactory.getEntity("field2"));
+ assertValue("&&&foo", entityFactory.getEntity("field3"));
+ assertValue("foo&&&", entityFactory.getEntity("field4"));
+ assertValue("@foo@@", entityFactory.getEntity("field5"));
+ assertValue("&foo&&", entityFactory.getEntity("field6"));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.pgac.fixedlength.EntityParserTestBase#getSource()
+ */
+ protected String getSource() {
+ return "defaultOptions.test";
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DefaultOptionsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DelimiterTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DelimiterTest.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DelimiterTest.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DelimiterTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,32 @@
+package com.pgac.flatfile;
+
+/**
+ *
+ */
+public class DelimiterTest extends EntityParserTestBase {
+ public void test1() throws Exception {
+ StringBuffer buf = new StringBuffer("XX");
+ for (int i = 0; i < 9; i++) {
+ buf.append("\r\nXX");
+ }
+ assertValue(buf.toString(), entityFactory.getEntity("array38"));
+ assertValue(buf.append("\r\n").toString(), entityFactory
+ .getEntity("array40"));
+ assertValue("foo\r\nbar\r\nbaz", entityFactory.getEntity("map13"));
+ assertValue("foo\r\nbar\r\nbaz\r\n", entityFactory.getEntity("map15"));
+ assertValue("foo\r\nbar\r\nwhy\r\nbaz", entityFactory
+ .getEntity("map18"));
+ assertValue("foo\r\nbar\r\nwhy\r\nbaz\r\n", entityFactory
+ .getEntity("map20"));
+ assertValue("foo bar baz\r\nfoo bar baz\r\nfoo bar baz\r\n",
entityFactory.getEntity("map39"));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.pgac.fixedlength.EntityParserTestBase#getSource()
+ */
+ protected String getSource() {
+ return "delimiter.test";
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DelimiterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DynamicFieldTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DynamicFieldTest.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DynamicFieldTest.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DynamicFieldTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,224 @@
+package com.pgac.flatfile;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+import com.pgac.flatfile.DynamicField;
+import com.pgac.flatfile.EntityArray;
+import com.pgac.flatfile.FieldSupport.Overflow;
+import com.pgac.flatfile.FieldSupport.Underflow;
+
+/**
+ * Test dynamic fields.
+ */
+public class DynamicFieldTest extends EntityParserTestBase {
+ private static final int BUFFER_SIZE = 20;
+
+ private static final byte[] SMALL_BYTES = new byte[0];
+ private static final byte[] LARGE_BYTES = new byte[1024];
+
+ static {
+ Arrays.fill(LARGE_BYTES, (byte) 'a');
+ }
+
+ public void test1() throws Exception {
+ DynamicField df = get("df1");
+ assertEquals(0, df.length());
+ assertBounds(df, 0, 1);
+ assertLoad(df);
+ }
+
+ public void test2() throws Exception {
+ DynamicField df = get("df2");
+ assertEquals(0, df.length());
+ assertBounds(df, DynamicField.Bounds.DEFAULT.getMinimum(), 1);
+ assertLoad(df);
+ }
+
+ public void test3() throws Exception {
+ DynamicField df = get("df3");
+ assertEquals(0, df.length());
+ assertBounds(df, 0, DynamicField.Bounds.DEFAULT.getMaximum());
+ assertLoad(df);
+ }
+
+ public void test4() throws Exception {
+ DynamicField df = get("df4");
+ assertEquals(0, df.length());
+ assertBounds(df, DynamicField.Bounds.DEFAULT);
+ assertLoad(df);
+ }
+
+ public void test5() throws Exception {
+ DynamicField df = get("df5");
+ assertEquals(3, df.length());
+ byte[] foo = "foo".getBytes();
+ assertEquals(foo, df.getValue());
+ assertBounds(df, DynamicField.Bounds.DEFAULT);
+ assertLoad(df);
+ }
+
+ public void test6() throws Exception {
+ DynamicField df = get("df6");
+ assertEquals(0, df.length());
+ assertBounds(df, 0, 0);
+ assertLoad(df);
+ }
+
+ public void test7() throws Exception {
+ DynamicField df = get("df7");
+ assertEquals(0, df.length());
+ assertBounds(df, DynamicField.Bounds.DEFAULT.getMinimum(), 0);
+ assertLoad(df);
+ }
+
+ public void test8() throws Exception {
+ DynamicField df = get("df8");
+ assertBounds(df, 1, 1);
+ assertEquals(new byte[] { ' ' }, df.getValue());
+ assertLoad(df);
+ }
+
+ public void test9() throws Exception {
+ DynamicField df = get("df9");
+ assertBounds(df, 1, 3);
+ assertEquals(" ".getBytes(), df.getValue());
+ assertLoad(df);
+ }
+
+ public void testUnboundedArray() throws Exception {
+ EntityArray a = (EntityArray)
entityFactory.getEntity("unboundedArray");
+ assertEquals(0, a.length());
+ a.getChild(1).setValue("foo".getBytes());
+ assertEquals("foo".getBytes(), a.getValue());
+ }
+
+ public void testUnboundedDelimitedArray() throws Exception {
+ EntityArray a = (EntityArray) entityFactory
+ .getEntity("unboundedDelimitedArray");
+ assertEquals("---".getBytes(), a.getValue());
+ a.getChild(1).setValue("foo".getBytes());
+ assertEquals("-foo--".getBytes(), a.getValue());
+ }
+
+ public void testBoundedArray() throws Exception {
+ EntityArray a = (EntityArray) entityFactory.getEntity("boundedArray");
+ assertEquals(" ".getBytes(), a.getValue());
+ a.getChild(1).setValue("foo".getBytes());
+ assertEquals(" foo ".getBytes(), a.getValue());
+ }
+
+ public void testBoundedDelimitedArray() throws Exception {
+ EntityArray a = (EntityArray) entityFactory
+ .getEntity("boundedDelimitedArray");
+ assertEquals(" \n \n \n".getBytes(), a.getValue());
+ a.getChild(1).setValue("foo".getBytes());
+ assertEquals(" \nfoo\n \n".getBytes(), a.getValue());
+
+ }
+
+ public void testNestedUncertainty() throws Exception {
+ EntityArray a = (EntityArray) entityFactory
+ .getEntity("nestedUncertainty");
+ assertTrue(a.isSizable());
+ a.setSize(10);
+ assertEquals(SMALL_BYTES, a.getValue());
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < 10; i++) {
+ byte[] b = new byte[i + 1];
+ Arrays.fill(b, (byte) ((int) 'a' + i));
+ buf.append(new String(b));
+ a.getChild(i).setValue(b);
+ }
+ assertEquals(buf.toString().getBytes(), a.getValue());
+ }
+
+ private void assertBounds(DynamicField df, int min, int max) {
+ assertBounds(df, new DynamicField.Bounds(min, max));
+ }
+
+ private void assertBounds(DynamicField df, DynamicField.Bounds bounds) {
+ assertEquals(bounds, df.getBounds());
+ testValue(df, SMALL_BYTES);
+ testValue(df, LARGE_BYTES);
+ }
+
+ private void assertLoad(DynamicField df) throws IOException {
+ df.readFrom(new ByteArrayInputStream(LARGE_BYTES));
+ int max = df.getBounds().getMaximum();
+ int expectedLength = Math.min(max, LARGE_BYTES.length);
+ assertEquals(expectedLength, df.length());
+ byte[] expec;
+ if (LARGE_BYTES.length < max) {
+ expec = LARGE_BYTES;
+ } else {
+ expec = new byte[max];
+ System.arraycopy(LARGE_BYTES, 0, expec, 0, expec.length);
+ }
+ assertEquals(expec, df.getValue());
+ }
+
+ private void testValue(DynamicField df, byte[] value) {
+ int len = value.length;
+ int min = df.getBounds().getMinimum();
+ int max = df.getBounds().getMaximum();
+ if (df.getUnderflow() == Underflow.ERROR && len < min
+ || df.getOverflow() == Overflow.ERROR && len > max) {
+ byte[] old = df.getValue();
+ try {
+ df.setValue(value);
+ fail(new String(value));
+ } catch (IllegalArgumentException e) {
+ assertEquals(old, df.getValue());
+ }
+ } else {
+ df.setValue(value);
+ assertTrue(len < min || len > max
+ || Arrays.equals(value, df.getValue()));
+ }
+ }
+
+ private DynamicField get(String name) {
+ return (DynamicField) entityFactory.getEntity(name);
+ }
+
+ /**
+ * Detailed comparison
+ * @param a
+ * @param b
+ */
+ private void assertEquals(byte[] a, byte[] b) {
+ if (a != b) {
+ if (a == null || b == null) {
+ fail();
+ }
+ assertEquals(a.length, b.length);
+ byte[] checkA = new byte[BUFFER_SIZE];
+ byte[] checkB = new byte[BUFFER_SIZE];
+ int cur = 0;
+ while (cur < a.length) {
+ int len = Math.min(BUFFER_SIZE, a.length - cur);
+ System.arraycopy(a, cur, checkA, 0, len);
+ System.arraycopy(b, cur, checkB, 0, len);
+ if (len < BUFFER_SIZE) {
+ Arrays.fill(checkA, len, BUFFER_SIZE, (byte) 0);
+ Arrays.fill(checkB, len, BUFFER_SIZE, (byte) 0);
+ }
+ if (!Arrays.equals(checkA, checkB)) {
+ String stringA = new String(checkA, 0, len);
+ String stringB = new String(checkB, 0, len);
+ fail("difference in (" + cur + " - " + (cur + len - 1)
+ + "); expected \"" + stringA + "\" but was \""
+ + stringB + "\"");
+ }
+ cur += len;
+ }
+ }
+ }
+
+ protected String getSource() {
+ return "dynamicField.test";
+ }
+
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/DynamicFieldTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/EntityArrayLifecycleTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/EntityArrayLifecycleTest.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/EntityArrayLifecycleTest.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/EntityArrayLifecycleTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,71 @@
+package com.pgac.flatfile;
+
+import com.pgac.flatfile.EntityArray;
+
+public class EntityArrayLifecycleTest extends EntityParserTestBase {
+
+ public void testMe() throws Exception {
+ EntityArray e = (EntityArray) entityFactory.getEntity("hypo");
+ try {
+ e.getValue();
+ fail("should fail");
+ } catch (IllegalStateException ise) {
+ // okay
+ }
+ assertTrue(e.isSizable());
+ e.setSize(5);
+ e.fill((byte) 'a');
+ assertValue("aaaaaaaaaa", e);
+ e = (EntityArray) entityFactory.getEntity("hypo");
+ assertTrue(e.isSizable());
+ e.setSize(2);
+ e.fill((byte) 'b');
+ assertValue("bbbb", e);
+ e = (EntityArray) entityFactory.getEntity("complete");
+ assertFalse(e.isSizable());
+ expectInvalidSize(e, e.size() + 1,
+ "should fail to set size of completed entity",
+ IllegalStateException.class);
+ e.setSize(e.size());
+ e = (EntityArray) entityFactory.getEntity("rangeMin1");
+ assertTrue(e.isSizable());
+ expectInvalidSize(e, 0, "should fail to set size < 1",
+ IllegalArgumentException.class);
+ e.setSize(665);
+ assertEquals(665, e.size());
+ e = (EntityArray) entityFactory.getEntity("explicitRange");
+ expectInvalidSize(e, 0, "should fail to set size < 1",
+ IllegalArgumentException.class);
+ expectInvalidSize(e, 4, "should fail to set size > 4",
+ IllegalArgumentException.class);
+ e.setSize(3);
+ assertEquals(3, e.size());
+ e = (EntityArray) entityFactory.getEntity("optional");
+ assertEquals(0, e.getMinimumSize());
+ assertEquals(1, e.getMaximumSize());
+ e.setSize(0);
+ assertEquals(0, e.size());
+ assertEquals(0, e.getValue().length);
+ e = (EntityArray) entityFactory.getEntity("optional2");
+ assertEquals(0, e.getMinimumSize());
+ assertEquals(1, e.getMaximumSize());
+ e.setSize(0);
+ assertEquals(0, e.size());
+ assertEquals(0, e.getValue().length);
+ }
+
+ private void expectInvalidSize(EntityArray e, int size,
+ String failureMessage, Class exceptionType) {
+ try {
+ e.setSize(size);
+ fail(failureMessage);
+ } catch (Exception exc) {
+ assertTrue("Unexpected exception " + exc, exceptionType == null
+ || exceptionType.isInstance(exc));
+ }
+ }
+
+ protected String getSource() {
+ return "entityarraylifecycle.test";
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/EntityArrayLifecycleTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/EntityParserTestBase.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/EntityParserTestBase.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/EntityParserTestBase.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/EntityParserTestBase.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,30 @@
+package com.pgac.flatfile;
+
+import com.pgac.flatfile.Entity;
+import com.pgac.flatfile.dsl.ParserEntityFactory;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public abstract class EntityParserTestBase extends TestCase {
+
+ protected ParserEntityFactory entityFactory;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ entityFactory = new ParserEntityFactory(getClass().getResourceAsStream(
+ getSource()));
+ }
+
+ protected abstract String getSource();
+
+ protected void assertValue(String s, Entity e) {
+ assertEquals(s, new String(e.getValue()));
+ }
+
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/EntityParserTestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/FieldOptionsTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/FieldOptionsTest.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/FieldOptionsTest.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/FieldOptionsTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,39 @@
+package com.pgac.flatfile;
+
+/**
+ *
+ */
+public class FieldOptionsTest extends EntityParserTestBase {
+
+ public void test1() {
+ assertValue("foo ", entityFactory.getEntity("field1"));
+ assertValue("fooxxx", entityFactory.getEntity("field2"));
+ assertValue("fooxxx", entityFactory.getEntity("field3"));
+ assertValue("xxxfoo", entityFactory.getEntity("field4"));
+ assertValue("xfooxx", entityFactory.getEntity("field5"));
+ try {
+ assertValue("fo", entityFactory.getEntity("field6"));
+ fail("value foo too big and overflow = default (error)");
+ } catch (IllegalArgumentException e) {
+ }
+ assertValue("fo", entityFactory.getEntity("field7"));
+ assertValue("ob", entityFactory.getEntity("field8"));
+ assertValue("foo", entityFactory.getEntity("field9"));
+ assertValue("owl", entityFactory.getEntity("field10"));
+ assertValue("03.14", entityFactory.getEntity("field11"));
+ assertValue("foo bar", entityFactory.getEntity("field12"));
+ assertValue("foo b", entityFactory.getEntity("field13"));
+ assertValue("foofoo", entityFactory.getEntity("field14"));
+ assertValue("foofoo", entityFactory.getEntity("field15"));
+ assertValue("foofoo", entityFactory.getEntity("field16"));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.pgac.fixedlength.EntityParserTestBase#getSource()
+ */
+ protected String getSource() {
+ return "fieldOptions.test";
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/FieldOptionsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/FillerTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/FillerTest.java?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/FillerTest.java
(added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/FillerTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,21 @@
+package com.pgac.flatfile;
+
+import com.pgac.flatfile.EntityMap;
+
+/**
+ *
+ */
+public class FillerTest extends EntityParserTestBase {
+
+ public void testFiller() throws Exception {
+ EntityMap withFiller = (EntityMap) entityFactory
+ .getEntity("withFiller");
+ assertEquals(3, withFiller.getChildMap().size());
+ assertValue("foo bar---nothing-goes-here---baz", withFiller);
+ }
+
+ protected String getSource() {
+ return "filler.test";
+ }
+
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/FillerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/ImmutableTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/ImmutableTest.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/ImmutableTest.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/ImmutableTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,47 @@
+package com.pgac.flatfile;
+
+import com.pgac.flatfile.Entity;
+import com.pgac.flatfile.IndexedEntityCollection;
+import com.pgac.flatfile.NamedEntityCollection;
+
+/**
+ *
+ */
+public class ImmutableTest extends EntityParserTestBase {
+ public void test1() throws Exception {
+ Entity test1 = entityFactory.getEntity("test1");
+ assertValue("FOOxBARxBAZ", test1);
+ test1.fill((byte) 'y');
+ assertValue("FOOyBARyBAZ", test1);
+ }
+
+ public void test2() throws Exception {
+ Entity test2 = entityFactory.getEntity("test2");
+ assertTrue(test2 instanceof IndexedEntityCollection);
+ test2.fill((byte) '0');
+ assertValue("submarine", test2);
+ }
+
+ public void test3() throws Exception {
+ NamedEntityCollection test3 = (NamedEntityCollection) entityFactory
+ .getEntity("test3");
+ // verify the immutable children are still Entities:
+ test3.getChild("a");
+ test3.getChild("c");
+ assertValue("whatyouworry", test3);
+ }
+
+ public void test4() throws Exception {
+ assertValue("xxxxxxxxxx", entityFactory.getEntity("test4"));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.pgac.fixedlength.EntityParserTestBase#getSource()
+ */
+ protected String getSource() {
+ // TODO Auto-generated method stub
+ return "immutable.test";
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/ImmutableTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/LengthCheckTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/LengthCheckTest.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/LengthCheckTest.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/LengthCheckTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,29 @@
+package com.pgac.flatfile;
+
+import com.pgac.flatfile.EntityFactory;
+import com.pgac.flatfile.dsl.ParserEntityFactory;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class LengthCheckTest extends TestCase {
+ public void test1() throws Exception {
+ EntityFactory entityFactory = new ParserEntityFactory(getClass()
+ .getResourceAsStream("lengthcheck1.test"));
+ entityFactory.getEntity("foo");
+ entityFactory.getEntity("bar");
+ }
+
+ public void test2() throws Exception {
+ try {
+ EntityFactory entityFactory = new ParserEntityFactory(getClass()
+ .getResourceAsStream("lengthcheck2.test"));
+ entityFactory.getEntity("foo");
+ fail("should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // okay
+ }
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/LengthCheckTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/RunParser.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/RunParser.java?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/RunParser.java
(added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/RunParser.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,17 @@
+package com.pgac.flatfile;
+
+import antlr.TokenBuffer;
+
+import com.pgac.flatfile.dsl.EntityLexer;
+import com.pgac.flatfile.dsl.EntityParser;
+
+/**
+ *
+ */
+public class RunParser {
+ public static void main(String[] args) throws Exception {
+ EntityParser p = new EntityParser(new TokenBuffer(new EntityLexer(
+ RunParser.class.getResourceAsStream("fieldOptions.test"))));
+ p.parse();
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/RunParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/TypesTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/TypesTest.java?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/TypesTest.java
(added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/TypesTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,93 @@
+package com.pgac.flatfile;
+
+import com.pgac.flatfile.EntityArray;
+import com.pgac.flatfile.EntityMap;
+import com.pgac.flatfile.Field;
+
+/**
+ *
+ */
+public class TypesTest extends EntityParserTestBase {
+
+ public void testTypes() throws Exception {
+ // test typedefs
+ EntityMap test2 = (EntityMap) entityFactory.getEntity("types");
+ assertEquals(49, test2.length());
+
+ EntityArray foo = (EntityArray) test2.getChild("foo");
+ assertEquals(8, foo.length());
+ int sz = foo.size();
+ assertEquals(4, sz);
+ for (int i = 1; i < sz; i++) {
+ Field fooI = (Field) foo.getChild(i);
+ assertEquals(2, fooI.length());
+ }
+ for (int i = 1; i <= 2; i++) {
+ Field fooI = (Field) test2.getChild("foo" + i);
+ assertEquals(2, fooI.length());
+ }
+ for (int i = 1; i <= 2; i++) {
+ EntityArray barI = (EntityArray) test2.getChild("bar" + i);
+ assertEquals(4, barI.length());
+ sz = barI.size();
+ assertEquals(2, sz);
+ for (int j = 0; j < sz; j++) {
+ Field child = (Field) barI.getChild(j);
+ assertEquals(2, child.length());
+ }
+ }
+ EntityArray baz = (EntityArray) test2.getChild("baz");
+ assertEquals(9, baz.length());
+ sz = baz.size();
+ assertEquals(3, sz);
+ for (int i = 0; i < sz; i++) {
+ EntityMap child = (EntityMap) baz.getChild(i);
+ assertEquals(3, child.length());
+ assertEquals(2, child.getChildren().size());
+ Field a = (Field) child.getChild("a");
+ assertEquals(1, a.length());
+ Field b = (Field) child.getChild("b");
+ assertEquals(2, b.length());
+ }
+ EntityMap nest = (EntityMap) test2.getChild("nest");
+ assertEquals(19, nest.length());
+ assertEquals(4, nest.getChildren().size());
+ Field nestFoo = (Field) nest.getChild("foo");
+ assertEquals(2, nestFoo.length());
+ char[] barChar = new char[] { 'A', 'B' };
+ for (int i = 0; i < barChar.length; i++) {
+ EntityArray bar = (EntityArray) nest.getChild("bar" + barChar[i]);
+ assertEquals(4, bar.length());
+ int barSize = bar.size();
+ assertEquals(2, barSize);
+ for (int j = 0; j < barSize; j++) {
+ Field child = (Field) bar.getChild(j);
+ assertEquals(2, child.length());
+ }
+ }
+ EntityArray nestBaz = (EntityArray) test2.getChild("baz");
+ assertEquals(9, nestBaz.length());
+ int nestBazSize = nestBaz.size();
+ assertEquals(3, nestBazSize);
+ for (int i = 0; i < nestBazSize; i++) {
+ EntityMap child = (EntityMap) nestBaz.getChild(i);
+ assertEquals(3, child.length());
+ assertEquals(2, child.getChildren().size());
+ Field a = (Field) child.getChild("a");
+ assertEquals(1, a.length());
+ Field b = (Field) child.getChild("b");
+ assertEquals(2, b.length());
+ }
+
+ assertEquals(1, test2.getChild("normal").length());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.pgac.fixedlength.EntityParserTestBase#getSource()
+ */
+ protected String getSource() {
+ return "types.test";
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/TypesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/ValuesTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/ValuesTest.java?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/ValuesTest.java
(added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/ValuesTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,58 @@
+package com.pgac.flatfile;
+
+import com.pgac.flatfile.Entity;
+import com.pgac.flatfile.EntityArray;
+import com.pgac.flatfile.EntityMap;
+
+/**
+ *
+ */
+public class ValuesTest extends EntityParserTestBase {
+
+ public void testValues() throws Exception {
+ EntityMap values = (EntityMap) entityFactory.getEntity("values");
+ assertValue("A", values.getChild("A"));
+ assertValue("BB", values.getChild("BB"));
+ assertValue("CCC", values.getChild("CCC"));
+ assertValue("DDDD", values.getChild("DDDD"));
+ assertValue("AAAA", values.getChild("A4"));
+ assertValue("BBBB", values.getChild("B4"));
+ assertValue("CCCC", values.getChild("C4"));
+ assertValue("DDDD", values.getChild("D4"));
+ testArray((EntityArray) ((EntityMap) values.getChild("initarray"))
+ .getChild("array"));
+ testArray((EntityArray) values.getChild("array"));
+ assertValue("twv", values.getChild("x"));
+ assertValue("vwt", values.getChild("y"));
+ assertValue("123123", values.getChild("z"));
+ assertValue("twvtwv", values.getChild("typeWithValue"));
+ }
+
+ private void testArray(EntityArray array) throws Exception {
+ assertValue("123456", array);
+ assertValue("12", array.getChild(0));
+ assertValue("34", array.getChild(1));
+ assertValue("56", array.getChild(2));
+ }
+
+ public void testImplicitLength() throws Exception {
+ Entity e = entityFactory.getEntity("implicitLength");
+ assertEquals(12, e.length());
+ assertValue("foo-bar-baz!", e);
+ }
+
+ public void testOverrideChildren() throws Exception {
+ Entity e = entityFactory.getEntity("overrideChildren");
+ assertEquals(45, e.length());
+ assertEquals("", new String(e.getValue()).trim());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.pgac.fixedlength.EntityParserTestBase#getSource()
+ */
+ protected String getSource() {
+ return "values.test";
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/ValuesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/basic.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/basic.test?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/basic.test (added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/basic.test Thu
Sep 4 09:39:28 2008
@@ -0,0 +1,22 @@
+//record layout:
+
+basic {
+ foo (1),
+ bar (2),
+ baz (3),
+
+ simpleArray (1) [3],
+
+ complex {
+ foo (1),
+ bar (2),
+ baz (3)
+ },
+
+ complexArray {
+ foo (1),
+ bar (2),
+ baz (3)
+ } [3]
+
+}
\ No newline at end of file
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/Bar.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/Bar.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/Bar.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/Bar.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,50 @@
+package com.pgac.flatfile.conversion;
+
+public class Bar {
+ private String x;
+ private Foo[] foos;
+ private String y;
+
+ /**
+ * @return the foos
+ */
+ public synchronized Foo[] getFoos() {
+ return foos;
+ }
+
+ /**
+ * @param foos the foos to set
+ */
+ public synchronized void setFoos(Foo[] foos) {
+ this.foos = foos;
+ }
+
+ /**
+ * @return the x
+ */
+ public synchronized String getX() {
+ return x;
+ }
+
+ /**
+ * @param x the x to set
+ */
+ public synchronized void setX(String x) {
+ this.x = x;
+ }
+
+ /**
+ * @return the y
+ */
+ public synchronized String getY() {
+ return y;
+ }
+
+ /**
+ * @param y the y to set
+ */
+ public synchronized void setY(String y) {
+ this.y = y;
+ }
+
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/Bar.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/BasicConversionTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/BasicConversionTest.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/BasicConversionTest.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/BasicConversionTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,24 @@
+package com.pgac.flatfile.conversion;
+
+/**
+ *
+ */
+public class BasicConversionTest extends ConversionTestBase {
+
+ protected TestPair[] getTestPairs() {
+ return new TestPair[] {
+ new TestPair("abcdefghij;123456", new Foo("abcdefghij",
123456)),
+ new TestPair("abcdefg ;012345", new Foo("abcdefg", 12345)),
+ new TestPair("abcdefghij;234567", new Foo("abcdefghijk",
+ 1234567)) };
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.pgac.fixedlength.EntityParserTestBase#getSource()
+ */
+ protected String getSource() {
+ return "basic.test";
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/BasicConversionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/ConversionTestBase.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/ConversionTestBase.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/ConversionTestBase.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/ConversionTestBase.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,103 @@
+package com.pgac.flatfile.conversion;
+
+import net.sf.morph.reflect.Reflector;
+import net.sf.morph.reflect.reflectors.SimpleDelegatingReflector;
+import net.sf.morph.transform.DecoratedConverter;
+import net.sf.morph.transform.Transformer;
+import net.sf.morph.transform.copiers.PropertyNameMatchingCopier;
+import net.sf.morph.transform.transformers.SimpleDelegatingTransformer;
+
+//import com.pgac.fixedlength.morph.EntityInstantiatingReflector;
+import com.pgac.flatfile.Entity;
+import com.pgac.flatfile.EntityParserTestBase;
+import com.pgac.flatfile.dsl.DefaultEntityNameStrategy;
+import com.pgac.flatfile.dsl.EntityNameStrategy;
+import com.pgac.flatfile.morph.ContainerToIndexedEntityCollectionCopier;
+import com.pgac.flatfile.morph.EntityCollectionReflector;
+import com.pgac.flatfile.morph.EntityInstantiatingReflector;
+
+/**
+ *
+ */
+public abstract class ConversionTestBase extends EntityParserTestBase {
+ private static final EntityNameStrategy DEFAULT_NAME_STRATEGY = new
DefaultEntityNameStrategy();
+
+ protected static class TestPair {
+ private String entityValue;
+
+ private Object modelObject;
+
+ public TestPair(String entityValue, Object modelObject) {
+ this.entityValue = entityValue;
+ this.modelObject = modelObject;
+ }
+
+ public synchronized String getEntityValue() {
+ return entityValue;
+ }
+
+ public synchronized Object getModelObject() {
+ return modelObject;
+ }
+ }
+
+ protected DecoratedConverter converter;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.pgac.fixedlength.EntityParserTestBase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ entityFactory.setEntityNameStrategy(getEntityNameStrategy());
+ Reflector reflector = new SimpleDelegatingReflector(new Reflector[] {
+ new EntityInstantiatingReflector(entityFactory),
+ new EntityCollectionReflector() }, true);
+ PropertyNameMatchingCopier entityCopier = new
PropertyNameMatchingCopier();
+ entityCopier.setDestinationClasses(new Class[] { Entity.class });
+ entityCopier.setReflector(reflector);
+ SimpleDelegatingTransformer sdt = new SimpleDelegatingTransformer(
+ new Transformer[] {
+ new ContainerToIndexedEntityCollectionCopier(),
+ entityCopier }, true);
+ converter = sdt;
+ }
+
+ public void testMe() throws Exception {
+ TestPair[] pairs = getTestPairs();
+ for (int i = 0; i < pairs.length; i++) {
+ assertConversion(pairs[i]);
+ }
+ }
+
+ protected void assertConversion(TestPair pair) {
+ Entity e = (Entity) converter.convert(Entity.class, pair
+ .getModelObject());
+ assertValue(pair.getEntityValue(), e);
+ }
+
+ /**
+ * Override this method for multiple test pairs
+ * @return
+ */
+ protected TestPair[] getTestPairs() {
+ return new TestPair[] { getTestPair() };
+ }
+
+ /**
+ * Override this method for a single test pair
+ * @return
+ */
+ protected TestPair getTestPair() {
+ throw new UnsupportedOperationException("getTestPair");
+ }
+
+ /**
+ * Override to provide a different naming strategy
+ * @return
+ */
+ protected EntityNameStrategy getEntityNameStrategy() {
+ return DEFAULT_NAME_STRATEGY;
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/ConversionTestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/Foo.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/Foo.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/Foo.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/Foo.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,34 @@
+package com.pgac.flatfile.conversion;
+
+/**
+ *
+ */
+public class Foo {
+ private String a;
+ private int b;
+
+ public Foo() {
+ // default
+ }
+
+ public Foo(String a, int b) {
+ setA(a);
+ setB(b);
+ }
+
+ public synchronized String getA() {
+ return a;
+ }
+
+ public synchronized void setA(String a) {
+ this.a = a;
+ }
+
+ public synchronized int getB() {
+ return b;
+ }
+
+ public synchronized void setB(int b) {
+ this.b = b;
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/Foo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/NestedConversionTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/NestedConversionTest.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/NestedConversionTest.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/NestedConversionTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,30 @@
+package com.pgac.flatfile.conversion;
+
+public class NestedConversionTest extends ConversionTestBase {
+ protected TestPair[] getTestPairs() {
+ Foo[] foos = new Foo[] { new Foo("abcdefghij", 123456),
+ new Foo("abcdefg", 12345), new Foo("abcdefghijk", 1234567) };
+ Bar bar1 = new Bar();
+ bar1.setFoos(foos);
+ bar1.setX("X");
+ bar1.setY("Y");
+
+ Bar bar2 = new Bar();
+ bar2.setX("X");
+ bar2.setY("Y");
+ bar2.setFoos(new Foo[0]);
+ Bar bar3 = new Bar();
+ bar3.setX("x");
+ bar3.setY("y");
+ bar3.setFoos(null);
+ return new TestPair[] {
+ new TestPair(
+ "Xabcdefghij;123456abcdefg
;012345abcdefghij;234567Y",
+ bar1), new TestPair("XY", bar2),
+ new TestPair("xy", bar3) };
+ }
+
+ protected String getSource() {
+ return "nested.test";
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/NestedConversionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/basic.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/basic.test?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/basic.test
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/basic.test
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,7 @@
[EMAIL PROTECTED] overflow=TRUNCATE;
+
+foo {
+ a (10)
+ ? ';'!
+ b (6) pad='0' justify=RIGHT
+}
\ No newline at end of file
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/nested.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/nested.test?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/nested.test
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/conversion/nested.test
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,13 @@
[EMAIL PROTECTED] overflow=TRUNCATE;
+
+foo {
+ a (10)
+ ? ';'!
+ b (6) pad='0' justify=RIGHT
+}
+
+bar {
+ x (1)
+ foos $foo []
+ y (1)
+}
\ No newline at end of file
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/defaultOptions.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/defaultOptions.test?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/defaultOptions.test
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/defaultOptions.test
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,8 @@
[EMAIL PROTECTED] pad='@' justify=RIGHT; //default field options
+
+field1 (6) "foo"
+field2 (6) justify=LEFT "foo"
+field3 (6) pad='&' "foo"
+field4 (6) pad='&' justify=LEFT "foo"
+field5 (6) justify=CENTER "foo"
+field6 (6) pad='&' justify=CENTER "foo"
Added: commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/delimiter.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/delimiter.test?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/delimiter.test
(added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/delimiter.test
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,36 @@
+//test entity collections, i.e. arrays and maps, with a record delimiter:
+
+array38 "XX" [10] delim="\r\n" delimAfter=false : 38
+array40 "XX" [10] delim="\r\n" : 40
+
+map13 {
+ foo "foo"
+ bar "bar"
+ baz "baz"
+} delim="\r\n" delimAfter=false : 13
+
+map15 {
+ foo "foo"
+ bar "bar"
+ baz "baz"
+} delim="\r\n" : 15
+
+map18 {
+ foo "foo"
+ bar "bar"
+ ? "why"
+ baz "baz"
+} delim="\r\n" delimAfter=false : 18
+
+map20 {
+ foo "foo"
+ bar "bar"
+ ? "why"
+ baz "baz"
+} delim="\r\n" : 20
+
+map39 {
+ foo "foo"
+ bar "bar"
+ baz "baz"
+} delim=' ' delimAfter=false [3] delim="\r\n" : 39
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/dynamicField.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/dynamicField.test?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/dynamicField.test
(added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/dynamicField.test
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,16 @@
+df1 (0..1)
+df2 (..1)
+df3 (0..)
+df4 (*)
+df5 (*) "foo"
+//for fun:
+df6 (0..0)
+df7 (..0)
+df8 (1..1)
+df9 (1..3)
+//arrays:
+unboundedArray (*) [3]
+unboundedDelimitedArray (*) [3] delim='-' suppressEmptyChildren=false
+boundedArray (1..3) [3]
+boundedDelimitedArray (1..3) [3] delim='\n' suppressEmptyChildren=false
+nestedUncertainty (*) []
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/entityarraylifecycle.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/entityarraylifecycle.test?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/entityarraylifecycle.test
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/entityarraylifecycle.test
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,13 @@
+foo (2)
+
+hypo $foo[]
+
+complete $foo[2]
+
+rangeMin1 (1) [1..]
+
+explicitRange (1) [1..3]
+
+optional (1) [0..1]
+
+optional2 (1) [..1]
\ No newline at end of file
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/fieldOptions.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/fieldOptions.test?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/fieldOptions.test
(added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/fieldOptions.test
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,26 @@
+field1 (6) "foo"
+field2 (6) pad='x' "foo"
+field3 (6) pad='x' justify=LEFT "foo"
+field4 (6) pad='x' justify=RIGHT "foo"
+field5 (6) pad='x' justify=CENTER "foo"
+field6 (2) justify=CENTER "foo"
+field7 (2) justify=CENTER overflow=TRUNCATE "foo"
+field8 (2) justify=CENTER overflow=TRUNCATE "foobar"
+field9 (3) justify=LEFT overflow=TRUNCATE "fool"
+field10 (3) justify=RIGHT overflow=TRUNCATE "fowl"
+field11 (5) justify=RIGHT pad='0' "3.14"
+field12 { //you'll see that we can set nested values now too because we are so
cool!
+ foo (3)
+ ? ' '!
+ bar (3)
+} "childMap[foo].value"=foo bar=bar
+field13 { //added @ syntax to override auto translation of non-collection
entities to strings
+ foo (3)
+ ? ' '!
+ bar (3)
+} "@foo.value"=foo "@bar.justify"=RIGHT bar=b
+field14 {
+ foo (3)
+} [2] "@prototype.foo"=foo
+field15 (3) [2] prototype=foo
+field16 (3) [2] "@prototype.value"=foo
\ No newline at end of file
Added: commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/filler.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/filler.test?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/filler.test
(added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/filler.test Thu
Sep 4 09:39:28 2008
@@ -0,0 +1,7 @@
+withFiller {
+ foo (3) "foo"
+ ? ' '
+ bar (3) "bar"
+ ? "---nothing-goes-here---"
+ baz (3) "baz"
+}
\ No newline at end of file
Added: commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/immutable.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/immutable.test?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/immutable.test
(added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/immutable.test
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,17 @@
+test1 {
+ ? "FOO"!
+ ? " "
+ ? "BAR"!
+ ? " "
+ ? "BAZ"!
+} 'x'*
+
+test2 (3) [3] "submarine"!
+
+test3 {
+ a "what"!
+ b "me "
+ c "worry"!
+} "tap your toe"
+
+test4 { ? (10) 'x'*! } 'y'*
\ No newline at end of file
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/lengthcheck1.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/lengthcheck1.test?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/lengthcheck1.test
(added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/lengthcheck1.test
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,11 @@
+foo {
+ x (2) [100] //200
+ y (100) [2] //200
+ z { //120
+ a (10)
+ b (20)
+ c (30)
+ } [2]
+} : 520
+
+bar { $foo } ' '* : 520
\ No newline at end of file
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/lengthcheck2.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/lengthcheck2.test?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/lengthcheck2.test
(added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/lengthcheck2.test
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,9 @@
+foo {
+ x (2) [100] //200
+ y (100) [2] //200
+ z { //120
+ a (10)
+ b (20)
+ c (30)
+ } [2]
+} : 521
\ No newline at end of file
Added:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/morph/TextToByteConverterTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/morph/TextToByteConverterTest.java?rev=692147&view=auto
==============================================================================
---
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/morph/TextToByteConverterTest.java
(added)
+++
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/morph/TextToByteConverterTest.java
Thu Sep 4 09:39:28 2008
@@ -0,0 +1,22 @@
+/**
+ *
+ */
+package com.pgac.flatfile.morph;
+
+import com.pgac.flatfile.morph.TextToByteConverter;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class TextToByteConverterTest extends TestCase {
+ public void test1() throws Exception {
+ TextToByteConverter cnv = new TextToByteConverter();
+ assertEquals((byte) 'a', ((Byte) cnv.convert(Byte.class, "a"))
+ .byteValue());
+ assertEquals((byte) 'a', ((Byte) cnv.convert(Byte.class, "asinine"))
+ .byteValue());
+ assertEquals("a", cnv.convert(String.class, new Byte((byte) 'a')));
+ }
+}
Propchange:
commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/morph/TextToByteConverterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/types.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/types.test?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/types.test (added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/types.test Thu
Sep 4 09:39:28 2008
@@ -0,0 +1,20 @@
+foo (2)
+bar (2) [2]
+baz { a (1) b(2) } [3]
+nest {
+ $foo
+ barA $bar
+ barB $bar
+ $baz
+}
+
+types {
+ $foo [4]
+ foo1 $foo
+ foo2 $foo
+ bar1 $bar
+ bar2 $bar
+ $baz
+ $nest
+ normal (1)
+}
\ No newline at end of file
Added: commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/values.test
URL:
http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/values.test?rev=692147&view=auto
==============================================================================
--- commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/values.test
(added)
+++ commons/sandbox/flatfile/trunk/src/test/com/pgac/flatfile/values.test Thu
Sep 4 09:39:28 2008
@@ -0,0 +1,29 @@
+typeWithValue (3) "twv"
+
+values {
+ A (1) 'A'
+ B (1) "B"
+ BB (2) "BB"
+ CCC (3) "CCC"
+ DDDD (4) 'D'*
+ A4 (1) "A" [4]
+ B4 (1) [4] "BBBB"
+ C4 "C" [4]
+ D4 (1) [4] 'D'*
+ initarray {
+ array (2) [3]
+ } "123456"
+ array (2) [3] "123456"
+ x $typeWithValue
+ y $typeWithValue "vwt" //overridden from typedef
+ z $typeWithValue "123" [2]
+ $typeWithValue [2]
+}
+
+implicitLength "foo-bar-baz!"
+
+overrideChildren {
+ someContent "safljasdfj"
+ moreContent "asjglasjglasjgl"
+ evenMoreContent "asldgjasgjasjgklasdf"
+} ' '*