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

259 lines
9.0 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;
import org.schabi.newpipe.extractor.ExtractorAsserts;
2018-10-11 21:10:22 +02:00
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
2023-03-22 01:00:05 +01:00
import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
2018-10-11 21:10:22 +02:00
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeChannelExtractor;
2023-03-22 01:00:05 +01:00
import java.util.Set;
import java.util.stream.Collectors;
2021-12-27 21:08:08 +01:00
import static org.junit.jupiter.api.Assertions.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
2018-10-11 21:10:22 +02:00
/**
* Test for {@link PeertubeChannelExtractor}
*/
public class PeertubeChannelExtractorTest {
public static class LaQuadratureDuNet implements BaseChannelExtractorTest {
2018-10-11 21:10:22 +02:00
private static PeertubeChannelExtractor extractor;
2021-12-27 21:08:08 +01:00
@BeforeAll
2018-10-11 21:10:22 +02:00
public static void setUp() throws Exception {
2019-11-19 22:38:17 +01:00
NewPipe.init(DownloaderTestImpl.getInstance());
2019-03-09 19:03:51 +01:00
// setting instance might break test when running in parallel
PeerTube.setInstance(new PeertubeInstance("https://framatube.org", "Framatube"));
2018-10-11 21:10:22 +02:00
extractor = (PeertubeChannelExtractor) PeerTube
.getChannelExtractor("https://framatube.org/video-channels/lqdn_channel@video.lqdn.fr/videos");
2018-10-11 21:10:22 +02:00
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testServiceId() {
assertEquals(PeerTube.getServiceId(), extractor.getServiceId());
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testName() throws ParsingException {
assertEquals("La Quadrature du Net", extractor.getName());
2018-10-11 21:10:22 +02:00
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testId() throws ParsingException {
assertEquals("video-channels/lqdn_channel@video.lqdn.fr", extractor.getId());
2018-10-11 21:10:22 +02:00
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testUrl() throws ParsingException {
assertEquals("https://framatube.org/video-channels/lqdn_channel@video.lqdn.fr", extractor.getUrl());
2018-10-11 21:10:22 +02:00
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testOriginalUrl() throws ParsingException {
assertEquals("https://framatube.org/video-channels/lqdn_channel@video.lqdn.fr/videos", extractor.getOriginalUrl());
2018-10-11 21:10:22 +02:00
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testDescription() throws ParsingException {
assertNotNull(extractor.getDescription());
}
@Test
public void testParentChannelName() throws ParsingException {
assertEquals("lqdn", extractor.getParentChannelName());
}
@Test
public void testParentChannelUrl() throws ParsingException {
assertEquals("https://video.lqdn.fr/accounts/lqdn", extractor.getParentChannelUrl());
}
@Test
public void testParentChannelAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getParentChannelAvatarUrl());
}
2018-10-11 21:10:22 +02:00
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getAvatarUrl());
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testBannerUrl() throws ParsingException {
assertNull(extractor.getBannerUrl());
2018-10-11 21:10:22 +02:00
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testFeedUrl() throws ParsingException {
assertEquals("https://framatube.org/feeds/videos.xml?videoChannelId=1126", extractor.getFeedUrl());
2018-10-11 21:10:22 +02:00
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testSubscriberCount() throws ParsingException {
ExtractorAsserts.assertGreaterOrEqual(230, extractor.getSubscriberCount());
2018-10-11 21:10:22 +02:00
}
2023-03-22 01:00:05 +01:00
@Test
@Override
public void testVerified() throws Exception {
assertFalse(extractor.isVerified());
}
2023-03-22 01:00:05 +01:00
@Test
@Override
public void testTabs() throws Exception {
2023-03-22 01:00:05 +01:00
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
}
2018-10-11 21:10:22 +02:00
}
public static class ChatSceptique implements BaseChannelExtractorTest {
2018-10-11 21:10:22 +02:00
private static PeertubeChannelExtractor extractor;
2021-12-27 21:08:08 +01:00
@BeforeAll
2018-10-11 21:10:22 +02:00
public static void setUp() throws Exception {
2019-11-19 22:38:17 +01:00
NewPipe.init(DownloaderTestImpl.getInstance());
2019-03-09 19:03:51 +01:00
// setting instance might break test when running in parallel
PeerTube.setInstance(new PeertubeInstance("https://framatube.org", "Framatube"));
2018-10-11 21:10:22 +02:00
extractor = (PeertubeChannelExtractor) PeerTube
.getChannelExtractor("https://framatube.org/api/v1/video-channels/chatsceptique@skeptikon.fr");
2018-10-11 21:10:22 +02:00
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Additional Testing
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testGetPageInNewExtractor() throws Exception {
final ChannelExtractor newExtractor = PeerTube.getChannelExtractor(extractor.getUrl());
2023-04-14 14:10:26 +02:00
newExtractor.fetchPage();
2018-10-11 21:10:22 +02:00
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testServiceId() {
assertEquals(PeerTube.getServiceId(), extractor.getServiceId());
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testName() throws ParsingException {
assertEquals("Chat Sceptique", extractor.getName());
2018-10-11 21:10:22 +02:00
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testId() throws ParsingException {
assertEquals("video-channels/chatsceptique@skeptikon.fr", extractor.getId());
2018-10-11 21:10:22 +02:00
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testUrl() throws ParsingException {
assertEquals("https://framatube.org/video-channels/chatsceptique@skeptikon.fr", extractor.getUrl());
2018-10-11 21:10:22 +02:00
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testOriginalUrl() throws ParsingException {
assertEquals("https://framatube.org/api/v1/video-channels/chatsceptique@skeptikon.fr", extractor.getOriginalUrl());
2018-10-11 21:10:22 +02:00
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testDescription() throws ParsingException {
assertNotNull(extractor.getDescription());
}
@Test
public void testParentChannelName() throws ParsingException {
assertEquals("nathan", extractor.getParentChannelName());
}
@Test
public void testParentChannelUrl() throws ParsingException {
assertEquals("https://skeptikon.fr/accounts/nathan", extractor.getParentChannelUrl());
}
@Test
public void testParentChannelAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getParentChannelAvatarUrl());
}
2018-10-11 21:10:22 +02:00
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testAvatarUrl() throws ParsingException {
assertIsSecureUrl(extractor.getAvatarUrl());
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testBannerUrl() throws ParsingException {
assertNull(extractor.getBannerUrl());
2018-10-11 21:10:22 +02:00
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testFeedUrl() throws ParsingException {
assertEquals("https://framatube.org/feeds/videos.xml?videoChannelId=137", extractor.getFeedUrl());
2018-10-11 21:10:22 +02:00
}
@Test
@Override
2018-10-11 21:10:22 +02:00
public void testSubscriberCount() throws ParsingException {
ExtractorAsserts.assertGreaterOrEqual(700, extractor.getSubscriberCount());
2018-10-11 21:10:22 +02:00
}
2023-03-22 01:00:05 +01:00
@Test
@Override
public void testVerified() throws Exception {
assertFalse(extractor.isVerified());
}
2023-03-22 01:00:05 +01:00
@Test
@Override
public void testTabs() throws Exception {
2023-03-22 01:00:05 +01:00
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
}
2018-10-11 21:10:22 +02:00
}
}