allow getMessages with limit directly from Query instance
backported from commit 7684b2e089cd99ede6d294d3f69aa38e39a82074
This commit is contained in:
parent
8748dd883b
commit
4b69343d39
@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
## unreleased
|
## unreleased
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
* Querying trips with limit directly from `Query` instance (#19)
|
* Querying trips and messages with limit directly from `Query` instance (#19)
|
||||||
|
|
||||||
|
|
||||||
## 1.3.2 - 2022-08-30
|
## 1.3.2 - 2022-08-30
|
||||||
|
@ -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.
|
||||||
*
|
*
|
||||||
@ -611,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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -337,12 +337,13 @@ class UraClientTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
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"));
|
||||||
@ -352,23 +353,35 @@ 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
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user