From 6bd5a792ddbede5f887e88f26a53483f902fd55c Mon Sep 17 00:00:00 2001 From: Sandro La Bruzzo Date: Thu, 9 Feb 2023 16:13:34 +0100 Subject: [PATCH] Added vocabolary mocks --- .../dhp/common/vocabulary/VocabularyTest.java | 84 +++++++++++++++++++ .../eu/dnetlib/dhp/common/vocabulary/terms | 34 ++++++++ 2 files changed, 118 insertions(+) create mode 100644 dhp-common/src/test/java/eu/dnetlib/dhp/common/vocabulary/VocabularyTest.java create mode 100644 dhp-common/src/test/resources/eu/dnetlib/dhp/common/vocabulary/terms diff --git a/dhp-common/src/test/java/eu/dnetlib/dhp/common/vocabulary/VocabularyTest.java b/dhp-common/src/test/java/eu/dnetlib/dhp/common/vocabulary/VocabularyTest.java new file mode 100644 index 000000000..6529d43da --- /dev/null +++ b/dhp-common/src/test/java/eu/dnetlib/dhp/common/vocabulary/VocabularyTest.java @@ -0,0 +1,84 @@ +package eu.dnetlib.dhp.common.vocabulary; + +import eu.dnetlib.dhp.schema.oaf.Qualifier; +import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; +import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; +import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +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; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import static org.mockito.Mockito.lenient; + + +@ExtendWith(MockitoExtension.class) +public class VocabularyTest { + + + @Mock + protected ISLookUpService isLookUpService; + + protected VocabularyGroup vocabularies; + + @BeforeEach + public void setUpVocabulary() throws ISLookUpException, IOException { + + lenient().when(isLookUpService.quickSearchProfile(VocabularyGroup.VOCABULARIES_XQUERY)).thenReturn(vocs()); + + lenient() + .when(isLookUpService.quickSearchProfile(VocabularyGroup.VOCABULARY_SYNONYMS_XQUERY)) + .thenReturn(synonyms()); + vocabularies = VocabularyGroup.loadVocsFromIS(isLookUpService); + } + + private static List vocs() throws IOException { + return IOUtils + .readLines( + Objects + .requireNonNull( + VocabularyTest.class.getResourceAsStream("/eu/dnetlib/dhp/transform/terms.txt"))); + } + + private static List synonyms() throws IOException { + return IOUtils + .readLines( + Objects + .requireNonNull( + VocabularyTest.class.getResourceAsStream("/eu/dnetlib/dhp/transform/synonyms.txt"))); + } + + + @Test + void testVocabularyMatch () throws Exception{ + final String s= IOUtils.toString(this.getClass().getResourceAsStream("terms")); + + for (String s1 : s.split("\n")) { + + final Qualifier t1 = vocabularies.getSynonymAsQualifier("dnet:publication_resource", s1); + + if (t1 == null) { + System.err.println(s1+ " Missing"); + } + else { + System.out.println("syn=" + s1 + " term = " + t1.getClassid()); + + + System.out.println(vocabularies.getSynonymAsQualifier("dnet:result_typologies", t1.getClassid()).getClassname()); + } + } + + + + + + } +} diff --git a/dhp-common/src/test/resources/eu/dnetlib/dhp/common/vocabulary/terms b/dhp-common/src/test/resources/eu/dnetlib/dhp/common/vocabulary/terms new file mode 100644 index 000000000..abeed4cc8 --- /dev/null +++ b/dhp-common/src/test/resources/eu/dnetlib/dhp/common/vocabulary/terms @@ -0,0 +1,34 @@ +grant +book +report-series +report-component +book-series +peer-review +component +report +book-track +database +standard +journal-volume +proceedings-series +preprint +book-section +letter +reference-book +edited-book +journal-issue +dataset +reference-entry +dissertation +book-chapter +book-part +journal +book-set +working_paper +dissertation +other +proceedings-article +journal-article +other +proceedings +monograph \ No newline at end of file