diff --git a/src/main/java/eu/dissco/core/translator/service/DwcaService.java b/src/main/java/eu/dissco/core/translator/service/DwcaService.java index 9a56b6d..69e441a 100644 --- a/src/main/java/eu/dissco/core/translator/service/DwcaService.java +++ b/src/main/java/eu/dissco/core/translator/service/DwcaService.java @@ -361,8 +361,8 @@ private String getTableName(ArchiveFile archiveFile) { var fullSourceSystemId = webClientProperties.getSourceSystemId(); var minifiedSourceSystemId = fullSourceSystemId.substring(fullSourceSystemId.indexOf('/') + 1) .replace("-", "_"); - var tableName = (minifiedSourceSystemId + "_" + archiveFile.getRowType() - .prefixedName()).toLowerCase() + var tableName = "temp_" + (minifiedSourceSystemId + "_" + archiveFile.getRowType() + .simpleName()).toLowerCase() .replace(":", "_"); tableName = tableName.replace("/", "_"); return tableName.replace(".", "_"); diff --git a/src/test/java/eu/dissco/core/translator/component/InstitutionNameComponentTest.java b/src/test/java/eu/dissco/core/translator/component/InstitutionNameComponentTest.java index 186238e..dd0b70f 100644 --- a/src/test/java/eu/dissco/core/translator/component/InstitutionNameComponentTest.java +++ b/src/test/java/eu/dissco/core/translator/component/InstitutionNameComponentTest.java @@ -2,7 +2,6 @@ import static eu.dissco.core.translator.TestUtils.loadResourceFile; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -11,7 +10,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import eu.dissco.core.translator.exception.OrganisationException; -import java.io.IOException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import org.junit.jupiter.api.BeforeEach; diff --git a/src/test/java/eu/dissco/core/translator/repository/BatchInserterTest.java b/src/test/java/eu/dissco/core/translator/repository/BatchInserterTest.java index dfd88aa..8ed84be 100644 --- a/src/test/java/eu/dissco/core/translator/repository/BatchInserterTest.java +++ b/src/test/java/eu/dissco/core/translator/repository/BatchInserterTest.java @@ -24,16 +24,28 @@ import org.junit.jupiter.params.provider.MethodSource; import org.postgresql.copy.CopyManager; import org.postgresql.core.BaseConnection; -import org.testcontainers.shaded.org.yaml.snakeyaml.events.Event.ID; class BatchInserterTest extends BaseRepositoryIT { - private BatchInserter batchInserter; - private static final String TABLE_NAME = "xxx_xxx_xxx_core"; - private final Field ID_FIELD = DSL.field("dwcaid", String.class); + private static final String TABLE_NAME = "temp_xxx_xxx_xxx_core"; private static final Field DATA_FIELD = DSL.field("data", JSONB.class); private static final String RECORD_ID = "11a8a4c6-3188-4305-9688-d68942f4038e"; private static final String RECORD_ID_ALT = "32546f7b-f62a-4368-8c60-922f1cba4ab8"; + private final Field ID_FIELD = DSL.field("dwcaid", String.class); + private BatchInserter batchInserter; + + private static Stream badStrings() { + return Stream.of( + Arguments.of("bad \b string"), + Arguments.of("bad \f string"), + Arguments.of("bad \n string"), + Arguments.of("bad \r string"), + Arguments.of("bad \t string"), + Arguments.of("bad, string"), + Arguments.of("bad \\N string") + ); + } + @BeforeEach void setup() throws SQLException { var connection = DriverManager.getConnection(dataSource.getJdbcUrl(), dataSource.getUsername(), @@ -48,7 +60,7 @@ void setup() throws SQLException { } @AfterEach - void destroy(){ + void destroy() { context.dropTableIfExists(getTable(TABLE_NAME)).execute(); } @@ -113,18 +125,6 @@ void testBadCharacters() throws Exception { assertThat(MAPPER.readTree(result.get(DATA_FIELD).data())).isEqualTo(expected); } - private static Stream badStrings(){ - return Stream.of( - Arguments.of("bad \b string"), - Arguments.of("bad \f string"), - Arguments.of("bad \n string"), - Arguments.of("bad \r string"), - Arguments.of("bad \t string"), - Arguments.of("bad, string"), - Arguments.of("bad \\N string") - ); - } - private List> givenCoreRecords() { var records = new ArrayList>(); records.add(Pair.of(RECORD_ID, givenJsonNode())); @@ -132,7 +132,7 @@ private List> givenCoreRecords() { return records; } - private JsonNode givenJsonNode(){ + private JsonNode givenJsonNode() { var node = MAPPER.createObjectNode(); node.put("test", "test"); node.put("data", "value"); diff --git a/src/test/java/eu/dissco/core/translator/repository/DwcaRepositoryTest.java b/src/test/java/eu/dissco/core/translator/repository/DwcaRepositoryTest.java index 530eb68..6b0df30 100644 --- a/src/test/java/eu/dissco/core/translator/repository/DwcaRepositoryTest.java +++ b/src/test/java/eu/dissco/core/translator/repository/DwcaRepositoryTest.java @@ -30,12 +30,11 @@ @ExtendWith(MockitoExtension.class) class DwcaRepositoryTest extends BaseRepositoryIT { - private DwcaRepository repository; - @Mock - BatchInserter batchInserter; - private final Field idField = DSL.field("dwcaid", String.class); private final Field dataField = DSL.field("data", JSONB.class); + @Mock + BatchInserter batchInserter; + private DwcaRepository repository; private static JsonNode givenRecord(String corruptedValue) { var objectNode = MAPPER.createObjectNode(); @@ -52,7 +51,7 @@ void setup() { @Test void getCoreRecords() { // Given - var tableName = "XXX-XXX-XXX_Core"; + var tableName = "temp_XXX-XXX-XXX_Core"; var records = givenCoreRecords(); repository.createTable(tableName); postRecords(tableName, records); @@ -70,7 +69,7 @@ void getCoreRecords() { @Test void getCorruptCoreRecords() { // Given - var tableName = "XXX-XXX-XXX_Core"; + var tableName = "temp_XXX-XXX-XXX_Core"; var records = List.of( Pair.of(UUID.randomUUID().toString(), givenRecord("\u0000 someCorruptedInformation"))); repository.createTable(tableName); @@ -89,7 +88,7 @@ void getCorruptCoreRecords() { @Test void getCoreExtensionRecords() { // Given - var tableName = "XXX-XXX-XXX_Extension"; + var tableName = "temp_XXX-XXX-XXX_Extension"; var records = givenExtensionRecord(); repository.createTable(tableName); postRecords(tableName, records); @@ -106,7 +105,7 @@ void getCoreExtensionRecords() { @Test void testPostRecords() throws Exception { // Given - var tableName = "XXX-XXX-XXX_Extension"; + var tableName = "temp_XXX-XXX-XXX_Extension"; var records = givenExtensionRecord(); // When diff --git a/src/test/java/eu/dissco/core/translator/service/DwcaServiceTest.java b/src/test/java/eu/dissco/core/translator/service/DwcaServiceTest.java index ee27014..14d61ee 100644 --- a/src/test/java/eu/dissco/core/translator/service/DwcaServiceTest.java +++ b/src/test/java/eu/dissco/core/translator/service/DwcaServiceTest.java @@ -132,7 +132,7 @@ void testCopyTableFails() throws Exception { // Given givenDWCA("/dwca-rbins.zip"); doThrow(new DisscoRepositoryException("", new Exception())).when(dwcaRepository) - .postRecords(eq("abc_ddd_asd_dwc_occurrence"), anyList()); + .postRecords(eq("temp_abc_ddd_asd_occurrence"), anyList()); // When service.retrieveData(); @@ -229,9 +229,9 @@ void testRetrieveDataWithGbifMedia() throws Exception { // Given givenDWCA("/dwca-kew-gbif-media.zip"); given(dwcaRepository.getCoreRecords(anyList(), anyString())).willReturn(givenSpecimenMap(19)); - given(dwcaRepository.getRecords(anyList(), eq("abc_ddd_asd_dwc_identification"))).willReturn( + given(dwcaRepository.getRecords(anyList(), eq("temp_abc_ddd_asd_identification"))).willReturn( Map.of()); - given(dwcaRepository.getRecords(anyList(), eq("abc_ddd_asd_gbif_multimedia"))).willReturn( + given(dwcaRepository.getRecords(anyList(), eq("temp_abc_ddd_asd_multimedia"))).willReturn( givenImageMap(19)); given(digitalSpecimenDirector.assembleDigitalSpecimenTerm(any(JsonNode.class), anyBoolean())) .willReturn(givenDigitalSpecimen()); @@ -267,7 +267,8 @@ void testRetrieveDataWithAcMedia() throws Exception { // Given givenDWCA("/dwca-naturalis-ac-media.zip"); given(dwcaRepository.getCoreRecords(anyList(), anyString())).willReturn(givenSpecimenMap(14)); - given(dwcaRepository.getRecords(anyList(), eq("abc_ddd_asd_http___rs_tdwg_org_ac_terms_multimedia"))).willReturn(givenImageMap(14)); + given(dwcaRepository.getRecords(anyList(), + eq("temp_abc_ddd_asd_multimedia"))).willReturn(givenImageMap(14)); given(digitalSpecimenDirector.assembleDigitalSpecimenTerm(any(JsonNode.class), anyBoolean())) .willReturn(givenDigitalSpecimen()); given(digitalSpecimenDirector.assembleDigitalMediaObjects(anyBoolean(), any(JsonNode.class), @@ -292,7 +293,7 @@ void testRetrieveDataWithInvalidAcMedia() throws Exception { givenDWCA("/dwca-invalid-ac-media.zip"); given(dwcaRepository.getCoreRecords(anyList(), anyString())).willReturn(givenSpecimenMap(1)); given(dwcaRepository.getRecords(anyList(), - eq("abc_ddd_asd_http___rs_tdwg_org_ac_terms_multimedia"))).willReturn(givenImageMap(1)); + eq("temp_abc_ddd_asd_multimedia"))).willReturn(givenImageMap(1)); given(digitalSpecimenDirector.assembleDigitalSpecimenTerm(any(JsonNode.class), anyBoolean())) .willReturn(givenDigitalSpecimen()); given(digitalSpecimenDirector.assembleDigitalMediaObjects(anyBoolean(), any(JsonNode.class), diff --git a/src/test/java/eu/dissco/core/translator/service/KafkaServiceTest.java b/src/test/java/eu/dissco/core/translator/service/KafkaServiceTest.java index e5ec99e..8097dbf 100644 --- a/src/test/java/eu/dissco/core/translator/service/KafkaServiceTest.java +++ b/src/test/java/eu/dissco/core/translator/service/KafkaServiceTest.java @@ -48,7 +48,8 @@ void testSendMessage() throws JsonProcessingException { service.sendMessage("test-topic", digitalSpecimenEvent); // Then - then(kafkaTemplate).should().send("test-topic", MAPPER.writeValueAsString(digitalSpecimenEvent)); + then(kafkaTemplate).should() + .send("test-topic", MAPPER.writeValueAsString(digitalSpecimenEvent)); } private DigitalSpecimenEvent givenDigitalSpecimenEvent() { diff --git a/src/test/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirectorTest.java b/src/test/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirectorTest.java index c6ddea6..31b9a1b 100644 --- a/src/test/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirectorTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/BiocaseDigitalObjectDirectorTest.java @@ -51,7 +51,8 @@ void setup() { void testConstructAbcdDigitalSpecimen() throws Exception { // Given var specimenJson = givenAbcdSpecimenJson(); - given(institutionNameComponent.getWikiDataName(anyString())).willReturn("Tallinn University of Technology"); + given(institutionNameComponent.getWikiDataName(anyString())).willReturn( + "Tallinn University of Technology"); given(termMapper.retrieveTerm(any(Term.class), eq(specimenJson), eq(false))).willReturn( "a mapped term"); given(termMapper.retrieveTerm(any(OrganisationId.class), eq(specimenJson), eq(false))) diff --git a/src/test/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirectorTest.java b/src/test/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirectorTest.java index c12126e..bca38cf 100644 --- a/src/test/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirectorTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/DwcaDigitalObjectDirectorTest.java @@ -38,7 +38,8 @@ class DwcaDigitalObjectDirectorTest { @BeforeEach void setup() { - director = new DwcaDigitalObjectDirector(MAPPER, termMapper, institutionNameComponent, webClientProperties, + director = new DwcaDigitalObjectDirector(MAPPER, termMapper, institutionNameComponent, + webClientProperties, fdoProperties); } @@ -46,7 +47,8 @@ void setup() { void testConstructDwcaDigitalSpecimen() throws Exception { // Given var specimenJson = givenDwcaSpecimenJson(); - given(institutionNameComponent.getRorName(anyString())).willReturn("National Museum of Natural History"); + given(institutionNameComponent.getRorName(anyString())).willReturn( + "National Museum of Natural History"); given(termMapper.retrieveTerm(any(Term.class), eq(specimenJson), eq(true))).willReturn( "a mapped term"); given(termMapper.retrieveTerm(any(OrganisationId.class), eq(specimenJson), eq(true))) @@ -69,7 +71,8 @@ void testConstructDwcaDigitalSpecimen() throws Exception { void testConstructDwcaDigitalMediaObject() throws JsonProcessingException, OrganisationException { // Given var specimenJson = givenDwcaMediaObject(); - given(institutionNameComponent.getRorName(anyString())).willReturn("National Museum of Natural History"); + given(institutionNameComponent.getRorName(anyString())).willReturn( + "National Museum of Natural History"); given(termMapper.retrieveTerm(any(Term.class), eq(specimenJson), eq(true))).willReturn( "a mapped term"); diff --git a/src/test/java/eu/dissco/core/translator/terms/specimen/DataGeneralizationsTest.java b/src/test/java/eu/dissco/core/translator/terms/specimen/DataGeneralizationsTest.java index 8ee8072..e97474d 100644 --- a/src/test/java/eu/dissco/core/translator/terms/specimen/DataGeneralizationsTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/specimen/DataGeneralizationsTest.java @@ -3,7 +3,6 @@ import static eu.dissco.core.translator.TestUtils.MAPPER; import static org.assertj.core.api.Assertions.assertThat; -import eu.dissco.core.translator.terms.specimen.DataGeneralizations; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; diff --git a/src/test/java/eu/dissco/core/translator/terms/specimen/InformationWithheldTest.java b/src/test/java/eu/dissco/core/translator/terms/specimen/InformationWithheldTest.java index b545fc7..a2c020e 100644 --- a/src/test/java/eu/dissco/core/translator/terms/specimen/InformationWithheldTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/specimen/InformationWithheldTest.java @@ -3,7 +3,6 @@ import static eu.dissco.core.translator.TestUtils.MAPPER; import static org.assertj.core.api.Assertions.assertThat; -import eu.dissco.core.translator.terms.specimen.InformationWithheld; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension;