diff --git a/fda-database-service/rest-service/src/test/java/at/tuwien/endpoint/EndpointUnitTest.java b/fda-database-service/rest-service/src/test/java/at/tuwien/endpoint/EndpointUnitTest.java index c8cbfd1d4d4f7bfdb686e4c2873c64e7ba92f997..99c6aa4a7be90482e2353bea61e1bc9fe12c2c4e 100644 --- a/fda-database-service/rest-service/src/test/java/at/tuwien/endpoint/EndpointUnitTest.java +++ b/fda-database-service/rest-service/src/test/java/at/tuwien/endpoint/EndpointUnitTest.java @@ -9,6 +9,7 @@ import at.tuwien.config.DockerConfig; import at.tuwien.config.ReadyConfig; import at.tuwien.endpoints.DatabaseEndpoint; import at.tuwien.exception.*; +import at.tuwien.repository.jpa.DatabaseRepository; import at.tuwien.service.DatabaseService; import com.github.dockerjava.api.DockerClient; import com.github.dockerjava.api.command.CreateContainerResponse; @@ -16,8 +17,10 @@ import com.github.dockerjava.api.exception.ConflictException; import com.github.dockerjava.api.exception.NotModifiedException; import com.github.dockerjava.api.model.HostConfig; import com.github.dockerjava.api.model.Network; +import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -25,16 +28,15 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit.jupiter.SpringExtension; -import java.nio.channels.Channel; import java.util.Arrays; import java.util.List; import java.util.Objects; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Mockito.after; import static org.mockito.Mockito.when; +@Log4j2 @SpringBootTest @ExtendWith(SpringExtension.class) public class EndpointUnitTest extends BaseUnitTest { @@ -42,15 +44,18 @@ public class EndpointUnitTest extends BaseUnitTest { @MockBean private ReadyConfig readyConfig; - @MockBean - private Channel channel; - @MockBean private DatabaseService databaseService; @Autowired private DatabaseEndpoint databaseEndpoint; + @MockBean + private RabbitTemplate rabbitTemplate; + + @MockBean + private DatabaseRepository databaseRepository; + @BeforeAll public static void beforeAll() throws InterruptedException { afterAll(); @@ -79,7 +84,8 @@ public class EndpointUnitTest extends BaseUnitTest { .withIpv4Address(BROKER_IP) .withHostName(BROKER_HOSTNAME) .exec(); - dockerClient.startContainerCmd(request.getId()).exec(); + dockerClient.startContainerCmd(request.getId()) + .exec(); Thread.sleep(5 * 1000); } @@ -92,7 +98,7 @@ public class EndpointUnitTest extends BaseUnitTest { .withShowAll(true) .exec() .forEach(container -> { - System.out.println("DELETE CONTAINER " + Arrays.toString(container.getNames())); + log.debug("Delete container " + Arrays.toString(container.getNames())); try { dockerClient.stopContainerCmd(container.getId()).exec(); } catch (NotModifiedException e) { @@ -110,7 +116,7 @@ public class EndpointUnitTest extends BaseUnitTest { .stream() .filter(n -> n.getName().startsWith("fda")) .forEach(network -> { - System.out.println("DELETE NETWORK " + network.getName()); + log.debug("Delete network " + network.getName()); dockerClient.removeNetworkCmd(network.getId()).exec(); }); } diff --git a/fda-database-service/rest-service/src/test/java/at/tuwien/service/AmqpServiceIntegrationTest.java b/fda-database-service/rest-service/src/test/java/at/tuwien/service/AmqpServiceIntegrationTest.java index 24b0c5165b24fba5438cd6c9c18e9da2f716e096..d7e6e1547f810de556b9d1faa9fc863110866f30 100644 --- a/fda-database-service/rest-service/src/test/java/at/tuwien/service/AmqpServiceIntegrationTest.java +++ b/fda-database-service/rest-service/src/test/java/at/tuwien/service/AmqpServiceIntegrationTest.java @@ -48,6 +48,7 @@ public class AmqpServiceIntegrationTest extends BaseUnitTest { @BeforeAll public static void beforeAll() throws InterruptedException { + afterAll(); final DockerConfig dockerConfig = new DockerConfig(); final HostConfig hostConfig = dockerConfig.hostConfig(); final DockerClient dockerClient = dockerConfig.dockerClientConfiguration(); diff --git a/fda-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceIntegrationTest.java b/fda-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceIntegrationTest.java index 80685dec1767697a718f6438dfa119364175ba5c..21445900ecfb98b4a73e2970c510b358ba343a5c 100644 --- a/fda-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceIntegrationTest.java +++ b/fda-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceIntegrationTest.java @@ -75,7 +75,7 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest { private CreateContainerResponse response1; @BeforeAll - public static void beforeAll() { + public static void beforeAll() throws InterruptedException { afterAll(); final DockerConfig dockerConfig = new DockerConfig(); final HostConfig hostConfig = dockerConfig.hostConfig(); @@ -112,6 +112,7 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest { .exec(); /* start container */ dockerClient.startContainerCmd(request.getId()).exec(); + Thread.sleep(5 * 1000); } @AfterAll diff --git a/fda-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceUnitTest.java b/fda-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceUnitTest.java index f8fb0d233feac378042ed24a41c5bb79129d73f3..188f6c7d0ee2efa2d9d9758dbd237635eabddd52 100644 --- a/fda-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceUnitTest.java +++ b/fda-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceUnitTest.java @@ -53,6 +53,7 @@ public class DatabaseServiceUnitTest extends BaseUnitTest { @BeforeAll public static void beforeAll() throws InterruptedException { + afterAll(); final DockerConfig dockerConfig = new DockerConfig(); final HostConfig hostConfig = dockerConfig.hostConfig(); final DockerClient dockerClient = dockerConfig.dockerClientConfiguration(); diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java index d342dfbfc03fb059d6939ebe2ce95001ef4150d4..037ef13738d805e8f4b4b6076ee185085353ca59 100644 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java @@ -65,6 +65,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { public final static ColumnTypeDto COLUMN_1_1_TYPE_DTO = ColumnTypeDto.NUMBER; public final static Boolean COLUMN_1_1_NULL = false; public final static Boolean COLUMN_1_1_UNIQUE = true; + public final static Boolean COLUMN_1_1_AUTO_GENERATED = false; public final static String COLUMN_1_1_FOREIGN_KEY = null; public final static String COLUMN_1_1_CHECK = null; public final static List<String> COLUMN_1_1_ENUM_VALUES = null; @@ -78,6 +79,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { public final static ColumnTypeDto COLUMN_1_2_TYPE_DTO = ColumnTypeDto.DATE; public final static Boolean COLUMN_1_2_NULL = true; public final static Boolean COLUMN_1_2_UNIQUE = false; + public final static Boolean COLUMN_1_2_AUTO_GENERATED = false; public final static String COLUMN_1_2_FOREIGN_KEY = null; public final static String COLUMN_1_2_CHECK = null; public final static List<String> COLUMN_1_2_ENUM_VALUES = null; @@ -91,6 +93,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { public final static ColumnTypeDto COLUMN_1_3_TYPE_DTO = ColumnTypeDto.STRING; public final static Boolean COLUMN_1_3_NULL = true; public final static Boolean COLUMN_1_3_UNIQUE = false; + public final static Boolean COLUMN_1_3_AUTO_GENERATED = false; public final static String COLUMN_1_3_FOREIGN_KEY = null; public final static String COLUMN_1_3_CHECK = null; public final static List<String> COLUMN_1_3_ENUM_VALUES = null; @@ -104,6 +107,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { public final static ColumnTypeDto COLUMN_1_4_TYPE_DTO = ColumnTypeDto.STRING; public final static Boolean COLUMN_1_4_NULL = true; public final static Boolean COLUMN_1_4_UNIQUE = false; + public final static Boolean COLUMN_1_4_AUTO_GENERATED = false; public final static String COLUMN_1_4_FOREIGN_KEY = null; public final static String COLUMN_1_4_CHECK = null; public final static List<String> COLUMN_1_4_ENUM_VALUES = null; @@ -117,6 +121,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { public final static ColumnTypeDto COLUMN_1_5_TYPE_DTO = ColumnTypeDto.NUMBER; public final static Boolean COLUMN_1_5_NULL = true; public final static Boolean COLUMN_1_5_UNIQUE = false; + public final static Boolean COLUMN_1_5_AUTO_GENERATED = false; public final static String COLUMN_1_5_FOREIGN_KEY = null; public final static String COLUMN_1_5_CHECK = null; public final static List<String> COLUMN_1_5_ENUM_VALUES = null; @@ -130,6 +135,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { public final static ColumnTypeDto COLUMN_3_1_TYPE_DTO = ColumnTypeDto.STRING; public final static Boolean COLUMN_3_1_NULL = false; public final static Boolean COLUMN_3_1_UNIQUE = false; + public final static Boolean COLUMN_3_1_AUTO_GENERATED = false; public final static String COLUMN_3_1_FOREIGN_KEY = null; public final static String COLUMN_3_1_CHECK = null; public final static List<String> COLUMN_3_1_ENUM_VALUES = null; @@ -143,6 +149,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { public final static ColumnTypeDto COLUMN_3_2_TYPE_DTO = ColumnTypeDto.ENUM; public final static Boolean COLUMN_3_2_NULL = false; public final static Boolean COLUMN_3_2_UNIQUE = false; + public final static Boolean COLUMN_3_2_AUTO_GENERATED = false; public final static String COLUMN_3_2_FOREIGN_KEY = null; public final static String COLUMN_3_2_CHECK = null; public final static List<String> COLUMN_3_2_ENUM_VALUES = List.of("sheep", "calf", "undetermined", "sheep or goat", "goat", "not anal."); @@ -156,6 +163,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { public final static ColumnTypeDto COLUMN_3_3_TYPE_DTO = ColumnTypeDto.STRING; public final static Boolean COLUMN_3_3_NULL = false; public final static Boolean COLUMN_3_3_UNIQUE = false; + public final static Boolean COLUMN_3_3_AUTO_GENERATED = false; public final static String COLUMN_3_3_FOREIGN_KEY = null; public final static String COLUMN_3_3_CHECK = null; public final static List<String> COLUMN_3_3_ENUM_VALUES = null; @@ -312,6 +320,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { .columnType(COLUMN_3_1_TYPE) .isNullAllowed(COLUMN_3_1_NULL) .isUnique(COLUMN_3_1_UNIQUE) + .autoGenerated(COLUMN_3_1_AUTO_GENERATED) .isPrimaryKey(COLUMN_3_1_PRIMARY) .enumValues(COLUMN_3_1_ENUM_VALUES) .build(), @@ -325,6 +334,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { .columnType(COLUMN_3_2_TYPE) .isNullAllowed(COLUMN_3_2_NULL) .isUnique(COLUMN_3_2_UNIQUE) + .autoGenerated(COLUMN_3_2_AUTO_GENERATED) .isPrimaryKey(COLUMN_3_2_PRIMARY) .enumValues(COLUMN_3_2_ENUM_VALUES) .build(), @@ -338,6 +348,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { .columnType(COLUMN_3_3_TYPE) .isNullAllowed(COLUMN_3_3_NULL) .isUnique(COLUMN_3_3_UNIQUE) + .autoGenerated(COLUMN_3_3_AUTO_GENERATED) .isPrimaryKey(COLUMN_3_3_PRIMARY) .enumValues(COLUMN_3_3_ENUM_VALUES) .build()); @@ -352,6 +363,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { .columnType(COLUMN_1_1_TYPE) .isNullAllowed(COLUMN_1_1_NULL) .isUnique(COLUMN_1_1_UNIQUE) + .autoGenerated(COLUMN_1_1_AUTO_GENERATED) .isPrimaryKey(COLUMN_1_1_PRIMARY) .enumValues(COLUMN_1_1_ENUM_VALUES) .build(), @@ -365,6 +377,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { .columnType(COLUMN_1_2_TYPE) .isNullAllowed(COLUMN_1_2_NULL) .isUnique(COLUMN_1_2_UNIQUE) + .autoGenerated(COLUMN_1_2_AUTO_GENERATED) .isPrimaryKey(COLUMN_1_2_PRIMARY) .enumValues(COLUMN_1_2_ENUM_VALUES) .build(), @@ -378,6 +391,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { .columnType(COLUMN_1_3_TYPE) .isNullAllowed(COLUMN_1_3_NULL) .isUnique(COLUMN_1_3_UNIQUE) + .autoGenerated(COLUMN_1_3_AUTO_GENERATED) .isPrimaryKey(COLUMN_1_3_PRIMARY) .enumValues(COLUMN_1_3_ENUM_VALUES) .build(), @@ -391,6 +405,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { .columnType(COLUMN_1_4_TYPE) .isNullAllowed(COLUMN_1_4_NULL) .isUnique(COLUMN_1_4_UNIQUE) + .autoGenerated(COLUMN_1_4_AUTO_GENERATED) .isPrimaryKey(COLUMN_1_4_PRIMARY) .enumValues(COLUMN_1_4_ENUM_VALUES) .build(), @@ -404,6 +419,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { .columnType(COLUMN_1_5_TYPE) .isNullAllowed(COLUMN_1_5_NULL) .isUnique(COLUMN_1_5_UNIQUE) + .autoGenerated(COLUMN_1_5_AUTO_GENERATED) .isPrimaryKey(COLUMN_1_5_PRIMARY) .enumValues(COLUMN_1_5_ENUM_VALUES) .build()); diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java b/fda-table-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java index 222c5c1c88024ab5aa9cb0432e38c2c0783530c1..057e57d64d3ad8d13b617ed3d7e25c47d7469b0a 100644 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java @@ -10,9 +10,11 @@ import com.github.dockerjava.core.DockerClientBuilder; import com.github.dockerjava.core.DockerClientConfig; import com.github.dockerjava.httpclient5.ApacheDockerHttpClient; import com.github.dockerjava.transport.DockerHttpClient; +import lombok.extern.log4j.Log4j2; import java.util.Objects; +@Log4j2 public class DockerConfig { private final static DockerClientConfig dockerClientConfig = DefaultDockerClientConfig.createDefaultConfigBuilder() @@ -34,12 +36,14 @@ public class DockerConfig { public static void startContainer(Container container) throws InterruptedException { final InspectContainerResponse inspect = dockerClient.inspectContainerCmd(container.getHash()) .exec(); + log.trace("container {} state {}", container.getHash(), inspect.getState().getStatus()); if (Objects.equals(inspect.getState().getStatus(), "running")) { return; } + log.trace("container {} needs to be started", container.getHash()); dockerClient.startContainerCmd(container.getHash()) .exec(); - Thread.sleep(6 * 1000L); + Thread.sleep(12 * 1000L); } public static void stopContainer(Container container) { diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java b/fda-table-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java index c1fa1bdc90bf7a3ac6936b0064512a82b61edf16..39926a27fc717610934a55dcc7c10259fb7cd118 100644 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java @@ -1,6 +1,7 @@ package at.tuwien.config; import at.tuwien.entities.database.table.Table; +import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Configurable; import org.springframework.context.annotation.Bean; @@ -10,6 +11,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; +@Log4j2 @Configurable public class MariaDbConfig { @@ -22,8 +24,9 @@ public class MariaDbConfig { } public static void clearDatabase(Table table) throws SQLException { - final Connection connection = DriverManager.getConnection("jdbc:mariadb://" + table.getDatabase().getContainer().getInternalName() + "/" + table.getDatabase().getInternalName(), - "mariadb", "mariadb"); + final String jdbc = "jdbc:mariadb://" + table.getDatabase().getContainer().getInternalName() + "/" + table.getDatabase().getInternalName(); + log.trace("connect to database {}", jdbc); + final Connection connection = DriverManager.getConnection(jdbc, "mariadb", "mariadb"); final Statement statement = connection.createStatement(); statement.execute("DELETE FROM " + table.getInternalName() + ";"); connection.close(); 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 a0ac8069e13439247c4e54c8d5881b74cf0a029d..c4f126ee5433beaaa3a744d91a6c717c35120edb 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 @@ -80,18 +80,19 @@ public class DataEndpointIntegrationTest extends BaseUnitTest { .withSubnet("172.28.0.0/16"))) .withEnableIpv6(false) .exec(); - final CreateContainerResponse request = dockerClient.createContainerCmd(IMAGE_2_REPOSITORY + ":" + IMAGE_2_TAG) + /* create container */ + final String bind = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + log.trace("container bind {}", bind); + final CreateContainerResponse response = dockerClient.createContainerCmd(IMAGE_2_REPOSITORY + ":" + IMAGE_2_TAG) .withHostConfig(hostConfig.withNetworkMode("fda-userdb")) .withName(CONTAINER_1_INTERNALNAME) .withIpv4Address(CONTAINER_1_IP) .withHostName(CONTAINER_1_INTERNALNAME) - .withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", - "MARIADB_DATABASE=weather") - .withBinds(Bind.parse(new File("./weather").toPath().toAbsolutePath() - + ":/docker-entrypoint-initdb.d")) + .withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=weather") + .withBinds(Bind.parse(bind)) .exec(); /* set hash */ - CONTAINER_1.setHash(request.getId()); + CONTAINER_1.setHash(response.getId()); } @Transactional diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/mapper/TableMapperIntegrationTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/mapper/TableMapperIntegrationTest.java index f18a4189acf2f3cb4a641de984b017e00d55c1c3..bd407531397ed67248434b9ce1f638e95b1367e4 100644 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/mapper/TableMapperIntegrationTest.java +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/mapper/TableMapperIntegrationTest.java @@ -4,6 +4,8 @@ import at.tuwien.BaseUnitTest; import at.tuwien.api.database.table.TableCreateDto; import at.tuwien.api.database.table.columns.ColumnCreateDto; import at.tuwien.api.database.table.columns.ColumnTypeDto; +import at.tuwien.config.DockerConfig; +import at.tuwien.config.MariaDbConfig; import at.tuwien.config.ReadyConfig; import at.tuwien.exception.ArbitraryPrimaryKeysException; import at.tuwien.exception.ImageNotSupportedException; @@ -13,16 +15,15 @@ import at.tuwien.repository.jpa.ImageRepository; import com.github.dockerjava.api.DockerClient; import com.github.dockerjava.api.command.CreateContainerResponse; import com.github.dockerjava.api.exception.NotModifiedException; +import com.github.dockerjava.api.model.Bind; import com.github.dockerjava.api.model.HostConfig; +import com.github.dockerjava.api.model.Network; import com.github.dockerjava.api.model.PortBinding; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; import org.jooq.*; import org.jooq.impl.DSL; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -31,6 +32,7 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; +import java.io.File; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -65,39 +67,41 @@ public class TableMapperIntegrationTest extends BaseUnitTest { @Autowired private DatabaseRepository databaseRepository; - private String CONTAINER_1_IP; - - @Transactional - @BeforeEach - public void beforeEach() throws InterruptedException { - afterEach(); + @BeforeAll + public static void beforeAll() { + afterAll(); + /* create network */ + dockerClient.createNetworkCmd() + .withName("fda-userdb") + .withIpam(new Network.Ipam() + .withConfig(new Network.Ipam.Config() + .withSubnet("172.28.0.0/16"))) + .withEnableIpv6(false) + .exec(); /* create container */ - final CreateContainerResponse request = dockerClient.createContainerCmd(IMAGE_1_REPOSITORY + ":" + IMAGE_1_TAG) - .withHostConfig(hostConfig.withNetworkMode("bridge")) + final String bind = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + log.trace("container bind {}", bind); + final CreateContainerResponse request = dockerClient.createContainerCmd(IMAGE_2_REPOSITORY + ":" + IMAGE_2_TAG) + .withHostConfig(hostConfig.withNetworkMode("fda-userdb")) .withName(CONTAINER_1_INTERNALNAME) - .withPortBindings(PortBinding.parse("5433:5432")) + .withIpv4Address(CONTAINER_1_IP) .withHostName(CONTAINER_1_INTERNALNAME) - .withEnv("POSTGRES_USER=postgres", "POSTGRES_PASSWORD=postgres", "POSTGRES_DB=weather") - .exec(); - /* start container */ - dockerClient.startContainerCmd(request.getId()) + .withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=weather") + .withBinds(Bind.parse(bind)) .exec(); - Thread.sleep(3000); - CONTAINER_1_IP = dockerClient.inspectContainerCmd(request.getId()) - .exec() - .getNetworkSettings() - .getNetworks() - .get("bridge") - .getIpAddress(); + CONTAINER_1.setHash(request.getId()); + /* set database */ + TABLE_1.setDatabase(DATABASE_1); } - @AfterEach - public void afterEach() { + @AfterAll + public static void afterAll() { + /* stop containers and remove them */ dockerClient.listContainersCmd() .withShowAll(true) .exec() .forEach(container -> { - System.out.println("DELETE CONTAINER " + Arrays.toString(container.getNames())); + log.info("Delete container {}", Arrays.asList(container.getNames())); try { dockerClient.stopContainerCmd(container.getId()).exec(); } catch (NotModifiedException e) { @@ -105,12 +109,21 @@ public class TableMapperIntegrationTest extends BaseUnitTest { } dockerClient.removeContainerCmd(container.getId()).exec(); }); + /* remove networks */ + dockerClient.listNetworksCmd() + .exec() + .stream() + .filter(n -> n.getName().startsWith("fda")) + .forEach(network -> { + log.info("Delete network {}", network.getName()); + dockerClient.removeNetworkCmd(network.getId()).exec(); + }); } private DSLContext open() throws SQLException { - final String url = "jdbc:postgresql://" + CONTAINER_1_IP + "/" + DATABASE_1_INTERNALNAME; - final Connection connection = DriverManager.getConnection(url, postgresProperties); - return DSL.using(connection, SQLDialect.POSTGRES); + final String jdbc = "jdbc:mariadb://" + CONTAINER_1_IP + "/" + DATABASE_1_INTERNALNAME; + final Connection connection = DriverManager.getConnection(jdbc, "mariadb", "mariadb"); + return DSL.using(connection, SQLDialect.MARIADB); } private static TableCreateDto instance() { @@ -158,12 +171,15 @@ public class TableMapperIntegrationTest extends BaseUnitTest { @Test public void tableCreateDtoToCreateTableColumnStep_success() throws SQLException, ArbitraryPrimaryKeysException, - ImageNotSupportedException, TableMalformedException { + ImageNotSupportedException, TableMalformedException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); + + /* test */ final DSLContext context = open(); tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) .execute(); - - /* test */ assertEquals(1, context.meta() .getTables() .stream() @@ -181,7 +197,12 @@ public class TableMapperIntegrationTest extends BaseUnitTest { @Test public void tableCreateDtoToCreateTableColumnStep_twoColumnPrimaryKey_succeeds() throws SQLException, - ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException { + ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); + + /* test */ final DSLContext context = open(); final TableCreateDto TABLE_2_CREATE_DTO = instance(); TABLE_2_CREATE_DTO.getColumns()[1] @@ -192,8 +213,6 @@ public class TableMapperIntegrationTest extends BaseUnitTest { .setType(ColumnTypeDto.NUMBER); tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) .execute(); - - /* test */ assertEquals(1, context.meta() .getTables() .stream() @@ -223,15 +242,18 @@ public class TableMapperIntegrationTest extends BaseUnitTest { @Test public void tableCreateDtoToCreateTableColumnStep_primaryKeyBlob_succeeds() throws SQLException, - ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException { + ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); + + /* test */ final DSLContext context = open(); final TableCreateDto TABLE_2_CREATE_DTO = instance(); TABLE_2_CREATE_DTO.getColumns()[0] .setType(ColumnTypeDto.BLOB); tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) .execute(); - - /* test */ assertEquals(1, context.meta() .getTables() .stream() @@ -251,15 +273,18 @@ public class TableMapperIntegrationTest extends BaseUnitTest { @Test public void tableCreateDtoToCreateTableColumnStep_primaryKeyDate_succeeds() throws SQLException, - ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException { + ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); + + /* test */ final DSLContext context = open(); final TableCreateDto TABLE_2_CREATE_DTO = instance(); TABLE_2_CREATE_DTO.getColumns()[0] .setType(ColumnTypeDto.DATE); tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) .execute(); - - /* test */ assertEquals(1, context.meta() .getTables() .stream() @@ -279,15 +304,18 @@ public class TableMapperIntegrationTest extends BaseUnitTest { @Test public void tableCreateDtoToCreateTableColumnStep_primaryKeyText_succeeds() throws SQLException, - ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException { + ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); + + /* test */ final DSLContext context = open(); final TableCreateDto TABLE_2_CREATE_DTO = instance(); TABLE_2_CREATE_DTO.getColumns()[0] .setType(ColumnTypeDto.TEXT); tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) .execute(); - - /* test */ assertEquals(1, context.meta() .getTables() .stream() @@ -307,15 +335,18 @@ public class TableMapperIntegrationTest extends BaseUnitTest { @Test public void tableCreateDtoToCreateTableColumnStep_primaryKeyString_succeeds() throws SQLException, - ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException { + ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); + + /* test */ final DSLContext context = open(); final TableCreateDto TABLE_2_CREATE_DTO = instance(); TABLE_2_CREATE_DTO.getColumns()[0] .setType(ColumnTypeDto.STRING); tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) .execute(); - - /* test */ assertEquals(1, context.meta() .getTables() .stream() @@ -334,13 +365,17 @@ public class TableMapperIntegrationTest extends BaseUnitTest { } @Test - public void tableCreateDtoToCreateTableColumnStep_primaryKeyEnum_fails() throws SQLException { + @Disabled + public void tableCreateDtoToCreateTableColumnStep_primaryKeyEnum_fails() throws SQLException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); + + /* test */ final DSLContext context = open(); final TableCreateDto TABLE_2_CREATE_DTO = instance(); TABLE_2_CREATE_DTO.getColumns()[0] .setType(ColumnTypeDto.ENUM); - - /* test */ assertThrows(ArbitraryPrimaryKeysException.class, () -> { tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) .execute(); @@ -348,27 +383,32 @@ public class TableMapperIntegrationTest extends BaseUnitTest { } @Test - public void tableCreateDtoToCreateTableColumnStep_noPrimaryKey_fails() throws SQLException { + public void tableCreateDtoToCreateTableColumnStep_noPrimaryKey_succeeds() throws SQLException, InterruptedException, + TableMalformedException, ArbitraryPrimaryKeysException, ImageNotSupportedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); + + /* test */ final DSLContext context = open(); final TableCreateDto TABLE_2_CREATE_DTO = instance(); TABLE_2_CREATE_DTO.getColumns()[0] .setPrimaryKey(false); - - /* test */ - assertThrows(ArbitraryPrimaryKeysException.class, () -> { - tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) - .execute(); - }); + tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) + .execute(); } @Test - public void tableCreateDtoToCreateTableColumnStep_primaryKeyNull_fails() throws SQLException { + public void tableCreateDtoToCreateTableColumnStep_primaryKeyNull_fails() throws SQLException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); + + /* test */ final DSLContext context = open(); final TableCreateDto TABLE_2_CREATE_DTO = instance(); TABLE_2_CREATE_DTO.getColumns()[0] .setNullAllowed(true); - - /* test */ assertThrows(ArbitraryPrimaryKeysException.class, () -> { tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) .execute(); @@ -377,11 +417,14 @@ public class TableMapperIntegrationTest extends BaseUnitTest { @Test public void tableCreateDtoToCreateTableColumnStep_uniqueConstraint_success() throws SQLException, - ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException { - final DSLContext context = open(); - final TableCreateDto TABLE_2_CREATE_DTO = instance(); + ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); /* test */ + final DSLContext context = open(); + final TableCreateDto TABLE_2_CREATE_DTO = instance(); tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) .execute(); assertEquals(1, context.meta() @@ -396,13 +439,16 @@ public class TableMapperIntegrationTest extends BaseUnitTest { @Test public void tableCreateDtoToCreateTableColumnStep_uniqueConstraint2_success() throws SQLException, - ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException { + ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); + + /* test */ final DSLContext context = open(); final TableCreateDto TABLE_2_CREATE_DTO = instance(); TABLE_2_CREATE_DTO.getColumns()[1] .setUnique(true); - - /* test */ tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) .execute(); assertEquals(1, context.meta() @@ -424,8 +470,14 @@ public class TableMapperIntegrationTest extends BaseUnitTest { } @Test + @Disabled public void tableCreateDtoToCreateTableColumnStep_enum_success() throws SQLException, - ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException { + ArbitraryPrimaryKeysException, ImageNotSupportedException, TableMalformedException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); + + /* test */ final DSLContext context = open(); final TableCreateDto TABLE_2_CREATE_DTO = instance(); final ColumnCreateDto[] columns = new ColumnCreateDto[]{COLUMNS_CSV01[0], COLUMNS_CSV01[1], COLUMNS_CSV01[2], @@ -439,28 +491,32 @@ public class TableMapperIntegrationTest extends BaseUnitTest { .enumValues(new String[]{"MALE", "FEMALE", "OTHER"}) .build()}; TABLE_2_CREATE_DTO.setColumns(columns); - - /* test */ tableMapper.tableCreateDtoToCreateTableColumnStep(context, TABLE_2_CREATE_DTO) .execute(); } @Test @Disabled - public void tableCreateDtoToCreateTableColumnStep_checkConstraint_success() throws SQLException { - final DSLContext context = open(); - final TableCreateDto TABLE_2_CREATE_DTO = instance(); + public void tableCreateDtoToCreateTableColumnStep_checkConstraint_success() throws SQLException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); /* test */ + final DSLContext context = open(); + final TableCreateDto TABLE_2_CREATE_DTO = instance(); } @Test @Disabled - public void tableCreateDtoToCreateTableColumnStep_foreignKey_success() throws SQLException { - final DSLContext context = open(); - final TableCreateDto TABLE_2_CREATE_DTO = instance(); + public void tableCreateDtoToCreateTableColumnStep_foreignKey_success() throws SQLException, InterruptedException { + /* mock */ + DockerConfig.startContainer(CONTAINER_1); + MariaDbConfig.clearDatabase(TABLE_1); /* test */ + final DSLContext context = open(); + final TableCreateDto TABLE_2_CREATE_DTO = instance(); } } diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/service/DataServiceIntegrationTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/service/DataServiceIntegrationTest.java index a34a5f1c5d2607cc148692fbc57c38ccdd1d53b0..f2d80aa71ef3d20be489884aef07219ba721abcf 100644 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/service/DataServiceIntegrationTest.java +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/service/DataServiceIntegrationTest.java @@ -77,23 +77,26 @@ public class DataServiceIntegrationTest extends BaseUnitTest { .withSubnet("172.28.0.0/16"))) .withEnableIpv6(false) .exec(); + /* create container */ + final String bind = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + log.trace("container bind {}", bind); final CreateContainerResponse request = dockerClient.createContainerCmd(IMAGE_2_REPOSITORY + ":" + IMAGE_2_TAG) .withHostConfig(hostConfig.withNetworkMode("fda-userdb")) .withName(CONTAINER_1_INTERNALNAME) .withIpv4Address(CONTAINER_1_IP) .withHostName(CONTAINER_1_INTERNALNAME) .withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=weather") - .withBinds(Bind.parse(new File("./src/test/resources/weather").toPath().toAbsolutePath() - + ":/docker-entrypoint-initdb.d")) + .withBinds(Bind.parse(bind)) .exec(); + final String bind3 = new File("./src/test/resources/species").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + log.trace("container 3 bind {}", bind3); final CreateContainerResponse request3 = dockerClient.createContainerCmd(IMAGE_2_REPOSITORY + ":" + IMAGE_2_TAG) .withHostConfig(hostConfig.withNetworkMode("fda-userdb")) .withName(CONTAINER_3_INTERNALNAME) .withIpv4Address(CONTAINER_3_IP) .withHostName(CONTAINER_3_INTERNALNAME) .withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=biomedical") - .withBinds(Bind.parse(new File("./src/test/resources/species").toPath().toAbsolutePath() - + ":/docker-entrypoint-initdb.d")) + .withBinds(Bind.parse(bind3)) .exec(); /* set hash */ CONTAINER_1.setHash(request.getId()); @@ -147,7 +150,7 @@ public class DataServiceIntegrationTest extends BaseUnitTest { .delimiter(',') .skipHeader(true) .nullElement("NA") - .csvLocation("test:src/test/resources/csv/csv_01.csv") + .csvLocation("test:csv/csv_01.csv") .build(); /* mock */ @@ -169,7 +172,7 @@ public class DataServiceIntegrationTest extends BaseUnitTest { .delimiter(',') .skipHeader(true) .nullElement("NA") - .csvLocation("test:src/test/resources/csv/csv_01.csv") + .csvLocation("test:csv/csv_01.csv") .build(); /* mock */ @@ -190,7 +193,7 @@ public class DataServiceIntegrationTest extends BaseUnitTest { .delimiter(';') .skipHeader(true) .nullElement("NA") - .csvLocation("test:src/test/resources/csv/csv_01.csv") + .csvLocation("test:csv/csv_01.csv") .build(); /* mock */ @@ -212,7 +215,7 @@ public class DataServiceIntegrationTest extends BaseUnitTest { .delimiter(',') .skipHeader(true) .nullElement("NA") - .csvLocation("test:src/test/resources/csv/csv_02.csv") + .csvLocation("test:csv/csv_02.csv") .build(); /* mock */ @@ -232,7 +235,7 @@ public class DataServiceIntegrationTest extends BaseUnitTest { .delimiter(';') .skipHeader(true) .nullElement("NA") - .csvLocation("test:src/test/resources/csv/csv_09.csv") + .csvLocation("test:csv/csv_09.csv") .build(); /* mock */ @@ -246,12 +249,12 @@ public class DataServiceIntegrationTest extends BaseUnitTest { } @Test - public void insertFromFile_notRunning_fails() throws SQLException { + public void insertFromFile_notRunning_fails() { final TableInsertDto request = TableInsertDto.builder() .delimiter(';') .skipHeader(true) .nullElement("NA") - .csvLocation("test:src/test/resources/csv/csv_01.csv") + .csvLocation("test:csv/csv_01.csv") .build(); /* mock */ diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/service/DataServiceUnitTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/service/DataServiceUnitTest.java index 7467baf582f0a49a0cd55ed1c9fcae74c91d2bd4..7e20f436a145add0287bbedc4dc60d5b5c996acd 100644 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/service/DataServiceUnitTest.java +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/service/DataServiceUnitTest.java @@ -70,14 +70,15 @@ public class DataServiceUnitTest extends BaseUnitTest { .withEnableIpv6(false) .exec(); /* create container */ + final String bind = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + log.trace("container bind {}", bind); final CreateContainerResponse response = dockerClient.createContainerCmd(IMAGE_2_REPOSITORY + ":" + IMAGE_2_TAG) .withHostConfig(hostConfig.withNetworkMode("fda-userdb")) .withName(CONTAINER_1_INTERNALNAME) .withIpv4Address(CONTAINER_1_IP) .withHostName(CONTAINER_1_INTERNALNAME) .withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=weather") - .withBinds(Bind.parse(new File("./src/test/resources/weather").toPath().toAbsolutePath() - + ":/docker-entrypoint-initdb.d")) + .withBinds(Bind.parse(bind)) .exec(); /* start */ CONTAINER_1.setHash(response.getId()); diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java index 1a2c90a6030febaf73effbb7c2c9a3e7d9e4ec53..30881b3d54c0614965e0608e8fc89c2d9c50178a 100644 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java @@ -84,14 +84,15 @@ public class TableServiceIntegrationTest extends BaseUnitTest { .withEnableIpv6(false) .exec(); /* create container */ + final String bind = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + log.trace("container bind {}", bind); final CreateContainerResponse response = dockerClient.createContainerCmd(IMAGE_2_REPOSITORY + ":" + IMAGE_2_TAG) .withHostConfig(hostConfig.withNetworkMode("fda-userdb")) .withName(CONTAINER_1_INTERNALNAME) .withIpv4Address(CONTAINER_1_IP) .withHostName(CONTAINER_1_INTERNALNAME) .withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=weather") - .withBinds(Bind.parse(new File("./src/test/resources/weather").toPath().toAbsolutePath() - + ":/docker-entrypoint-initdb.d")) + .withBinds(Bind.parse(bind)) .exec(); CONTAINER_1.setHash(response.getId()); } diff --git a/fda-table-service/rest-service/src/test/resources/application.properties b/fda-table-service/rest-service/src/test/resources/application.properties index 8d1717d7e449e5a0b5056d43101938200a4e9dcb..37d0065cbfcf5238b15a77d294de951a169c9521 100644 --- a/fda-table-service/rest-service/src/test/resources/application.properties +++ b/fda-table-service/rest-service/src/test/resources/application.properties @@ -16,6 +16,9 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.show-sql=false +# logging +logging.level.at.tuwien.=trace + # disable elasticsearch spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration diff --git a/fda-table-service/services/src/main/java/at/tuwien/mapper/TableMapper.java b/fda-table-service/services/src/main/java/at/tuwien/mapper/TableMapper.java index 55e03ea01e864f3d9a52154cff2666cefb6add3f..c9b789f4e9a18769abf6aced9892bba9848d33fd 100644 --- a/fda-table-service/services/src/main/java/at/tuwien/mapper/TableMapper.java +++ b/fda-table-service/services/src/main/java/at/tuwien/mapper/TableMapper.java @@ -15,6 +15,8 @@ import at.tuwien.exception.TableMalformedException; import org.apache.commons.lang.WordUtils; import org.jooq.*; import org.jooq.impl.DefaultDataType; +import org.jooq.meta.jaxb.CustomType; +import org.jooq.meta.jaxb.ForcedType; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; @@ -110,7 +112,7 @@ public interface TableMapper { } default String columnCreateDtoToEnumTypeName(TableCreateDto table, ColumnCreateDto data) { - return "__" + nameToInternalName(table.getName()) + "_" + nameToInternalName(data.getName()); + return nameToInternalName(table.getName()) + "_" + nameToInternalName(data.getName()); } // FIXME @@ -175,10 +177,11 @@ public interface TableMapper { if (!column.getType().equals(ColumnTypeDto.ENUM)) { continue; } + throw new ImageNotSupportedException("Currently enums are not supported"); /* create type */ - context.createType(columnCreateDtoToEnumTypeName(data, column)) - .asEnum(column.getEnumValues()) - .execute(); +// context.createType(columnCreateDtoToEnumTypeName(data, column)) +// .asEnum(column.getEnumValues()) +// .execute(); } /* columns */ for (ColumnCreateDto column : data.getColumns()) { @@ -226,9 +229,9 @@ public interface TableMapper { } default Field<?> primaryKeyField(ColumnCreateDto column) { -// if (column.getType().equals(ColumnTypeDto.TEXT) || column.getType().equals(ColumnTypeDto.BLOB)) { -// return field(sql(nameToInternalName(column.getName()) + "(255)")); -// } + if (column.getType().equals(ColumnTypeDto.TEXT) || column.getType().equals(ColumnTypeDto.BLOB)) { + return field(sql(nameToInternalName(column.getName()) + " (255)")); + } return field(nameToInternalName(column.getName())); } @@ -247,6 +250,15 @@ public interface TableMapper { .collect(Collectors.toList()); } + default ForcedType columnCreateDtoToForcedType(TableCreateDto data, ColumnCreateDto column) { + final String name = columnCreateDtoToEnumTypeName(data, column); + final ForcedType type = new ForcedType() + .withName(name) + .withTypes("varchar") + .withExpression(".*" + name + ".*"); + return type; + } + default DataType<?> columnTypeDtoToDataType(TableCreateDto table, ColumnCreateDto data) { if (data.getPrimaryKey()) { if (data.getType().equals(ColumnTypeDto.NUMBER)) { diff --git a/fda-table-service/services/src/main/java/at/tuwien/service/impl/MariaDataService.java b/fda-table-service/services/src/main/java/at/tuwien/service/impl/MariaDataService.java index 1ffdb34c545a4c5bfac7a87c4128bf921da2398f..1becaf0a13c7feb75be6d01984f49698b812795e 100644 --- a/fda-table-service/services/src/main/java/at/tuwien/service/impl/MariaDataService.java +++ b/fda-table-service/services/src/main/java/at/tuwien/service/impl/MariaDataService.java @@ -130,14 +130,15 @@ public class MariaDataService extends JdbcConnector implements DataService { data.setDelimiter(','); } boolean isClassPathFile = false; - if (!FileUtils.isTestFile(data.getCsvLocation()) && !FileUtils.isUrl(data.getCsvLocation())) { - log.trace("read prod file from /tmp/{}", data.getCsvLocation()); - data.setCsvLocation("/tmp/" + data.getCsvLocation()); - } else { + if (FileUtils.isTestFile(data.getCsvLocation())) { isClassPathFile = true; - /* assume it is test file */ log.trace("read test file from {}", data.getCsvLocation().substring(5)); data.setCsvLocation(data.getCsvLocation().substring(5)); + } else if (FileUtils.isUrl(data.getCsvLocation())) { + log.trace("read remote file from {}", data.getCsvLocation()); + } else { + log.trace("read prod file from /tmp/{}", data.getCsvLocation()); + data.setCsvLocation("/tmp/" + data.getCsvLocation()); } final CSVParser csvParser = new CSVParserBuilder() .withSeparator(data.getDelimiter()) @@ -179,7 +180,8 @@ public class MariaDataService extends JdbcConnector implements DataService { headers = rows.get(0); log.trace("csv headers {}", headers); } - if (!TableUtils.needsPrimaryKey(table) && /* auto-generated id columns have -1 in size */ + final boolean needsPrimaryKey = TableUtils.needsPrimaryKey(table); + if (!needsPrimaryKey && /* auto-generated id columns have -1 in size */ headers.size() != table.getColumns().size() && /* differ */ table.getColumns().stream().noneMatch(TableColumn::getAutoGenerated)) { log.error("Header size is not the same as cell size and none is auto-generated: header size={}, column " + diff --git a/fda-ui/.env-docker b/fda-ui/.env-docker index 6f618dcf77c12036af72265f8b1540829846b7ce..1162dbf84aa1fbe6887c7bb4a64e3f39387d5eba 100644 --- a/fda-ui/.env-docker +++ b/fda-ui/.env-docker @@ -1,3 +1,2 @@ -# DB Service API url # GATEWAY SERVICE API="http://fda-gateway-service:9095"