NewPipeExtractor/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTe...

125 lines
5.5 KiB
Java
Raw Normal View History

2018-10-11 21:10:22 +02:00
package org.schabi.newpipe.extractor.services.peertube;
2021-12-27 21:08:08 +01:00
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
2018-10-11 21:10:22 +02:00
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
import org.schabi.newpipe.extractor.NewPipe;
2020-04-15 14:09:46 +02:00
import org.schabi.newpipe.extractor.Page;
2018-10-11 21:10:22 +02:00
import org.schabi.newpipe.extractor.comments.CommentsInfo;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeCommentsExtractor;
2020-05-02 08:21:47 +02:00
import org.schabi.newpipe.extractor.utils.Utils;
2018-10-11 21:10:22 +02:00
import java.io.IOException;
import java.util.List;
2021-12-27 21:08:08 +01:00
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
2018-10-11 21:10:22 +02:00
public class PeertubeCommentsExtractorTest {
2020-05-31 13:33:14 +02:00
public static class Default {
private static PeertubeCommentsExtractor extractor;
2018-10-11 21:10:22 +02:00
2021-12-27 21:08:08 +01:00
@BeforeAll
2020-05-31 13:33:14 +02:00
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (PeertubeCommentsExtractor) PeerTube
.getCommentsExtractor("https://framatube.org/w/kkGMgK9ZtnKfYAgnEtQxbv");
2020-05-31 13:33:14 +02:00
}
2018-10-11 21:10:22 +02:00
2020-05-31 13:33:14 +02:00
@Test
void testGetComments() throws IOException, ExtractionException {
final String comment = "I love this";
2020-05-31 13:33:14 +02:00
InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
boolean result = findInComments(comments, comment);
2020-07-06 20:23:41 +02:00
2020-05-31 13:33:14 +02:00
while (comments.hasNextPage() && !result) {
2020-04-15 14:09:46 +02:00
comments = extractor.getPage(comments.getNextPage());
result = findInComments(comments, comment);
2020-05-31 13:33:14 +02:00
}
2020-07-06 20:23:41 +02:00
2020-05-31 13:33:14 +02:00
assertTrue(result);
2018-10-11 21:10:22 +02:00
}
2020-07-06 20:23:41 +02:00
2020-05-31 13:33:14 +02:00
@Test
void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
final String comment = "Thanks for creating such an informative video";
final CommentsInfo commentsInfo =
CommentsInfo.getInfo("https://framatube.org/w/kkGMgK9ZtnKfYAgnEtQxbv");
2020-05-31 13:33:14 +02:00
assertEquals("Comments", commentsInfo.getName());
2020-07-06 20:23:41 +02:00
boolean result = findInComments(commentsInfo.getRelatedItems(), comment);
2020-07-06 20:23:41 +02:00
2020-04-15 14:09:46 +02:00
Page nextPage = commentsInfo.getNextPage();
InfoItemsPage<CommentsInfoItem> moreItems = new InfoItemsPage<>(null, nextPage, null);
while (moreItems.hasNextPage() && !result) {
moreItems = CommentsInfo.getMoreItems(PeerTube, commentsInfo, nextPage);
result = findInComments(moreItems.getItems(), comment);
2020-04-15 14:09:46 +02:00
nextPage = moreItems.getNextPage();
2020-05-31 13:33:14 +02:00
}
2020-07-06 20:23:41 +02:00
2020-05-31 13:33:14 +02:00
assertTrue(result);
2018-10-11 21:10:22 +02:00
}
2020-07-06 20:23:41 +02:00
2020-05-31 13:33:14 +02:00
@Test
void testGetCommentsAllData() throws IOException, ExtractionException {
extractor.getInitialPage()
.getItems()
.forEach(commentsInfoItem -> {
assertFalse(Utils.isBlank(commentsInfoItem.getUploaderUrl()));
assertFalse(Utils.isBlank(commentsInfoItem.getUploaderName()));
assertFalse(Utils.isBlank(commentsInfoItem.getUploaderAvatarUrl()));
assertFalse(Utils.isBlank(commentsInfoItem.getCommentId()));
assertFalse(Utils.isBlank(commentsInfoItem.getCommentText().getContent()));
assertFalse(Utils.isBlank(commentsInfoItem.getName()));
assertFalse(Utils.isBlank(commentsInfoItem.getTextualUploadDate()));
assertFalse(Utils.isBlank(commentsInfoItem.getThumbnailUrl()));
assertFalse(Utils.isBlank(commentsInfoItem.getUrl()));
assertEquals(-1, commentsInfoItem.getLikeCount());
assertTrue(Utils.isBlank(commentsInfoItem.getTextualLikeCount()));
});
2020-05-31 13:33:14 +02:00
}
2020-07-06 20:23:41 +02:00
private boolean findInComments(final InfoItemsPage<CommentsInfoItem> comments,
final String comment) {
2020-05-31 13:33:14 +02:00
return findInComments(comments.getItems(), comment);
2018-10-11 21:10:22 +02:00
}
2020-07-06 20:23:41 +02:00
private boolean findInComments(final List<CommentsInfoItem> comments,
final String comment) {
return comments.stream()
.anyMatch(commentsInfoItem ->
commentsInfoItem.getCommentText().getContent().contains(comment));
2020-05-31 13:33:14 +02:00
}
2018-10-11 21:10:22 +02:00
}
2020-05-31 13:33:14 +02:00
public static class DeletedComments {
private static PeertubeCommentsExtractor extractor;
2021-12-27 21:08:08 +01:00
@BeforeAll
2020-05-31 13:33:14 +02:00
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (PeertubeCommentsExtractor) PeerTube
.getCommentsExtractor("https://framatube.org/videos/watch/217eefeb-883d-45be-b7fc-a788ad8507d3");
}
@Test
void testGetComments() throws IOException, ExtractionException {
2020-05-31 13:33:14 +02:00
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
assertTrue(comments.getErrors().isEmpty());
}
@Test
void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
2020-05-31 13:33:14 +02:00
final CommentsInfo commentsInfo = CommentsInfo.getInfo("https://framatube.org/videos/watch/217eefeb-883d-45be-b7fc-a788ad8507d3");
assertTrue(commentsInfo.getErrors().isEmpty());
2018-10-11 21:10:22 +02:00
}
}
}