Package org.opentripplanner.routing.core

Source Code of org.opentripplanner.routing.core.RoutingContextTest

/* This program is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>. */

package org.opentripplanner.routing.core;

import org.junit.Test;
import org.onebusaway.gtfs.model.calendar.ServiceDate;
import org.onebusaway.gtfs.services.calendar.CalendarService;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.vertextype.PatternArriveVertex;

import java.util.Collections;
import java.util.TimeZone;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class RoutingContextTest {

    @Test
    public void testSetServiceDays() throws Exception {

        String agencyId = "AGENCY";
        Graph graph = mock(Graph.class);
        RoutingRequest routingRequest = mock(RoutingRequest.class);
        CalendarService calendarService = mock(CalendarService.class);

        when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("Europe/Budapest"));
        when(graph.getCalendarService()).thenReturn(calendarService);
        when(graph.getAgencyIds()).thenReturn(Collections.<String>singletonList(agencyId));
        when(calendarService.getTimeZoneForAgencyId(agencyId)).thenReturn(TimeZone.getTimeZone("Europe/Budapest"));

        when(routingRequest.getSecondsSinceEpoch())
            .thenReturn(
                1393750800L /* 2014-03-02T10:00:00+01:00 */,

                1396126800L /* 2014-03-29T22:00:00+01:00 */,
                1396132200L /* 2014-03-29T23:30:00+01:00 */,
                1396135800L /* 2014-03-30T00:30:00+01:00 */,

                1401696000L /* 2014-06-02T10:00:00+02:00 */,

                1414272600L /* 2014-10-25T23:30:00+02:00 */,
                1414276200L /* 2014-10-26T00:30:00+02:00 */,
                1414279800L /* 2014-10-26T01:30:00+02:00 */
            );

        verifyServiceDays(routingRequest, graph, new ServiceDate(201431), new ServiceDate(201432), new ServiceDate(201433));

        verifyServiceDays(routingRequest, graph, new ServiceDate(20143, 28), new ServiceDate(20143, 29), new ServiceDate(20143, 30));
        verifyServiceDays(routingRequest, graph, new ServiceDate(20143, 28), new ServiceDate(20143, 29), new ServiceDate(20143, 30));
        verifyServiceDays(routingRequest, graph, new ServiceDate(20143, 29), new ServiceDate(20143, 30), new ServiceDate(20143, 31));

        verifyServiceDays(routingRequest, graph, new ServiceDate(201461), new ServiceDate(201462), new ServiceDate(201463));

        verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 10, 24), new ServiceDate(2014, 10, 25), new ServiceDate(2014, 10, 26));
        verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 10, 25), new ServiceDate(2014, 10, 26), new ServiceDate(2014, 10, 27));
        verifyServiceDays(routingRequest, graph, new ServiceDate(2014, 10, 25), new ServiceDate(2014, 10, 26), new ServiceDate(2014, 10, 27));
    }

    private void verifyServiceDays(RoutingRequest routingRequest, Graph graph, ServiceDate ... dates) {
        RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, mock(PatternArriveVertex.class));

        for(int i = 0; i < dates.length; ++i) {
            assertEquals("date " + i, dates[i], routingContext.serviceDays.get(i).getServiceDate());
        }
    }
}
TOP

Related Classes of org.opentripplanner.routing.core.RoutingContextTest

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.