]> git.basschouten.com Git - openhab-addons.git/blob
4b73bd3333ecc85056095a43496d75e48a793ec7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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 a {@link TimetablesApiTestModule}.
24  * 
25  * @author Sönke Küper - initial contribution.
26  */
27 @NonNullByDefault
28 public interface TimetablesV1ImplTestHelper {
29
30     static final String EVA_LEHRTE = "8000226";
31     static final String EVA_HANNOVER_HBF = "8000152";
32     static final String CLIENT_ID = "bdwrpmxuo6157jrekftlbcc6ju9awo";
33     static final String CLIENT_SECRET = "354c8161cd7fb0936c840240280c131e";
34
35     /**
36      * Creates a {@link TimetablesApiTestModule} that uses http response data from file system.
37      * Uses default-testdata from directory /timetablesData
38      */
39     default TimetablesApiTestModule createApiWithTestdata() throws Exception {
40         return this.createApiWithTestdata("/timetablesData");
41     }
42
43     /**
44      * Creates a {@link TimetablesApiTestModule} that uses http response data from file system.
45      * 
46      * @param dataDirectory Directory within test-resources containing the stub-data.
47      */
48     default TimetablesApiTestModule createApiWithTestdata(String dataDirectory) throws Exception {
49         final URL timetablesData = getClass().getResource(dataDirectory);
50         assertNotNull(timetablesData);
51         final File testDataDir = new File(timetablesData.toURI());
52         final TimetableStubHttpCallable httpStub = new TimetableStubHttpCallable(testDataDir);
53         final TimetablesV1Impl timeTableApi = new TimetablesV1Impl(CLIENT_ID, CLIENT_SECRET, httpStub);
54         return new TimetablesApiTestModule(timeTableApi, httpStub);
55     }
56 }