From 032728f05da1d2ae92694ada39f84789f48e226c Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sat, 14 Sep 2024 15:42:21 +0200 Subject: [PATCH] [FIX] correct Many to Many (normal way) anf first value field --- .../kar/archidata/dataAccess/DataAccess.java | 1 + .../kar/archidata/dataAccess/DataFactory.java | 3 +- .../dataAccess/addOn/AddOnManyToMany.java | 20 +++++++--- src/org/kar/archidata/db/DBEntry.java | 1 + test/src/test/kar/archidata/ConfigureDb.java | 40 +++++++++++++++++++ test/src/test/kar/archidata/TestJson.java | 17 +------- test/src/test/kar/archidata/TestListJson.java | 17 +------- .../test/kar/archidata/TestManyToMany.java | 21 ++-------- .../src/test/kar/archidata/TestManyToOne.java | 17 +------- .../src/test/kar/archidata/TestOneToMany.java | 17 +------- test/src/test/kar/archidata/TestRawQuery.java | 25 +++--------- .../test/kar/archidata/TestSimpleTable.java | 18 +-------- .../archidata/TestSimpleTableSoftDelete.java | 16 +------- .../src/test/kar/archidata/TestTypeEnum1.java | 17 +------- .../src/test/kar/archidata/TestTypeEnum2.java | 17 +------- test/src/test/kar/archidata/TestTypes.java | 17 +------- .../archidata/model/TypeManyToManyRemote.java | 9 ++++- 17 files changed, 95 insertions(+), 178 deletions(-) create mode 100644 test/src/test/kar/archidata/ConfigureDb.java diff --git a/src/org/kar/archidata/dataAccess/DataAccess.java b/src/org/kar/archidata/dataAccess/DataAccess.java index 784af47..48ff408 100644 --- a/src/org/kar/archidata/dataAccess/DataAccess.java +++ b/src/org/kar/archidata/dataAccess/DataAccess.java @@ -1297,6 +1297,7 @@ public class DataAccess { throws SQLException, IOException { final QueryOptions options = new QueryOptions(option); final DBEntry entry = DBInterfaceOption.getAutoEntry(options); + LOGGER.info("Query : '{}'", query); try (final Statement stmt = entry.connection.createStatement()) { return stmt.executeUpdate(query); } diff --git a/src/org/kar/archidata/dataAccess/DataFactory.java b/src/org/kar/archidata/dataAccess/DataFactory.java index ba8cd3d..89e39f4 100644 --- a/src/org/kar/archidata/dataAccess/DataFactory.java +++ b/src/org/kar/archidata/dataAccess/DataFactory.java @@ -165,7 +165,7 @@ public class DataFactory { final String comment = AnnotationTools.getComment(elem); final String defaultValue = AnnotationTools.getDefault(elem); - if (fieldId == 0) { + if (mainTableBuilder.toString().length() == 0) { mainTableBuilder.append("\n\t\t`"); } else { mainTableBuilder.append(",\n\t\t`"); @@ -404,6 +404,7 @@ public class DataFactory { } final boolean dataInThisObject = tmpOut.toString().length() > 0; if (dataInThisObject) { + LOGGER.info("Previous Object : '{}'", reverseOut.toString()); final boolean dataInPreviousObject = reverseOut.toString().length() > 0; if (dataInPreviousObject) { tmpOut.append(", "); diff --git a/src/org/kar/archidata/dataAccess/addOn/AddOnManyToMany.java b/src/org/kar/archidata/dataAccess/addOn/AddOnManyToMany.java index 5bfb436..6a51375 100644 --- a/src/org/kar/archidata/dataAccess/addOn/AddOnManyToMany.java +++ b/src/org/kar/archidata/dataAccess/addOn/AddOnManyToMany.java @@ -109,13 +109,18 @@ public class AddOnManyToMany implements DataAccessAddOn { @NotNull final CountInOut count, final QueryOptions options) throws Exception { final ManyToMany manyToMany = AnnotationTools.getManyToMany(field); - final String linkTableName = generateLinkTableName(tableName, name); + String linkTableName = generateLinkTableName(tableName, name); + if (manyToMany.mappedBy() != null && manyToMany.mappedBy().length() != 0) { + // TODO: get the remote table name ..... + final String remoteTableName = AnnotationTools.getTableName(manyToMany.targetEntity()); + linkTableName = generateLinkTableName(remoteTableName, manyToMany.mappedBy()); + } final Class objectClass = (Class) ((ParameterizedType) field.getGenericType()) .getActualTypeArguments()[0]; final String tmpVariable = "tmp_" + Integer.toString(count.value); querySelect.append(" (SELECT GROUP_CONCAT("); querySelect.append(tmpVariable); - if (manyToMany.mappedBy() == null) { + if (manyToMany.mappedBy() == null || manyToMany.mappedBy().length() == 0) { querySelect.append(".object2Id "); } else { querySelect.append(".object1Id "); @@ -148,7 +153,7 @@ public class AddOnManyToMany implements DataAccessAddOn { querySelect.append(" = "); querySelect.append(tmpVariable); querySelect.append("."); - if (manyToMany.mappedBy() == null) { + if (manyToMany.mappedBy() == null || manyToMany.mappedBy().length() == 0) { querySelect.append("object1Id "); } else { querySelect.append("object2Id "); @@ -156,7 +161,7 @@ public class AddOnManyToMany implements DataAccessAddOn { if (!"sqlite".equals(ConfigBaseVariable.getDBType())) { querySelect.append(" GROUP BY "); querySelect.append(tmpVariable); - if (manyToMany.mappedBy() == null) { + if (manyToMany.mappedBy() == null || manyToMany.mappedBy().length() == 0) { querySelect.append(".object1Id"); } else { querySelect.append(".object2Id"); @@ -522,6 +527,12 @@ public class AddOnManyToMany implements DataAccessAddOn { final boolean createIfNotExist, final boolean createDrop, final int fieldId) throws Exception { + + final ManyToMany manyToMany = AnnotationTools.getManyToMany(field); + if (manyToMany.mappedBy() != null && manyToMany.mappedBy().length() != 0) { + // not the reference model to create base: + return; + } final String linkTableName = generateLinkTableNameField(tableName, field); final QueryOptions options = new QueryOptions(new OverrideTableName(linkTableName)); final Class objectClass = (Class) ((ParameterizedType) field.getGenericType()) @@ -540,7 +551,6 @@ public class AddOnManyToMany implements DataAccessAddOn { postActionList.addAll(sqlCommand); } } else if (primaryType == UUID.class) { - if (objectClass == Long.class) { final List sqlCommand = DataFactory.createTable(LinkTableUUIDLong.class, options); postActionList.addAll(sqlCommand); diff --git a/src/org/kar/archidata/db/DBEntry.java b/src/org/kar/archidata/db/DBEntry.java index de51803..c24f620 100644 --- a/src/org/kar/archidata/db/DBEntry.java +++ b/src/org/kar/archidata/db/DBEntry.java @@ -63,6 +63,7 @@ public class DBEntry implements Closeable { this.connection = DriverManager.getConnection(this.config.getUrl(), this.config.getLogin(), this.config.getPassword()); } catch (final SQLException ex) { + LOGGER.error("Connection db fail: " + ex.getMessage() + " On URL: " + this.config.getUrl(true)); throw new IOException("Connection db fail: " + ex.getMessage() + " On URL: " + this.config.getUrl(true)); } diff --git a/test/src/test/kar/archidata/ConfigureDb.java b/test/src/test/kar/archidata/ConfigureDb.java new file mode 100644 index 0000000..dc80bf4 --- /dev/null +++ b/test/src/test/kar/archidata/ConfigureDb.java @@ -0,0 +1,40 @@ +package test.kar.archidata; + +import java.io.IOException; + +import org.kar.archidata.GlobalConfiguration; +import org.kar.archidata.db.DBEntry; +import org.kar.archidata.tools.ConfigBaseVariable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ConfigureDb { + final static private Logger LOGGER = LoggerFactory.getLogger(ConfigureDb.class); + + public static void configure() throws IOException { + if (true) { + if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) { + ConfigBaseVariable.dbType = "sqlite"; + ConfigBaseVariable.dbHost = "memory"; + // for test we need to connect all time the DB + ConfigBaseVariable.dbKeepConnected = "true"; + } + } else { + // Enable this if you want to access to a local MySQL base to test with an adminer + ConfigBaseVariable.bdDatabase = "test_db"; + ConfigBaseVariable.dbPort = "3906"; + ConfigBaseVariable.dbUser = "root"; + //ConfigBaseVariable.dbPassword = "password"; + } + // Connect the dataBase... + final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); + entry.connect(); + } + + public static void clear() throws IOException { + LOGGER.info("Remove the test db"); + DBEntry.closeAllForceMode(); + ConfigBaseVariable.clearAllValue(); + + } +} diff --git a/test/src/test/kar/archidata/TestJson.java b/test/src/test/kar/archidata/TestJson.java index 5781ef0..197bf50 100644 --- a/test/src/test/kar/archidata/TestJson.java +++ b/test/src/test/kar/archidata/TestJson.java @@ -11,11 +11,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; -import org.kar.archidata.GlobalConfiguration; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataFactory; -import org.kar.archidata.db.DBEntry; -import org.kar.archidata.tools.ConfigBaseVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,22 +26,12 @@ public class TestJson { @BeforeAll public static void configureWebServer() throws Exception { - if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) { - ConfigBaseVariable.dbType = "sqlite"; - ConfigBaseVariable.dbHost = "memory"; - // for test we need to connect all time the DB - ConfigBaseVariable.dbKeepConnected = "true"; - } - // Connect the dataBase... - final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); - entry.connect(); + ConfigureDb.configure(); } @AfterAll public static void removeDataBase() throws IOException { - LOGGER.info("Remove the test db"); - DBEntry.closeAllForceMode(); - ConfigBaseVariable.clearAllValue(); + ConfigureDb.clear(); } @Order(1) diff --git a/test/src/test/kar/archidata/TestListJson.java b/test/src/test/kar/archidata/TestListJson.java index d166a73..d4b0262 100644 --- a/test/src/test/kar/archidata/TestListJson.java +++ b/test/src/test/kar/archidata/TestListJson.java @@ -12,11 +12,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; -import org.kar.archidata.GlobalConfiguration; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataFactory; -import org.kar.archidata.db.DBEntry; -import org.kar.archidata.tools.ConfigBaseVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,22 +26,12 @@ public class TestListJson { @BeforeAll public static void configureWebServer() throws Exception { - if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) { - ConfigBaseVariable.dbType = "sqlite"; - ConfigBaseVariable.dbHost = "memory"; - // for test we need to connect all time the DB - ConfigBaseVariable.dbKeepConnected = "true"; - } - // Connect the dataBase... - final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); - entry.connect(); + ConfigureDb.configure(); } @AfterAll public static void removeDataBase() throws IOException { - LOGGER.info("Remove the test db"); - DBEntry.closeAllForceMode(); - ConfigBaseVariable.clearAllValue(); + ConfigureDb.clear(); } @Order(1) diff --git a/test/src/test/kar/archidata/TestManyToMany.java b/test/src/test/kar/archidata/TestManyToMany.java index 5daf8c2..28c89a1 100644 --- a/test/src/test/kar/archidata/TestManyToMany.java +++ b/test/src/test/kar/archidata/TestManyToMany.java @@ -11,12 +11,9 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; -import org.kar.archidata.GlobalConfiguration; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.addOn.AddOnManyToMany; -import org.kar.archidata.db.DBEntry; -import org.kar.archidata.tools.ConfigBaseVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,22 +28,12 @@ public class TestManyToMany { @BeforeAll public static void configureWebServer() throws Exception { - if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) { - ConfigBaseVariable.dbType = "sqlite"; - ConfigBaseVariable.dbHost = "memory"; - // for test we need to connect all time the DB - ConfigBaseVariable.dbKeepConnected = "true"; - } - // Connect the dataBase... - final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); - entry.connect(); + ConfigureDb.configure(); } @AfterAll public static void removeDataBase() throws IOException { - LOGGER.info("Remove the test db"); - DBEntry.closeAllForceMode(); - ConfigBaseVariable.clearAllValue(); + ConfigureDb.clear(); } @Order(1) @@ -129,7 +116,7 @@ public class TestManyToMany { Assertions.assertNotNull(retrieve.otherData); Assertions.assertEquals(insertedData.otherData, retrieve.otherData); Assertions.assertNotNull(retrieve.remote); - Assertions.assertEquals(retrieve.remote.size(), 2); + Assertions.assertEquals(2, retrieve.remote.size()); Assertions.assertEquals(retrieve.remote.get(0), insertedRemote1.id); Assertions.assertEquals(retrieve.remote.get(1), insertedRemote2.id); @@ -141,7 +128,7 @@ public class TestManyToMany { Assertions.assertNotNull(retrieveExpand.otherData); Assertions.assertEquals(insertedData.otherData, retrieveExpand.otherData); Assertions.assertNotNull(retrieveExpand.remote); - Assertions.assertEquals(retrieveExpand.remote.size(), 2); + Assertions.assertEquals(2, retrieveExpand.remote.size()); Assertions.assertEquals(retrieveExpand.remote.get(0).id, insertedRemote1.id); Assertions.assertEquals(retrieveExpand.remote.get(1).id, insertedRemote2.id); diff --git a/test/src/test/kar/archidata/TestManyToOne.java b/test/src/test/kar/archidata/TestManyToOne.java index 68f2dc7..2619191 100644 --- a/test/src/test/kar/archidata/TestManyToOne.java +++ b/test/src/test/kar/archidata/TestManyToOne.java @@ -11,11 +11,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; -import org.kar.archidata.GlobalConfiguration; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataFactory; -import org.kar.archidata.db.DBEntry; -import org.kar.archidata.tools.ConfigBaseVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,22 +30,12 @@ public class TestManyToOne { @BeforeAll public static void configureWebServer() throws Exception { - if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) { - ConfigBaseVariable.dbType = "sqlite"; - ConfigBaseVariable.dbHost = "memory"; - // for test we need to connect all time the DB - ConfigBaseVariable.dbKeepConnected = "true"; - } - // Connect the dataBase... - final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); - entry.connect(); + ConfigureDb.configure(); } @AfterAll public static void removeDataBase() throws IOException { - LOGGER.info("Remove the test db"); - DBEntry.closeAllForceMode(); - ConfigBaseVariable.clearAllValue(); + ConfigureDb.clear(); } @Order(1) diff --git a/test/src/test/kar/archidata/TestOneToMany.java b/test/src/test/kar/archidata/TestOneToMany.java index 48cd999..e2b2e27 100644 --- a/test/src/test/kar/archidata/TestOneToMany.java +++ b/test/src/test/kar/archidata/TestOneToMany.java @@ -11,11 +11,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; -import org.kar.archidata.GlobalConfiguration; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataFactory; -import org.kar.archidata.db.DBEntry; -import org.kar.archidata.tools.ConfigBaseVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,22 +30,12 @@ public class TestOneToMany { @BeforeAll public static void configureWebServer() throws Exception { - if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) { - ConfigBaseVariable.dbType = "sqlite"; - ConfigBaseVariable.dbHost = "memory"; - // for test we need to connect all time the DB - ConfigBaseVariable.dbKeepConnected = "true"; - } - // Connect the dataBase... - final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); - entry.connect(); + ConfigureDb.configure(); } @AfterAll public static void removeDataBase() throws IOException { - LOGGER.info("Remove the test db"); - DBEntry.closeAllForceMode(); - ConfigBaseVariable.clearAllValue(); + ConfigureDb.clear(); } @Order(1) diff --git a/test/src/test/kar/archidata/TestRawQuery.java b/test/src/test/kar/archidata/TestRawQuery.java index 3483d02..21a41fd 100644 --- a/test/src/test/kar/archidata/TestRawQuery.java +++ b/test/src/test/kar/archidata/TestRawQuery.java @@ -11,11 +11,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; -import org.kar.archidata.GlobalConfiguration; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataFactory; -import org.kar.archidata.db.DBEntry; -import org.kar.archidata.tools.ConfigBaseVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,22 +25,12 @@ public class TestRawQuery { @BeforeAll public static void configureWebServer() throws Exception { - if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) { - ConfigBaseVariable.dbType = "sqlite"; - ConfigBaseVariable.dbHost = "memory"; - // for test we need to connect all time the DB - ConfigBaseVariable.dbKeepConnected = "true"; - } - // Connect the dataBase... - final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); - entry.connect(); + ConfigureDb.configure(); } @AfterAll public static void removeDataBase() throws IOException { - LOGGER.info("Remove the test db"); - DBEntry.closeAllForceMode(); - ConfigBaseVariable.clearAllValue(); + ConfigureDb.clear(); } @Order(1) @@ -83,13 +70,13 @@ public class TestRawQuery { test.floatData = 7.0F; DataAccess.insert(test); { - String query = """ + final String query = """ SELECT * FROM TypesTable WHERE `intData` = ? ORDER BY id DESC """; - List parameters = List.of(Integer.valueOf(99)); + final List parameters = List.of(Integer.valueOf(99)); // Try to retrieve all the data: final List retrieve = DataAccess.query(TypesTable.class, query, parameters); @@ -102,13 +89,13 @@ public class TestRawQuery { } { - String query = """ + final String query = """ SELECT DISTINCT intData FROM TypesTable WHERE `intData` = ? ORDER BY id DESC """; - List parameters = List.of(Integer.valueOf(99)); + final List parameters = List.of(Integer.valueOf(99)); // Try to retrieve all the data: final List retrieve = DataAccess.query(TypesTable.class, query, parameters); diff --git a/test/src/test/kar/archidata/TestSimpleTable.java b/test/src/test/kar/archidata/TestSimpleTable.java index ff9d4f3..dce854f 100644 --- a/test/src/test/kar/archidata/TestSimpleTable.java +++ b/test/src/test/kar/archidata/TestSimpleTable.java @@ -14,12 +14,9 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; -import org.kar.archidata.GlobalConfiguration; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.QueryOptions; -import org.kar.archidata.db.DBEntry; -import org.kar.archidata.tools.ConfigBaseVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,26 +33,15 @@ public class TestSimpleTable { @BeforeAll public static void configureWebServer() throws Exception { - if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) { - ConfigBaseVariable.dbType = "sqlite"; - ConfigBaseVariable.dbHost = "memory"; - // for test we need to connect all time the DB - ConfigBaseVariable.dbKeepConnected = "true"; - } // Clear the static test: idOfTheObject = null; startAction = null; - - // Connect the dataBase... - final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); - entry.connect(); + ConfigureDb.configure(); } @AfterAll public static void removeDataBase() throws IOException { - LOGGER.info("Remove the test db"); - DBEntry.closeAllForceMode(); - ConfigBaseVariable.clearAllValue(); + ConfigureDb.clear(); } @Order(1) diff --git a/test/src/test/kar/archidata/TestSimpleTableSoftDelete.java b/test/src/test/kar/archidata/TestSimpleTableSoftDelete.java index eb411cf..3faccf2 100644 --- a/test/src/test/kar/archidata/TestSimpleTableSoftDelete.java +++ b/test/src/test/kar/archidata/TestSimpleTableSoftDelete.java @@ -14,11 +14,9 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; -import org.kar.archidata.GlobalConfiguration; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.QueryOptions; -import org.kar.archidata.db.DBEntry; import org.kar.archidata.tools.ConfigBaseVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,26 +34,16 @@ public class TestSimpleTableSoftDelete { @BeforeAll public static void configureWebServer() throws Exception { - if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) { - ConfigBaseVariable.dbType = "sqlite"; - ConfigBaseVariable.dbHost = "memory"; - // for test we need to connect all time the DB - ConfigBaseVariable.dbKeepConnected = "true"; - } // Clear the static test: idOfTheObject = null; startAction = null; - // Connect the dataBase... - final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); - entry.connect(); + ConfigureDb.configure(); } @AfterAll public static void removeDataBase() throws IOException { - LOGGER.info("Remove the test db"); - DBEntry.closeAllForceMode(); - ConfigBaseVariable.clearAllValue(); + ConfigureDb.clear(); } @Order(1) diff --git a/test/src/test/kar/archidata/TestTypeEnum1.java b/test/src/test/kar/archidata/TestTypeEnum1.java index 2803d11..5e10264 100644 --- a/test/src/test/kar/archidata/TestTypeEnum1.java +++ b/test/src/test/kar/archidata/TestTypeEnum1.java @@ -11,11 +11,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; -import org.kar.archidata.GlobalConfiguration; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataFactory; -import org.kar.archidata.db.DBEntry; -import org.kar.archidata.tools.ConfigBaseVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,22 +26,12 @@ public class TestTypeEnum1 { @BeforeAll public static void configureWebServer() throws Exception { - if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) { - ConfigBaseVariable.dbType = "sqlite"; - ConfigBaseVariable.dbHost = "memory"; - // for test we need to connect all time the DB - ConfigBaseVariable.dbKeepConnected = "true"; - } - // Connect the dataBase... - final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); - entry.connect(); + ConfigureDb.configure(); } @AfterAll public static void removeDataBase() throws IOException { - LOGGER.info("Remove the test db"); - DBEntry.closeAllForceMode(); - ConfigBaseVariable.clearAllValue(); + ConfigureDb.clear(); } @Order(1) diff --git a/test/src/test/kar/archidata/TestTypeEnum2.java b/test/src/test/kar/archidata/TestTypeEnum2.java index fe7ba85..dc78878 100644 --- a/test/src/test/kar/archidata/TestTypeEnum2.java +++ b/test/src/test/kar/archidata/TestTypeEnum2.java @@ -11,11 +11,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; -import org.kar.archidata.GlobalConfiguration; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataFactory; -import org.kar.archidata.db.DBEntry; -import org.kar.archidata.tools.ConfigBaseVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,22 +26,12 @@ public class TestTypeEnum2 { @BeforeAll public static void configureWebServer() throws Exception { - if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) { - ConfigBaseVariable.dbType = "sqlite"; - ConfigBaseVariable.dbHost = "memory"; - // for test we need to connect all time the DB - ConfigBaseVariable.dbKeepConnected = "true"; - } - // Connect the dataBase... - final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); - entry.connect(); + ConfigureDb.configure(); } @AfterAll public static void removeDataBase() throws IOException { - LOGGER.info("Remove the test db"); - DBEntry.closeAllForceMode(); - ConfigBaseVariable.clearAllValue(); + ConfigureDb.clear(); } @Order(1) diff --git a/test/src/test/kar/archidata/TestTypes.java b/test/src/test/kar/archidata/TestTypes.java index 6b8f3e4..b3f5405 100644 --- a/test/src/test/kar/archidata/TestTypes.java +++ b/test/src/test/kar/archidata/TestTypes.java @@ -16,11 +16,8 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; -import org.kar.archidata.GlobalConfiguration; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataFactory; -import org.kar.archidata.db.DBEntry; -import org.kar.archidata.tools.ConfigBaseVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,22 +30,12 @@ public class TestTypes { @BeforeAll public static void configureWebServer() throws Exception { - if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) { - ConfigBaseVariable.dbType = "sqlite"; - ConfigBaseVariable.dbHost = "memory"; - // for test we need to connect all time the DB - ConfigBaseVariable.dbKeepConnected = "true"; - } - // Connect the dataBase... - final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); - entry.connect(); + ConfigureDb.configure(); } @AfterAll public static void removeDataBase() throws IOException { - LOGGER.info("Remove the test db"); - DBEntry.closeAllForceMode(); - ConfigBaseVariable.clearAllValue(); + ConfigureDb.clear(); } @Order(1) diff --git a/test/src/test/kar/archidata/model/TypeManyToManyRemote.java b/test/src/test/kar/archidata/model/TypeManyToManyRemote.java index ba94471..8e4f14e 100644 --- a/test/src/test/kar/archidata/model/TypeManyToManyRemote.java +++ b/test/src/test/kar/archidata/model/TypeManyToManyRemote.java @@ -1,8 +1,15 @@ package test.kar.archidata.model; +import java.util.List; + import org.kar.archidata.model.GenericData; -public class TypeManyToManyRemote extends GenericData { +import jakarta.persistence.FetchType; +import jakarta.persistence.ManyToMany; +public class TypeManyToManyRemote extends GenericData { + @ManyToMany(fetch = FetchType.LAZY, targetEntity = TypeManyToManyRoot.class, mappedBy = "remote") + public List remoteToParent; public String data; + } \ No newline at end of file