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

119 lines
5.1 KiB
Java
Raw Normal View History

2018-10-11 21:10:22 +02:00
package org.schabi.newpipe.extractor.services.peertube;
import org.junit.BeforeClass;
import org.junit.Test;
2019-11-19 22:38:17 +01:00
import org.schabi.newpipe.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;
2020-04-15 14:09:46 +02:00
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.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
2020-05-31 13:33:14 +02:00
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (PeertubeCommentsExtractor) PeerTube
.getCommentsExtractor("https://framatube.org/videos/watch/04af977f-4201-4697-be67-a8d8cae6fa7a");
}
2018-10-11 21:10:22 +02:00
2020-05-31 13:33:14 +02:00
@Test
public void testGetComments() throws IOException, ExtractionException {
InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
boolean result = findInComments(comments, "@root A great documentary on a great guy.");
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());
2020-05-31 13:33:14 +02:00
result = findInComments(comments, "@root A great documentary on a great guy.");
}
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
public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
2020-04-15 14:09:46 +02:00
CommentsInfo commentsInfo = CommentsInfo.getInfo("https://framatube.org/videos/watch/a8ea95b8-0396-49a6-8f30-e25e25fb2828");
2020-05-31 13:33:14 +02:00
assertEquals("Comments", commentsInfo.getName());
2020-07-06 20:23:41 +02:00
2020-05-31 13:33:14 +02:00
boolean result = findInComments(commentsInfo.getRelatedItems(), "Loved it!!!");
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);
2020-05-31 13:33:14 +02:00
result = findInComments(moreItems.getItems(), "Loved it!!!");
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
public void testGetCommentsAllData() throws IOException, ExtractionException {
2020-04-15 14:09:46 +02:00
InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
for (CommentsInfoItem c : comments.getItems()) {
2020-05-31 13:33:14 +02:00
assertFalse(Utils.isBlank(c.getUploaderUrl()));
assertFalse(Utils.isBlank(c.getUploaderName()));
assertFalse(Utils.isBlank(c.getUploaderAvatarUrl()));
assertFalse(Utils.isBlank(c.getCommentId()));
assertFalse(Utils.isBlank(c.getCommentText()));
assertFalse(Utils.isBlank(c.getName()));
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
assertFalse(Utils.isBlank(c.getUrl()));
2020-04-15 14:09:46 +02:00
assertFalse(c.getLikeCount() != -1);
2020-05-31 13:33:14 +02:00
}
}
2020-07-06 20:23:41 +02:00
2020-04-15 14:09:46 +02:00
private boolean findInComments(InfoItemsPage<CommentsInfoItem> comments, 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
2020-04-15 14:09:46 +02:00
private boolean findInComments(List<CommentsInfoItem> comments, String comment) {
for (CommentsInfoItem c : comments) {
2020-05-31 13:33:14 +02:00
if (c.getCommentText().contains(comment)) {
return true;
}
}
return false;
}
2018-10-11 21:10:22 +02:00
}
2020-05-31 13:33:14 +02:00
public static class DeletedComments {
private static PeertubeCommentsExtractor extractor;
@BeforeClass
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
public void testGetComments() throws IOException, ExtractionException {
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
assertTrue(comments.getErrors().isEmpty());
}
@Test
public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
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
}
}
}