/** The node to interact with. */
private final Node node;
+ private final SoneUriCreator soneUriCreator;
+
/** The high-level client to use for requests. */
private final HighLevelSimpleClient client;
private final RequestClient requestClient = new RequestClientBuilder().realTime().build();
private final RequestClient imageLoader = new RequestClientBuilder().realTime().build();
@Inject
- public FreenetInterface(EventBus eventBus, Node node) {
+ public FreenetInterface(EventBus eventBus, Node node, SoneUriCreator soneUriCreator) {
this.eventBus = eventBus;
this.node = node;
+ this.soneUriCreator = soneUriCreator;
this.client = node.clientCore.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS, false, true);
}
}
try {
logger.log(Level.FINEST, String.format("Unsubscribing from USK for %s…", sone));
- node.clientCore.uskManager.unsubscribe(USK.create(sone.getRequestUri()), uskCallback);
+ node.clientCore.uskManager.unsubscribe(USK.create(soneUriCreator.getRequestUri(sone)), uskCallback);
} catch (MalformedURLException mue1) {
- logger.log(Level.FINE, String.format("Could not unsubscribe USK “%s”!", sone.getRequestUri()), mue1);
+ logger.log(Level.FINE, String.format("Could not unsubscribe USK “%s”!", soneUriCreator.getRequestUri(sone)), mue1);
}
}
import net.pterodactylus.sone.core.event.*
import net.pterodactylus.sone.data.*
import net.pterodactylus.sone.data.impl.*
+import net.pterodactylus.sone.freenet.wot.DefaultIdentity
import net.pterodactylus.sone.test.*
import net.pterodactylus.sone.test.Matchers.*
import net.pterodactylus.sone.test.TestUtil.*
private val fetchResult = mock<FetchResult>()
private val backgroundFetchCallback = mock<BackgroundFetchCallback>()
private val clientGetter = mock<ClientGetter>()
+ private val soneUriCreator = SoneUriCreator()
private val freenetInterface: FreenetInterface
init {
setField(node, "random", randomSource)
setField(nodeClientCore, "uskManager", uskManager)
setField(nodeClientCore, "clientContext", mock<ClientContext>())
- freenetInterface = FreenetInterface(eventBus, node)
+ freenetInterface = FreenetInterface(eventBus, node, soneUriCreator)
insertToken = freenetInterface.InsertToken(image)
insertToken.setBucket(bucket)
}
fun setupSone() {
val insertSsk = createRandom(randomSource, "test-0")
whenever(sone.id).thenReturn(insertSsk.uri.routingKey.asFreenetBase64)
- whenever(sone.requestUri).thenReturn(insertSsk.uri.uskForSSK())
+ whenever(sone.identity).thenReturn(DefaultIdentity("id", "name", insertSsk.uri.toString()))
}
@Before
@Test
fun `sone with wrong request uri will not be subscribed`() {
- whenever(sone.requestUri).thenReturn(FreenetURI("KSK@GPLv3.txt"))
freenetInterface.registerUsk(FreenetURI("KSK@GPLv3.txt"), null)
verify(uskManager, never()).subscribe(any(USK::class.java), any(USKCallback::class.java), anyBoolean(), any(RequestClient::class.java))
}
}
@Test
- fun `unregistering aregistered sone unregisters the sone`() {
- freenetInterface.registerActiveUsk(sone.requestUri, mock())
+ fun `unregistering a registered sone unregisters the sone`() {
+ freenetInterface.registerActiveUsk(soneUriCreator.getRequestUri(sone), mock())
freenetInterface.unregisterUsk(sone)
verify(uskManager).unsubscribe(any(USK::class.java), any(USKCallback::class.java))
}
@Test
- fun `unregistering asone with awrong request key will not unsubscribe`() {
- whenever(sone.requestUri).thenReturn(FreenetURI("KSK@GPLv3.txt"))
- freenetInterface.registerUsk(sone.requestUri, null)
+ fun `unregistering a sone with a wrong request key will not unsubscribe`() {
+ freenetInterface.registerUsk(FreenetURI("KSK@GPLv3.txt"), null)
freenetInterface.unregisterUsk(sone)
verify(uskManager, never()).unsubscribe(any(USK::class.java), any(USKCallback::class.java))
}