package net.pterodactylus.fcp.quelaton;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasItem;
public class PluginCommands {
+ private static final String CLASS_NAME = "foo.plugin.Plugin";
+
private List<String> lines;
private String identifier;
public class ReloadPlugin {
- private static final String CLASS_NAME = "foo.plugin.Plugin";
-
@Test
public void reloadingPluginWorks() throws InterruptedException, ExecutionException, IOException {
Future<Optional<PluginInfo>> pluginInfo = fcpClient.reloadPlugin().plugin(CLASS_NAME).execute();
- connectAndAssert(() -> matchesFcpMessage(
+ connectAndAssert(() -> matchReloadPluginMessage());
+ replyWithPluginInfo();
+ verifyPluginInfo(pluginInfo);
+ }
+
+ @Test
+ public void reloadingPluginWithMaxWaitTimeWorks()
+ throws InterruptedException, ExecutionException, IOException {
+ Future<Optional<PluginInfo>> pluginInfo =
+ fcpClient.reloadPlugin().waitFor(1234).plugin(CLASS_NAME).execute();
+ connectAndAssert(() -> allOf(matchReloadPluginMessage(), hasItem("MaxWaitTime=1234")));
+ replyWithPluginInfo();
+ verifyPluginInfo(pluginInfo);
+ }
+
+ @Test
+ public void reloadingPluginWithPurgeWorks()
+ throws InterruptedException, ExecutionException, IOException {
+ Future<Optional<PluginInfo>> pluginInfo =
+ fcpClient.reloadPlugin().purge().plugin(CLASS_NAME).execute();
+ connectAndAssert(() -> allOf(matchReloadPluginMessage(), hasItem("Purge=true")));
+ replyWithPluginInfo();
+ verifyPluginInfo(pluginInfo);
+ }
+
+ @Test
+ public void reloadingPluginWithStoreWorks()
+ throws InterruptedException, ExecutionException, IOException {
+ Future<Optional<PluginInfo>> pluginInfo =
+ fcpClient.reloadPlugin().addToConfig().plugin(CLASS_NAME).execute();
+ connectAndAssert(() -> allOf(matchReloadPluginMessage(), hasItem("Store=true")));
+ replyWithPluginInfo();
+ verifyPluginInfo(pluginInfo);
+ }
+
+ private Matcher<List<String>> matchReloadPluginMessage() {
+ return matchesFcpMessage(
"ReloadPlugin",
"Identifier=" + identifier,
"PluginName=" + CLASS_NAME,
"EndMessage"
- ));
- replyWithPluginInfo();
- verifyPluginInfo(pluginInfo);
+ );
+ }
+
+ }
+
+ public class RemovePlugin {
+
+ @Test
+ public void removingPluginWorks() throws InterruptedException, ExecutionException, IOException {
+ Future<Boolean> pluginRemoved = fcpClient.removePlugin().plugin(CLASS_NAME).execute();
+ connectAndAssert(() -> matchPluginRemovedMessage());
+ replyWithPluginRemoved();
+ assertThat(pluginRemoved.get(), is(true));
+ }
+
+ private void replyWithPluginRemoved() throws IOException {
+ fcpServer.writeLine(
+ "PluginRemoved",
+ "Identifier=" + identifier,
+ "PluginName=" + CLASS_NAME,
+ "EndMessage"
+ );
+ }
+
+ private Matcher<List<String>> matchPluginRemovedMessage() {
+ return matchesFcpMessage(
+ "RemovePlugin",
+ "Identifier=" + identifier,
+ "PluginName=" + CLASS_NAME,
+ "EndMessage"
+ );
}
}