From bd39c233c16429b24d5602e6cdbb3ecf1e03ca16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 23 Nov 2024 00:45:40 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20test=20for=20DataFound=20for?= =?utf8?q?=20unknown=20identifiers=20not=20touching=20anything=20else?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/fcp/highlevel/FcpClientTest.java | 23 ++++++++++++++++++++++ .../java/net/pterodactylus/fcp/test/Requests.java | 9 +++++++++ 2 files changed, 32 insertions(+) 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()); } -- 2.7.4