Rename Keyed interface to WithUri
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 10 Jul 2015 05:18:54 +0000 (07:18 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 10 Jul 2015 05:18:54 +0000 (07:18 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/ClientPutCommand.java
src/main/java/net/pterodactylus/fcp/quelaton/ClientPutCommandImpl.java
src/main/java/net/pterodactylus/fcp/quelaton/Keyed.java [deleted file]
src/main/java/net/pterodactylus/fcp/quelaton/WithUri.java [new file with mode: 0644]
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index 231af10..bb6e099 100644 (file)
@@ -14,8 +14,8 @@ import net.pterodactylus.fcp.Key;
 public interface ClientPutCommand {
 
        ClientPutCommand named(String targetFilename);
-       Keyed<Optional<Key>> redirectTo(String uri);
-       Keyed<Optional<Key>> from(File file);
-       Lengthed<Keyed<Optional<Key>>> from(InputStream inputStream);
+       WithUri<Optional<Key>> redirectTo(String uri);
+       WithUri<Optional<Key>> from(File file);
+       Lengthed<WithUri<Optional<Key>>> from(InputStream inputStream);
 
 }
index 39d525a..d401f8d 100644 (file)
@@ -54,31 +54,31 @@ class ClientPutCommandImpl implements ClientPutCommand {
        }
 
        @Override
-       public Keyed<Optional<Key>> redirectTo(String uri) {
+       public WithUri<Optional<Key>> redirectTo(String uri) {
                this.redirectUri.set(Objects.requireNonNull(uri, "uri must not be null"));
                return this::key;
        }
 
        @Override
-       public Keyed<Optional<Key>> from(File file) {
+       public WithUri<Optional<Key>> from(File file) {
                this.file.set(Objects.requireNonNull(file, "file must not be null"));
                return this::key;
        }
 
        @Override
-       public Lengthed<Keyed<Optional<Key>>> from(InputStream inputStream) {
+       public Lengthed<WithUri<Optional<Key>>> from(InputStream inputStream) {
                payload.set(Objects.requireNonNull(inputStream, "inputStream must not be null"));
                return this::length;
        }
 
-       private Keyed<Optional<Key>> length(long length) {
+       private WithUri<Optional<Key>> length(long length) {
                this.length.set(length);
                return this::key;
        }
 
-       private ListenableFuture<Optional<Key>> key(Key key) {
+       private ListenableFuture<Optional<Key>> key(String uri) {
                String identifier = new RandomIdentifierGenerator().generate();
-               ClientPut clientPut = createClientPutCommand(key.getKey(), identifier);
+               ClientPut clientPut = createClientPutCommand(uri, identifier);
                return threadPool.submit(() -> new ClientPutReplySequence().send(clientPut).get());
        }
 
diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/Keyed.java b/src/main/java/net/pterodactylus/fcp/quelaton/Keyed.java
deleted file mode 100644 (file)
index ea10ab9..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-package net.pterodactylus.fcp.quelaton;
-
-import net.pterodactylus.fcp.Key;
-
-import com.google.common.util.concurrent.ListenableFuture;
-
-/**
- * The terminal operation of an FCP command, requiring a {@link Key}.
- *
- * @param <R>
- *     The type of the command result
- * @author <a href="mailto:bombe@freenetproject.org">David ‘Bombe’ Roden</a>
- */
-public interface Keyed<R> {
-
-       ListenableFuture<R> key(Key key);
-
-}
diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/WithUri.java b/src/main/java/net/pterodactylus/fcp/quelaton/WithUri.java
new file mode 100644 (file)
index 0000000..76ffeaf
--- /dev/null
@@ -0,0 +1,16 @@
+package net.pterodactylus.fcp.quelaton;
+
+import com.google.common.util.concurrent.ListenableFuture;
+
+/**
+ * The terminal operation of an FCP command, requiring a Freenet URI.
+ *
+ * @param <R>
+ *     The type of the command result
+ * @author <a href="mailto:bombe@freenetproject.org">David ‘Bombe’ Roden</a>
+ */
+public interface WithUri<R> {
+
+       ListenableFuture<R> uri(String uri);
+
+}
index 6af103c..da3ba42 100644 (file)
@@ -294,7 +294,7 @@ public class DefaultFcpClientTest {
                fcpClient.clientPut()
                        .from(new ByteArrayInputStream("Hello\n".getBytes()))
                        .length(6)
-                       .key(new Key("KSK@foo.txt"));
+                       .uri("KSK@foo.txt");
                connectNode();
                List<String> lines = fcpServer.collectUntil(is("Hello"));
                assertThat(lines, matchesFcpMessage("ClientPut", "UploadFrom=direct", "DataLength=6", "URI=KSK@foo.txt"));
@@ -306,7 +306,7 @@ public class DefaultFcpClientTest {
                Future<Optional<Key>> key = fcpClient.clientPut()
                        .from(new ByteArrayInputStream("Hello\n".getBytes()))
                        .length(6)
-                       .key(new Key("KSK@foo.txt"));
+                       .uri("KSK@foo.txt");
                connectNode();
                List<String> lines = fcpServer.collectUntil(is("Hello"));
                String identifier = extractIdentifier(lines);
@@ -330,7 +330,7 @@ public class DefaultFcpClientTest {
                Future<Optional<Key>> key = fcpClient.clientPut()
                        .from(new ByteArrayInputStream("Hello\n".getBytes()))
                        .length(6)
-                       .key(new Key("KSK@foo.txt"));
+                       .uri("KSK@foo.txt");
                connectNode();
                List<String> lines = fcpServer.collectUntil(is("Hello"));
                String identifier = extractIdentifier(lines);
@@ -355,7 +355,7 @@ public class DefaultFcpClientTest {
                        .named("otherName.txt")
                        .from(new ByteArrayInputStream("Hello\n".getBytes()))
                        .length(6)
-                       .key(new Key("KSK@foo.txt"));
+                       .uri("KSK@foo.txt");
                connectNode();
                List<String> lines = fcpServer.collectUntil(is("Hello"));
                assertThat(lines, matchesFcpMessage("ClientPut", "TargetFilename=otherName.txt", "UploadFrom=direct",
@@ -365,7 +365,7 @@ public class DefaultFcpClientTest {
        @Test
        public void clientPutWithRedirectSendsCorrectCommand()
        throws IOException, ExecutionException, InterruptedException {
-               fcpClient.clientPut().redirectTo("KSK@bar.txt").key(new Key("KSK@foo.txt"));
+               fcpClient.clientPut().redirectTo("KSK@bar.txt").uri("KSK@foo.txt");
                connectNode();
                List<String> lines = fcpServer.collectUntil(is("EndMessage"));
                assertThat(lines,
@@ -374,7 +374,7 @@ public class DefaultFcpClientTest {
 
        @Test
        public void clientPutWithFileSendsCorrectCommand() throws InterruptedException, ExecutionException, IOException {
-               fcpClient.clientPut().from(new File("/tmp/data.txt")).key(new Key("KSK@foo.txt"));
+               fcpClient.clientPut().from(new File("/tmp/data.txt")).uri("KSK@foo.txt");
                connectNode();
                List<String> lines = fcpServer.collectUntil(is("EndMessage"));
                assertThat(lines,
@@ -385,7 +385,7 @@ public class DefaultFcpClientTest {
        public void clientPutWithFileCanCompleteTestDdaSequence()
        throws IOException, ExecutionException, InterruptedException {
                File tempFile = createTempFile();
-               fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).key(new Key("KSK@foo.txt"));
+               fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).uri("KSK@foo.txt");
                connectNode();
                List<String> lines = fcpServer.collectUntil(is("EndMessage"));
                String identifier = extractIdentifier(lines);
@@ -438,7 +438,7 @@ public class DefaultFcpClientTest {
        @Test
        public void clientPutDoesNotReactToProtocolErrorForDifferentIdentifier()
        throws InterruptedException, ExecutionException, IOException {
-               Future<Optional<Key>> key = fcpClient.clientPut().from(new File("/tmp/data.txt")).key(new Key("KSK@foo.txt"));
+               Future<Optional<Key>> key = fcpClient.clientPut().from(new File("/tmp/data.txt")).uri("KSK@foo.txt");
                connectNode();
                List<String> lines = fcpServer.collectUntil(is("EndMessage"));
                String identifier = extractIdentifier(lines);
@@ -460,7 +460,7 @@ public class DefaultFcpClientTest {
        @Test
        public void clientPutAbortsOnProtocolErrorOtherThan25()
        throws InterruptedException, ExecutionException, IOException {
-               Future<Optional<Key>> key = fcpClient.clientPut().from(new File("/tmp/data.txt")).key(new Key("KSK@foo.txt"));
+               Future<Optional<Key>> key = fcpClient.clientPut().from(new File("/tmp/data.txt")).uri("KSK@foo.txt");
                connectNode();
                List<String> lines = fcpServer.collectUntil(is("EndMessage"));
                String identifier = extractIdentifier(lines);
@@ -477,7 +477,7 @@ public class DefaultFcpClientTest {
        public void clientPutDoesNotReplyToWrongTestDdaReply() throws IOException, ExecutionException,
        InterruptedException {
                File tempFile = createTempFile();
-               fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).key(new Key("KSK@foo.txt"));
+               fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).uri("KSK@foo.txt");
                connectNode();
                List<String> lines = fcpServer.collectUntil(is("EndMessage"));
                String identifier = extractIdentifier(lines);
@@ -520,7 +520,7 @@ public class DefaultFcpClientTest {
        public void clientPutSendsResponseEvenIfFileCanNotBeRead()
        throws IOException, ExecutionException, InterruptedException {
                File tempFile = createTempFile();
-               fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).key(new Key("KSK@foo.txt"));
+               fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).uri("KSK@foo.txt");
                connectNode();
                List<String> lines = fcpServer.collectUntil(is("EndMessage"));
                String identifier = extractIdentifier(lines);
@@ -557,7 +557,7 @@ public class DefaultFcpClientTest {
        public void clientPutDoesNotResendOriginalClientPutOnTestDDACompleteWithWrongDirectory()
        throws IOException, ExecutionException, InterruptedException {
                File tempFile = createTempFile();
-               fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).key(new Key("KSK@foo.txt"));
+               fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).uri("KSK@foo.txt");
                connectNode();
                List<String> lines = fcpServer.collectUntil(is("EndMessage"));
                String identifier = extractIdentifier(lines);