Added future tolerance to Date10 and Date4 parsers; simplified the use of generics in all the FieldParseInfo subclasses. Added a test for the future tolerance of date parsers.
git-svn-id: https://j8583.svn.sourceforge.net/svnroot/j8583/j8583@85 db60a039-f72e-0410-b1d2-baa000846441
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package j8583;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
import com.solab.iso8583.IsoType;
|
||||
import com.solab.iso8583.IsoValue;
|
||||
import com.solab.iso8583.MessageFactory;
|
||||
import com.solab.iso8583.parse.Date10ParseInfo;
|
||||
import com.solab.iso8583.parse.Date4ParseInfo;
|
||||
|
||||
/** Test that the dates are formatted and parsed correctly.
|
||||
*
|
||||
* @author Enrique Zamudio
|
||||
*/
|
||||
public class TestDates {
|
||||
|
||||
private MessageFactory mf;
|
||||
|
||||
@Before
|
||||
public void init() throws IOException {
|
||||
mf = new MessageFactory();
|
||||
mf.setCharacterEncoding("UTF-8");
|
||||
mf.setCustomField(48, new CustomField48());
|
||||
mf.setConfigPath("config.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDate4FutureTolerance() throws ParseException, IOException {
|
||||
long now = System.currentTimeMillis();
|
||||
long today = now - (now % 86400000l);
|
||||
Date soon = new Date(now + 50000);
|
||||
byte[] buf = IsoType.DATE4.format(soon).getBytes();
|
||||
IsoValue<Date> comp = new Date4ParseInfo().parse(buf, 0, null);
|
||||
assert comp.getValue().after(new Date(today));
|
||||
//Now with the binary
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
comp.write(bout, true);
|
||||
IsoValue<Date> bin = new Date4ParseInfo().parseBinary(bout.toByteArray(), 0, null);
|
||||
Assert.assertEquals(comp.getValue().getTime(), bin.getValue().getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDate10FutureTolerance() throws ParseException, IOException {
|
||||
Date soon = new Date(System.currentTimeMillis() + 50000);
|
||||
byte[] buf = IsoType.DATE10.format(soon).getBytes();
|
||||
IsoValue<Date> comp = new Date10ParseInfo().parse(buf, 0, null);
|
||||
assert comp.getValue().after(new Date());
|
||||
//Now with the binary
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
comp.write(bout, true);
|
||||
IsoValue<Date> bin = new Date10ParseInfo().parseBinary(bout.toByteArray(), 0, null);
|
||||
Assert.assertEquals(comp.getValue().getTime(), bin.getValue().getTime());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user