diff --git a/.classpath b/.classpath index f0e9804..881e822 100644 --- a/.classpath +++ b/.classpath @@ -14,20 +14,21 @@ + - - + - + + diff --git a/src/main/java/eu/dnetlib/app/directindex/clients/DatasourceManagerClient.java b/src/main/java/eu/dnetlib/app/directindex/clients/DatasourceManagerClient.java index b301a3c..f4796b1 100644 --- a/src/main/java/eu/dnetlib/app/directindex/clients/DatasourceManagerClient.java +++ b/src/main/java/eu/dnetlib/app/directindex/clients/DatasourceManagerClient.java @@ -119,4 +119,12 @@ public class DatasourceManagerClient implements HasCache { } } + public String getDsmApiUrl() { + return dsmApiUrl; + } + + public void setDsmApiUrl(final String dsmApiUrl) { + this.dsmApiUrl = dsmApiUrl; + } + } diff --git a/src/test/java/eu/dnetlib/app/directindex/clients/DatasourceManagerClientTest.java b/src/test/java/eu/dnetlib/app/directindex/clients/DatasourceManagerClientTest.java new file mode 100644 index 0000000..512243b --- /dev/null +++ b/src/test/java/eu/dnetlib/app/directindex/clients/DatasourceManagerClientTest.java @@ -0,0 +1,51 @@ +package eu.dnetlib.app.directindex.clients; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +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; +import eu.dnetlib.app.directindex.input.DatasourceEntry; + +@Disabled +class DatasourceManagerClientTest { + + // Class Under test + private DatasourceManagerClient dsmClient; + + private static final String DSM_URL = "https://services.openaire.eu/openaire/ds"; + + @BeforeEach + public void initEach() { + dsmClient = new DatasourceManagerClient(); + dsmClient.setDsmApiUrl(DSM_URL); + } + + @Test + void testFindDatasource() throws DirectIndexApiException { + final DatasourceEntry ds = dsmClient.findDatasource("openaire____::re3data"); + assertNotNull(ds); + assertEquals("openaire____::re3data", ds.getId()); + assertEquals("Registry of Research Data Repository", ds.getName()); + assertEquals("re3data_____", ds.getPrefix()); + } + + @Test + void testFindDatasourceUnknown() throws DirectIndexApiException { + final DatasourceEntry ds = dsmClient.findDatasource("unknown_____::12345"); + assertNotNull(ds); + assertEquals(DatasourceEntry.UNKNOWN_DATASOURCE.getId(), ds.getId()); + assertEquals(DatasourceEntry.UNKNOWN_DATASOURCE.getName(), ds.getName()); + assertEquals(DatasourceEntry.UNKNOWN_DATASOURCE.getPrefix(), ds.getPrefix()); + } + + @Test + void testFindDatasourceInvalid() throws DirectIndexApiException { + dsmClient.setDsmApiUrl("http://invalid/url"); + assertThrows(DirectIndexApiException.class, () -> dsmClient.findDatasource("invalid_____::12345")); + } +} diff --git a/src/test/java/eu/dnetlib/app/directindex/clients/VocabularyClientTest.java b/src/test/java/eu/dnetlib/app/directindex/clients/VocabularyClientTest.java index 366aff4..def6ab8 100644 --- a/src/test/java/eu/dnetlib/app/directindex/clients/VocabularyClientTest.java +++ b/src/test/java/eu/dnetlib/app/directindex/clients/VocabularyClientTest.java @@ -19,7 +19,7 @@ class VocabularyClientTest { private static final String VOCABULARY_URL = "https://services.openaire.eu/provision/mvc/vocabularies"; @BeforeEach - public void initEach() throws DirectIndexApiException { + public void initEach() { vocabularyClient = new VocabularyClient(); vocabularyClient.setVocApiUrl(VOCABULARY_URL); }