Compare commits

...

11 Commits
main ... v1.3.3

Author SHA1 Message Date
251e60d66f
prepare release 1.3.3
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-21 15:46:15 +01:00
c5f13f6652
deps: bump jackson-databind from 2.13.3 to 2.14.0
All checks were successful
continuous-integration/drone/push Build is passing
Plus some minor test dependency updates.

Cherry-picked from 55271011b677b4450693d403463e86c75887e3bf
2022-11-21 15:42:24 +01:00
30b151a15d
ci: enable SonarQube analysis for pull requests
All checks were successful
continuous-integration/drone/push Build is passing
Cherry-picked from 7cb5aefb5badf2bff333928fe429498fe9c8a73e
2022-11-21 15:41:36 +01:00
27d5f1b861
add implementation details and classpath to JAR manifest
Cherry-picked from 0573ed1ade96be91a724a08ea19f85e63aca8105
2022-11-21 15:41:06 +01:00
5152c4e667
docs: correct forStops() calls in README
All checks were successful
continuous-integration/drone/push Build is passing
backported from 591476cc6011210c01624214d7f57e099a48ea66
2022-11-21 15:32:05 +01:00
4b69343d39
allow getMessages with limit directly from Query instance
backported from commit 7684b2e089cd99ede6d294d3f69aa38e39a82074
2022-11-21 15:32:04 +01:00
8748dd883b
allow getTrips with limit directly from Query instance
backported from commit 406fe076f1763f3757cfdd4bceb3568676679b03
2022-11-21 15:31:54 +01:00
0ee348ee0d
minor code clean-ups
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-30 12:42:18 +02:00
a91005967c
update copyright notice 2022-08-30 12:40:15 +02:00
b7ce0a3c3e
update dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-30 12:33:39 +02:00
a0bcd96054
migrate to GH actions for CI 2022-08-30 12:33:38 +02:00
19 changed files with 179 additions and 85 deletions

View File

@ -4,9 +4,9 @@ name: java8
steps: steps:
- name: test - name: test
image: maven:3-openjdk-8 image: maven:3-eclipse-temurin-8
commands: commands:
- mvn clean test - mvn -B clean test
--- ---
kind: pipeline kind: pipeline
@ -15,17 +15,17 @@ name: java11
steps: steps:
- name: test - name: test
image: maven:3-openjdk-11 image: maven:3-eclipse-temurin-11
commands: commands:
- mvn clean test - mvn -B clean test
--- ---
kind: pipeline kind: pipeline
type: docker type: docker
name: java15 name: java17
steps: steps:
- name: test - name: test
image: maven:3-openjdk-15 image: maven:3-eclipse-temurin-17
commands: commands:
- mvn clean test - mvn -B clean test

33
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,33 @@
name: CI
on: [ push, pull_request ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
jdk: [ 8, 11, 17 ]
include:
- jdk: 11
analysis: true
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.jdk }}
distribution: 'temurin'
- name: Test
run: mvn -B -P coverage clean verify
- name: Analysis
if: matrix.analysis
run: >
mvn -B sonar:sonar
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.organization=stklcode-github
-Dsonar.login=$SONAR_TOKEN
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

View File

@ -1,17 +0,0 @@
language: java
jdk:
- openjdk8
- openjdk11
- openjdk15
install: true
addons:
sonarcloud:
organization: "stklcode-github"
token:
secure: "FkEe/+MKpF4pSX3ZYOgu7oeIKf0460Q3XVLUhIX9bk2dyY8hoab74oCo4FtD7jim0+ZC13JVHGDX7iOQMUtS5EZ+x+pA0qpppzCK5zV8afN/l46HJ07kJldvr+EH0klbDVMFZQ5dT7r/w6CoDzjtENHzKQAJLcheUVDNpkcuBdaplTqIAVf3lQpKtOuVjQJ5qZDwwS5wsHNqPcYbcEGrPmcKDVnp3mD3bfI6dT1bbRt845QcD73rPYkQKxen8eIwJxFf5MZStgvbj7yphPxPGwoLAsoLP6LpThTDYcrg+vgUnSs+l9GckL3IbhPAmecixLbKVnphBZzRTvpdMTt5KeOoAJ2nM6RLs5cRCqiEgLEioWkVaSH5WxoBj38Z1h4fTsDV3dTcCuQWX8GFxdeeTelu+XbatdRWMnUgiF7oax+uNvR62fasTbAc7dWPJbARiD7ZbkWH4nHEY07xKKx87xzUz36ZeEHGoBXgqnLmv/FCwqMrEpOoIT41fc0WYtdIA4wjRoAyG0u+wNBMbVlf4PK72seM4b/bmU+TtmaaVla/SvNOiz+A3DHxtJEUScPcL3QGjviddglMf+wyD6VXVViq9VuYRKZFyjpuoNpb5lwEbwmRnmLabBx8jBgyPinjpmqHYlIntcPAwuyLRaqTHFcmCrbeeZEf7KaPRYKx+Cs="
cache:
directories:
- '$HOME/.m2/repository'
- '$HOME/.sonar/cache'
script:
- if [ "$TRAVIS_JDK_VERSION" == "openjdk11" ]; then mvn -P coverage clean package sonar:sonar; else mvn clean test; fi

