Skip to content

Commit

Permalink
Merge pull request #51 from DiSSCo/bug-fix/fix-table-names
Browse files Browse the repository at this point in the history
Fix table name and run auto-format
  • Loading branch information
samleeflang authored Dec 12, 2023
2 parents f8b6d4c + da16395 commit 463b7f4
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(".", "_");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> ID_FIELD = DSL.field("dwcaid", String.class);
private static final String TABLE_NAME = "temp_xxx_xxx_xxx_core";
private static final Field<JSONB> 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<String> ID_FIELD = DSL.field("dwcaid", String.class);
private BatchInserter batchInserter;

private static Stream<Arguments> 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(),
Expand All @@ -48,7 +60,7 @@ void setup() throws SQLException {
}

@AfterEach
void destroy(){
void destroy() {
context.dropTableIfExists(getTable(TABLE_NAME)).execute();
}

Expand Down Expand Up @@ -113,26 +125,14 @@ void testBadCharacters() throws Exception {
assertThat(MAPPER.readTree(result.get(DATA_FIELD).data())).isEqualTo(expected);
}

private static Stream<Arguments> 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<Pair<String, JsonNode>> givenCoreRecords() {
var records = new ArrayList<Pair<String, JsonNode>>();
records.add(Pair.of(RECORD_ID, givenJsonNode()));
records.add(Pair.of(RECORD_ID_ALT, MAPPER.createObjectNode()));
return records;
}

private JsonNode givenJsonNode(){
private JsonNode givenJsonNode() {
var node = MAPPER.createObjectNode();
node.put("test", "test");
node.put("data", "value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
@ExtendWith(MockitoExtension.class)
class DwcaRepositoryTest extends BaseRepositoryIT {

private DwcaRepository repository;
@Mock
BatchInserter batchInserter;

private final Field<String> idField = DSL.field("dwcaid", String.class);
private final Field<JSONB> dataField = DSL.field("data", JSONB.class);
@Mock
BatchInserter batchInserter;
private DwcaRepository repository;

private static JsonNode givenRecord(String corruptedValue) {
var objectNode = MAPPER.createObjectNode();
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ class DwcaDigitalObjectDirectorTest {

@BeforeEach
void setup() {
director = new DwcaDigitalObjectDirector(MAPPER, termMapper, institutionNameComponent, webClientProperties,
director = new DwcaDigitalObjectDirector(MAPPER, termMapper, institutionNameComponent,
webClientProperties,
fdoProperties);
}

@Test
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)))
Expand All @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 463b7f4

Please sign in to comment.