import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
}
@Test
- public void clientGetDownloadsDataForCorrectIdentifier()
- throws InterruptedException, ExecutionException, IOException {
- Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
- connectNode();
- List<String> lines = fcpServer.collectUntil(is("EndMessage"));
- assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
- String identifier = extractIdentifier(lines);
- fcpServer.writeLine(
- "AllData",
- "Identifier=not-test",
- "DataLength=12",
- "StartupTime=1435610539000",
- "CompletionTime=1435610540000",
- "Metadata.ContentType=text/plain;charset=latin-9",
- "Data",
- "Hello World"
- );
- fcpServer.writeLine(
- "AllData",
- "Identifier=" + identifier,
- "DataLength=6",
- "StartupTime=1435610539000",
- "CompletionTime=1435610540000",
- "Metadata.ContentType=text/plain;charset=utf-8",
- "Data",
- "Hello"
- );
- Optional<Data> data = dataFuture.get();
- assertThat(data.get().getMimeType(), is("text/plain;charset=utf-8"));
- assertThat(data.get().size(), is(6L));
- assertThat(ByteStreams.toByteArray(data.get().getInputStream()),
- is("Hello\n".getBytes(StandardCharsets.UTF_8)));
- }
-
- @Test
- public void clientGetRecognizesGetFailed() throws InterruptedException, ExecutionException, IOException {
- Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
- connectNode();
- List<String> lines = fcpServer.collectUntil(is("EndMessage"));
- assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
- String identifier = extractIdentifier(lines);
- fcpServer.writeLine(
- "GetFailed",
- "Identifier=" + identifier,
- "Code=3",
- "EndMessage"
- );
- Optional<Data> data = dataFuture.get();
- assertThat(data.isPresent(), is(false));
- }
-
- @Test
- public void clientGetRecognizesGetFailedForCorrectIdentifier()
- throws InterruptedException, ExecutionException, IOException {
- Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
- connectNode();
- List<String> lines = fcpServer.collectUntil(is("EndMessage"));
- assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
- String identifier = extractIdentifier(lines);
- fcpServer.writeLine(
- "GetFailed",
- "Identifier=not-test",
- "Code=3",
- "EndMessage"
- );
- fcpServer.writeLine(
- "GetFailed",
- "Identifier=" + identifier,
- "Code=3",
- "EndMessage"
- );
- Optional<Data> data = dataFuture.get();
- assertThat(data.isPresent(), is(false));
- }
-
- @Test(expected = ExecutionException.class)
- public void clientGetRecognizesConnectionClosed() throws InterruptedException, ExecutionException, IOException {
- Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
- connectNode();
- List<String> lines = fcpServer.collectUntil(is("EndMessage"));
- assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
- fcpServer.close();
- dataFuture.get();
- }
-
- @Test
public void defaultFcpClientReusesConnection() throws InterruptedException, ExecutionException, IOException {
Future<FcpKeyPair> keyPair = fcpClient.generateKeypair().execute();
connectNode();
keyPair.get();
}
- @Test
- public void clientGetWithIgnoreDataStoreSettingSendsCorrectCommands()
- throws InterruptedException, ExecutionException, IOException {
- fcpClient.clientGet().ignoreDataStore().uri("KSK@foo.txt").execute();
- connectNode();
- List<String> lines = fcpServer.collectUntil(is("EndMessage"));
- assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "IgnoreDS=true"));
- }
-
- @Test
- public void clientGetWithDataStoreOnlySettingSendsCorrectCommands()
- throws InterruptedException, ExecutionException, IOException {
- fcpClient.clientGet().dataStoreOnly().uri("KSK@foo.txt").execute();
- connectNode();
- List<String> lines = fcpServer.collectUntil(is("EndMessage"));
- assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "DSonly=true"));
+ private Matcher<List<String>> matchesFcpMessage(String name, String... requiredLines) {
+ return matchesFcpMessageWithTerminator(name, "EndMessage", requiredLines);
}
- @Test
- public void clientGetWithMaxSizeSettingSendsCorrectCommands()
- throws InterruptedException, ExecutionException, IOException {
- fcpClient.clientGet().maxSize(1048576).uri("KSK@foo.txt").execute();
- connectNode();
- List<String> lines = fcpServer.collectUntil(is("EndMessage"));
- assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "MaxSize=1048576"));
+ private Matcher<List<String>> matchesDataMessage(String name, String... requiredLines) {
+ return matchesFcpMessageWithTerminator(name, "Data", requiredLines);
}
- @Test
- public void clientGetWithPrioritySettingSendsCorrectCommands()
- throws InterruptedException, ExecutionException, IOException {
- fcpClient.clientGet().priority(Priority.interactive).uri("KSK@foo.txt").execute();
- connectNode();
- List<String> lines = fcpServer.collectUntil(is("EndMessage"));
- assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "PriorityClass=1"));
- }
+ private Matcher<Iterable<String>> hasHead(String firstElement) {
+ return new TypeSafeDiagnosingMatcher<Iterable<String>>() {
+ @Override
+ protected boolean matchesSafely(Iterable<String> iterable, Description mismatchDescription) {
+ if (!iterable.iterator().hasNext()) {
+ mismatchDescription.appendText("is empty");
+ return false;
+ }
+ String element = iterable.iterator().next();
+ if (!element.equals(firstElement)) {
+ mismatchDescription.appendText("starts with ").appendValue(element);
+ return false;
+ }
+ return true;
+ }
- @Test
- public void clientGetWithRealTimeSettingSendsCorrectCommands()
- throws InterruptedException, ExecutionException, IOException {
- fcpClient.clientGet().realTime().uri("KSK@foo.txt").execute();
- connectNode();
- List<String> lines = fcpServer.collectUntil(is("EndMessage"));
- assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "RealTimeFlag=true"));
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("starts with ").appendValue(firstElement);
+ }
+ };
}
- @Test
- public void clientGetWithGlobalSettingSendsCorrectCommands()
- throws InterruptedException, ExecutionException, IOException {
- fcpClient.clientGet().global().uri("KSK@foo.txt").execute();
- connectNode();
- List<String> lines = fcpServer.collectUntil(is("EndMessage"));
- assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "Global=true"));
+ private Matcher<List<String>> matchesFcpMessageWithTerminator(
+ String name, String terminator, String... requiredLines) {
+ return allOf(hasHead(name), hasParameters(1, 1, requiredLines), hasTail(terminator));
}
- private Matcher<List<String>> matchesFcpMessage(String name, String... requiredLines) {
+ private Matcher<List<String>> hasParameters(int ignoreStart, int ignoreEnd, String... lines) {
return new TypeSafeDiagnosingMatcher<List<String>>() {
@Override
protected boolean matchesSafely(List<String> item, Description mismatchDescription) {
- if (!item.get(0).equals(name)) {
- mismatchDescription.appendText("FCP message is named ").appendValue(item.get(0));
+ if (item.size() < (ignoreStart + ignoreEnd)) {
+ mismatchDescription.appendText("has only ").appendValue(item.size()).appendText(" elements");
return false;
}
- for (String requiredLine : requiredLines) {
- if (item.indexOf(requiredLine) < 1) {
- mismatchDescription.appendText("FCP message does not contain ").appendValue(requiredLine);
+ for (String line : lines) {
+ if ((item.indexOf(line) < ignoreStart) || (item.indexOf(line) >= (item.size() - ignoreEnd))) {
+ mismatchDescription.appendText("does not contains ").appendValue(line);
return false;
}
}
@Override
public void describeTo(Description description) {
- description.appendText("FCP message named ").appendValue(name);
- description.appendValueList(", containing the lines ", ", ", "", requiredLines);
+ description.appendText("contains ").appendValueList("(", ", ", ")", lines);
+ description.appendText(", ignoring the first ").appendValue(ignoreStart);
+ description.appendText(" and the last ").appendValue(ignoreEnd);
+ }
+ };
+ }
+
+ private Matcher<List<String>> hasTail(String... lastElements) {
+ return new TypeSafeDiagnosingMatcher<List<String>>() {
+ @Override
+ protected boolean matchesSafely(List<String> list, Description mismatchDescription) {
+ if (list.size() < lastElements.length) {
+ mismatchDescription.appendText("is too small");
+ return false;
+ }
+ List<String> tail = list.subList(list.size() - lastElements.length, list.size());
+ if (!tail.equals(Arrays.asList(lastElements))) {
+ mismatchDescription.appendText("ends with ").appendValueList("(", ", ", ")", tail);
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("ends with ").appendValueList("(", ", ", ")", lastElements);
}
};
}
.execute();
connectNode();
List<String> lines = fcpServer.collectUntil(is("Hello"));
- assertThat(lines, matchesFcpMessage("ClientPut", "UploadFrom=direct", "DataLength=6", "URI=KSK@foo.txt"));
+ assertThat(lines, allOf(
+ hasHead("ClientPut"),
+ hasParameters(1, 2, "UploadFrom=direct", "DataLength=6", "URI=KSK@foo.txt"),
+ hasTail("EndMessage", "Hello")
+ ));
}
@Test
.execute();
connectNode();
List<String> lines = fcpServer.collectUntil(is("Hello"));
- assertThat(lines, matchesFcpMessage("ClientPut", "TargetFilename=otherName.txt", "UploadFrom=direct",
- "DataLength=6", "URI=KSK@foo.txt"));
+ assertThat(lines, allOf(
+ hasHead("ClientPut"),
+ hasParameters(1, 2, "TargetFilename=otherName.txt", "UploadFrom=direct", "DataLength=6", "URI=KSK@foo.txt"),
+ hasTail("EndMessage", "Hello")
+ ));
}
@Test
"TestDDARequest",
"Directory=" + tempFile.getParent(),
"WantReadDirectory=true",
- "WantWriteDirectory=false",
- "EndMessage"
+ "WantWriteDirectory=false"
));
fcpServer.writeLine(
"TestDDAReply",
assertThat(lines, matchesFcpMessage(
"TestDDAResponse",
"Directory=" + tempFile.getParent(),
- "ReadContent=test-content",
- "EndMessage"
+ "ReadContent=test-content"
));
fcpServer.writeLine(
"TestDDAComplete",
"TestDDARequest",
"Directory=" + tempFile.getParent(),
"WantReadDirectory=true",
- "WantWriteDirectory=false",
- "EndMessage"
+ "WantWriteDirectory=false"
));
fcpServer.writeLine(
"TestDDAReply",
assertThat(lines, matchesFcpMessage(
"TestDDAResponse",
"Directory=" + tempFile.getParent(),
- "ReadContent=test-content",
- "EndMessage"
+ "ReadContent=test-content"
));
}
"TestDDARequest",
"Directory=" + tempFile.getParent(),
"WantReadDirectory=true",
- "WantWriteDirectory=false",
- "EndMessage"
+ "WantWriteDirectory=false"
));
fcpServer.writeLine(
"TestDDAReply",
assertThat(lines, matchesFcpMessage(
"TestDDAResponse",
"Directory=" + tempFile.getParent(),
- "ReadContent=failed-to-read",
- "EndMessage"
+ "ReadContent=failed-to-read"
));
}
"TestDDARequest",
"Directory=" + tempFile.getParent(),
"WantReadDirectory=true",
- "WantWriteDirectory=false",
- "EndMessage"
+ "WantWriteDirectory=false"
));
}
"Identifier=" + identifier,
"GiveOpennetRef=false",
"WithPrivate=false",
- "WithVolatile=false",
- "EndMessage"
+ "WithVolatile=false"
));
fcpServer.writeLine(
"NodeData",
"Identifier=" + identifier,
"GiveOpennetRef=true",
"WithPrivate=false",
- "WithVolatile=false",
- "EndMessage"
+ "WithVolatile=false"
));
fcpServer.writeLine(
"NodeData",
"Identifier=" + identifier,
"GiveOpennetRef=false",
"WithPrivate=true",
- "WithVolatile=false",
- "EndMessage"
+ "WithVolatile=false"
));
fcpServer.writeLine(
"NodeData",
"Identifier=" + identifier,
"GiveOpennetRef=false",
"WithPrivate=false",
- "WithVolatile=true",
- "EndMessage"
+ "WithVolatile=true"
));
fcpServer.writeLine(
"NodeData",
String identifier = extractIdentifier(lines);
assertThat(lines, matchesFcpMessage(
"GetConfig",
- "Identifier=" + identifier,
- "EndMessage"
+ "Identifier=" + identifier
));
fcpServer.writeLine(
"ConfigData",
assertThat(lines, matchesFcpMessage(
"GetConfig",
"Identifier=" + identifier,
- "WithCurrent=true",
- "EndMessage"
+ "WithCurrent=true"
));
fcpServer.writeLine(
"ConfigData",
assertThat(lines, matchesFcpMessage(
"GetConfig",
"Identifier=" + identifier,
- "WithDefaults=true",
- "EndMessage"
+ "WithDefaults=true"
));
fcpServer.writeLine(
"ConfigData",
assertThat(lines, matchesFcpMessage(
"GetConfig",
"Identifier=" + identifier,
- "WithSortOrder=true",
- "EndMessage"
+ "WithSortOrder=true"
));
fcpServer.writeLine(
"ConfigData",
assertThat(lines, matchesFcpMessage(
"GetConfig",
"Identifier=" + identifier,
- "WithExpertFlag=true",
- "EndMessage"
+ "WithExpertFlag=true"
));
fcpServer.writeLine(
"ConfigData",
assertThat(lines, matchesFcpMessage(
"GetConfig",
"Identifier=" + identifier,
- "WithForceWriteFlag=true",
- "EndMessage"
+ "WithForceWriteFlag=true"
));
fcpServer.writeLine(
"ConfigData",
assertThat(lines, matchesFcpMessage(
"GetConfig",
"Identifier=" + identifier,
- "WithShortDescription=true",
- "EndMessage"
+ "WithShortDescription=true"
));
fcpServer.writeLine(
"ConfigData",
assertThat(lines, matchesFcpMessage(
"GetConfig",
"Identifier=" + identifier,
- "WithLongDescription=true",
- "EndMessage"
+ "WithLongDescription=true"
));
fcpServer.writeLine(
"ConfigData",
assertThat(lines, matchesFcpMessage(
"GetConfig",
"Identifier=" + identifier,
- "WithDataTypes=true",
- "EndMessage"
+ "WithDataTypes=true"
));
fcpServer.writeLine(
"ConfigData",
assertThat(lines, matchesFcpMessage(
"ModifyConfig",
"Identifier=" + identifier,
- "foo.bar=baz",
- "EndMessage"
+ "foo.bar=baz"
));
fcpServer.writeLine(
"ConfigData",
@Test
public void defaultFcpClientCanGenerateKeypair() throws ExecutionException, InterruptedException, IOException {
Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
- connectAndAssert(() ->matchesFcpMessage("GenerateSSK", "EndMessage"));
+ connectAndAssert(() -> matchesFcpMessage("GenerateSSK"));
replyWithKeyPair();
FcpKeyPair keyPair = keyPairFuture.get();
assertThat(keyPair.getPublicKey(), is(REQUEST_URI));
return matchesFcpMessage(
"ListPeer",
"Identifier=" + identifier,
- "NodeIdentifier=" + nodeId,
- "EndMessage"
+ "NodeIdentifier=" + nodeId
);
}
return matchesFcpMessage(
"ListPeers",
"WithVolatile=" + withVolatile,
- "WithMetadata=" + withMetadata,
- "EndMessage"
+ "WithMetadata=" + withMetadata
);
}
private Matcher<List<String>> matchesAddPeer() {
return matchesFcpMessage(
"AddPeer",
- "Identifier=" + identifier,
- "EndMessage"
+ "Identifier=" + identifier
);
}
"ModifyPeer",
"Identifier=" + identifier,
"NodeIdentifier=" + nodeIdentifier,
- setting + "=" + value,
- "EndMessage"
+ setting + "=" + value
);
}
return matchesFcpMessage(
"RemovePeer",
"Identifier=" + identifier,
- "NodeIdentifier=" + nodeIdentifier,
- "EndMessage"
+ "NodeIdentifier=" + nodeIdentifier
);
}
private Matcher<List<String>> matchesListPeerNotes(String nodeIdentifier) {
return matchesFcpMessage(
"ListPeerNotes",
- "NodeIdentifier=" + nodeIdentifier,
- "EndMessage"
+ "NodeIdentifier=" + nodeIdentifier
);
}
"Identifier=" + identifier,
"NodeIdentifier=" + nodeIdentifier,
"PeerNoteType=1",
- "NoteText=Zm9v",
- "EndMessage"
+ "NoteText=Zm9v"
);
}
"Identifier=" + identifier,
"PluginURL=superPlugin",
"URLType=official",
- "OfficialSource=" + officialSource,
- "EndMessage"
+ "OfficialSource=" + officialSource
);
}
"LoadPlugin",
"Identifier=" + identifier,
"PluginURL=" + url,
- "URLType=" + urlType,
- "EndMessage"
+ "URLType=" + urlType
);
}
public void failedLoad() throws ExecutionException, InterruptedException, IOException {
Future<Optional<PluginInfo>> pluginInfo =
fcpClient.loadPlugin().officialFromFreenet("superPlugin").execute();
- connectAndAssert(() -> matchesFcpMessage("LoadPlugin", "EndMessage"));
+ connectAndAssert(() -> matchesFcpMessage("LoadPlugin"));
replyWithProtocolError();
assertThat(pluginInfo.get().isPresent(), is(false));
}
return matchesFcpMessage(
"ReloadPlugin",
"Identifier=" + identifier,
- "PluginName=" + CLASS_NAME,
- "EndMessage"
+ "PluginName=" + CLASS_NAME
);
}
return matchesFcpMessage(
"RemovePlugin",
"Identifier=" + identifier,
- "PluginName=" + CLASS_NAME,
- "EndMessage"
+ "PluginName=" + CLASS_NAME
);
}
return matchesFcpMessage(
"GetPluginInfo",
"Identifier=" + identifier,
- "PluginName=" + CLASS_NAME,
- "EndMessage"
+ "PluginName=" + CLASS_NAME
);
}
@Test
public void subscriptionWorks() throws InterruptedException, ExecutionException, IOException {
Future<Optional<UskSubscription>> uskSubscription = fcpClient.subscribeUsk().uri(URI).execute();
- connectAndAssert(() -> matchesFcpMessage("SubscribeUSK", "URI=" + URI, "EndMessage"));
+ connectAndAssert(() -> matchesFcpMessage("SubscribeUSK", "URI=" + URI));
replyWithSubscribed();
assertThat(uskSubscription.get().get().getUri(), is(URI));
AtomicInteger edition = new AtomicInteger();
@Test
public void subscriptionUpdatesMultipleTimes() throws InterruptedException, ExecutionException, IOException {
Future<Optional<UskSubscription>> uskSubscription = fcpClient.subscribeUsk().uri(URI).execute();
- connectAndAssert(() -> matchesFcpMessage("SubscribeUSK", "URI=" + URI, "EndMessage"));
+ connectAndAssert(() -> matchesFcpMessage("SubscribeUSK", "URI=" + URI));
replyWithSubscribed();
assertThat(uskSubscription.get().get().getUri(), is(URI));
AtomicInteger edition = new AtomicInteger();
@Test
public void subscriptionCanBeCancelled() throws InterruptedException, ExecutionException, IOException {
Future<Optional<UskSubscription>> uskSubscription = fcpClient.subscribeUsk().uri(URI).execute();
- connectAndAssert(() -> matchesFcpMessage("SubscribeUSK", "URI=" + URI, "EndMessage"));
+ connectAndAssert(() -> matchesFcpMessage("SubscribeUSK", "URI=" + URI));
replyWithSubscribed();
assertThat(uskSubscription.get().get().getUri(), is(URI));
AtomicBoolean updated = new AtomicBoolean();
uskSubscription.get().get().onUpdate(e -> updated.set(true));
uskSubscription.get().get().cancel();
- readMessage(() -> matchesFcpMessage("UnsubscribeUSK", "Identifier=" + identifier, "EndMessage"));
+ readMessage(() -> matchesFcpMessage("UnsubscribeUSK", "Identifier=" + identifier));
sendUpdateNotification(23);
assertThat(updated.get(), is(false));
}
}
+ public class ClientGet {
+
+ @Test
+ public void works() throws InterruptedException, ExecutionException, IOException {
+ Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
+ connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
+ replyWithAllData("not-test", "Hello World", "text/plain;charset=latin-9");
+ replyWithAllData(identifier, "Hello", "text/plain;charset=utf-8");
+ Optional<Data> data = dataFuture.get();
+ verifyData(data);
+ }
+
+ @Test
+ public void getFailedIsRecognized() throws InterruptedException, ExecutionException, IOException {
+ Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
+ connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
+ replyWithGetFailed(identifier);
+ Optional<Data> data = dataFuture.get();
+ assertThat(data.isPresent(), is(false));
+ }
+
+ @Test
+ public void getFailedForDifferentIdentifierIsIgnored()
+ throws InterruptedException, ExecutionException, IOException {
+ Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
+ connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
+ replyWithGetFailed("not-test");
+ replyWithAllData(identifier, "Hello", "text/plain;charset=utf-8");
+ Optional<Data> data = dataFuture.get();
+ verifyData(data);
+ }
+
+ @Test(expected = ExecutionException.class)
+ public void connectionClosedIsRecognized() throws InterruptedException, ExecutionException, IOException {
+ Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
+ connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
+ fcpServer.close();
+ dataFuture.get();
+ }
+
+ @Test
+ public void withIgnoreData() throws InterruptedException, ExecutionException, IOException {
+ fcpClient.clientGet().ignoreDataStore().uri("KSK@foo.txt").execute();
+ connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "IgnoreDS=true"));
+ }
+
+ @Test
+ public void withDataStoreOnly() throws InterruptedException, ExecutionException, IOException {
+ fcpClient.clientGet().dataStoreOnly().uri("KSK@foo.txt").execute();
+ connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "DSonly=true"));
+ }
+
+ @Test
+ public void clientGetWithMaxSizeSettingSendsCorrectCommands()
+ throws InterruptedException, ExecutionException, IOException {
+ fcpClient.clientGet().maxSize(1048576).uri("KSK@foo.txt").execute();
+ connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "MaxSize=1048576"));
+ }
+
+ @Test
+ public void clientGetWithPrioritySettingSendsCorrectCommands()
+ throws InterruptedException, ExecutionException, IOException {
+ fcpClient.clientGet().priority(Priority.interactive).uri("KSK@foo.txt").execute();
+ connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "PriorityClass=1"));
+ }
+
+ @Test
+ public void clientGetWithRealTimeSettingSendsCorrectCommands()
+ throws InterruptedException, ExecutionException, IOException {
+ fcpClient.clientGet().realTime().uri("KSK@foo.txt").execute();
+ connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "RealTimeFlag=true"));
+ }
+
+ @Test
+ public void clientGetWithGlobalSettingSendsCorrectCommands()
+ throws InterruptedException, ExecutionException, IOException {
+ fcpClient.clientGet().global().uri("KSK@foo.txt").execute();
+ connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "Global=true"));
+ }
+
+ private void replyWithGetFailed(String identifier) throws IOException {
+ fcpServer.writeLine(
+ "GetFailed",
+ "Identifier=" + identifier,
+ "Code=3",
+ "EndMessage"
+ );
+ }
+
+ private void replyWithAllData(String identifier, String text, String contentType) throws IOException {
+ fcpServer.writeLine(
+ "AllData",
+ "Identifier=" + identifier,
+ "DataLength=" + (text.length() + 1),
+ "StartupTime=1435610539000",
+ "CompletionTime=1435610540000",
+ "Metadata.ContentType=" + contentType,
+ "Data",
+ text
+ );
+ }
+
+ private void verifyData(Optional<Data> data) throws IOException {
+ assertThat(data.get().getMimeType(), is("text/plain;charset=utf-8"));
+ assertThat(data.get().size(), is(6L));
+ assertThat(ByteStreams.toByteArray(data.get().getInputStream()),
+ is("Hello\n".getBytes(StandardCharsets.UTF_8)));
+ }
+
+ }
+
}