From: David ‘Bombe’ Roden Date: Tue, 29 Jul 2014 17:53:00 +0000 (+0200) Subject: Add class that activates the FCP interface from an option. X-Git-Tag: 0.9-rc1^2~3^2~201 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b343a185e8b89ea5973bf57ec74217652834f5ea;p=Sone.git Add class that activates the FCP interface from an option. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 860effb..4ee0258 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -76,6 +76,7 @@ import net.pterodactylus.sone.database.PostReplyProvider; import net.pterodactylus.sone.database.SoneProvider; import net.pterodactylus.sone.fcp.FcpInterface; import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired; +import net.pterodactylus.sone.fcp.FcpInterface.SetActive; import net.pterodactylus.sone.freenet.wot.Identity; import net.pterodactylus.sone.freenet.wot.IdentityManager; import net.pterodactylus.sone.freenet.wot.OwnIdentity; @@ -1998,14 +1999,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, options.addIntegerOption("PositiveTrust", new DefaultOption(75, new IntegerRangePredicate(0, 100))); options.addIntegerOption("NegativeTrust", new DefaultOption(-25, new IntegerRangePredicate(-100, 100))); options.addStringOption("TrustComment", new DefaultOption("Set from Sone Web Interface")); - options.addBooleanOption("ActivateFcpInterface", new DefaultOption(false, new OptionWatcher() { - - @Override - @SuppressWarnings("synthetic-access") - public void optionChanged(Option option, Boolean oldValue, Boolean newValue) { - fcpInterface.setActive(newValue); - } - })); + options.addBooleanOption("ActivateFcpInterface", new DefaultOption(false, fcpInterface.new SetActive())); options.addIntegerOption("FcpFullAccessRequired", new DefaultOption(2, new OptionWatcher() { @Override diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java index 02d84cc..c71fd82 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java +++ b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java @@ -26,19 +26,22 @@ import java.util.logging.Level; import java.util.logging.Logger; import net.pterodactylus.sone.core.Core; +import net.pterodactylus.sone.core.Options.Option; +import net.pterodactylus.sone.core.Options.OptionWatcher; import net.pterodactylus.sone.freenet.fcp.Command.AccessType; import net.pterodactylus.sone.freenet.fcp.Command.ErrorResponse; import net.pterodactylus.sone.freenet.fcp.Command.Response; import net.pterodactylus.util.logging.Logging; -import com.google.inject.Inject; - import freenet.pluginmanager.FredPluginFCP; import freenet.pluginmanager.PluginNotFoundException; import freenet.pluginmanager.PluginReplySender; import freenet.support.SimpleFieldSet; import freenet.support.api.Bucket; +import com.google.common.annotations.VisibleForTesting; +import com.google.inject.Inject; + /** * Implementation of an FCP interface for other clients or plugins to * communicate with Sone. @@ -106,6 +109,11 @@ public class FcpInterface { // ACCESSORS // + @VisibleForTesting + boolean isActive() { + return active; + } + /** * Sets whether the FCP interface should handle requests. If {@code active} * is {@code false}, all requests are answered with an error. @@ -216,4 +224,13 @@ public class FcpInterface { } } + public class SetActive implements OptionWatcher { + + @Override + public void optionChanged(Option option, Boolean oldValue, Boolean newValue) { + setActive(newValue); + } + + } + } diff --git a/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.java b/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.java new file mode 100644 index 0000000..6ecd687 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.java @@ -0,0 +1,32 @@ +package net.pterodactylus.sone.fcp; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import net.pterodactylus.sone.fcp.FcpInterface.SetActive; + +import org.junit.Test; + +/** + * Unit test for {@link FcpInterface} and its subclasses. + * + * @author David ‘Bombe’ Roden + */ +public class FcpInterfaceTest { + + private final FcpInterface fcpInterface = new FcpInterface(null); + private final SetActive setActive = fcpInterface.new SetActive(); + + @Test + public void setActiveCanActivateFcpInterface() { + setActive.optionChanged(null, null, true); + assertThat(fcpInterface.isActive(), is(true)); + } + + @Test + public void setActiveCanDeactivateFcpInterface() { + setActive.optionChanged(null, null, false); + assertThat(fcpInterface.isActive(), is(false)); + } + +}