Package com.asakusafw.runtime.value

Examples of com.asakusafw.runtime.value.DateOption


    @Test
    public void invalid_date() throws Exception {
        CsvParser parser = create(String.valueOf("?"));
        assertThat(parser.next(), is(true));
        try {
            parser.fill(new DateOption());
            fail();
        } catch (CsvFormatException e) {
            assertThat(e.getStatus().getReason(), is(Reason.INVALID_CELL_FORMAT));
        }
    }
View Full Code Here


        CsvConfiguration conf = createConfiguration();
        RCReader reader = new RCReader("1999-12-31\r\n".getBytes(conf.getCharset()), count);
        try {
            int rows = 0;
            CsvParser parser = new CsvParser(reader, "testing", conf);
            DateOption date = new DateOption();
            while (parser.next()) {
                parser.fill(date);
                parser.endRecord();
                if (rows == 0) {
                    assertThat(date, is(new DateOption(new Date(1999, 12, 31))));
                }
                rows++;
            }
            parser.close();
            assertThat(rows, is(count));
View Full Code Here

     * dateの値を解析するテスト。
     * @throws Exception 例外が発生した場合
     */
    @Test
    public void fillDate() throws Exception {
        DateOption value = new DateOption();
        create("date");

        assertThat(parser.next(), is(true));
        parser.fill(value);
        assertThat(value.get(), is(date(2000, 2, 9)));
        parser.fill(value);
        assertThat(value.get(), is(date(2000, 3, 1)));
        parser.fill(value);
        assertThat(value.get(), is(date(100, 3, 30)));
        parser.endRecord();

        assertThat(parser.next(), is(true));
        parser.fill(value);
        assertThat(value.isNull(), is(true));
        parser.fill(value);
        assertThat(value.get(), is(date(1, 1, 1)));
        parser.fill(value);
        assertThat(value.get(), is(date(9999, 12, 31)));
        parser.endRecord();

        assertThat(parser.next(), is(true));
        parser.fill(value);
        assertThat(value.isNull(), is(true));
        parser.fill(value);
        assertThat(value.isNull(), is(true));
        parser.fill(value);
        assertThat(value.isNull(), is(true));

        assertThat(parser.next(), is(false));
    }
View Full Code Here

     * test for date values.
     * @throws Exception if failed
     */
    @Test
    public void date_values() throws Exception {
        assertRestorable(new DateOption(new Date(2011, 3, 31)));
        assertRestorable(new DateOption(new Date(1971, 4, 1)));
        assertRestorable(new DateOption());

        dateFormat = "yyyy-MM\"dd";
        assertRestorable(new DateOption(new Date(2011, 3, 31)));
        assertRestorable(new DateOption(new Date(1971, 4, 1)));

        dateFormat = "yyyy-MM,dd";
        assertRestorable(new DateOption(new Date(2011, 3, 31)));
        assertRestorable(new DateOption(new Date(1971, 4, 1)));

        dateFormat = "yyyy-MM\ndd";
        assertRestorable(new DateOption(new Date(2011, 3, 31)));
        assertRestorable(new DateOption(new Date(1971, 4, 1)));

        dateFormat = "yyyy-MM\rdd";
        assertRestorable(new DateOption(new Date(2011, 3, 31)));
        assertRestorable(new DateOption(new Date(1971, 4, 1)));
    }
View Full Code Here

     * @throws Exception if failed
     */
    @Test
    public void date_values_direct() throws Exception {
        dateFormat = "yyyyMMdd";
        assertRestorable(new DateOption(new Date(2011, 3, 31)));
        assertRestorable(new DateOption(new Date(1971, 4, 1)));
        assertRestorable(new DateOption());
    }
View Full Code Here

    @Test
    public void stress_date() throws Exception {
        int count = 5000000;
        CsvEmitter emitter = new CsvEmitter(new VoidOutputStream(), "testing", createConfiguration());
        try {
            DateOption value = new DateOption(new Date(1999, 12, 31));
            for (int i = 0; i < count; i++) {
                emitter.emit(value);
                emitter.endRecord();
            }
        } finally {
View Full Code Here

     * @throws Exception if failed
     */
    @Test
    public void placeholder_date() throws Exception {
        Mock mock = new Mock(spec(DATE, "yyyy/MM/dd"));
        mock.setMock(new DateOption(new Date(2012, 2, 3)));
        assertThat(mock.apply(), is("2012/02/03"));
    }
View Full Code Here

     * @throws Exception if failed
     */
    @Test
    public void placeholder_date_null() throws Exception {
        Mock mock = new Mock(spec(DATE, "yyyy/MM/dd"));
        mock.setMock(new DateOption());
        mock.apply(); // no error
    }
View Full Code Here

     */
    @Test
    public void serialize() throws Exception {
        Mock mock = new Mock(plain("left"), spec(NATURAL), plain("right"), spec(DATE, "yyyy/MM/dd"));

        mock.setMock("", "0", "", new DateOption(new Date(2012, 1, 2)));
        byte[] s0 = ser(mock);
        Mock r0 = new Mock(plain("left"), spec(NATURAL), plain("right"), spec(DATE, "yyyy/MM/dd"));
        des(r0, s0);

        assertThat(r0.apply(), is("left0right2012/01/02"));
View Full Code Here

     * @throws Exception if failed
     */
    @Test
    public void compare() throws Exception {
        Mock a = new Mock(plain("left"), spec(NATURAL), plain("right"), spec(DATE, "yyyy"));
        a.setMock("", "0", "", new DateOption(new Date(2012, 1, 2)));

        Mock b = new Mock(plain("left"), spec(NATURAL), plain("right"), spec(DATE, "yyyy"));
        b.setMock("", "1", "", new DateOption(new Date(2012, 1, 2)));

        Mock c = new Mock(plain("left"), spec(NATURAL), plain("right"), spec(DATE, "yyyy"));
        c.setMock("", "1", "", new DateOption(new Date(2013, 1, 2)));

        Mock d = new Mock(plain("left"), spec(NATURAL), plain("right"), spec(DATE, "yyyy"));
        d.setMock("LLLLLLLLLLLLLL", "0", "RRRRRRRRRRRRRR", new DateOption(new Date(2012, 2, 3)));

        assertThat(cmp(a, b), is(not(0)));
        assertThat(cmp(b, c), is(not(0)));
        assertThat(cmp(a, d), is(equalTo(0)));
    }
View Full Code Here

TOP

Related Classes of com.asakusafw.runtime.value.DateOption

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.