import freenet.node.RequestStarter;
import freenet.support.api.Bucket;
-import com.google.common.annotations.VisibleForTesting;
-
/**
* The Sone downloader is responsible for download Sones as they are updated.
*
* The core
* @param freenetInterface
* The Freenet interface
- */
- @Inject
- public SoneDownloaderImpl(Core core, FreenetInterface freenetInterface) {
- this(core, freenetInterface, new SoneParser(core));
- }
-
- /**
- * Creates a new Sone downloader.
- *
- * @param core
- * The core
- * @param freenetInterface
- * The Freenet interface
* @param soneParser
*/
- @VisibleForTesting
+ @Inject
SoneDownloaderImpl(Core core, FreenetInterface freenetInterface, SoneParser soneParser) {
super("Sone Downloader", false);
this.core = core;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.inject.Inject;
+
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Profile.DuplicateField;
import net.pterodactylus.sone.data.Profile.EmptyFieldName;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.database.Database;
import net.pterodactylus.sone.database.PostBuilder;
import net.pterodactylus.sone.database.PostReplyBuilder;
import net.pterodactylus.sone.database.SoneBuilder;
private static final Logger logger = getLogger(SoneParser.class.getName());
private static final int MAX_PROTOCOL_VERSION = 0;
- private final Core core;
+ private final Database database;
- public SoneParser(Core core) {
- this.core = core;
+ @Inject
+ public SoneParser(Database database) {
+ this.database = database;
}
public Sone parseSone(Sone originalSone, InputStream soneInputStream) throws SoneException {
return null;
}
- SoneBuilder soneBuilder = core.soneBuilder().from(originalSone.getIdentity());
+ SoneBuilder soneBuilder = database.newSoneBuilder().from(originalSone.getIdentity());
if (originalSone.isLocal()) {
soneBuilder = soneBuilder.local();
}
return null;
}
try {
- PostBuilder postBuilder = core.postBuilder();
+ PostBuilder postBuilder = database.newPostBuilder();
/* TODO - parse time correctly. */
postBuilder.withId(postId).from(sone.getId()).withTime(Long.parseLong(postTime)).withText(postText);
if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
return null;
}
try {
- PostReplyBuilder postReplyBuilder = core.postReplyBuilder();
+ PostReplyBuilder postReplyBuilder = database.newPostReplyBuilder();
/* TODO - parse time correctly. */
postReplyBuilder.withId(replyId).from(sone.getId()).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
replies.add(postReplyBuilder.build());
}
Album parent = null;
if (parentId != null) {
- parent = core.getAlbum(parentId);
+ parent = database.getAlbum(parentId);
if (parent == null) {
logger.log(Level.WARNING, String.format("Downloaded Sone %s has album with invalid parent!", sone));
return null;
}
}
- Album album = core.albumBuilder()
+ Album album = database.newAlbumBuilder()
.withId(id)
.by(sone)
.build()
logger.log(Level.WARNING, String.format("Downloaded Sone %s contains image %s with invalid dimensions (%s, %s)!", sone, imageId, imageWidthString, imageHeightString));
return null;
}
- Image image = core.imageBuilder().withId(imageId).build().modify().setSone(sone).setKey(imageKey).setCreationTime(creationTime).update();
+ Image image = database.newImageBuilder().withId(imageId).build().modify().setSone(sone).setKey(imageKey).setCreationTime(creationTime).update();
image = image.modify().setTitle(imageTitle).setDescription(imageDescription).update();
image = image.modify().setWidth(imageWidth).setHeight(imageHeight).update();
album.addImage(image);
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Sone.SoneStatus;
import net.pterodactylus.sone.freenet.wot.Identity;
+import net.pterodactylus.sone.test.GuiceKt;
import freenet.client.ClientMetadata;
import freenet.client.FetchResult;
@Test
public void soneDownloaderCanBeCreatedByDependencyInjection() {
- assertThat(getBaseInjector().getInstance(SoneDownloader.class), notNullValue());
+ assertThat(getBaseInjector().createChildInjector(
+ GuiceKt.supply(SoneParser.class).byInstance(mock(SoneParser.class))
+ ).getInstance(SoneDownloader.class), notNullValue());
}
}
import net.pterodactylus.sone.data.Profile;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.database.AlbumBuilder;
+import net.pterodactylus.sone.database.Database;
import net.pterodactylus.sone.database.ImageBuilder;
import net.pterodactylus.sone.database.PostBuilder;
import net.pterodactylus.sone.database.PostReplyBuilder;
*/
public class SoneParserTest {
- private final Core core = mock(Core.class);
- private final SoneParser soneParser = new SoneParser(core);
+ private final Database database = mock(Database.class);
+ private final SoneParser soneParser = new SoneParser(database);
private final Sone sone = mock(Sone.class);
private FreenetURI requestUri = mock(FreenetURI.class);
private final PostBuilder postBuilder = mock(PostBuilder.class);
@Before
public void setupSoneBuilder() {
- when(core.soneBuilder()).thenAnswer(new Answer<SoneBuilder>() {
+ when(database.newSoneBuilder()).thenAnswer(new Answer<SoneBuilder>() {
@Override
public SoneBuilder answer(InvocationOnMock invocation) {
return new MemorySoneBuilder(null);
return post;
}
});
- when(core.postBuilder()).thenReturn(postBuilder);
+ when(database.newPostBuilder()).thenReturn(postBuilder);
}
@Before
return postReply;
}
});
- when(core.postReplyBuilder()).thenReturn(postReplyBuilder);
+ when(database.newPostReplyBuilder()).thenReturn(postReplyBuilder);
}
@Before
return album;
}
});
- when(core.albumBuilder()).thenReturn(albumBuilder);
+ when(database.newAlbumBuilder()).thenReturn(albumBuilder);
}
@Before
public void setupAlbums() {
- when(core.getAlbum(anyString())).thenAnswer(new Answer<Album>() {
+ when(database.getAlbum(anyString())).thenAnswer(new Answer<Album>() {
@Override
public Album answer(InvocationOnMock invocation)
throws Throwable {
return image;
}
});
- when(core.imageBuilder()).thenReturn(imageBuilder);
+ when(database.newImageBuilder()).thenReturn(imageBuilder);
}
@Before
public void setupImages() {
- when(core.getImage(anyString())).thenAnswer(new Answer<Image>() {
+ when(database.getImage(anyString())).thenAnswer(new Answer<Image>() {
@Override
public Image answer(InvocationOnMock invocation)
throws Throwable {