From: David ‘Bombe’ Roden Date: Fri, 22 Nov 2024 23:45:40 +0000 (+0100) Subject: ✅ Add test for DataFound for unknown identifiers not touching anything else X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=bd39c233c16429b24d5602e6cdbb3ecf1e03ca16;p=jFCPlib.git ✅ Add test for DataFound for unknown identifiers not touching anything else --- diff --git a/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java b/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java index d1423de..d71fc3c 100644 --- a/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java @@ -56,6 +56,7 @@ import static net.pterodactylus.fcp.test.PeerMatchers.peerWithIdentity; import static net.pterodactylus.fcp.test.Peers.createPeer; import static net.pterodactylus.fcp.test.Requests.isGetRequest; import static net.pterodactylus.fcp.test.Requests.isPutRequest; +import static net.pterodactylus.fcp.test.Requests.isRequest; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.anything; @@ -683,12 +684,34 @@ public class FcpClientTest { } } + @Test + public void getRequestsIgnoresDataFoundForUnknownIdentifier() throws IOException, FcpException { + FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::sendDataFoundForUnknownIdentifier)); + try (FcpClient fcpClient = new FcpClient(fcpConnection)) { + Collection requests = fcpClient.getRequests(true); + assertThat(requests, containsInAnyOrder( + isRequest(equalTo("get1"), matches("complete", m -> !m.isComplete())), + isRequest(equalTo("get1-global"), matches("complete", m -> !m.isComplete())), + isRequest(equalTo("put1"), matches("complete", m -> !m.isComplete())), + isRequest(equalTo("put1-global"), matches("complete", m -> !m.isComplete())), + isRequest(equalTo("put2"), matches("complete", m -> !m.isComplete())), + isRequest(equalTo("put2-global"), matches("complete", m -> !m.isComplete())) + )); + } + } + private void sendDataFound(FcpListener listener, FcpConnection connection) { listener.receivedDataFound(connection, new DataFound( new FcpMessage("DataFound").put("Identifier", "get1").put("Metadata.ContentType", "application/test").put("DataLength", "12345")) ); } + private void sendDataFoundForUnknownIdentifier(FcpListener listener, FcpConnection connection) { + listener.receivedDataFound(connection, new DataFound( + new FcpMessage("DataFound").put("Identifier", "unknown").put("Metadata.ContentType", "application/test").put("DataLength", "12345")) + ); + } + private void sendRequests(FcpListener listener, FcpConnection connection) { listener.receivedPersistentGet(connection, new PersistentGet(new FcpMessage("PersistentGet").put("Identifier", "get1").put("Global", "false"))); listener.receivedPersistentPut(connection, new PersistentPut(new FcpMessage("PersistentPut").put("Identifier", "put1").put("Global", "false"))); diff --git a/src/test/java/net/pterodactylus/fcp/test/Requests.java b/src/test/java/net/pterodactylus/fcp/test/Requests.java index 65d5734..092ce59 100644 --- a/src/test/java/net/pterodactylus/fcp/test/Requests.java +++ b/src/test/java/net/pterodactylus/fcp/test/Requests.java @@ -12,6 +12,15 @@ import static org.hamcrest.Matchers.instanceOf; public class Requests { + public static Matcher isRequest() { + return isRequest(anything()); + } + + @SafeVarargs + public static Matcher isRequest(Matcher identifier, Matcher... requestMatchers) { + return isRequest(anything(), identifier, requestMatchers); + } + public static Matcher isGetRequest() { return isGetRequest(anything()); }