allow getMessages with limit directly from Query instance
This commit is contained in:
parent
406fe076f1
commit
7684b2e089
@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
* Updated dependencies
|
* Updated dependencies
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
* Querying trips with limit directly from `Query` instance (#18)
|
* Querying trips and messages with limit directly from `Query` instance (#18)
|
||||||
|
|
||||||
### Misc
|
### Misc
|
||||||
* Tested with JDK 19
|
* Tested with JDK 19
|
||||||
|
@ -395,6 +395,20 @@ public class UraClient implements Serializable {
|
|||||||
return getMessages(query, null);
|
return getMessages(query, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of messages with limit.
|
||||||
|
* If forStops() has been called, those will be used as filter.
|
||||||
|
*
|
||||||
|
* @param limit Maximum number of results.
|
||||||
|
* @return List of trips.
|
||||||
|
* @throws UraClientException Error with API communication.
|
||||||
|
* @since 2.0.4
|
||||||
|
*/
|
||||||
|
public List<Message> getMessages(final Integer limit) throws UraClientException {
|
||||||
|
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.
|
||||||
*
|
*
|
||||||
@ -690,5 +704,17 @@ public class UraClient implements Serializable {
|
|||||||
public List<Message> getMessages() throws UraClientException {
|
public List<Message> getMessages() throws UraClientException {
|
||||||
return UraClient.this.getMessages(this);
|
return UraClient.this.getMessages(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get trips for set filters.
|
||||||
|
*
|
||||||
|
* @param limit Maximum number of results.
|
||||||
|
* @return List of matching messages.
|
||||||
|
* @throws UraClientException Error with API communication.
|
||||||
|
* @since 2.0.4
|
||||||
|
*/
|
||||||
|
public List<Message> getMessages(final Integer limit) throws UraClientException {
|
||||||
|
return UraClient.this.getMessages(this, limit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,12 +349,13 @@ public class UraClientTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMessages() throws UraClientException {
|
public void getMessages() throws UraClientException {
|
||||||
|
UraClient uraClient = new UraClient(wireMock.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(wireMock.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"));
|
||||||
@ -365,6 +366,12 @@ public class UraClientTest {
|
|||||||
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));
|
||||||
|
|
||||||
mockHttpToException();
|
mockHttpToException();
|
||||||
UraClientException exception = assertThrows(
|
UraClientException exception = assertThrows(
|
||||||
UraClientException.class,
|
UraClientException.class,
|
||||||
@ -377,19 +384,25 @@ public class UraClientTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMessagesForStop() throws UraClientException {
|
public void getMessagesForStop() throws UraClientException {
|
||||||
|
UraClient uraClient = new UraClient(wireMock.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(wireMock.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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user