From b14f21191098fdc8386903c01eecc05d2e04da7c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 22 Nov 2024 23:52:36 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20test=20for=20getting=20global?= =?utf8?q?=20requests?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/fcp/highlevel/FcpClientTest.java | 41 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java b/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java index c18e9f8..4a3a49f 100644 --- a/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java @@ -643,13 +643,42 @@ public class FcpClientTest { } } + @Test + public void getGetRequestsWithGlobalReturnsGlobalGetRequests() throws IOException, FcpException { + FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), this::sendRequests); + try (FcpClient fcpClient = new FcpClient(fcpConnection)) { + Collection requests = fcpClient.getGetRequests(true); + assertThat(requests, containsInAnyOrder(isGetRequest(equalTo("get1")), isGetRequest(equalTo("get1-global")))); + } + } + + @Test + public void getPutRequestsWithGlobalReturnsGlobalPutRequests() throws IOException, FcpException { + FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), this::sendRequests); + try (FcpClient fcpClient = new FcpClient(fcpConnection)) { + Collection requests = fcpClient.getPutRequests(true); + assertThat(requests, containsInAnyOrder( + isPutRequest(equalTo("put1")), + isPutRequest(equalTo("put2")), + isPutRequest(equalTo("put1-global")), + isPutRequest(equalTo("put2-global")) + )); + } + } + private void sendRequests(FcpListener listener, FcpConnection connection) { - listener.receivedPersistentGet(connection, new PersistentGet(new FcpMessage("PersistentGet").put("Identifier", "get1"))); - listener.receivedPersistentPut(connection, new PersistentPut(new FcpMessage("PersistentPut").put("Identifier", "put1"))); - listener.receivedPersistentPut(connection, new PersistentPut(new FcpMessage("PersistentPut").put("Identifier", "put2"))); - listener.receivedPersistentPutDir(connection, new PersistentPutDir(new FcpMessage("PersistentPutDir").put("Identifier", "putdir1"))); - listener.receivedPersistentPutDir(connection, new PersistentPutDir(new FcpMessage("PersistentPutDir").put("Identifier", "putdir2"))); - listener.receivedPersistentPutDir(connection, new PersistentPutDir(new FcpMessage("PersistentPutDir").put("Identifier", "putdir3"))); + 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"))); + listener.receivedPersistentPut(connection, new PersistentPut(new FcpMessage("PersistentPut").put("Identifier", "put2").put("Global", "false"))); + listener.receivedPersistentPutDir(connection, new PersistentPutDir(new FcpMessage("PersistentPutDir").put("Identifier", "putdir1").put("Global", "false"))); + listener.receivedPersistentPutDir(connection, new PersistentPutDir(new FcpMessage("PersistentPutDir").put("Identifier", "putdir2").put("Global", "false"))); + listener.receivedPersistentPutDir(connection, new PersistentPutDir(new FcpMessage("PersistentPutDir").put("Identifier", "putdir3").put("Global", "false"))); + listener.receivedPersistentGet(connection, new PersistentGet(new FcpMessage("PersistentGet").put("Identifier", "get1-global").put("Global", "true"))); + listener.receivedPersistentPut(connection, new PersistentPut(new FcpMessage("PersistentPut").put("Identifier", "put1-global").put("Global", "true"))); + listener.receivedPersistentPut(connection, new PersistentPut(new FcpMessage("PersistentPut").put("Identifier", "put2-global").put("Global", "true"))); + listener.receivedPersistentPutDir(connection, new PersistentPutDir(new FcpMessage("PersistentPutDir").put("Identifier", "putdir1-global").put("Global", "true"))); + listener.receivedPersistentPutDir(connection, new PersistentPutDir(new FcpMessage("PersistentPutDir").put("Identifier", "putdir2-global").put("Global", "true"))); + listener.receivedPersistentPutDir(connection, new PersistentPutDir(new FcpMessage("PersistentPutDir").put("Identifier", "putdir3-global").put("Global", "true"))); listener.receivedEndListPersistentRequests(connection, new EndListPersistentRequests(new FcpMessage("EndListPersistentRequests"))); } -- 2.7.4