From 494b62f0af46d340f4fcd65e7ce0eb7c0c579ec1 Mon Sep 17 00:00:00 2001 From: Martin Weise <martin.weise@tuwien.ac.at> Date: Thu, 30 Sep 2021 21:22:50 +0200 Subject: [PATCH] okay stopping now, coverage is good --- .../endpoint/DataEndpointIntegrationTest.java | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/DataEndpointIntegrationTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/DataEndpointIntegrationTest.java index 26cb329826..ef40a34714 100644 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/DataEndpointIntegrationTest.java +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/DataEndpointIntegrationTest.java @@ -2,6 +2,7 @@ package at.tuwien.endpoint; import at.tuwien.BaseUnitTest; import at.tuwien.api.database.table.*; +import at.tuwien.config.PostgresConfig; import at.tuwien.config.ReadyConfig; import at.tuwien.endpoints.DataEndpoint; import at.tuwien.exception.*; @@ -30,6 +31,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import javax.transaction.Transactional; import java.io.File; +import java.sql.SQLException; import java.time.Instant; import java.util.*; @@ -124,7 +126,7 @@ public class DataEndpointIntegrationTest extends BaseUnitTest { @Test public void insertFromTuple_succeeds() throws TableNotFoundException, TableMalformedException, - DatabaseNotFoundException, ImageNotSupportedException { + DatabaseNotFoundException, ImageNotSupportedException, SQLException { final Map<String, Object> map = new LinkedHashMap<>() {{ put(COLUMN_1_NAME, 4); put(COLUMN_2_NAME, Instant.now()); @@ -136,17 +138,23 @@ public class DataEndpointIntegrationTest extends BaseUnitTest { .data(List.of(map)) .build(); + /* mock */ + PostgresConfig.clearDatabase(); + /* test */ final ResponseEntity<?> response = dataEndpoint.insertFromTuple(DATABASE_1_ID, TABLE_1_ID, request); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); } @Test - public void insertFromTuple_empty_fails() { + public void insertFromTuple_empty_fails() throws SQLException { final TableCsvDto request = TableCsvDto.builder() .data(List.of()) .build(); + /* mock */ + PostgresConfig.clearDatabase(); + /* test */ assertThrows(TableMalformedException.class, () -> { dataEndpoint.insertFromTuple(DATABASE_1_ID, TABLE_1_ID, request); @@ -154,15 +162,51 @@ public class DataEndpointIntegrationTest extends BaseUnitTest { } @Test - public void insertFromTuple_empty2_fails() { + public void insertFromTuple_empty2_fails() throws SQLException { final TableCsvDto request = TableCsvDto.builder() .data(List.of(Map.of())) .build(); + /* mock */ + PostgresConfig.clearDatabase(); + /* test */ assertThrows(TableMalformedException.class, () -> { dataEndpoint.insertFromTuple(DATABASE_1_ID, TABLE_1_ID, request); }); } + @Test + public void insertFromFile_succeeds() throws TableNotFoundException, TableMalformedException, + DatabaseNotFoundException, ImageNotSupportedException, FileStorageException, SQLException { + final TableInsertDto request = TableInsertDto.builder() + .delimiter(',') + .skipHeader(true) + .nullElement("NA") + .csvLocation("test:src/test/resources/csv/csv_01.csv") + .build(); + + /* mock */ + PostgresConfig.clearDatabase(); + + /* test */ + final ResponseEntity<?> response = dataEndpoint.insertFromFile(DATABASE_1_ID, TABLE_1_ID, request); + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + } + + @Test + public void getAll_succeeds() throws TableNotFoundException, TableMalformedException, + DatabaseNotFoundException, ImageNotSupportedException, SQLException, DatabaseConnectionException { + final Instant timestamp = Instant.now(); + final Long page = 0L; + final Long size = 1L; + + /* mock */ + PostgresConfig.clearDatabase(); + + /* test */ + final ResponseEntity<?> response = dataEndpoint.getAll(DATABASE_1_ID, TABLE_1_ID, timestamp, page, size); + assertEquals(HttpStatus.OK, response.getStatusCode()); + } + } -- GitLab