Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renenable WebFetchers test #5388

Merged
merged 3 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ dependencies {
exclude module: "log4j-core"
}


testCompile 'io.github.classgraph:classgraph:4.8.47'
testCompile 'junit:junit:4.12'
testImplementation 'org.junit.jupiter:junit-jupiter:5.5.2'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.5.2'
Expand All @@ -207,9 +209,6 @@ dependencies {
testRuntime group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '3.0.0-20190915.182552-364'
testCompile 'org.mockito:mockito-core:3.0.0'
//testCompile 'com.github.tomakehurst:wiremock:2.24.1'
testCompile ('org.reflections:reflections:0.9.11') {
exclude module: "jsr305"
}
testCompile 'org.xmlunit:xmlunit-core:2.6.3'
testCompile 'org.xmlunit:xmlunit-matchers:2.6.3'
testCompile 'com.tngtech.archunit:archunit-junit5-api:0.11.0'
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/module-info.test
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@
--add-opens
// Needed for localization tests
javafx.fxml/javafx.fxml=org.jabref

--add-modules
io.github.classgraph

--add-reads
org.jabref=io.github.classgraph
68 changes: 43 additions & 25 deletions src/test/java/org/jabref/logic/importer/WebFetchersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
import org.jabref.logic.importer.fetcher.IsbnViaOttoBibFetcher;
import org.jabref.logic.importer.fetcher.MrDLibFetcher;

import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfoList;
import io.github.classgraph.ScanResult;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.reflections.Reflections;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

// TODO: Reenable as soon as https://github.com/ronmamo/reflections/issues/202 is fixed
@Disabled
class WebFetchersTest {

private Reflections reflections = new Reflections("org.jabref");
private ImportFormatPreferences importFormatPreferences;
private ClassGraph classGraph = new ClassGraph().enableAllInfo().whitelistPackages("org.jabref");

@BeforeEach
void setUp() throws Exception {
Expand All @@ -34,50 +33,69 @@ void setUp() throws Exception {
void getIdBasedFetchersReturnsAllFetcherDerivingFromIdBasedFetcher() throws Exception {
List<IdBasedFetcher> idFetchers = WebFetchers.getIdBasedFetchers(importFormatPreferences);

Set<Class<? extends IdBasedFetcher>> expected = reflections.getSubTypesOf(IdBasedFetcher.class);
expected.remove(AbstractIsbnFetcher.class);
expected.remove(IdBasedParserFetcher.class);
// Remove special ISBN fetcher since we don't want to expose them to the user
expected.remove(IsbnViaChimboriFetcher.class);
expected.remove(IsbnViaEbookDeFetcher.class);
expected.remove(IsbnViaOttoBibFetcher.class);
assertEquals(expected, getClasses(idFetchers));
try (ScanResult scanResult = classGraph.scan()) {

ClassInfoList controlClasses = scanResult.getClassesImplementing(IdBasedFetcher.class.getCanonicalName());
Set<Class<?>> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet());

expected.remove(AbstractIsbnFetcher.class);
expected.remove(IdBasedParserFetcher.class);
// Remove special ISBN fetcher since we don't want to expose them to the user
expected.remove(IsbnViaChimboriFetcher.class);
expected.remove(IsbnViaEbookDeFetcher.class);
expected.remove(IsbnViaOttoBibFetcher.class);
assertEquals(expected, getClasses(idFetchers));
}
}

@Test
void getEntryBasedFetchersReturnsAllFetcherDerivingFromEntryBasedFetcher() throws Exception {
List<EntryBasedFetcher> idFetchers = WebFetchers.getEntryBasedFetchers(importFormatPreferences);

Set<Class<? extends EntryBasedFetcher>> expected = reflections.getSubTypesOf(EntryBasedFetcher.class);
expected.remove(EntryBasedParserFetcher.class);
expected.remove(MrDLibFetcher.class);
assertEquals(expected, getClasses(idFetchers));
try (ScanResult scanResult = classGraph.scan()) {
ClassInfoList controlClasses = scanResult.getClassesImplementing(EntryBasedFetcher.class.getCanonicalName());
Set<Class<?>> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet());

expected.remove(EntryBasedParserFetcher.class);
expected.remove(MrDLibFetcher.class);
assertEquals(expected, getClasses(idFetchers));
}
}

@Test
void getSearchBasedFetchersReturnsAllFetcherDerivingFromSearchBasedFetcher() throws Exception {
List<SearchBasedFetcher> searchBasedFetchers = WebFetchers.getSearchBasedFetchers(importFormatPreferences);
try (ScanResult scanResult = classGraph.scan()) {
ClassInfoList controlClasses = scanResult.getClassesImplementing(SearchBasedFetcher.class.getCanonicalName());
Set<Class<?>> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet());

Set<Class<? extends SearchBasedFetcher>> expected = reflections.getSubTypesOf(SearchBasedFetcher.class);
expected.remove(SearchBasedParserFetcher.class);
assertEquals(expected, getClasses(searchBasedFetchers));
expected.remove(SearchBasedParserFetcher.class);
assertEquals(expected, getClasses(searchBasedFetchers));
}
}

@Test
void getFullTextFetchersReturnsAllFetcherDerivingFromFullTextFetcher() throws Exception {
List<FulltextFetcher> fullTextFetchers = WebFetchers.getFullTextFetchers(importFormatPreferences);

Set<Class<? extends FulltextFetcher>> expected = reflections.getSubTypesOf(FulltextFetcher.class);
assertEquals(expected, getClasses(fullTextFetchers));
try (ScanResult scanResult = classGraph.scan()) {
ClassInfoList controlClasses = scanResult.getClassesImplementing(FulltextFetcher.class.getCanonicalName());
Set<Class<?>> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet());
assertEquals(expected, getClasses(fullTextFetchers));
}
}

@Test
void getIdFetchersReturnsAllFetcherDerivingFromIdFetcher() throws Exception {
List<IdFetcher> idFetchers = WebFetchers.getIdFetchers(importFormatPreferences);

Set<Class<? extends IdFetcher>> expected = reflections.getSubTypesOf(IdFetcher.class);
expected.remove(IdParserFetcher.class);
assertEquals(expected, getClasses(idFetchers));
try (ScanResult scanResult = classGraph.scan()) {
ClassInfoList controlClasses = scanResult.getClassesImplementing(IdFetcher.class.getCanonicalName());
Set<Class<?>> expected = controlClasses.loadClasses().stream().collect(Collectors.toSet());

expected.remove(IdParserFetcher.class);
assertEquals(expected, getClasses(idFetchers));
}
}

private Set<? extends Class<?>> getClasses(List<?> objects) {
Expand Down