Skip to content

Commit

Permalink
Renenable WebFetchers test
Browse files Browse the repository at this point in the history
Replace outdated reflection library with classgraph library
  • Loading branch information
Siedlerchr committed Oct 4, 2019
1 parent 79f9c86 commit 1197cb6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
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"
}


compile "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
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@
requires de.saxsys.mvvmfx.validation;
requires richtextfx;
requires unirest.java;
requires 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

0 comments on commit 1197cb6

Please sign in to comment.