View File

@ -1,6 +1,20 @@
# Changelog # Changelog
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## 1.3.3 - 2022-11-21
### Security
* Updated Jackson dependency to 2.14.0
### Fixed
* Querying trips and messages with limit directly from `Query` instance (#19)
## 1.3.2 - 2022-08-30
### Improvements
* Dependency updates
## 1.3.1 - 2020-12-12 ## 1.3.1 - 2020-12-12
### Fixed ### Fixed
* Allow reopening an `AsyncUraTripReader` without raising an exception (#13) * Allow reopening an `AsyncUraTripReader` without raising an exception (#13)

View File

@ -39,13 +39,13 @@ List<Stop> stops = ura.forPosition(51.51009, -0.1345734, 200)
```java ```java
// Get next 10 trips for given stops and lines in a single direction (all filters optional) // Get next 10 trips for given stops and lines in a single direction (all filters optional)
List<Trip> trips = ura.forStop("100000") List<Trip> trips = ura.forStops("100000")
.forLines("25", "35") .forLines("25", "35")
.forDirection(1) .forDirection(1)
.getTrips(10); .getTrips(10);
// Get trips from given stop towards your destination // Get trips from given stop towards your destination
List<Trip> trips = ura.forStopByName("Piccadilly Circus") List<Trip> trips = ura.forStopsByName("Piccadilly Circus")
.towards("Marble Arch") .towards("Marble Arch")
.getTrips(); .getTrips();
``` ```
@ -54,7 +54,7 @@ List<Trip> trips = ura.forStopByName("Piccadilly Circus")
```java ```java
// Get next 10 trips for given stops and lines in a single direction (all filters optional) // Get next 10 trips for given stops and lines in a single direction (all filters optional)
List<Message> msgs = ura.forStop("100000") List<Message> msgs = ura.forStops("100000")
.getMessages(); .getMessages();
``` ```
@ -63,7 +63,7 @@ List<Message> msgs = ura.forStop("100000")
<dependency> <dependency>
<groupId>de.stklcode.pubtrans</groupId> <groupId>de.stklcode.pubtrans</groupId>
<artifactId>juraclient</artifactId> <artifactId>juraclient</artifactId>
<version>1.3.0</version> <version>1.3.3</version>
</dependency> </dependency>
``` ```

29
pom.xml
View File

@ -5,7 +5,7 @@
<groupId>de.stklcode.pubtrans</groupId> <groupId>de.stklcode.pubtrans</groupId>
<artifactId>juraclient</artifactId> <artifactId>juraclient</artifactId>
<version>1.3.1</version> <version>1.3.3</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -21,7 +21,7 @@
<licenses> <licenses>
<license> <license>
<name>Apache License 2.0</name> <name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url> <url>https://www.apache.org/licenses/LICENSE-2.0.html</url>
<distribution>repo</distribution> <distribution>repo</distribution>
</license> </license>
</licenses> </licenses>
@ -49,12 +49,13 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.11.3</version> <version>2.14.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId> <artifactId>junit-jupiter</artifactId>
<version>5.7.0</version> <version>5.9.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -65,8 +66,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.tomakehurst</groupId> <groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId> <artifactId>wiremock-jre8</artifactId>
<version>2.27.2</version> <version>2.35.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
@ -76,7 +77,7 @@
<dependency> <dependency>
<groupId>org.sonarsource.scanner.maven</groupId> <groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId> <artifactId>sonar-maven-plugin</artifactId>
<version>3.7.0.1746</version> <version>3.9.1.2184</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
@ -86,7 +87,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.10.1</version>
<configuration> <configuration>
<source>1.8</source> <source>1.8</source>
<target>1.8</target> <target>1.8</target>
@ -95,9 +96,13 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version> <version>3.3.0</version>
<configuration> <configuration>
<archive> <archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries> <manifestEntries>
<Automatic-Module-Name>de.stklcode.pubtrans.juraclient</Automatic-Module-Name> <Automatic-Module-Name>de.stklcode.pubtrans.juraclient</Automatic-Module-Name>
</manifestEntries> </manifestEntries>
@ -120,7 +125,7 @@
<plugin> <plugin>
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version> <version>0.8.8</version>
<executions> <executions>
<execution> <execution>
<id>prepare-agent</id> <id>prepare-agent</id>
@ -175,7 +180,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version> <version>3.4.1</version>
<configuration> <configuration>
<overview>${basedir}/src/main/javadoc/overview.html</overview> <overview>${basedir}/src/main/javadoc/overview.html</overview>
<source>1.8</source> <source>1.8</source>
@ -200,7 +205,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId> <artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version> <version>3.0.1</version>
<executions> <executions>
<execution> <execution>
<id>sign-artifacts</id> <id>sign-artifacts</id>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Stefan Kalscheuer * Copyright 2016-2022 Stefan Kalscheuer
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -192,7 +192,7 @@ public class UraClient implements Serializable {
/** /**
* Get list of trips. * Get list of trips.
* If forStops() and/or forLines() has been called, those will be used as filter. * If {@link #forStops(String...)} and/or {@link #forLines(String...)} has been called, those will be used as filter.
* *
* @return List of trips. * @return List of trips.
*/ */
@ -202,7 +202,7 @@ public class UraClient implements Serializable {
/** /**
* Get list of trips with limit. * Get list of trips with limit.
* If forStops() and/or forLines() has been called, those will be used as filter. * If {@link #forStops(String...)} and/or {@link #forLines(String...)} has been called, those will be used as filter.
* *
* @param limit Maximum number of results. * @param limit Maximum number of results.
* @return List of trips. * @return List of trips.
@ -236,7 +236,7 @@ public class UraClient implements Serializable {
String version = null; String version = null;
String line = br.readLine(); String line = br.readLine();
while (line != null && (limit == null || trips.size() < limit)) { while (line != null && (limit == null || trips.size() < limit)) {
List l = mapper.readValue(line, List.class); List<?> l = mapper.readValue(line, List.class);
/* Check if result exists and has correct response type */ /* Check if result exists and has correct response type */
if (l != null && !l.isEmpty()) { if (l != null && !l.isEmpty()) {
if (l.get(0).equals(RES_TYPE_URA_VERSION)) { if (l.get(0).equals(RES_TYPE_URA_VERSION)) {
@ -311,7 +311,7 @@ public class UraClient implements Serializable {
BufferedReader br = new BufferedReader(new InputStreamReader(is))) { BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
List l = mapper.readValue(line, List.class); List<?> l = mapper.readValue(line, List.class);
/* Check if result exists and has correct response type */ /* Check if result exists and has correct response type */
if (l != null && !l.isEmpty() && l.get(0).equals(RES_TYPE_STOP)) { if (l != null && !l.isEmpty() && l.get(0).equals(RES_TYPE_STOP)) {
stops.add(new Stop(l)); stops.add(new Stop(l));
@ -346,6 +346,18 @@ public class UraClient implements Serializable {
return getMessages(query, null); return getMessages(query, null);
} }
/**
* Get list of messages with limit.
*
* @param limit Maximum number of results.
* @return List of trips.
* @since 1.3.3
*/
public List<Message> getMessages(final Integer limit) {
return getMessages(new Query(), limit);
}
/** /**
* Get list of messages for given stopIDs with result limit. * Get list of messages for given stopIDs with result limit.
* *
@ -361,7 +373,7 @@ public class UraClient implements Serializable {
String version = null; String version = null;
String line = br.readLine(); String line = br.readLine();
while (line != null && (limit == null || messages.size() < limit)) { while (line != null && (limit == null || messages.size() < limit)) {
List l = mapper.readValue(line, List.class); List<?> l = mapper.readValue(line, List.class);
/* Check if result exists and has correct response type */ /* Check if result exists and has correct response type */
if (l != null && !l.isEmpty()) { if (l != null && !l.isEmpty()) {
if (l.get(0).equals(RES_TYPE_URA_VERSION)) { if (l.get(0).equals(RES_TYPE_URA_VERSION)) {
@ -566,6 +578,17 @@ public class UraClient implements Serializable {
return UraClient.this.getTrips(this); return UraClient.this.getTrips(this);
} }
/**
* Get trips for set filters.
*
* @param limit Maximum number of results.
* @return List of matching trips.
* @since 1.3.3
*/
public List<Trip> getTrips(final Integer limit) {
return UraClient.this.getTrips(this, limit);
}
/** /**
* Get trips for set filters. * Get trips for set filters.
* *
@ -600,5 +623,16 @@ public class UraClient implements Serializable {
public List<Message> getMessages() { public List<Message> getMessages() {
return UraClient.this.getMessages(this); return UraClient.this.getMessages(this);
} }
/**
* Get trips for set filters with limit.
*
* @param limit Maximum number of results.
* @return List of matching messages.
* @since 1.3.3
*/
public List<Message> getMessages(final Integer limit) {
return UraClient.this.getMessages(this, limit);
}
} }
} }

View File

@ -87,7 +87,7 @@ public class Message implements Model {
* @param raw List of attributes from JSON line * @param raw List of attributes from JSON line
* @throws IOException Thrown on invalid line format. * @throws IOException Thrown on invalid line format.
*/ */
public Message(final List raw) throws IOException { public Message(final List<?> raw) throws IOException {
this(raw, null); this(raw, null);
} }
@ -98,7 +98,7 @@ public class Message implements Model {
* @param version API version * @param version API version
* @throws IOException Thrown on invalid line format. * @throws IOException Thrown on invalid line format.
*/ */
public Message(final List raw, final String version) throws IOException { public Message(final List<?> raw, final String version) throws IOException {
if (raw == null || raw.size() < NUM_OF_FIELDS) { if (raw == null || raw.size() < NUM_OF_FIELDS) {
throw new IOException("Invalid number of fields"); throw new IOException("Invalid number of fields");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Stefan Kalscheuer * Copyright 2016-2022 Stefan Kalscheuer
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +33,7 @@ interface Model extends Serializable {
* @param actual Actual class. * @param actual Actual class.
* @return The Exception. * @return The Exception.
*/ */
static IOException typeErrorString(int field, Class actual) { static IOException typeErrorString(int field, Class<?> actual) {
return typeError(field, actual, "String"); return typeError(field, actual, "String");
} }
@ -45,7 +45,7 @@ interface Model extends Serializable {
* @param expected Expected type. * @param expected Expected type.
* @return The Exception. * @return The Exception.
*/ */
static IOException typeError(int field, Class actual, String expected) { static IOException typeError(int field, Class<?> actual, String expected) {
return new IOException(String.format("Field %d not of expected type %s, found %s", return new IOException(String.format("Field %d not of expected type %s, found %s",
field, expected, actual.getSimpleName())); field, expected, actual.getSimpleName()));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Stefan Kalscheuer * Copyright 2016-2022 Stefan Kalscheuer
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -72,7 +72,7 @@ public final class Stop implements Model {
* @param raw List of attributes from JSON line * @param raw List of attributes from JSON line
* @throws IOException Thrown on invalid line format. * @throws IOException Thrown on invalid line format.
*/ */
public Stop(final List raw) throws IOException { public Stop(final List<?> raw) throws IOException {
if (raw == null || raw.size() < F_NUM_OF_FIELDS) { if (raw == null || raw.size() < F_NUM_OF_FIELDS) {
throw new IOException("Invalid number of fields"); throw new IOException("Invalid number of fields");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Stefan Kalscheuer * Copyright 2016-2022 Stefan Kalscheuer
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -142,7 +142,7 @@ public final class Trip implements Model {
* @param raw List of attributes from JSON line * @param raw List of attributes from JSON line
* @throws IOException Thrown on invalid line format. * @throws IOException Thrown on invalid line format.
*/ */
public Trip(final List raw) throws IOException { public Trip(final List<?> raw) throws IOException {
this(raw, null); this(raw, null);
} }
@ -153,7 +153,7 @@ public final class Trip implements Model {
* @param version API version * @param version API version
* @throws IOException Thrown on invalid line format. * @throws IOException Thrown on invalid line format.
*/ */
public Trip(final List raw, final String version) throws IOException { public Trip(final List<?> raw, final String version) throws IOException {
if (raw == null || raw.size() < NUM_OF_FIELDS) { if (raw == null || raw.size() < NUM_OF_FIELDS) {
throw new IOException("Invalid number of fields"); throw new IOException("Invalid number of fields");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Stefan Kalscheuer * Copyright 2016-2022 Stefan Kalscheuer
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Stefan Kalscheuer * Copyright 2016-2022 Stefan Kalscheuer
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Stefan Kalscheuer * Copyright 2016-2022 Stefan Kalscheuer
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -83,7 +83,7 @@ public class AsyncUraTripReader implements AutoCloseable {
String version = null; String version = null;
String line = br.readLine(); String line = br.readLine();
while (line != null && !this.canceled) { while (line != null && !this.canceled) {
List l = mapper.readValue(line, List.class); List<?> l = mapper.readValue(line, List.class);
// Check if result exists and has correct response type. // Check if result exists and has correct response type.
if (l != null && !l.isEmpty()) { if (l != null && !l.isEmpty()) {
if (l.get(0).equals(RES_TYPE_URA_VERSION)) { if (l.get(0).equals(RES_TYPE_URA_VERSION)) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Stefan Kalscheuer * Copyright 2016-2022 Stefan Kalscheuer
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,11 +45,11 @@ import static org.hamcrest.core.Is.is;
* *
* @author Stefan Kalscheuer * @author Stefan Kalscheuer
*/ */
public class UraClientTest { class UraClientTest {
private static WireMockServer httpMock; private static WireMockServer httpMock;
@BeforeAll @BeforeAll
public static void setUp() { static void setUp() {
// Initialize HTTP mock. // Initialize HTTP mock.
httpMock = new WireMockServer(WireMockConfiguration.options().dynamicPort()); httpMock = new WireMockServer(WireMockConfiguration.options().dynamicPort());
httpMock.start(); httpMock.start();
@ -57,13 +57,13 @@ public class UraClientTest {
} }
@AfterAll @AfterAll
public static void tearDown() { static void tearDown() {
httpMock.stop(); httpMock.stop();
httpMock = null; httpMock = null;
} }
@Test @Test
public void getStopsTest() { void getStopsTest() {
// Mock the HTTP call. // Mock the HTTP call.
mockHttpToFile(2, "instant_V2_stops.txt"); mockHttpToFile(2, "instant_V2_stops.txt");
@ -89,7 +89,7 @@ public class UraClientTest {
} }
@Test @Test
public void getStopsForLineTest() { void getStopsForLineTest() {
// Mock the HTTP call. // Mock the HTTP call.
mockHttpToFile(2, "instant_V2_stops_line.txt"); mockHttpToFile(2, "instant_V2_stops_line.txt");
@ -107,7 +107,7 @@ public class UraClientTest {
} }
@Test @Test
public void getStopsForPositionTest() { void getStopsForPositionTest() {
// Mock the HTTP call. // Mock the HTTP call.
mockHttpToFile(1, "instant_V1_stops_circle.txt"); mockHttpToFile(1, "instant_V1_stops_circle.txt");
@ -133,7 +133,7 @@ public class UraClientTest {
} }
@Test @Test
public void getTripsForDestinationNamesTest() { void getTripsForDestinationNamesTest() {
// Mock the HTTP call. // Mock the HTTP call.
mockHttpToFile(1, "instant_V1_trips_destination.txt"); mockHttpToFile(1, "instant_V1_trips_destination.txt");
@ -156,7 +156,7 @@ public class UraClientTest {
} }
@Test @Test
public void getTripsTowardsTest() { void getTripsTowardsTest() {
// Mock the HTTP call. // Mock the HTTP call.
mockHttpToFile(1, "instant_V1_trips_towards.txt"); mockHttpToFile(1, "instant_V1_trips_towards.txt");
@ -171,7 +171,7 @@ public class UraClientTest {
} }
@Test @Test
public void getTripsTest() { void getTripsTest() {
// Mock the HTTP call. // Mock the HTTP call.
mockHttpToFile(1, "instant_V1_trips_all.txt"); mockHttpToFile(1, "instant_V1_trips_all.txt");
@ -189,6 +189,12 @@ public class UraClientTest {
assertThat(trips.get(8).getVisitID(), is(30)); assertThat(trips.get(8).getVisitID(), is(30));
assertThat(trips.get(9).getStop().getId(), is("100002")); assertThat(trips.get(9).getStop().getId(), is("100002"));
// With limit.
trips = new UraClient(httpMock.baseUrl()).getTrips(5);
assertThat(trips, hasSize(5));
trips = new UraClient(httpMock.baseUrl()).getTrips(11);
assertThat(trips, hasSize(10));
// Repeat test for API V2. // Repeat test for API V2.
mockHttpToFile(2, "instant_V2_trips_all.txt"); mockHttpToFile(2, "instant_V2_trips_all.txt");
@ -224,7 +230,7 @@ public class UraClientTest {
} }
@Test @Test
public void getTripsForStopTest() { void getTripsForStopTest() {
// Mock the HTTP call. // Mock the HTTP call.
mockHttpToFile(1, "instant_V1_trips_stop.txt"); mockHttpToFile(1, "instant_V1_trips_stop.txt");
@ -239,6 +245,12 @@ public class UraClientTest {
assertThat(trips.get(2).getLineName(), is("25")); assertThat(trips.get(2).getLineName(), is("25"));
assertThat(trips.get(3).getStop().getIndicator(), is("H.15")); assertThat(trips.get(3).getStop().getIndicator(), is("H.15"));
// With limit.
trips = new UraClient(httpMock.baseUrl())
.forStops("100000")
.getTrips(7);
assertThat(trips, hasSize(7));
// Get trips for stop name "Uniklinik" and verify some values. // Get trips for stop name "Uniklinik" and verify some values.
mockHttpToFile(1, "instant_V1_trips_stop_name.txt"); mockHttpToFile(1, "instant_V1_trips_stop_name.txt");
trips = new UraClient(httpMock.baseUrl()) trips = new UraClient(httpMock.baseUrl())
@ -254,7 +266,7 @@ public class UraClientTest {
} }
@Test @Test
public void getTripsForLine() { void getTripsForLine() {
// Mock the HTTP call. // Mock the HTTP call.
mockHttpToFile(1, "instant_V1_trips_line.txt"); mockHttpToFile(1, "instant_V1_trips_line.txt");
@ -303,7 +315,7 @@ public class UraClientTest {
} }
@Test @Test
public void getTripsForStopAndLine() { void getTripsForStopAndLine() {
// Mock the HTTP call. // Mock the HTTP call.
mockHttpToFile(1, "instant_V1_trips_stop_line.txt"); mockHttpToFile(1, "instant_V1_trips_stop_line.txt");
@ -324,13 +336,14 @@ public class UraClientTest {
@Test @Test
public void getMessages() { void getMessages() {
UraClient uraClient = new UraClient(httpMock.baseUrl());
// Mock the HTTP call. // Mock the HTTP call.
mockHttpToFile(1, "instant_V1_messages.txt"); mockHttpToFile(1, "instant_V1_messages.txt");
// Get messages without filter and verify some values. // Get messages without filter and verify some values.
List<Message> messages = new UraClient(httpMock.baseUrl()) List<Message> messages = uraClient.getMessages();
.getMessages();
assertThat(messages, hasSize(2)); assertThat(messages, hasSize(2));
assertThat(messages.get(0).getStop().getId(), is("100707")); assertThat(messages.get(0).getStop().getId(), is("100707"));
assertThat(messages.get(0).getUuid(), is("016e1231d4e30014_100707")); assertThat(messages.get(0).getUuid(), is("016e1231d4e30014_100707"));
@ -340,23 +353,35 @@ public class UraClientTest {
assertThat(messages.get(1).getPriority(), is(0)); assertThat(messages.get(1).getPriority(), is(0));
assertThat(messages.get(0).getText(), is("Sehr geehrte Fahrgäste, wegen Strassenbauarbeiten kann diese Haltestelle nicht von den Bussen der Linien 17, 44 und N2 angefahren werden.")); assertThat(messages.get(0).getText(), is("Sehr geehrte Fahrgäste, wegen Strassenbauarbeiten kann diese Haltestelle nicht von den Bussen der Linien 17, 44 und N2 angefahren werden."));
assertThat(messages.get(1).getText(), is("Sehr geehrte Fahrgäste, diese Haltestelle wird vorübergehend von den Linien 47, 147 und N3 nicht angefahren.")); assertThat(messages.get(1).getText(), is("Sehr geehrte Fahrgäste, diese Haltestelle wird vorübergehend von den Linien 47, 147 und N3 nicht angefahren."));
// With limit.
messages = uraClient.getMessages(1);
assertThat(messages, hasSize(1));
messages = uraClient.getMessages(3);
assertThat(messages, hasSize(2));
} }
@Test @Test
public void getMessagesForStop() { void getMessagesForStop() {
UraClient uraClient = new UraClient(httpMock.baseUrl(), "/interfaces/ura/instant_V2", "/interfaces/ura/stream");
// Mock the HTTP call. // Mock the HTTP call.
mockHttpToFile(2, "instant_V2_messages_stop.txt"); mockHttpToFile(2, "instant_V2_messages_stop.txt");
// Get trips for stop ID 100707 (Berensberger Str.) and verify some values. // Get trips for stop ID 100707 (Berensberger Str.) and verify some values.
List<Message> messages = new UraClient(httpMock.baseUrl(), "/interfaces/ura/instant_V2", "/interfaces/ura/stream") List<Message> messages = uraClient.forStops("100707").getMessages();
.forStops("100707")
.getMessages();
assertThat(messages, hasSize(1)); assertThat(messages, hasSize(1));
assertThat(messages.stream().filter(t -> !t.getStop().getId().equals("100707")).findAny(), is(Optional.empty())); assertThat(messages.stream().filter(t -> !t.getStop().getId().equals("100707")).findAny(), is(Optional.empty()));
assertThat(messages.get(0).getUuid(), is("016e1231d4e30014_100707")); assertThat(messages.get(0).getUuid(), is("016e1231d4e30014_100707"));
assertThat(messages.get(0).getType(), is(0)); assertThat(messages.get(0).getType(), is(0));
assertThat(messages.get(0).getPriority(), is(3)); assertThat(messages.get(0).getPriority(), is(3));
assertThat(messages.get(0).getText(), is("Sehr geehrte Fahrgäste, wegen Strassenbauarbeiten kann diese Haltestelle nicht von den Bussen der Linien 17, 44 und N2 angefahren werden.")); assertThat(messages.get(0).getText(), is("Sehr geehrte Fahrgäste, wegen Strassenbauarbeiten kann diese Haltestelle nicht von den Bussen der Linien 17, 44 und N2 angefahren werden."));
// With limit.
messages = uraClient.forStops("100707").getMessages(0);
assertThat(messages, hasSize(0));
messages = uraClient.forStops("100707").getMessages(2);
assertThat(messages, hasSize(1));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Stefan Kalscheuer * Copyright 2016-2022 Stefan Kalscheuer
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Stefan Kalscheuer * Copyright 2016-2022 Stefan Kalscheuer
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Stefan Kalscheuer * Copyright 2016-2022 Stefan Kalscheuer
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2020 Stefan Kalscheuer * Copyright 2016-2022 Stefan Kalscheuer
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -162,7 +162,7 @@ public class AsyncUraTripReaderTest {
* @throws IOException Error reading or writing mocked data. * @throws IOException Error reading or writing mocked data.
*/ */
@Test @Test
public void streamClosedTest() throws InterruptedException, IOException { void streamClosedTest() throws InterruptedException, IOException {
// Callback counter for some unhandy async mockery. // Callback counter for some unhandy async mockery.
final AtomicInteger counter = new AtomicInteger(0); final AtomicInteger counter = new AtomicInteger(0);