dnet-hadoop/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/aggregation/AbstractVocabularyTest.java

59 lines
1.8 KiB
Java
Raw Normal View History

2021-02-04 10:30:49 +01:00
package eu.dnetlib.dhp.aggregation;
import static org.mockito.Mockito.lenient;
2021-02-04 10:30:49 +01:00
import java.io.IOException;
import java.util.Collections;
import java.util.List;
2021-06-21 09:36:40 +02:00
import java.util.Objects;
2021-02-04 10:30:49 +01:00
import org.apache.commons.io.IOUtils;
import org.mockito.Mock;
2021-02-04 10:30:49 +01:00
import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup;
import eu.dnetlib.dhp.transformation.TransformationFactory;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
2021-02-04 10:30:49 +01:00
public abstract class AbstractVocabularyTest {
2021-02-04 10:30:49 +01:00
@Mock
protected ISLookUpService isLookUpService;
2021-02-04 10:30:49 +01:00
protected VocabularyGroup vocabularies;
2021-02-04 10:30:49 +01:00
public void setUpVocabulary() throws ISLookUpException, IOException {
lenient().when(isLookUpService.quickSearchProfile(VocabularyGroup.VOCABULARIES_XQUERY)).thenReturn(vocs());
2021-02-04 10:30:49 +01:00
lenient()
.when(isLookUpService.quickSearchProfile(VocabularyGroup.VOCABULARY_SYNONYMS_XQUERY))
.thenReturn(synonyms());
vocabularies = VocabularyGroup.loadVocsFromIS(isLookUpService);
}
2021-02-04 10:30:49 +01:00
private static List<String> vocs() throws IOException {
return IOUtils
2021-06-21 09:36:40 +02:00
.readLines(
Objects
.requireNonNull(
AbstractVocabularyTest.class.getResourceAsStream("/eu/dnetlib/dhp/transform/terms.txt")));
}
2021-02-04 10:30:49 +01:00
private static List<String> synonyms() throws IOException {
return IOUtils
2021-06-21 09:36:40 +02:00
.readLines(
Objects
.requireNonNull(
AbstractVocabularyTest.class.getResourceAsStream("/eu/dnetlib/dhp/transform/synonyms.txt")));
}
2021-02-04 10:30:49 +01:00
protected void mockupTrasformationRule(final String trule, final String path) throws Exception {
2021-06-21 09:36:40 +02:00
final String trValue = IOUtils.toString(Objects.requireNonNull(this.getClass().getResourceAsStream(path)));
2021-02-04 10:30:49 +01:00
lenient()
.when(isLookUpService.quickSearchProfile(String.format(TransformationFactory.TRULE_XQUERY, trule)))
.thenReturn(Collections.singletonList(trValue));
}
2021-02-04 10:30:49 +01:00
}