2020-11-13 10:05:02 +01:00
|
|
|
|
|
|
|
package eu.dnetlib.dhp.oa.graph.raw;
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
import static org.mockito.Mockito.lenient;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
2021-08-12 11:32:26 +02:00
|
|
|
import org.dom4j.DocumentException;
|
2020-11-13 10:05:02 +01:00
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
|
import org.mockito.Mock;
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
|
2021-01-25 15:43:04 +01:00
|
|
|
import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup;
|
2021-05-10 16:43:39 +02:00
|
|
|
import eu.dnetlib.dhp.oa.graph.clean.GraphCleaningFunctionsTest;
|
2020-11-13 10:05:02 +01:00
|
|
|
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
|
|
|
import eu.dnetlib.dhp.schema.oaf.*;
|
2021-04-27 15:44:01 +02:00
|
|
|
import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils;
|
2020-11-13 10:05:02 +01:00
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
2021-08-11 12:13:22 +02:00
|
|
|
class GenerateEntitiesApplicationTest {
|
2020-11-13 10:05:02 +01:00
|
|
|
|
|
|
|
@Mock
|
|
|
|
private ISLookUpService isLookUpService;
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
private VocabularyGroup vocs;
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
public void setUp() throws IOException, ISLookUpException {
|
|
|
|
|
|
|
|
lenient().when(isLookUpService.quickSearchProfile(VocabularyGroup.VOCABULARIES_XQUERY)).thenReturn(vocs());
|
|
|
|
lenient()
|
|
|
|
.when(isLookUpService.quickSearchProfile(VocabularyGroup.VOCABULARY_SYNONYMS_XQUERY))
|
|
|
|
.thenReturn(synonyms());
|
|
|
|
|
|
|
|
vocs = VocabularyGroup.loadVocsFromIS(isLookUpService);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-08-12 11:32:26 +02:00
|
|
|
void testMergeResult() throws IOException, DocumentException {
|
2020-11-13 10:05:02 +01:00
|
|
|
Result publication = getResult("oaf_record.xml", Publication.class);
|
|
|
|
Result dataset = getResult("odf_dataset.xml", Dataset.class);
|
|
|
|
Result software = getResult("odf_software.xml", Software.class);
|
|
|
|
Result orp = getResult("oaf_orp.xml", OtherResearchProduct.class);
|
|
|
|
|
|
|
|
verifyMerge(publication, dataset, Publication.class, ModelConstants.PUBLICATION_RESULTTYPE_CLASSID);
|
|
|
|
verifyMerge(dataset, publication, Publication.class, ModelConstants.PUBLICATION_RESULTTYPE_CLASSID);
|
|
|
|
|
|
|
|
verifyMerge(publication, software, Publication.class, ModelConstants.PUBLICATION_RESULTTYPE_CLASSID);
|
|
|
|
verifyMerge(software, publication, Publication.class, ModelConstants.PUBLICATION_RESULTTYPE_CLASSID);
|
|
|
|
|
|
|
|
verifyMerge(publication, orp, Publication.class, ModelConstants.PUBLICATION_RESULTTYPE_CLASSID);
|
|
|
|
verifyMerge(orp, publication, Publication.class, ModelConstants.PUBLICATION_RESULTTYPE_CLASSID);
|
|
|
|
|
|
|
|
verifyMerge(dataset, software, Dataset.class, ModelConstants.DATASET_RESULTTYPE_CLASSID);
|
|
|
|
verifyMerge(software, dataset, Dataset.class, ModelConstants.DATASET_RESULTTYPE_CLASSID);
|
|
|
|
|
|
|
|
verifyMerge(dataset, orp, Dataset.class, ModelConstants.DATASET_RESULTTYPE_CLASSID);
|
|
|
|
verifyMerge(orp, dataset, Dataset.class, ModelConstants.DATASET_RESULTTYPE_CLASSID);
|
|
|
|
|
|
|
|
verifyMerge(software, orp, Software.class, ModelConstants.SOFTWARE_RESULTTYPE_CLASSID);
|
|
|
|
verifyMerge(orp, software, Software.class, ModelConstants.SOFTWARE_RESULTTYPE_CLASSID);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected <T extends Result> void verifyMerge(Result publication, Result dataset, Class<T> clazz,
|
|
|
|
String resultType) {
|
|
|
|
final Result merge = OafMapperUtils.mergeResults(publication, dataset);
|
|
|
|
assertTrue(clazz.isAssignableFrom(merge.getClass()));
|
|
|
|
assertEquals(resultType, merge.getResulttype().getClassid());
|
|
|
|
}
|
|
|
|
|
2021-08-12 11:32:26 +02:00
|
|
|
protected <T extends Result> Result getResult(String xmlFileName, Class<T> clazz)
|
|
|
|
throws IOException, DocumentException {
|
2020-11-13 10:05:02 +01:00
|
|
|
final String xml = IOUtils.toString(getClass().getResourceAsStream(xmlFileName));
|
2020-11-30 12:00:38 +01:00
|
|
|
return new OdfToOafMapper(vocs, false, true)
|
2020-11-13 10:05:02 +01:00
|
|
|
.processMdRecord(xml)
|
|
|
|
.stream()
|
|
|
|
.filter(s -> clazz.isAssignableFrom(s.getClass()))
|
|
|
|
.map(s -> (Result) s)
|
|
|
|
.findFirst()
|
|
|
|
.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<String> vocs() throws IOException {
|
|
|
|
return IOUtils
|
2021-05-10 16:43:39 +02:00
|
|
|
.readLines(
|
|
|
|
GraphCleaningFunctionsTest.class.getResourceAsStream("/eu/dnetlib/dhp/oa/graph/clean/terms.txt"));
|
2020-11-13 10:05:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private List<String> synonyms() throws IOException {
|
|
|
|
return IOUtils
|
2021-05-10 16:43:39 +02:00
|
|
|
.readLines(
|
|
|
|
GraphCleaningFunctionsTest.class.getResourceAsStream("/eu/dnetlib/dhp/oa/graph/clean/synonyms.txt"));
|
2020-11-13 10:05:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|