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;
options.addIntegerOption("PositiveTrust", new DefaultOption<Integer>(75, new IntegerRangePredicate(0, 100)));
options.addIntegerOption("NegativeTrust", new DefaultOption<Integer>(-25, new IntegerRangePredicate(-100, 100)));
options.addStringOption("TrustComment", new DefaultOption<String>("Set from Sone Web Interface"));
- options.addBooleanOption("ActivateFcpInterface", new DefaultOption<Boolean>(false, new OptionWatcher<Boolean>() {
-
- @Override
- @SuppressWarnings("synthetic-access")
- public void optionChanged(Option<Boolean> option, Boolean oldValue, Boolean newValue) {
- fcpInterface.setActive(newValue);
- }
- }));
+ options.addBooleanOption("ActivateFcpInterface", new DefaultOption<Boolean>(false, fcpInterface.new SetActive()));
options.addIntegerOption("FcpFullAccessRequired", new DefaultOption<Integer>(2, new OptionWatcher<Integer>() {
@Override
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.
// 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.
}
}
+ public class SetActive implements OptionWatcher<Boolean> {
+
+ @Override
+ public void optionChanged(Option<Boolean> option, Boolean oldValue, Boolean newValue) {
+ setActive(newValue);
+ }
+
+ }
+
}
--- /dev/null
+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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+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));
+ }
+
+}