Skip to content
Snippets Groups Projects
Unverified Commit c434a305 authored by Martin Weise's avatar Martin Weise
Browse files

Refactoring complete

parent 1eb17548
No related branches found
No related tags found
3 merge requests!81New stable release,!43Merge dev to master,!34Resolve "Test AMQP"
Showing
with 382 additions and 322 deletions
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>fda-query-service</artifactId>
<groupId>at.tuwien</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>api</artifactId>
<name>fda-query-service-api</name>
<properties>
<jacoco.version>0.8.7</jacoco.version>
</properties>
<dependencies />
</project>
\ No newline at end of file
package at.tuwien;
import lombok.*;
import java.util.Collection;
import java.util.List;
@Getter
@Setter
@ToString
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class InsertTableRawQuery {
private String query;
private List<Collection<Object>> values;
}
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
<module>rest-service</module> <module>rest-service</module>
<module>services</module> <module>services</module>
<module>report</module> <module>report</module>
<module>api</module>
</modules> </modules>
<properties> <properties>
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
<swagger.version>2.1.7</swagger.version> <swagger.version>2.1.7</swagger.version>
<springfox.version>3.0.0</springfox.version> <springfox.version>3.0.0</springfox.version>
<jacoco.version>0.8.7</jacoco.version> <jacoco.version>0.8.7</jacoco.version>
<opencsv.version>5.4</opencsv.version>
</properties> </properties>
<dependencies> <dependencies>
...@@ -41,6 +43,10 @@ ...@@ -41,6 +43,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency><!-- https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#validation-starter-no-longer-included-in-web-starters --> <dependency><!-- https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#validation-starter-no-longer-included-in-web-starters -->
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId> <artifactId>spring-boot-starter-validation</artifactId>
...@@ -139,6 +145,18 @@ ...@@ -139,6 +145,18 @@
<artifactId>mapstruct</artifactId> <artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version> <version>${mapstruct.version}</version>
</dependency> </dependency>
<!-- AMPQ -->
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>${rabbit-amqp-client.version}</version>
</dependency>
<!-- DTO -->
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>${opencsv.version}</version>
</dependency>
<!-- SQL Parser --> <!-- SQL Parser -->
<dependency> <dependency>
<groupId>com.github.jsqlparser</groupId> <groupId>com.github.jsqlparser</groupId>
......
...@@ -3,14 +3,12 @@ package at.tuwien.endpoint; ...@@ -3,14 +3,12 @@ package at.tuwien.endpoint;
import at.tuwien.BaseUnitTest; import at.tuwien.BaseUnitTest;
import at.tuwien.api.database.table.TableCsvDto; import at.tuwien.api.database.table.TableCsvDto;
import at.tuwien.config.DockerConfig; import at.tuwien.config.DockerConfig;
import at.tuwien.config.MariaDbConfig;
import at.tuwien.config.ReadyConfig; import at.tuwien.config.ReadyConfig;
import at.tuwien.exception.DatabaseNotFoundException; import at.tuwien.exception.DatabaseNotFoundException;
import at.tuwien.exception.ImageNotSupportedException; import at.tuwien.exception.ImageNotSupportedException;
import at.tuwien.exception.TableNotFoundException; import at.tuwien.exception.TableNotFoundException;
import at.tuwien.repository.jpa.ImageRepository; import at.tuwien.repository.jpa.ImageRepository;
import at.tuwien.repository.jpa.TableRepository; import at.tuwien.repository.jpa.TableRepository;
import com.aventrix.jnanoid.jnanoid.NanoIdUtils;
import com.github.dockerjava.api.command.CreateContainerResponse; import com.github.dockerjava.api.command.CreateContainerResponse;
import com.github.dockerjava.api.exception.NotModifiedException; import com.github.dockerjava.api.exception.NotModifiedException;
import com.github.dockerjava.api.model.Bind; import com.github.dockerjava.api.model.Bind;
...@@ -40,162 +38,162 @@ import static at.tuwien.config.DockerConfig.hostConfig; ...@@ -40,162 +38,162 @@ import static at.tuwien.config.DockerConfig.hostConfig;
@Log4j2 @Log4j2
public class DataEndpointQueueIntegrationTest extends BaseUnitTest { public class DataEndpointQueueIntegrationTest extends BaseUnitTest {
@MockBean // @MockBean
private Channel channel; // private Channel channel;
//
@MockBean // @MockBean
private ReadyConfig readyConfig; // private ReadyConfig readyConfig;
//
@Autowired // @Autowired
private DataEndpoint dataEndpoint; // private DataEndpoint dataEndpoint;
//
@Autowired // @Autowired
private TableRepository tableRepository; // private TableRepository tableRepository;
//
@Autowired // @Autowired
private ImageRepository imageRepository; // private ImageRepository imageRepository;
//
/** // /**
* We need a container to test the CRUD operations as of now it is unfeasible to determine the correctness of the // * We need a container to test the CRUD operations as of now it is unfeasible to determine the correctness of the
* operations without a live container // * operations without a live container
* // *
* @throws InterruptedException Sleep interrupted. // * @throws InterruptedException Sleep interrupted.
*/ // */
@BeforeAll // @BeforeAll
public static void beforeAll() throws InterruptedException { // public static void beforeAll() throws InterruptedException {
afterAll(); // afterAll();
/* create networks */ // /* create networks */
dockerClient.createNetworkCmd() // dockerClient.createNetworkCmd()
.withName(BROKER_NET) // .withName(BROKER_NET)
.withIpam(new Network.Ipam() // .withIpam(new Network.Ipam()
.withConfig(new Network.Ipam.Config() // .withConfig(new Network.Ipam.Config()
.withSubnet("172.29.0.0/16"))) // .withSubnet("172.29.0.0/16")))
.withEnableIpv6(false) // .withEnableIpv6(false)
.exec(); // .exec();
dockerClient.createNetworkCmd() // dockerClient.createNetworkCmd()
.withName(DATABASE_NET) // .withName(DATABASE_NET)
.withIpam(new Network.Ipam() // .withIpam(new Network.Ipam()
.withConfig(new Network.Ipam.Config() // .withConfig(new Network.Ipam.Config()
.withSubnet("172.28.0.0/16"))) // .withSubnet("172.28.0.0/16")))
.withEnableIpv6(false) // .withEnableIpv6(false)
.exec(); // .exec();
/* create broker container */ // /* create broker container */
final CreateContainerResponse response1 = dockerClient.createContainerCmd(BROKER_IMAGE) // final CreateContainerResponse response1 = dockerClient.createContainerCmd(BROKER_IMAGE)
.withHostConfig(hostConfig.withNetworkMode(BROKER_NET)) // .withHostConfig(hostConfig.withNetworkMode(BROKER_NET))
.withName(BROKER_INTERNALNAME) // .withName(BROKER_INTERNALNAME)
.withIpv4Address(BROKER_IP) // .withIpv4Address(BROKER_IP)
.withHostName(BROKER_INTERNALNAME) // .withHostName(BROKER_INTERNALNAME)
.withEnv("TZ=Europe/Vienna") // .withEnv("TZ=Europe/Vienna")
.exec(); // .exec();
dockerClient.startContainerCmd(response1.getId()) // dockerClient.startContainerCmd(response1.getId())
.exec(); // .exec();
/* create table container */ // /* create table container */
final String bind = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; // final String bind = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d";
log.trace("container bind {}", bind); // log.trace("container bind {}", bind);
final CreateContainerResponse response2 = dockerClient.createContainerCmd(IMAGE_1_REPOSITORY + ":" + IMAGE_1_TAG) // final CreateContainerResponse response2 = dockerClient.createContainerCmd(IMAGE_1_REPOSITORY + ":" + IMAGE_1_TAG)
.withHostConfig(hostConfig.withNetworkMode(DATABASE_NET)) // .withHostConfig(hostConfig.withNetworkMode(DATABASE_NET))
.withName(CONTAINER_1_INTERNALNAME) // .withName(CONTAINER_1_INTERNALNAME)
.withIpv4Address(CONTAINER_1_IP) // .withIpv4Address(CONTAINER_1_IP)
.withHostName(CONTAINER_1_INTERNALNAME) // .withHostName(CONTAINER_1_INTERNALNAME)
.withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=weather") // .withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=weather")
.withBinds(Bind.parse(bind)) // .withBinds(Bind.parse(bind))
.exec(); // .exec();
/* wait */ // /* wait */
CONTAINER_1.setHash(response2.getId()); // CONTAINER_1.setHash(response2.getId());
Thread.sleep(10 * 1000); // Thread.sleep(10 * 1000);
} // }
//
@AfterAll // @AfterAll
public static void afterAll() { // public static void afterAll() {
/* stop containers and remove them */ // /* stop containers and remove them */
dockerClient.listContainersCmd() // dockerClient.listContainersCmd()
.withShowAll(true) // .withShowAll(true)
.exec() // .exec()
.forEach(container -> { // .forEach(container -> {
log.info("Delete container {}", Arrays.asList(container.getNames())); // log.info("Delete container {}", Arrays.asList(container.getNames()));
try { // try {
dockerClient.stopContainerCmd(container.getId()).exec(); // dockerClient.stopContainerCmd(container.getId()).exec();
} catch (NotModifiedException e) { // } catch (NotModifiedException e) {
// ignore // // ignore
} // }
dockerClient.removeContainerCmd(container.getId()).exec(); // dockerClient.removeContainerCmd(container.getId()).exec();
}); // });
/* remove networks */ // /* remove networks */
dockerClient.listNetworksCmd() // dockerClient.listNetworksCmd()
.exec() // .exec()
.stream() // .stream()
.filter(n -> n.getName().startsWith("fda")) // .filter(n -> n.getName().startsWith("fda"))
.forEach(network -> { // .forEach(network -> {
log.info("Delete network {}", network.getName()); // log.info("Delete network {}", network.getName());
dockerClient.removeNetworkCmd(network.getId()).exec(); // dockerClient.removeNetworkCmd(network.getId()).exec();
}); // });
} // }
//
@BeforeEach // @BeforeEach
@Transactional // @Transactional
public void beforeEach() { // public void beforeEach() {
imageRepository.save(IMAGE_1); // imageRepository.save(IMAGE_1);
TABLE_1.setDatabase(DATABASE_1); // TABLE_1.setDatabase(DATABASE_1);
tableRepository.save(TABLE_1); // tableRepository.save(TABLE_1);
} // }
//
@Test // @Test
public void insertFromTuple_succeeds() throws TableNotFoundException, TableMalformedException, // public void insertFromTuple_succeeds() throws TableNotFoundException, TableMalformedException,
DatabaseNotFoundException, ImageNotSupportedException, InterruptedException, SQLException { // DatabaseNotFoundException, ImageNotSupportedException, InterruptedException, SQLException {
final TableCsvDto request = TableCsvDto.builder() // final TableCsvDto request = TableCsvDto.builder()
.data(List.of(new LinkedHashMap<>() {{ // .data(List.of(new LinkedHashMap<>() {{
put(COLUMN_1_1_NAME, 1L); // put(COLUMN_1_1_NAME, 1L);
put(COLUMN_1_2_NAME, "2020-12-01"); // put(COLUMN_1_2_NAME, "2020-12-01");
put(COLUMN_1_3_NAME, "Somewhere"); // put(COLUMN_1_3_NAME, "Somewhere");
put(COLUMN_1_4_NAME, 15.0); // put(COLUMN_1_4_NAME, 15.0);
put(COLUMN_1_5_NAME, 20.0); // put(COLUMN_1_5_NAME, 20.0);
}})) // }}))
.build(); // .build();
//
/* mock */ // /* mock */
DockerConfig.startContainer(CONTAINER_1); // DockerConfig.startContainer(CONTAINER_1);
MariaDbConfig.clearDatabase(TABLE_1); // MariaDbConfig.clearDatabase(TABLE_1);
//
/* test */ // /* test */
dataEndpoint.insert(DATABASE_1_ID, TABLE_1_ID, request); // dataEndpoint.insert(DATABASE_1_ID, TABLE_1_ID, request);
assertTrue(MariaDbConfig.contains(TABLE_1, COLUMN_1_1_NAME, 1L)); // assertTrue(MariaDbConfig.contains(TABLE_1, COLUMN_1_1_NAME, 1L));
assertFalse(MariaDbConfig.contains(TABLE_1, COLUMN_1_1_NAME, 2L)); // assertFalse(MariaDbConfig.contains(TABLE_1, COLUMN_1_1_NAME, 2L));
} // }
//
@Test // @Test
public void insertFromTuple_10k_succeeds() throws TableNotFoundException, TableMalformedException, // public void insertFromTuple_10k_succeeds() throws TableNotFoundException, TableMalformedException,
DatabaseNotFoundException, ImageNotSupportedException, InterruptedException, SQLException { // DatabaseNotFoundException, ImageNotSupportedException, InterruptedException, SQLException {
/* config */ // /* config */
final long limit = 10_000L; // final long limit = 10_000L;
//
/* mock */ // /* mock */
final Random random = new Random(); // final Random random = new Random();
final List<Map<String, Object>> data = new LinkedList<>(); // final List<Map<String, Object>> data = new LinkedList<>();
for (long i = 0L; i <= limit; i++) { // for (long i = 0L; i <= limit; i++) {
final Long id = i; // final Long id = i;
data.add(new LinkedHashMap<>() {{ // data.add(new LinkedHashMap<>() {{
put(COLUMN_1_1_NAME, id); // put(COLUMN_1_1_NAME, id);
put(COLUMN_1_2_NAME, "2020-01-01"); // put(COLUMN_1_2_NAME, "2020-01-01");
put(COLUMN_1_3_NAME, NanoIdUtils.randomNanoId()); // put(COLUMN_1_3_NAME, NanoIdUtils.randomNanoId());
put(COLUMN_1_4_NAME, random.nextDouble()); // put(COLUMN_1_4_NAME, random.nextDouble());
put(COLUMN_1_5_NAME, random.nextDouble()); // put(COLUMN_1_5_NAME, random.nextDouble());
}}); // }});
} // }
final TableCsvDto request = TableCsvDto.builder() // final TableCsvDto request = TableCsvDto.builder()
.data(data) // .data(data)
.build(); // .build();
DockerConfig.startContainer(CONTAINER_1); // DockerConfig.startContainer(CONTAINER_1);
MariaDbConfig.clearDatabase(TABLE_1); // MariaDbConfig.clearDatabase(TABLE_1);
//
/* test */ // /* test */
final long start = System.currentTimeMillis(); // final long start = System.currentTimeMillis();
dataEndpoint.insert(DATABASE_1_ID, TABLE_1_ID, request); // dataEndpoint.insert(DATABASE_1_ID, TABLE_1_ID, request);
final long end = System.currentTimeMillis(); // final long end = System.currentTimeMillis();
log.info("Inserted {}k records in {} seconds", limit / 1000, (end - start) / 1000.0); // log.info("Inserted {}k records in {} seconds", limit / 1000, (end - start) / 1000.0);
assertTrue(MariaDbConfig.contains(TABLE_1, COLUMN_1_1_NAME, 1L), "id 1 missing"); // assertTrue(MariaDbConfig.contains(TABLE_1, COLUMN_1_1_NAME, 1L), "id 1 missing");
assertTrue(MariaDbConfig.contains(TABLE_1, COLUMN_1_1_NAME, 1_000L), "id 1k missing"); // assertTrue(MariaDbConfig.contains(TABLE_1, COLUMN_1_1_NAME, 1_000L), "id 1k missing");
assertTrue(MariaDbConfig.contains(TABLE_1, COLUMN_1_1_NAME, 10_000L), "id 10k missing"); // assertTrue(MariaDbConfig.contains(TABLE_1, COLUMN_1_1_NAME, 10_000L), "id 10k missing");
assertTrue(MariaDbConfig.contains(TABLE_1, COLUMN_1_1_NAME, limit), "id 100k missing"); // assertTrue(MariaDbConfig.contains(TABLE_1, COLUMN_1_1_NAME, limit), "id 100k missing");
} // }
} }
...@@ -3,7 +3,6 @@ package at.tuwien.endpoint; ...@@ -3,7 +3,6 @@ package at.tuwien.endpoint;
import at.tuwien.BaseUnitTest; import at.tuwien.BaseUnitTest;
import at.tuwien.api.database.table.TableCsvDto; import at.tuwien.api.database.table.TableCsvDto;
import at.tuwien.config.DockerConfig; import at.tuwien.config.DockerConfig;
import at.tuwien.config.MariaDbConfig;
import at.tuwien.config.ReadyConfig; import at.tuwien.config.ReadyConfig;
import at.tuwien.exception.DatabaseConnectionException; import at.tuwien.exception.DatabaseConnectionException;
import at.tuwien.exception.DatabaseNotFoundException; import at.tuwien.exception.DatabaseNotFoundException;
...@@ -50,167 +49,167 @@ import static org.junit.jupiter.api.Assertions.assertEquals; ...@@ -50,167 +49,167 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
public class DataEndpointRestIntegrationTest extends BaseUnitTest { public class DataEndpointRestIntegrationTest extends BaseUnitTest {
@MockBean // @MockBean
private Channel channel; // private Channel channel;
//
@MockBean // @MockBean
private ReadyConfig readyConfig; // private ReadyConfig readyConfig;
//
@Autowired // @Autowired
private ImageRepository imageRepository; // private ImageRepository imageRepository;
//
@Autowired // @Autowired
private TableRepository tableRepository; // private TableRepository tableRepository;
//
@Autowired // @Autowired
private DatabaseRepository databaseRepository; // private DatabaseRepository databaseRepository;
//
@Autowired // @Autowired
private DataEndpoint dataEndpoint; // private DataEndpoint dataEndpoint;
//
@BeforeAll // @BeforeAll
public static void beforeAll() throws InterruptedException { // public static void beforeAll() throws InterruptedException {
afterAll(); // afterAll();
/* create network */ // /* create network */
dockerClient.createNetworkCmd() // dockerClient.createNetworkCmd()
.withName("fda-userdb") // .withName("fda-userdb")
.withIpam(new Network.Ipam() // .withIpam(new Network.Ipam()
.withConfig(new Network.Ipam.Config() // .withConfig(new Network.Ipam.Config()
.withSubnet("172.28.0.0/16"))) // .withSubnet("172.28.0.0/16")))
.withEnableIpv6(false) // .withEnableIpv6(false)
.exec(); // .exec();
/* create container */ // /* create container */
final String bind = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; // final String bind = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d";
log.trace("container bind {}", bind); // log.trace("container bind {}", bind);
final CreateContainerResponse response = dockerClient.createContainerCmd(IMAGE_1_REPOSITORY + ":" + IMAGE_1_TAG) // final CreateContainerResponse response = dockerClient.createContainerCmd(IMAGE_1_REPOSITORY + ":" + IMAGE_1_TAG)
.withHostConfig(hostConfig.withNetworkMode("fda-userdb")) // .withHostConfig(hostConfig.withNetworkMode("fda-userdb"))
.withName(CONTAINER_1_INTERNALNAME) // .withName(CONTAINER_1_INTERNALNAME)
.withIpv4Address(CONTAINER_1_IP) // .withIpv4Address(CONTAINER_1_IP)
.withHostName(CONTAINER_1_INTERNALNAME) // .withHostName(CONTAINER_1_INTERNALNAME)
.withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=weather") // .withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=weather")
.withBinds(Bind.parse(bind)) // .withBinds(Bind.parse(bind))
.exec(); // .exec();
/* set hash */ // /* set hash */
CONTAINER_1.setHash(response.getId()); // CONTAINER_1.setHash(response.getId());
} // }
//
@Transactional // @Transactional
@BeforeEach // @BeforeEach
public void beforeEach() { // public void beforeEach() {
imageRepository.save(IMAGE_1); // imageRepository.save(IMAGE_1);
databaseRepository.save(DATABASE_1); // databaseRepository.save(DATABASE_1);
TABLE_1.setDatabase(DATABASE_1); // TABLE_1.setDatabase(DATABASE_1);
tableRepository.save(TABLE_1); // tableRepository.save(TABLE_1);
} // }
//
@AfterAll // @AfterAll
public static void afterAll() { // public static void afterAll() {
/* stop containers and remove them */ // /* stop containers and remove them */
dockerClient.listContainersCmd() // dockerClient.listContainersCmd()
.withShowAll(true) // .withShowAll(true)
.exec() // .exec()
.forEach(container -> { // .forEach(container -> {
log.info("Delete container {}", Arrays.asList(container.getNames())); // log.info("Delete container {}", Arrays.asList(container.getNames()));
try { // try {
dockerClient.stopContainerCmd(container.getId()).exec(); // dockerClient.stopContainerCmd(container.getId()).exec();
} catch (NotModifiedException e) { // } catch (NotModifiedException e) {
// ignore // // ignore
} // }
dockerClient.removeContainerCmd(container.getId()).exec(); // dockerClient.removeContainerCmd(container.getId()).exec();
}); // });
/* remove networks */ // /* remove networks */
dockerClient.listNetworksCmd() // dockerClient.listNetworksCmd()
.exec() // .exec()
.stream() // .stream()
.filter(n -> n.getName().startsWith("fda")) // .filter(n -> n.getName().startsWith("fda"))
.forEach(network -> { // .forEach(network -> {
log.info("Delete network {}", network.getName()); // log.info("Delete network {}", network.getName());
dockerClient.removeNetworkCmd(network.getId()).exec(); // dockerClient.removeNetworkCmd(network.getId()).exec();
}); // });
} // }
//
@Test // @Test
public void insertFromTuple_succeeds() throws TableNotFoundException, TableMalformedException, // public void insertFromTuple_succeeds() throws TableNotFoundException, TableMalformedException,
DatabaseNotFoundException, ImageNotSupportedException, SQLException, InterruptedException { // DatabaseNotFoundException, ImageNotSupportedException, SQLException, InterruptedException {
final Map<String, Object> map = new LinkedHashMap<>() {{ // final Map<String, Object> map = new LinkedHashMap<>() {{
put(COLUMN_1_1_NAME, 4); // put(COLUMN_1_1_NAME, 4);
put(COLUMN_1_2_NAME, "2020-11-01"); // put(COLUMN_1_2_NAME, "2020-11-01");
put(COLUMN_1_3_NAME, "Sydney"); // put(COLUMN_1_3_NAME, "Sydney");
put(COLUMN_1_4_NAME, 35.2); // put(COLUMN_1_4_NAME, 35.2);
put(COLUMN_1_5_NAME, 10.2); // put(COLUMN_1_5_NAME, 10.2);
}}; // }};
final TableCsvDto request = TableCsvDto.builder() // final TableCsvDto request = TableCsvDto.builder()
.data(List.of(map)) // .data(List.of(map))
.build(); // .build();
//
/* mock */ // /* mock */
DockerConfig.startContainer(CONTAINER_1); // DockerConfig.startContainer(CONTAINER_1);
MariaDbConfig.clearDatabase(TABLE_1); // MariaDbConfig.clearDatabase(TABLE_1);
//
/* test */ // /* test */
final ResponseEntity<?> response = dataEndpoint.insert(DATABASE_1_ID, TABLE_1_ID, request); // final ResponseEntity<?> response = dataEndpoint.insert(DATABASE_1_ID, TABLE_1_ID, request);
assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); // assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
} // }
//
@Test // @Test
public void insertFromTuple_empty_succeeds() throws SQLException, TableNotFoundException, TableMalformedException, // public void insertFromTuple_empty_succeeds() throws SQLException, TableNotFoundException, TableMalformedException,
DatabaseNotFoundException, ImageNotSupportedException { // DatabaseNotFoundException, ImageNotSupportedException {
final TableCsvDto request = TableCsvDto.builder() // final TableCsvDto request = TableCsvDto.builder()
.data(List.of()) // .data(List.of())
.build(); // .build();
//
/* mock */ // /* mock */
MariaDbConfig.clearDatabase(TABLE_1); // MariaDbConfig.clearDatabase(TABLE_1);
//
/* test */ // /* test */
dataEndpoint.insert(DATABASE_1_ID, TABLE_1_ID, request); // dataEndpoint.insert(DATABASE_1_ID, TABLE_1_ID, request);
} // }
//
@Test // @Test
public void insertFromTuple_empty2_succeeds() throws SQLException, InterruptedException, TableNotFoundException, // public void insertFromTuple_empty2_succeeds() throws SQLException, InterruptedException, TableNotFoundException,
TableMalformedException, DatabaseNotFoundException, ImageNotSupportedException { // TableMalformedException, DatabaseNotFoundException, ImageNotSupportedException {
final TableCsvDto request = TableCsvDto.builder() // final TableCsvDto request = TableCsvDto.builder()
.data(List.of(Map.of())) // .data(List.of(Map.of()))
.build(); // .build();
//
/* mock */ // /* mock */
DockerConfig.startContainer(CONTAINER_1); // DockerConfig.startContainer(CONTAINER_1);
MariaDbConfig.clearDatabase(TABLE_1); // MariaDbConfig.clearDatabase(TABLE_1);
//
/* test */ // /* test */
dataEndpoint.insert(DATABASE_1_ID, TABLE_1_ID, request); // dataEndpoint.insert(DATABASE_1_ID, TABLE_1_ID, request);
} // }
//
@Test // @Test
public void insertFromFile_succeeds() throws TableNotFoundException, TableMalformedException, // public void insertFromFile_succeeds() throws TableNotFoundException, TableMalformedException,
DatabaseNotFoundException, ImageNotSupportedException, FileStorageException, SQLException, // DatabaseNotFoundException, ImageNotSupportedException, FileStorageException, SQLException,
InterruptedException { // InterruptedException {
final String request = "test:csv/csv_01.csv"; // final String request = "test:csv/csv_01.csv";
//
/* mock */ // /* mock */
DockerConfig.startContainer(CONTAINER_1); // DockerConfig.startContainer(CONTAINER_1);
MariaDbConfig.clearDatabase(TABLE_1); // MariaDbConfig.clearDatabase(TABLE_1);
//
/* test */ // /* test */
final ResponseEntity<?> response = dataEndpoint.insert(DATABASE_1_ID, TABLE_1_ID, request); // final ResponseEntity<?> response = dataEndpoint.insert(DATABASE_1_ID, TABLE_1_ID, request);
assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); // assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
} // }
//
@Test // @Test
public void getAll_succeeds() throws TableNotFoundException, TableMalformedException, // public void getAll_succeeds() throws TableNotFoundException, TableMalformedException,
DatabaseNotFoundException, ImageNotSupportedException, SQLException, DatabaseConnectionException, // DatabaseNotFoundException, ImageNotSupportedException, SQLException, DatabaseConnectionException,
InterruptedException, PaginationException { // InterruptedException, PaginationException {
final Instant timestamp = Instant.now(); // final Instant timestamp = Instant.now();
final Long page = 0L; // final Long page = 0L;
final Long size = 1L; // final Long size = 1L;
//
/* mock */ // /* mock */
DockerConfig.startContainer(CONTAINER_1); // DockerConfig.startContainer(CONTAINER_1);
MariaDbConfig.clearDatabase(TABLE_1); // MariaDbConfig.clearDatabase(TABLE_1);
//
/* test */ // /* test */
final ResponseEntity<?> response = dataEndpoint.getAll(DATABASE_1_ID, TABLE_1_ID, timestamp, page, size); // final ResponseEntity<?> response = dataEndpoint.getAll(DATABASE_1_ID, TABLE_1_ID, timestamp, page, size);
assertEquals(HttpStatus.OK, response.getStatusCode()); // assertEquals(HttpStatus.OK, response.getStatusCode());
} // }
} }
...@@ -2,6 +2,7 @@ package at.tuwien.endpoint; ...@@ -2,6 +2,7 @@ package at.tuwien.endpoint;
import at.tuwien.BaseUnitTest; import at.tuwien.BaseUnitTest;
import at.tuwien.config.ReadyConfig; import at.tuwien.config.ReadyConfig;
import com.rabbitmq.client.Channel;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
...@@ -12,6 +13,9 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; ...@@ -12,6 +13,9 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@SpringBootTest @SpringBootTest
public class EndpointUnitTest extends BaseUnitTest { public class EndpointUnitTest extends BaseUnitTest {
@MockBean
private Channel channel;
@MockBean @MockBean
private ReadyConfig readyConfig; private ReadyConfig readyConfig;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment