From: David ‘Bombe’ Roden Date: Wed, 8 Feb 2023 11:46:07 +0000 (+0100) Subject: ✅ Add test for ClientGet command X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f5a364020e82cc09f3cda4ef95ed4fa831b4a951;p=jFCPlib.git ✅ Add test for ClientGet command --- diff --git a/src/test/java/net/pterodactylus/fcp/ClientGetTest.java b/src/test/java/net/pterodactylus/fcp/ClientGetTest.java new file mode 100644 index 0000000..5ebd4de --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/ClientGetTest.java @@ -0,0 +1,135 @@ +package net.pterodactylus.fcp; + +import java.util.function.Consumer; + +import org.hamcrest.Matcher; +import org.junit.Test; + +import static net.pterodactylus.fcp.Persistence.reboot; +import static net.pterodactylus.fcp.Priority.bulkSplitfile; +import static net.pterodactylus.fcp.Verbosity.COMPRESSION; +import static net.pterodactylus.fcp.Verbosity.PROGRESS; +import static net.pterodactylus.fcp.test.Matchers.isMessage; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.hasItem; + +/** + * Unit test for {@link ClientGet}. + */ +public class ClientGetTest { + + @Test + public void canCreateClientGet() { + ClientGet clientGet = new ClientGet("uri", "identifier"); + assertThat(clientGet, isMessage("ClientGet", + "URI=uri", + "Identifier=identifier", + "ReturnType=direct" + )); + } + + @Test + public void canCreateClientGetWithReturnType() { + ClientGet clientGet = new ClientGet("uri", "identifier", ReturnType.disk); + assertThat(clientGet, isMessage("ClientGet", + "URI=uri", + "Identifier=identifier", + "ReturnType=disk" + )); + } + + @Test + public void ignoreDataStoreFlagIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setIgnoreDataStore(true), "IgnoreDS=true"); + } + + @Test + public void setDataStoreOnlyFlagIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setDataStoreOnly(true), "DSonly=true"); + } + + @Test + public void verbosityIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setVerbosity(COMPRESSION.add(PROGRESS)), "Verbosity=513"); + } + + @Test + public void maxSizeIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setMaxSize(1234567), "MaxSize=1234567"); + } + + @Test + public void maxTempSizeIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setMaxTempSize(2345678), "MaxTempSize=2345678"); + } + + @Test + public void maxRetriesIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setMaxRetries(12), "MaxRetries=12"); + } + + @Test + public void priorityIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setPriority(bulkSplitfile), "PriorityClass=4"); + } + + @Test + public void realTimeFlagIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setRealTimeFlag(true), "RealTimeFlag=true"); + } + + @Test + public void persistenceIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setPersistence(reboot), "Persistence=reboot"); + } + + @Test + public void clientTokenIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setClientToken("clientToken"), "ClientToken=clientToken"); + } + + @Test + public void globalIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setGlobal(true), "Global=true"); + } + + @Test + public void binaryBlobIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setBinaryBlob(true), "BinaryBlob=true"); + } + + @Test + public void filterDataIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setFilterData(true), "FilterData=true"); + } + + @Test + public void allowedMimeTypesAreIncluded() { + testThatAFieldIsIncluded(cg -> cg.setAllowedMimeTypes("text/plain", "text/html"), "AllowedMIMETypes=text/plain;text/html"); + } + + @Test + public void filenameIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setFilename("file.dat"), "Filename=file.dat"); + } + + @Test + public void tempFilenameIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setTempFilename("temp.dat"), "TempFilename=temp.dat"); + } + + private void testThatAFieldIsIncluded(Consumer setter, String expectedResult) { + ClientGet clientGet = new ClientGet("uri", "identifier"); + setter.accept(clientGet); + assertThat(clientGet, isMessage("ClientGet", allOf( + containsBoilerPlate(), + hasItem(expectedResult) + ))); + } + + private static Matcher> containsBoilerPlate() { + return allOf(hasItem("URI=uri"), hasItem("Identifier=identifier"), hasItem("ReturnType=direct")); + } + +}