Package ch.pollet.jzic.parser

Source Code of ch.pollet.jzic.parser.ZoneParserTest

package ch.pollet.jzic.parser;

import ch.pollet.jzic.parser.ZoneParser;
import ch.pollet.jzic.datetime.DateTime;
import ch.pollet.jzic.timezone.Database;
import ch.pollet.jzic.timezone.Zone;
import ch.pollet.jzic.tokenizer.Tokenizer;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Christophe Pollet
*/
public class ZoneParserTest {
    @Test
    public void testContinueParsing() throws Exception {
    }

    @Test
    public void testParse() throws Exception {
        String line;
        Tokenizer t;
        Zone z;
        DateTime dt;
       
        Database db = new Database();
        ZoneParser zp = new ZoneParser(db);

        //-- Test 1
        line = "Zone1 1:34:08 - LMT 2000";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2000);
        dt.setMonth(1);
        dt.setDay(1);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        assertTrue(db.getZones().containsKey("Zone1"));
        z = db.getZones().get("Zone1").first();
        assertEquals(5648, z.getOffset());
        assertEquals(null, z.getRule());
        assertEquals("LMT", z.getFormat());
        assertEquals(dt, z.getUntil());

        //-- Test 2
        line = "Zone2 1:34:08 Rule LMT 2000 Feb 12 1u";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2000);
        dt.setMonth(2);
        dt.setDay(12);
        dt.setHour(1);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.UTC);

        z = db.getZones().get("Zone2").first();
        assertEquals("Rule", z.getRule());
        assertEquals(dt, z.getUntil());

        //-- Test 3
        line = "Zone3 1:34:08 Rule LMT 2000 Mar 12 1:30s";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2000);
        dt.setMonth(3);
        dt.setDay(12);
        dt.setHour(1);
        dt.setMinute(30);
        dt.setSecond(0);
        dt.setType(DateTime.Type.STD);

        z = db.getZones().get("Zone3").first();
        assertEquals(dt, z.getUntil());

        //-- Test 4
        line = "Zone4 1:34:08 Rule LMT 2000 Apr 12 1:30:44u";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2000);
        dt.setMonth(4);
        dt.setDay(12);
        dt.setHour(1);
        dt.setMinute(30);
        dt.setSecond(44);
        dt.setType(DateTime.Type.UTC);

        z = db.getZones().get("Zone4").first();
        assertEquals(dt, z.getUntil());

        //-- Test 5
        line = "Zone5 -1:34:08 Rule LMT";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(Integer.MAX_VALUE);
        dt.setMonth(12);
        dt.setDay(31);
        dt.setHour(23);
        dt.setMinute(59);
        dt.setSecond(59);
        dt.setType(DateTime.Type.WALL);

        z = db.getZones().get("Zone5").first();
        assertEquals(dt, z.getUntil());
        assertEquals(-5648, z.getOffset());

        //-- Test 6
        line = "Zone6 0 Rule LMT 2009 Sep lastSun";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(9);
        dt.setDay(27);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        z = db.getZones().get("Zone6").first();
        assertEquals(dt, z.getUntil());

        //-- Test 7
        line = "Zone7 0 Rule LMT 2009 Oct Mon>=3";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(10);
        dt.setDay(5);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        z = db.getZones().get("Zone7").first();
        assertEquals(dt, z.getUntil());

        //-- Test 8
        line = "Zone8 0 Rule LMT 2009 Nov Mon>=5";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(11);
        dt.setDay(9);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        z = db.getZones().get("Zone8").first();
        assertEquals(dt, z.getUntil());

        //-- Test 9
        line = "Zone9 0 Rule LMT 2009 Dec Mon<=8";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(12);
        dt.setDay(7);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        z = db.getZones().get("Zone9").first();
        assertEquals(dt, z.getUntil());

        //-- Test 10
        line = "Zone10 0 Rule LMT 2009 Dec Mon<=14";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(12);
        dt.setDay(14);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        z = db.getZones().get("Zone10").first();
        assertEquals(dt, z.getUntil());
    }

}
TOP

Related Classes of ch.pollet.jzic.parser.ZoneParserTest

TOP
Copyright © 2018 www.massapi.com. 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.