]> git.basschouten.com Git - openhab-addons.git/blob
9b30f7a65fa0188a38d668dfa4bf0210c43a8955
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.deutschebahn.internal.timetable;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.io.File;
18 import java.net.URL;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21
22 /**
23  * Helper interface for jUnit Tests to provide an {@link TimetablesApiTestModule}.
24  * 
25  * @author Sönke Küper - initial contribution.
26  */
27 @NonNullByDefault
28 public interface TimetablesV1ImplTestHelper {
29
30     public static final String EVA_LEHRTE = "8000226";
31     public static final String EVA_HANNOVER_HBF = "8000152";
32     public static final String AUTH_TOKEN = "354c8161cd7fb0936c840240280c131e";
33
34     /**
35      * Creates an {@link TimetablesApiTestModule} that uses http response data from file system.
36      * Uses default-testdata from directory /timetablesData
37      */
38     public default TimetablesApiTestModule createApiWithTestdata() throws Exception {
39         return this.createApiWithTestdata("/timetablesData");
40     }
41
42     /**
43      * Creates an {@link TimetablesApiTestModule} that uses http response data from file system.
44      * 
45      * @param dataDirectory Directory within test-resources containing the stub-data.
46      */
47     public default TimetablesApiTestModule createApiWithTestdata(String dataDirectory) throws Exception {
48         final URL timetablesData = getClass().getResource(dataDirectory);
49         assertNotNull(timetablesData);
50         final File testDataDir = new File(timetablesData.toURI());
51         final TimetableStubHttpCallable httpStub = new TimetableStubHttpCallable(testDataDir);
52         final TimetablesV1Impl timeTableApi = new TimetablesV1Impl(AUTH_TOKEN, httpStub);
53         return new TimetablesApiTestModule(timeTableApi, httpStub);
54     }
55 }