⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timekvpparsertest.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
字号:
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
 * This code is licensed under the GPL 2.0 license, availible at the root
 * application directory.
 */
package org.geoserver.ows.kvp;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import org.geoserver.ows.kvp.TimeKvpParser;

import junit.framework.TestCase;

        
/**
 * Test for the time parameter in a WMS request.
 * 
 * @author C閐ric Brian鏾n
 */
public class TimeKvpParserTest extends TestCase {
    /**
     * A time period for testing.
     */
    private final static String PERIOD = "2007-01-01T12Z/2007-01-31T12Z/P1DT12H";
    
    /**
     * Format of dates.
     */
    private final static DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH'Z'");

    /**
     * Tests only the increment part of the time parameter.
     *
     * @throws ParseException if the string can't be parsed.
     */
    public void testPeriod() throws ParseException {
        final long millisInDay = TimeKvpParser.MILLIS_IN_DAY;
        assertEquals(               millisInDay,  TimeKvpParser.parsePeriod("P1D"));
        assertEquals(             3*millisInDay,  TimeKvpParser.parsePeriod("P3D"));
        assertEquals(            14*millisInDay,  TimeKvpParser.parsePeriod("P2W"));
        assertEquals(             8*millisInDay,  TimeKvpParser.parsePeriod("P1W1D"));
        assertEquals(               millisInDay,  TimeKvpParser.parsePeriod("PT24H"));
        assertEquals(Math.round(1.5*millisInDay), TimeKvpParser.parsePeriod("P1.5D"));
    }

    /**
     * Compares the dates obtained by parsing the time parameter with the expected values.
     *
     * @throws ParseException if the string can't be parsed.
     */
    public void testInterval() throws ParseException {
        TimeKvpParser timeKvpParser = new TimeKvpParser("TIME");
        List l = (List) timeKvpParser.parse(PERIOD);
        // Verify that the list contains at least one element.
        assertFalse(l.isEmpty());
        assertEquals(format.parse("2007-01-01T12Z"), l.get(0));
        assertEquals(format.parse("2007-01-03T00Z"), l.get(1));
        assertEquals(format.parse("2007-01-04T12Z"), l.get(2));
        assertEquals(format.parse("2007-01-06T00Z"), l.get(3));
        assertEquals(format.parse("2007-01-07T12Z"), l.get(4));
        assertEquals(format.parse("2007-01-09T00Z"), l.get(5));
        assertEquals(format.parse("2007-01-10T12Z"), l.get(6));
        assertEquals(format.parse("2007-01-12T00Z"), l.get(7));
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -