From 6806381cc322d3668ddb6c465b3c1f11b7fd1639 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 23 Nov 2024 01:12:01 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20test=20for=20GetFailed=20being?= =?utf8?q?=20used=20in=20getRequests()?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/fcp/highlevel/FcpClientTest.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java b/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java index d71fc3c..75c540b 100644 --- a/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java @@ -712,6 +712,49 @@ public class FcpClientTest { ); } + @Test + public void getGetRequestIsCompleteAndFailedWhenGetFailedMessageIsReceived() throws Exception { + FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::sendGetFailed)); + try (FcpClient fcpClient = new FcpClient(fcpConnection)) { + Collection requests = fcpClient.getGetRequests(false); + assertThat(requests, contains(isGetRequest( + equalTo("get1"), + matches("complete", Request::isComplete), + matches("failed", Request::hasFailed), + matches("fatal", Request::isFatal), + matches("error code", m -> m.getErrorCode() == 123) + ))); + } + } + + @Test + public void getRequestIgnoresGetFailedForUnknownIdentifier() throws Exception { + FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::sendGetFailedForUnknownIdentifier)); + 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 sendGetFailed(FcpListener listener, FcpConnection connection) { + listener.receivedGetFailed(connection, new GetFailed( + new FcpMessage("GetFailed").put("Identifier", "get1").put("Fatal", "true").put("Code", "123")) + ); + } + + private void sendGetFailedForUnknownIdentifier(FcpListener listener, FcpConnection connection) { + listener.receivedGetFailed(connection, new GetFailed( + new FcpMessage("GetFailed").put("Identifier", "unknown")) + ); + } + 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"))); -- 2.7.4