From 348aa41058bffca2d8edde30eb4d630b700a1ed6 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Tue, 10 Dec 2024 09:35:14 +0100 Subject: [PATCH] test --- .classpath | 18 +++---- pom.xml | 2 +- .../directindex/clients/VocabularyClient.java | 10 +++- .../clients/VocabularyClientTest.java | 48 +++++++++++++++++++ .../mapping/SolrRecordMapperTest.java | 2 + 5 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 src/test/java/eu/dnetlib/app/directindex/clients/VocabularyClientTest.java diff --git a/.classpath b/.classpath index 266f5b3..f0e9804 100644 --- a/.classpath +++ b/.classpath @@ -6,27 +6,27 @@ - - - - - - - + + + + + + + - + - + diff --git a/pom.xml b/pom.xml index 20e08d8..ae009b7 100644 --- a/pom.xml +++ b/pom.xml @@ -188,7 +188,7 @@ org.apache.solr solr-solrj - 9.7.0 + 9.7.0 diff --git a/src/main/java/eu/dnetlib/app/directindex/clients/VocabularyClient.java b/src/main/java/eu/dnetlib/app/directindex/clients/VocabularyClient.java index 872bfa3..97c2c6f 100644 --- a/src/main/java/eu/dnetlib/app/directindex/clients/VocabularyClient.java +++ b/src/main/java/eu/dnetlib/app/directindex/clients/VocabularyClient.java @@ -45,7 +45,7 @@ public class VocabularyClient implements HasCache { public String findTermLabel(final String vocabulary, final String code) { try { - final String label = findVocabulary("dnet:pid_types").get(code); + final String label = findVocabulary(vocabulary).get(code); return StringUtils.firstNonBlank(label, code); } catch (final DirectIndexApiException e) { log.warn("Problem accessing vocabulary: " + vocabulary, e); @@ -159,4 +159,12 @@ public class VocabularyClient implements HasCache { } } + public String getVocApiUrl() { + return vocApiUrl; + } + + public void setVocApiUrl(final String vocApiUrl) { + this.vocApiUrl = vocApiUrl; + } + } diff --git a/src/test/java/eu/dnetlib/app/directindex/clients/VocabularyClientTest.java b/src/test/java/eu/dnetlib/app/directindex/clients/VocabularyClientTest.java new file mode 100644 index 0000000..366aff4 --- /dev/null +++ b/src/test/java/eu/dnetlib/app/directindex/clients/VocabularyClientTest.java @@ -0,0 +1,48 @@ +package eu.dnetlib.app.directindex.clients; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import eu.dnetlib.app.directindex.errors.DirectIndexApiException; + +@Disabled +class VocabularyClientTest { + + // Class Under test + private VocabularyClient vocabularyClient; + + private static final String VOCABULARY_URL = "https://services.openaire.eu/provision/mvc/vocabularies"; + + @BeforeEach + public void initEach() throws DirectIndexApiException { + vocabularyClient = new VocabularyClient(); + vocabularyClient.setVocApiUrl(VOCABULARY_URL); + } + + @Test + void testFindVocabulary() throws DirectIndexApiException { + assertFalse(vocabularyClient.findVocabulary("dnet:countries").isEmpty()); + assertFalse(vocabularyClient.findVocabulary("dnet:languages").isEmpty()); + assertFalse(vocabularyClient.findVocabulary("dnet:access_modes").isEmpty()); + assertFalse(vocabularyClient.findVocabulary("dnet:publication_resource").isEmpty()); + assertThrows(DirectIndexApiException.class, () -> vocabularyClient.findVocabulary("INVALID_VOC")); + } + + @Test + void testFindTermLabel() { + assertEquals("Italy", vocabularyClient.findTermLabel("dnet:countries", "IT")); + assertEquals("English", vocabularyClient.findTermLabel("dnet:languages", "eng")); + assertEquals("Open Access", vocabularyClient.findTermLabel("dnet:access_modes", "OPEN")); + assertEquals("Article", vocabularyClient.findTermLabel("dnet:publication_resource", "0001")); + + assertEquals("test", vocabularyClient.findTermLabel("INVALID_VOC", "test")); + assertEquals("test-lang", vocabularyClient.findTermLabel("dnet:languages", "test-lang")); + + } + +} diff --git a/src/test/java/eu/dnetlib/app/directindex/mapping/SolrRecordMapperTest.java b/src/test/java/eu/dnetlib/app/directindex/mapping/SolrRecordMapperTest.java index edf4a36..7ff0ae1 100644 --- a/src/test/java/eu/dnetlib/app/directindex/mapping/SolrRecordMapperTest.java +++ b/src/test/java/eu/dnetlib/app/directindex/mapping/SolrRecordMapperTest.java @@ -10,6 +10,7 @@ import static org.mockito.Mockito.verify; import org.apache.commons.lang3.StringUtils; import org.apache.solr.common.SolrInputDocument; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -28,6 +29,7 @@ import eu.dnetlib.app.directindex.input.ResultEntry; import eu.dnetlib.dhp.schema.solr.SolrRecord; import eu.dnetlib.dhp.solr.mapping.SolrInputDocumentMapper; +@Disabled @ExtendWith(MockitoExtension.class) class SolrRecordMapperTest {