[IX] it works with sqlite
This commit is contained in:
parent
0e88823094
commit
1713e20252
@ -47,9 +47,19 @@ public abstract class DBAccess implements Closeable {
|
||||
|
||||
public static final DBAccess createInterface(final DbIo io) throws InternalServerErrorException {
|
||||
if (io instanceof final DbIoMorphia ioMorphia) {
|
||||
return new DBAccessMorphia(ioMorphia);
|
||||
try {
|
||||
return new DBAccessMorphia(ioMorphia);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new InternalServerErrorException("Fail to create DB interface.");
|
||||
}
|
||||
} else if (io instanceof final DbIoSql ioSQL) {
|
||||
return new DBAccessSQL(ioSQL);
|
||||
try {
|
||||
return new DBAccessSQL(ioSQL);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new InternalServerErrorException("Fail to create DB interface.");
|
||||
}
|
||||
}
|
||||
throw new InternalServerErrorException("unknow DB interface ... ");
|
||||
}
|
||||
|
@ -76,8 +76,14 @@ public class DBAccessMorphia extends DBAccess {
|
||||
|
||||
private final DbIoMorphia db;
|
||||
|
||||
public DBAccessMorphia(final DbIoMorphia db) {
|
||||
public DBAccessMorphia(final DbIoMorphia db) throws IOException {
|
||||
this.db = db;
|
||||
db.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.db.close();
|
||||
}
|
||||
|
||||
public DbIoMorphia getInterface() {
|
||||
@ -936,9 +942,4 @@ public class DBAccessMorphia extends DBAccess {
|
||||
collection.deleteMany(new Document());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -75,8 +75,14 @@ public class DBAccessSQL extends DBAccess {
|
||||
|
||||
private final DbIoSql db;
|
||||
|
||||
public DBAccessSQL(final DbIoSql db) {
|
||||
public DBAccessSQL(final DbIoSql db) throws IOException {
|
||||
this.db = db;
|
||||
db.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.db.close();
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
@ -91,9 +97,8 @@ public class DBAccessSQL extends DBAccess {
|
||||
// TODO: check if the file exist or not ...
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
try (final PreparedStatement ps = getConnection().prepareStatement("show databases")) {
|
||||
// TODO : Maybe connect with a temporary not specified connection interface to a db ...
|
||||
final PreparedStatement ps = this.db.getConnection().prepareStatement("show databases");
|
||||
final ResultSet rs = ps.executeQuery();
|
||||
// LOGGER.info("List all tables: equals? '{}'", name);
|
||||
while (rs.next()) {
|
||||
@ -106,13 +111,6 @@ public class DBAccessSQL extends DBAccess {
|
||||
return false;
|
||||
} catch (final SQLException ex) {
|
||||
LOGGER.error("Can not check if the DB exist SQL-error !!! {}", ex.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
this.db.close();
|
||||
} catch (final IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new InternalServerErrorException("Can Not manage the DB-access");
|
||||
}
|
||||
@ -881,7 +879,7 @@ public class DBAccessSQL extends DBAccess {
|
||||
}
|
||||
LOGGER.debug("generate the query: '{}'", query.toString());
|
||||
// prepare the request:
|
||||
final PreparedStatement ps = this.db.getConnection().prepareStatement(query.toString(),
|
||||
final PreparedStatement ps = getConnection().prepareStatement(query.toString(),
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
final CountInOut iii = new CountInOut(1);
|
||||
@ -1617,9 +1615,4 @@ public class DBAccessSQL extends DBAccess {
|
||||
return outs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package org.kar.archidata.dataAccess.addOnMongo;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.sql.Types;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -26,8 +24,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.model.Filters;
|
||||
|
||||
@ -60,6 +56,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
final Object rootObject,
|
||||
final Document docSet,
|
||||
final Document docUnSet) throws Exception {
|
||||
/*
|
||||
final Object data = field.get(rootObject);
|
||||
if (data == null) {
|
||||
ps.setNull(iii.value, Types.VARCHAR);
|
||||
@ -68,6 +65,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
final String dataString = objectMapper.writeValueAsString(data);
|
||||
ps.setString(iii.value, dataString);
|
||||
iii.inc();
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -111,7 +109,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
final Object data,
|
||||
final QueryOptions options,
|
||||
final List<LazyGetter> lazyCall) throws Exception {
|
||||
|
||||
/*
|
||||
final String fieldName = AnnotationTools.getFieldName(field);
|
||||
if (!doc.containsKey(fieldName)) {
|
||||
field.set(data, null);
|
||||
@ -163,6 +161,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
final Object dataParsed = objectMapper.readValue(jsonData, field.getType());
|
||||
field.set(data, dataParsed);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,7 +15,6 @@ import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.LazyGetter;
|
||||
import org.kar.archidata.dataAccess.QueryAnd;
|
||||
import org.kar.archidata.dataAccess.QueryCondition;
|
||||
import org.kar.archidata.dataAccess.QueryInList;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
import org.kar.archidata.dataAccess.addOnSQL.model.LinkTableLongLong;
|
||||
import org.kar.archidata.dataAccess.addOnSQL.model.LinkTableLongUUID;
|
||||
@ -212,6 +211,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
final Object data,
|
||||
final QueryOptions options,
|
||||
final List<LazyGetter> lazyCall) throws Exception {
|
||||
/*
|
||||
if (field.getType() != List.class) {
|
||||
LOGGER.error("Can not ManyToMany with other than List Model: {}", field.getType().getCanonicalName());
|
||||
return;
|
||||
@ -283,6 +283,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.kar.archidata.db;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
@ -124,4 +125,31 @@ public class DbConfig {
|
||||
}
|
||||
return "dead_code";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (other == null || getClass() != other.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (other instanceof final DbConfig dbConfig) {
|
||||
return this.port == dbConfig.port //
|
||||
&& this.keepConnected == dbConfig.keepConnected //
|
||||
&& Objects.equals(this.type, dbConfig.type) //
|
||||
&& Objects.equals(this.hostname, dbConfig.hostname) //
|
||||
&& Objects.equals(this.login, dbConfig.login) //
|
||||
&& Objects.equals(this.password, dbConfig.password) //
|
||||
&& Objects.equals(this.dbName, dbConfig.dbName) //
|
||||
&& Objects.equals(this.classes, dbConfig.classes);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.type, this.hostname, this.port, this.login, this.password, this.dbName,
|
||||
this.keepConnected, this.classes);
|
||||
}
|
||||
}
|
||||
|
@ -11,55 +11,60 @@ public abstract class DbIo implements Closeable {
|
||||
|
||||
// we count the number of connection in the system to prevent disconnection in a middle of a stream.
|
||||
private int count = 0;
|
||||
|
||||
private static int idCount = 0;
|
||||
protected final int id;
|
||||
protected final DbConfig config;
|
||||
|
||||
protected DbIo(final DbConfig config) throws IOException {
|
||||
this.id = idCount;
|
||||
idCount += 10;
|
||||
this.config = config;
|
||||
// If we want to stay connected, we instantiate a basic connection (only force close can remove it).
|
||||
if (this.config.getKeepConnected()) {
|
||||
open();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized final void close() throws IOException {
|
||||
LOGGER.error("[{}] >>>>>>>>>>> Request close count={}", this.id, this.count);
|
||||
if (this.count <= 0) {
|
||||
LOGGER.error("Request one more close: {}", this.getClass().getCanonicalName());
|
||||
LOGGER.error("[{}] >>>>>>>>>>> Request one more close: {}", this.id, this.getClass().getCanonicalName());
|
||||
return;
|
||||
}
|
||||
this.count--;
|
||||
if (this.count == 0) {
|
||||
LOGGER.warn("close: {}", this.getClass().getCanonicalName());
|
||||
LOGGER.warn("v>>>>>>>>>>> close: {}", this.id, this.getClass().getCanonicalName());
|
||||
closeImplement();
|
||||
} else {
|
||||
LOGGER.debug("postponed close: {}", this.getClass().getCanonicalName());
|
||||
LOGGER.debug("v>>>>>>>>>>> postponed close: {}", this.id, this.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized final void closeForce() throws IOException {
|
||||
LOGGER.warn("Request Force close: {}", this.getClass().getCanonicalName());
|
||||
LOGGER.warn("[{}] >>>>>>>>>>> Request Force close count={}", this.id, this.count);
|
||||
if (this.count == 0) {
|
||||
LOGGER.info("Nothing to do in force close, DB is already closed");
|
||||
LOGGER.info("[{}] >>>>>>>>>>> Nothing to do in force close, DB is already closed", this.id);
|
||||
return;
|
||||
}
|
||||
if (this.config.getKeepConnected()) {
|
||||
if (this.count >= 2) {
|
||||
LOGGER.error("close: {} with {} connection on it", this.getClass().getCanonicalName(), this.count - 1);
|
||||
LOGGER.error("[{}] >>>>>>>>>>> force close: {} with {} connection on it", this.id,
|
||||
this.getClass().getCanonicalName(), this.count - 1);
|
||||
}
|
||||
} else if (this.count >= 1) {
|
||||
LOGGER.error("close: {} with {} connection on it", this.getClass().getCanonicalName(), this.count);
|
||||
LOGGER.error("[{}] >>>>>>>>>>> force close: {} with {} connection on it", this.id,
|
||||
this.getClass().getCanonicalName(), this.count);
|
||||
}
|
||||
this.count = 0;
|
||||
LOGGER.warn("close: {}", this.getClass().getCanonicalName());
|
||||
LOGGER.warn("[{}] >>>>>>>>>>> force close: {}", this.id, this.getClass().getCanonicalName());
|
||||
closeImplement();
|
||||
}
|
||||
|
||||
public synchronized final void open() throws IOException {
|
||||
LOGGER.warn("[{}] >>>>>>>>>>> Request open count={}", this.id, this.count);
|
||||
if (this.count == 0) {
|
||||
LOGGER.warn("open: {}", this.getClass().getCanonicalName());
|
||||
LOGGER.warn("[{}] >>>>>>>>>>> open: {}", this.id, this.getClass().getCanonicalName());
|
||||
openImplement();
|
||||
} else {
|
||||
LOGGER.debug("already open: {}", this.getClass().getCanonicalName());
|
||||
LOGGER.debug("[{}] >>>>>>>>>>> already open: {}", this.id, this.getClass().getCanonicalName());
|
||||
}
|
||||
this.count++;
|
||||
|
||||
|
@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DbIoFactory {
|
||||
final static Logger LOGGER = LoggerFactory.getLogger(DbIoFactory.class);
|
||||
private static List<DbIo> stored = new ArrayList<>();
|
||||
private static List<DbIo> dbIoStored = new ArrayList<>();
|
||||
|
||||
private DbIoFactory() throws IOException {}
|
||||
|
||||
@ -20,21 +20,21 @@ public class DbIoFactory {
|
||||
}
|
||||
|
||||
public static DbIo create(final DbConfig config) throws IOException {
|
||||
for (final DbIo elem : stored) {
|
||||
if (elem == null) {
|
||||
for (final DbIo dbIo : dbIoStored) {
|
||||
if (dbIo == null) {
|
||||
continue;
|
||||
}
|
||||
if (elem.compatible(config)) {
|
||||
elem.open();
|
||||
return elem;
|
||||
if (dbIo.compatible(config)) {
|
||||
dbIo.open();
|
||||
return dbIo;
|
||||
}
|
||||
}
|
||||
final DbIo tmp = createInstance(config);
|
||||
final DbIo dbIo = createInstance(config);
|
||||
if (config.getKeepConnected()) {
|
||||
stored.add(tmp);
|
||||
dbIoStored.add(dbIo);
|
||||
}
|
||||
tmp.open();
|
||||
return tmp;
|
||||
dbIo.open();
|
||||
return dbIo;
|
||||
}
|
||||
|
||||
private static DbIo createInstance(final DbConfig config) throws IOException {
|
||||
@ -51,15 +51,15 @@ public class DbIoFactory {
|
||||
}
|
||||
|
||||
public static void close() throws IOException {
|
||||
for (final DbIo entry : stored) {
|
||||
entry.close();
|
||||
for (final DbIo dbIo : dbIoStored) {
|
||||
dbIo.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeAllForceMode() throws IOException {
|
||||
for (final DbIo entry : stored) {
|
||||
for (final DbIo entry : dbIoStored) {
|
||||
entry.closeForce();
|
||||
}
|
||||
stored = new ArrayList<>();
|
||||
dbIoStored = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,10 @@ public class DbIoMorphia extends DbIo implements Closeable {
|
||||
|
||||
public DbIoMorphia(final DbConfig config) throws IOException {
|
||||
super(config);
|
||||
// If we want to stay connected, we instantiate a basic connection (only force close can remove it).
|
||||
if (this.config.getKeepConnected()) {
|
||||
open();
|
||||
}
|
||||
}
|
||||
|
||||
public Datastore getDatastore() {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.kar.archidata.db;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
@ -9,20 +8,25 @@ import java.sql.SQLException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DbIoSql extends DbIo implements Closeable {
|
||||
public class DbIoSql extends DbIo {
|
||||
final static Logger LOGGER = LoggerFactory.getLogger(DbIoSql.class);
|
||||
|
||||
private Connection connection = null;
|
||||
private Connection con = null;
|
||||
|
||||
public DbIoSql(final DbConfig config) throws IOException {
|
||||
super(config);
|
||||
// If we want to stay connected, we instantiate a basic connection (only force close can remove it).
|
||||
if (this.config.getKeepConnected()) {
|
||||
open();
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
if (this.connection == null) {
|
||||
LOGGER.error("Request closed connection !!!");
|
||||
if (this.con == null) {
|
||||
LOGGER.error("[{}] >>>>>>>>>> Retrieve a closed connection !!!", this.id);
|
||||
}
|
||||
return this.connection;
|
||||
LOGGER.error("[{}] ++++++++++ Retrieve connection {}", this.id, this.con);
|
||||
return this.con;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,23 +34,30 @@ public class DbIoSql extends DbIo implements Closeable {
|
||||
final String dbUrl = this.config.getUrl();
|
||||
final String login = this.config.getLogin();
|
||||
final String password = this.config.getPassword();
|
||||
LOGGER.error("[{}] >>>>>>>>>> openImplement ", this.id);
|
||||
try {
|
||||
this.connection = DriverManager.getConnection(dbUrl, login, password);
|
||||
this.con = DriverManager.getConnection(dbUrl, login, password);
|
||||
LOGGER.error("[{}] >>>>>>>>>> openImplement ==> {}", this.id, this.con);
|
||||
} catch (final SQLException ex) {
|
||||
LOGGER.error("Connection db fail: " + ex.getMessage() + " On URL: " + dbUrl);
|
||||
throw new IOException("Connection db fail: " + ex.getMessage() + " On URL: " + dbUrl);
|
||||
}
|
||||
if (this.con == null) {
|
||||
LOGGER.error("Request open of un-open connection !!!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void closeImplement() throws IOException {
|
||||
if (this.connection == null) {
|
||||
LOGGER.error("[{}] >>>>>>>>>> closeImplement ", this.id);
|
||||
if (this.con == null) {
|
||||
LOGGER.error("Request close of un-open connection !!!");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.connection.close();
|
||||
this.connection = null;
|
||||
this.con.close();
|
||||
this.con = null;
|
||||
} catch (final SQLException ex) {
|
||||
throw new IOException("Dis-connection db fail: " + ex.getMessage());
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
import org.kar.archidata.db.DbConfig;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.kar.archidata.migration.model.Migration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -26,24 +25,17 @@ public class MigrationEngine {
|
||||
// initialization of the migration if the DB is not present...
|
||||
private MigrationInterface init;
|
||||
|
||||
protected final DBAccess da;
|
||||
|
||||
public MigrationEngine() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this(DBAccess.createInterface());
|
||||
}
|
||||
|
||||
/** Migration engine constructor (empty). */
|
||||
public MigrationEngine(final DBAccess da) {
|
||||
this(da, new ArrayList<>(), null);
|
||||
public MigrationEngine() {
|
||||
this(new ArrayList<>(), null);
|
||||
}
|
||||
|
||||
/** Migration engine constructor (specific mode).
|
||||
* @param datas All the migration ordered.
|
||||
* @param init Initialization migration model. */
|
||||
public MigrationEngine(final DBAccess da, final List<MigrationInterface> datas, final MigrationInterface init) {
|
||||
public MigrationEngine(final List<MigrationInterface> datas, final MigrationInterface init) {
|
||||
this.datas = datas;
|
||||
this.init = init;
|
||||
this.da = da;
|
||||
}
|
||||
|
||||
/** Add a Migration in the list
|
||||
@ -61,17 +53,17 @@ public class MigrationEngine {
|
||||
/** Get the current version/migration name
|
||||
* @return Model represent the last migration. If null then no migration has been done.
|
||||
* @throws MigrationException */
|
||||
public Migration getCurrentVersion() throws MigrationException {
|
||||
if (!this.da.isTableExist("KAR_migration")) {
|
||||
public Migration getCurrentVersion(final DBAccess da) throws MigrationException {
|
||||
if (!da.isTableExist("KAR_migration")) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
List<Migration> data = null;
|
||||
try {
|
||||
data = this.da.gets(Migration.class, QueryOptions.READ_ALL_COLOMN);
|
||||
data = da.gets(Migration.class, QueryOptions.READ_ALL_COLOMN);
|
||||
} catch (final Exception e) {
|
||||
// Previous version does not have the same timeCode...
|
||||
data = this.da.gets(Migration.class);
|
||||
data = da.gets(Migration.class);
|
||||
}
|
||||
if (data == null) {
|
||||
LOGGER.error("Can not collect the migration table in the DB:{}");
|
||||
@ -111,12 +103,24 @@ public class MigrationEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public void migrateErrorThrow(final DbConfig config) throws MigrationException {
|
||||
try (final DBAccess da = DBAccess.createInterface(config)) {
|
||||
migrateErrorThrow(config, da);
|
||||
} catch (final InternalServerErrorException e) {
|
||||
e.printStackTrace();
|
||||
throw new MigrationException("TODO ...");
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new MigrationException("TODO ...");
|
||||
}
|
||||
}
|
||||
|
||||
/** Process the automatic migration of the system
|
||||
* @param config SQL connection for the migration
|
||||
* @throws IOException Error if access on the DB */
|
||||
@SuppressFBWarnings({ "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING",
|
||||
"SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE" })
|
||||
public void migrateErrorThrow(final DbConfig config) throws MigrationException {
|
||||
public void migrateErrorThrow(final DbConfig config, final DBAccess da) throws MigrationException {
|
||||
LOGGER.info("Execute migration ... [BEGIN]");
|
||||
// check the integrity of the migrations:
|
||||
LOGGER.info("List of availlable Migration: ");
|
||||
@ -144,13 +148,13 @@ public class MigrationEngine {
|
||||
|
||||
// STEP 1: Check the DB exist:
|
||||
LOGGER.info("Verify existance of '{}'", config.getDbName());
|
||||
boolean exist = this.da.isDBExist(config.getDbName());
|
||||
boolean exist = da.isDBExist(config.getDbName());
|
||||
if (!exist) {
|
||||
LOGGER.warn("DB: '{}' DOES NOT EXIST ==> create one", config.getDbName());
|
||||
// create the local DB:
|
||||
this.da.createDB(config.getDbName());
|
||||
da.createDB(config.getDbName());
|
||||
}
|
||||
exist = this.da.isDBExist(config.getDbName());
|
||||
exist = da.isDBExist(config.getDbName());
|
||||
while (!exist) {
|
||||
LOGGER.error("DB: '{}' DOES NOT EXIST after trying to create one ", config.getDbName());
|
||||
LOGGER.error("Waiting administrator create a new one, we check after 30 seconds...");
|
||||
@ -160,13 +164,13 @@ public class MigrationEngine {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
exist = this.da.isDBExist(config.getDbName());
|
||||
exist = da.isDBExist(config.getDbName());
|
||||
}
|
||||
LOGGER.info("DB '{}' exist.", config.getDbName());
|
||||
// STEP 2: Check migration table exist:
|
||||
LOGGER.info("Verify existance of migration table '{}'", "KAR_migration");
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
exist = this.da.isTableExist("KAR_migration");
|
||||
if (da instanceof final DBAccessSQL daSQL) {
|
||||
exist = da.isTableExist("KAR_migration");
|
||||
if (!exist) {
|
||||
LOGGER.info("'{}' Does not exist create a new one...", "KAR_migration");
|
||||
// create the table:
|
||||
@ -188,7 +192,7 @@ public class MigrationEngine {
|
||||
}
|
||||
}
|
||||
}
|
||||
final Migration currentVersion = getCurrentVersion();
|
||||
final Migration currentVersion = getCurrentVersion(da);
|
||||
List<MigrationInterface> toApply = new ArrayList<>();
|
||||
boolean needPlaceholder = false;
|
||||
if (currentVersion == null) {
|
||||
@ -230,7 +234,7 @@ public class MigrationEngine {
|
||||
final int id = 0;
|
||||
final int count = toApply.size();
|
||||
for (final MigrationInterface elem : toApply) {
|
||||
migrateSingle(elem, id, count);
|
||||
migrateSingle(da, elem, id, count);
|
||||
}
|
||||
if (needPlaceholder) {
|
||||
if (this.datas.size() == 0) {
|
||||
@ -246,7 +250,7 @@ public class MigrationEngine {
|
||||
migrationResult.count = 0;
|
||||
migrationResult.log = "Place-holder for first initialization";
|
||||
try {
|
||||
migrationResult = this.da.insert(migrationResult);
|
||||
migrationResult = da.insert(migrationResult);
|
||||
} catch (final Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@ -256,7 +260,8 @@ public class MigrationEngine {
|
||||
LOGGER.info("Execute migration ... [ END ]");
|
||||
}
|
||||
|
||||
public void migrateSingle(final MigrationInterface elem, final int id, final int count) throws MigrationException {
|
||||
public void migrateSingle(final DBAccess da, final MigrationInterface elem, final int id, final int count)
|
||||
throws MigrationException {
|
||||
LOGGER.info("---------------------------------------------------------");
|
||||
LOGGER.info("-- Migrate: [{}/{}] {} [BEGIN]", id, count, elem.getName());
|
||||
LOGGER.info("---------------------------------------------------------");
|
||||
@ -275,7 +280,7 @@ public class MigrationEngine {
|
||||
}
|
||||
migrationResult.log = log.toString();
|
||||
try {
|
||||
migrationResult = this.da.insert(migrationResult);
|
||||
migrationResult = da.insert(migrationResult);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new MigrationException(
|
||||
@ -283,7 +288,7 @@ public class MigrationEngine {
|
||||
}
|
||||
boolean ret = true;
|
||||
try {
|
||||
ret = elem.applyMigration(this.da, log, migrationResult);
|
||||
ret = elem.applyMigration(da, log, migrationResult);
|
||||
} catch (final Exception e) {
|
||||
log.append("\nFail in the migration apply ");
|
||||
log.append(e.getLocalizedMessage());
|
||||
@ -294,7 +299,7 @@ public class MigrationEngine {
|
||||
if (ret) {
|
||||
migrationResult.terminated = true;
|
||||
try {
|
||||
this.da.update(migrationResult, migrationResult.id, List.of("terminated"));
|
||||
da.update(migrationResult, migrationResult.id, List.of("terminated"));
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new MigrationException(
|
||||
@ -304,7 +309,7 @@ public class MigrationEngine {
|
||||
try {
|
||||
log.append("Fail in the migration engine...");
|
||||
migrationResult.log = log.toString();
|
||||
this.da.update(migrationResult, migrationResult.id, List.of("log"));
|
||||
da.update(migrationResult, migrationResult.id, List.of("log"));
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new MigrationException("Fail to update migration Log in the migration table: "
|
||||
@ -317,8 +322,8 @@ public class MigrationEngine {
|
||||
LOGGER.info("Migrate: [{}/{}] {} [ END ]", id, count, elem.getName());
|
||||
}
|
||||
|
||||
public void revertTo(final String migrationName) throws MigrationException {
|
||||
final Migration currentVersion = getCurrentVersion();
|
||||
public void revertTo(final DBAccess da, final String migrationName) throws MigrationException {
|
||||
final Migration currentVersion = getCurrentVersion(da);
|
||||
final List<MigrationInterface> toApply = new ArrayList<>();
|
||||
boolean find = false;
|
||||
for (int iii = this.datas.size() - 1; iii >= 0; iii--) {
|
||||
@ -336,11 +341,11 @@ public class MigrationEngine {
|
||||
final int id = 0;
|
||||
final int count = toApply.size();
|
||||
for (final MigrationInterface elem : toApply) {
|
||||
revertSingle(elem, id, count);
|
||||
revertSingle(da, elem, id, count);
|
||||
}
|
||||
}
|
||||
|
||||
public void revertSingle(final MigrationInterface elem, final int id, final int count) {
|
||||
public void revertSingle(final DBAccess da, final MigrationInterface elem, final int id, final int count) {
|
||||
LOGGER.info("Revert migration: {} [BEGIN]", elem.getName());
|
||||
|
||||
LOGGER.info("Revert migration: {} [ END ]", elem.getName());
|
||||
|
@ -37,7 +37,7 @@ import test.kar.archidata.dataAccess.model.TypesTable;
|
||||
public class ConfigureDb {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(ConfigureDb.class);
|
||||
final static private String modeTestForced = null;//"MONGO";
|
||||
static DBAccess dba = null;
|
||||
public static DBAccess da = null;
|
||||
|
||||
public static void configure() throws IOException, InternalServerErrorException, DataAccessException {
|
||||
String modeTest = System.getenv("TEST_E2E_MODE");
|
||||
@ -99,8 +99,7 @@ public class ConfigureDb {
|
||||
ConfigBaseVariable.dbUser = "root";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
dba = DBAccess.createInterface();
|
||||
|
||||
da = DBAccess.createInterface();
|
||||
removeDB();
|
||||
}
|
||||
|
||||
@ -118,11 +117,11 @@ public class ConfigureDb {
|
||||
if ("SQLITE-MEMORY".equalsIgnoreCase(modeTest)) {
|
||||
// nothing to do ...
|
||||
} else if ("SQLITE".equalsIgnoreCase(modeTest)) {
|
||||
dba.deleteDB(ConfigBaseVariable.bdDatabase);
|
||||
da.deleteDB(ConfigBaseVariable.bdDatabase);
|
||||
} else if ("MY-SQL".equalsIgnoreCase(modeTest)) {
|
||||
dba.deleteDB(ConfigBaseVariable.bdDatabase);
|
||||
da.deleteDB(ConfigBaseVariable.bdDatabase);
|
||||
} else if ("MONGO".equalsIgnoreCase(modeTest)) {
|
||||
dba.deleteDB(ConfigBaseVariable.bdDatabase);
|
||||
da.deleteDB(ConfigBaseVariable.bdDatabase);
|
||||
} else {}
|
||||
}
|
||||
|
||||
@ -131,6 +130,6 @@ public class ConfigureDb {
|
||||
removeDB();
|
||||
DbIoFactory.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
|
||||
da.close();
|
||||
}
|
||||
}
|
||||
|
@ -11,14 +11,11 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.dataAccess.model.SerializeAsJson;
|
||||
@ -29,8 +26,6 @@ import test.kar.archidata.dataAccess.model.SimpleTable;
|
||||
public class TestJson {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestJson.class);
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
@ -41,15 +36,11 @@ public class TestJson {
|
||||
ConfigureDb.clear();
|
||||
}
|
||||
|
||||
public TestJson() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testTableFactory() throws Exception {
|
||||
final List<String> sqlCommand = DataFactory.createTable(SerializeAsJson.class);
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
if (ConfigureDb.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
@ -64,7 +55,7 @@ public class TestJson {
|
||||
test.data = new SimpleTable();
|
||||
test.data.data = "plopppopql";
|
||||
|
||||
final SerializeAsJson insertedData = this.da.insert(test);
|
||||
final SerializeAsJson insertedData = ConfigureDb.da.insert(test);
|
||||
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
@ -74,7 +65,7 @@ public class TestJson {
|
||||
Assertions.assertEquals(test.data.data, insertedData.data.data);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final SerializeAsJson retrieve = this.da.get(SerializeAsJson.class, insertedData.id);
|
||||
final SerializeAsJson retrieve = ConfigureDb.da.get(SerializeAsJson.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
|
@ -12,14 +12,11 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.dataAccess.model.SerializeListAsJson;
|
||||
@ -29,8 +26,6 @@ import test.kar.archidata.dataAccess.model.SerializeListAsJson;
|
||||
public class TestListJson {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestListJson.class);
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
@ -41,15 +36,11 @@ public class TestListJson {
|
||||
ConfigureDb.clear();
|
||||
}
|
||||
|
||||
public TestListJson() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testTableInsertAndRetrieve() throws Exception {
|
||||
final List<String> sqlCommand = DataFactory.createTable(SerializeListAsJson.class);
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
if (ConfigureDb.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
@ -68,7 +59,7 @@ public class TestListJson {
|
||||
test.data.add(6);
|
||||
test.data.add(51);
|
||||
|
||||
final SerializeListAsJson insertedData = this.da.insert(test);
|
||||
final SerializeListAsJson insertedData = ConfigureDb.da.insert(test);
|
||||
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
@ -82,7 +73,7 @@ public class TestListJson {
|
||||
Assertions.assertEquals(test.data.get(4), insertedData.data.get(4));
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final SerializeListAsJson retrieve = this.da.get(SerializeListAsJson.class, insertedData.id);
|
||||
final SerializeListAsJson retrieve = ConfigureDb.da.get(SerializeListAsJson.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
|
@ -11,15 +11,12 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.addOnSQL.AddOnManyToMany;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.dataAccess.model.TypeManyToManyRemote;
|
||||
@ -31,8 +28,6 @@ import test.kar.archidata.dataAccess.model.TypeManyToManyRootExpand;
|
||||
public class TestManyToMany {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestManyToMany.class);
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
@ -43,17 +38,13 @@ public class TestManyToMany {
|
||||
ConfigureDb.clear();
|
||||
}
|
||||
|
||||
public TestManyToMany() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
final List<String> sqlCommand2 = DataFactory.createTable(TypeManyToManyRoot.class);
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypeManyToManyRemote.class);
|
||||
sqlCommand.addAll(sqlCommand2);
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
if (ConfigureDb.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
@ -66,14 +57,14 @@ public class TestManyToMany {
|
||||
public void testSimpleInsertAndRetieve() throws Exception {
|
||||
final TypeManyToManyRoot test = new TypeManyToManyRoot();
|
||||
test.otherData = "kjhlkjlkj";
|
||||
final TypeManyToManyRoot insertedData = this.da.insert(test);
|
||||
final TypeManyToManyRoot insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
Assertions.assertNull(insertedData.remote);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypeManyToManyRoot retrieve = this.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||
final TypeManyToManyRoot retrieve = ConfigureDb.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -82,7 +73,7 @@ public class TestManyToMany {
|
||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||
Assertions.assertNull(retrieve.remote);
|
||||
|
||||
this.da.delete(TypeManyToManyRoot.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypeManyToManyRoot.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(3)
|
||||
@ -91,24 +82,24 @@ public class TestManyToMany {
|
||||
|
||||
TypeManyToManyRemote remote = new TypeManyToManyRemote();
|
||||
remote.data = "remote1";
|
||||
final TypeManyToManyRemote insertedRemote1 = this.da.insert(remote);
|
||||
final TypeManyToManyRemote insertedRemote1 = ConfigureDb.da.insert(remote);
|
||||
Assertions.assertEquals(insertedRemote1.data, remote.data);
|
||||
|
||||
remote = new TypeManyToManyRemote();
|
||||
remote.data = "remote2";
|
||||
final TypeManyToManyRemote insertedRemote2 = this.da.insert(remote);
|
||||
final TypeManyToManyRemote insertedRemote2 = ConfigureDb.da.insert(remote);
|
||||
Assertions.assertEquals(insertedRemote2.data, remote.data);
|
||||
|
||||
final TypeManyToManyRoot test = new TypeManyToManyRoot();
|
||||
test.otherData = "kjhlkjlkj";
|
||||
final TypeManyToManyRoot insertedData = this.da.insert(test);
|
||||
final TypeManyToManyRoot insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
Assertions.assertNull(insertedData.remote);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
TypeManyToManyRoot retrieve = this.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||
TypeManyToManyRoot retrieve = ConfigureDb.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -118,10 +109,10 @@ public class TestManyToMany {
|
||||
Assertions.assertNull(retrieve.remote);
|
||||
|
||||
// Add remote elements
|
||||
AddOnManyToMany.addLink(this.da, TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote1.id);
|
||||
AddOnManyToMany.addLink(this.da, TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote2.id);
|
||||
AddOnManyToMany.addLink(ConfigureDb.da, TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote1.id);
|
||||
AddOnManyToMany.addLink(ConfigureDb.da, TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote2.id);
|
||||
|
||||
retrieve = this.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||
retrieve = ConfigureDb.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -133,7 +124,8 @@ public class TestManyToMany {
|
||||
Assertions.assertEquals(retrieve.remote.get(0), insertedRemote1.id);
|
||||
Assertions.assertEquals(retrieve.remote.get(1), insertedRemote2.id);
|
||||
|
||||
final TypeManyToManyRootExpand retrieveExpand = this.da.get(TypeManyToManyRootExpand.class, insertedData.id);
|
||||
final TypeManyToManyRootExpand retrieveExpand = ConfigureDb.da.get(TypeManyToManyRootExpand.class,
|
||||
insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieveExpand);
|
||||
Assertions.assertNotNull(retrieveExpand.id);
|
||||
@ -146,11 +138,11 @@ public class TestManyToMany {
|
||||
Assertions.assertEquals(retrieveExpand.remote.get(1).id, insertedRemote2.id);
|
||||
|
||||
// Remove an element
|
||||
long count = AddOnManyToMany.removeLink(this.da, TypeManyToManyRoot.class, retrieve.id, "remote",
|
||||
long count = AddOnManyToMany.removeLink(ConfigureDb.da, TypeManyToManyRoot.class, retrieve.id, "remote",
|
||||
insertedRemote1.id);
|
||||
Assertions.assertEquals(1, count);
|
||||
|
||||
retrieve = this.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||
retrieve = ConfigureDb.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -162,11 +154,11 @@ public class TestManyToMany {
|
||||
Assertions.assertEquals(retrieve.remote.get(0), insertedRemote2.id);
|
||||
|
||||
// Remove the second element
|
||||
count = AddOnManyToMany.removeLink(this.da, TypeManyToManyRoot.class, retrieve.id, "remote",
|
||||
count = AddOnManyToMany.removeLink(ConfigureDb.da, TypeManyToManyRoot.class, retrieve.id, "remote",
|
||||
insertedRemote2.id);
|
||||
Assertions.assertEquals(1, count);
|
||||
|
||||
retrieve = this.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||
retrieve = ConfigureDb.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -175,7 +167,7 @@ public class TestManyToMany {
|
||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||
Assertions.assertNull(retrieve.remote);
|
||||
|
||||
this.da.delete(TypeManyToManyRoot.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypeManyToManyRoot.class, insertedData.id);
|
||||
}
|
||||
|
||||
/* API TODO: - Replace list (permet de les ordonnées) - remove all links - delete en cascade .... (compliqué...) */
|
||||
|
@ -11,14 +11,11 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.dataAccess.model.TypeManyToOneRemote;
|
||||
@ -33,8 +30,6 @@ import test.kar.archidata.dataAccess.model.TypeManyToOneUUIDRootExpand;
|
||||
public class TestManyToOne {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestManyToOne.class);
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
@ -45,10 +40,6 @@ public class TestManyToOne {
|
||||
ConfigureDb.clear();
|
||||
}
|
||||
|
||||
public TestManyToOne() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
@ -56,7 +47,7 @@ public class TestManyToOne {
|
||||
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneRoot.class));
|
||||
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneUUIDRoot.class));
|
||||
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneUUIDRemote.class));
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
if (ConfigureDb.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
@ -69,32 +60,32 @@ public class TestManyToOne {
|
||||
public void testRemoteLong() throws Exception {
|
||||
TypeManyToOneRemote remote = new TypeManyToOneRemote();
|
||||
remote.data = "remote1";
|
||||
final TypeManyToOneRemote insertedRemote1 = this.da.insert(remote);
|
||||
final TypeManyToOneRemote insertedRemote1 = ConfigureDb.da.insert(remote);
|
||||
Assertions.assertEquals(insertedRemote1.data, remote.data);
|
||||
|
||||
remote = new TypeManyToOneRemote();
|
||||
remote.data = "remote2";
|
||||
final TypeManyToOneRemote insertedRemote2 = this.da.insert(remote);
|
||||
final TypeManyToOneRemote insertedRemote2 = ConfigureDb.da.insert(remote);
|
||||
Assertions.assertEquals(insertedRemote2.data, remote.data);
|
||||
|
||||
final TypeManyToOneRoot test = new TypeManyToOneRoot();
|
||||
test.otherData = "kjhlkjlkj";
|
||||
test.remoteId = insertedRemote2.id;
|
||||
final TypeManyToOneRoot insertedData = this.da.insert(test);
|
||||
final TypeManyToOneRoot insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
Assertions.assertEquals(test.otherData, insertedData.otherData);
|
||||
Assertions.assertEquals(insertedRemote2.id, insertedData.remoteId);
|
||||
|
||||
TypeManyToOneRoot retrieve = this.da.get(TypeManyToOneRoot.class, insertedData.id);
|
||||
TypeManyToOneRoot retrieve = ConfigureDb.da.get(TypeManyToOneRoot.class, insertedData.id);
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||
Assertions.assertEquals(insertedRemote2.id, retrieve.remoteId);
|
||||
|
||||
TypeManyToOneRootExpand retrieve2 = this.da.get(TypeManyToOneRootExpand.class, insertedData.id);
|
||||
TypeManyToOneRootExpand retrieve2 = ConfigureDb.da.get(TypeManyToOneRootExpand.class, insertedData.id);
|
||||
Assertions.assertNotNull(retrieve2);
|
||||
Assertions.assertNotNull(retrieve2.id);
|
||||
Assertions.assertEquals(insertedData.id, retrieve2.id);
|
||||
@ -105,21 +96,21 @@ public class TestManyToOne {
|
||||
|
||||
// remove values:
|
||||
try {
|
||||
final long count = this.da.delete(TypeManyToOneRemote.class, insertedRemote2.id);
|
||||
final long count = ConfigureDb.da.delete(TypeManyToOneRemote.class, insertedRemote2.id);
|
||||
Assertions.assertEquals(1L, count);
|
||||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// check fail:
|
||||
|
||||
retrieve = this.da.get(TypeManyToOneRoot.class, insertedData.id);
|
||||
retrieve = ConfigureDb.da.get(TypeManyToOneRoot.class, insertedData.id);
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||
Assertions.assertEquals(insertedRemote2.id, retrieve.remoteId);
|
||||
|
||||
retrieve2 = this.da.get(TypeManyToOneRootExpand.class, insertedData.id);
|
||||
retrieve2 = ConfigureDb.da.get(TypeManyToOneRootExpand.class, insertedData.id);
|
||||
Assertions.assertNotNull(retrieve2);
|
||||
Assertions.assertNotNull(retrieve2.id);
|
||||
Assertions.assertEquals(insertedData.id, retrieve2.id);
|
||||
@ -132,31 +123,32 @@ public class TestManyToOne {
|
||||
public void testRemoteUUID() throws Exception {
|
||||
TypeManyToOneUUIDRemote remote = new TypeManyToOneUUIDRemote();
|
||||
remote.data = "remote1";
|
||||
final TypeManyToOneUUIDRemote insertedRemote1 = this.da.insert(remote);
|
||||
final TypeManyToOneUUIDRemote insertedRemote1 = ConfigureDb.da.insert(remote);
|
||||
Assertions.assertEquals(insertedRemote1.data, remote.data);
|
||||
|
||||
remote = new TypeManyToOneUUIDRemote();
|
||||
remote.data = "remote2";
|
||||
final TypeManyToOneUUIDRemote insertedRemote2 = this.da.insert(remote);
|
||||
final TypeManyToOneUUIDRemote insertedRemote2 = ConfigureDb.da.insert(remote);
|
||||
Assertions.assertEquals(insertedRemote2.data, remote.data);
|
||||
|
||||
final TypeManyToOneUUIDRoot test = new TypeManyToOneUUIDRoot();
|
||||
test.otherData = "kjhlkjlkj";
|
||||
test.remoteUuid = insertedRemote2.uuid;
|
||||
final TypeManyToOneUUIDRoot insertedData = this.da.insert(test);
|
||||
final TypeManyToOneUUIDRoot insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.uuid);
|
||||
Assertions.assertEquals(test.otherData, insertedData.otherData);
|
||||
Assertions.assertEquals(insertedRemote2.uuid, insertedData.remoteUuid);
|
||||
|
||||
TypeManyToOneUUIDRoot retrieve = this.da.get(TypeManyToOneUUIDRoot.class, insertedData.uuid);
|
||||
TypeManyToOneUUIDRoot retrieve = ConfigureDb.da.get(TypeManyToOneUUIDRoot.class, insertedData.uuid);
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.uuid);
|
||||
Assertions.assertEquals(insertedData.uuid, retrieve.uuid);
|
||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||
Assertions.assertEquals(insertedRemote2.uuid, retrieve.remoteUuid);
|
||||
|
||||
TypeManyToOneUUIDRootExpand retrieve2 = this.da.get(TypeManyToOneUUIDRootExpand.class, insertedData.uuid);
|
||||
TypeManyToOneUUIDRootExpand retrieve2 = ConfigureDb.da.get(TypeManyToOneUUIDRootExpand.class,
|
||||
insertedData.uuid);
|
||||
Assertions.assertNotNull(retrieve2);
|
||||
Assertions.assertNotNull(retrieve2.uuid);
|
||||
Assertions.assertEquals(insertedData.uuid, retrieve2.uuid);
|
||||
@ -166,19 +158,19 @@ public class TestManyToOne {
|
||||
Assertions.assertEquals(insertedRemote2.data, retrieve2.remote.data);
|
||||
|
||||
// remove values:
|
||||
final long count = this.da.delete(TypeManyToOneUUIDRemote.class, insertedRemote2.uuid);
|
||||
final long count = ConfigureDb.da.delete(TypeManyToOneUUIDRemote.class, insertedRemote2.uuid);
|
||||
Assertions.assertEquals(1, count);
|
||||
|
||||
// check fail:
|
||||
|
||||
retrieve = this.da.get(TypeManyToOneUUIDRoot.class, insertedData.uuid);
|
||||
retrieve = ConfigureDb.da.get(TypeManyToOneUUIDRoot.class, insertedData.uuid);
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.uuid);
|
||||
Assertions.assertEquals(insertedData.uuid, retrieve.uuid);
|
||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||
Assertions.assertEquals(insertedRemote2.uuid, retrieve.remoteUuid);
|
||||
|
||||
retrieve2 = this.da.get(TypeManyToOneUUIDRootExpand.class, insertedData.uuid);
|
||||
retrieve2 = ConfigureDb.da.get(TypeManyToOneUUIDRootExpand.class, insertedData.uuid);
|
||||
Assertions.assertNotNull(retrieve2);
|
||||
Assertions.assertNotNull(retrieve2.uuid);
|
||||
Assertions.assertEquals(insertedData.uuid, retrieve2.uuid);
|
||||
|
@ -11,14 +11,11 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.dataAccess.model.TypeOneToManyRemote;
|
||||
@ -33,8 +30,6 @@ import test.kar.archidata.dataAccess.model.TypeOneToManyUUIDRootExpand;
|
||||
public class TestOneToMany {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestOneToMany.class);
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
@ -45,10 +40,6 @@ public class TestOneToMany {
|
||||
ConfigureDb.clear();
|
||||
}
|
||||
|
||||
public TestOneToMany() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
@ -56,7 +47,7 @@ public class TestOneToMany {
|
||||
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyRoot.class));
|
||||
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyUUIDRemote.class));
|
||||
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyUUIDRoot.class));
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
if (ConfigureDb.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
@ -71,13 +62,13 @@ public class TestOneToMany {
|
||||
|
||||
final TypeOneToManyRoot root = new TypeOneToManyRoot();
|
||||
root.otherData = "plouf";
|
||||
final TypeOneToManyRoot insertedRoot = this.da.insert(root);
|
||||
final TypeOneToManyRoot insertedRoot = ConfigureDb.da.insert(root);
|
||||
Assertions.assertEquals(insertedRoot.otherData, root.otherData);
|
||||
Assertions.assertNull(insertedRoot.remoteIds);
|
||||
|
||||
final TypeOneToManyRoot root2 = new TypeOneToManyRoot();
|
||||
root2.otherData = "plouf 2";
|
||||
final TypeOneToManyRoot insertedRoot2 = this.da.insert(root2);
|
||||
final TypeOneToManyRoot insertedRoot2 = ConfigureDb.da.insert(root2);
|
||||
Assertions.assertEquals(insertedRoot2.otherData, root2.otherData);
|
||||
Assertions.assertNull(insertedRoot2.remoteIds);
|
||||
|
||||
@ -86,34 +77,34 @@ public class TestOneToMany {
|
||||
final TypeOneToManyRemote remote10 = new TypeOneToManyRemote();
|
||||
remote10.data = "remote10";
|
||||
remote10.rootId = insertedRoot.id;
|
||||
final TypeOneToManyRemote insertedRemote10 = this.da.insert(remote10);
|
||||
final TypeOneToManyRemote insertedRemote10 = ConfigureDb.da.insert(remote10);
|
||||
Assertions.assertEquals(insertedRemote10.data, remote10.data);
|
||||
Assertions.assertEquals(insertedRemote10.rootId, remote10.rootId);
|
||||
|
||||
final TypeOneToManyRemote remote11 = new TypeOneToManyRemote();
|
||||
remote11.data = "remote11";
|
||||
remote11.rootId = insertedRoot.id;
|
||||
final TypeOneToManyRemote insertedRemote11 = this.da.insert(remote11);
|
||||
final TypeOneToManyRemote insertedRemote11 = ConfigureDb.da.insert(remote11);
|
||||
Assertions.assertEquals(insertedRemote11.data, remote11.data);
|
||||
Assertions.assertEquals(insertedRemote11.rootId, remote11.rootId);
|
||||
|
||||
final TypeOneToManyRemote remote20 = new TypeOneToManyRemote();
|
||||
remote20.data = "remote20";
|
||||
remote20.rootId = insertedRoot2.id;
|
||||
final TypeOneToManyRemote insertedRemote20 = this.da.insert(remote20);
|
||||
final TypeOneToManyRemote insertedRemote20 = ConfigureDb.da.insert(remote20);
|
||||
Assertions.assertEquals(insertedRemote20.data, remote20.data);
|
||||
Assertions.assertEquals(insertedRemote20.rootId, remote20.rootId);
|
||||
|
||||
// Check remote are inserted
|
||||
|
||||
final TypeOneToManyRoot retreiveRoot1 = this.da.get(TypeOneToManyRoot.class, insertedRoot.id);
|
||||
final TypeOneToManyRoot retreiveRoot1 = ConfigureDb.da.get(TypeOneToManyRoot.class, insertedRoot.id);
|
||||
Assertions.assertEquals(retreiveRoot1.otherData, insertedRoot.otherData);
|
||||
Assertions.assertNotNull(retreiveRoot1.remoteIds);
|
||||
Assertions.assertEquals(2, retreiveRoot1.remoteIds.size());
|
||||
Assertions.assertEquals(insertedRemote10.id, retreiveRoot1.remoteIds.get(0));
|
||||
Assertions.assertEquals(insertedRemote11.id, retreiveRoot1.remoteIds.get(1));
|
||||
|
||||
final TypeOneToManyRoot retreiveRoot2 = this.da.get(TypeOneToManyRoot.class, insertedRoot2.id);
|
||||
final TypeOneToManyRoot retreiveRoot2 = ConfigureDb.da.get(TypeOneToManyRoot.class, insertedRoot2.id);
|
||||
Assertions.assertEquals(retreiveRoot2.otherData, insertedRoot2.otherData);
|
||||
Assertions.assertNotNull(retreiveRoot2.remoteIds);
|
||||
Assertions.assertEquals(1, retreiveRoot2.remoteIds.size());
|
||||
@ -121,7 +112,8 @@ public class TestOneToMany {
|
||||
|
||||
// Check remote are inserted and expandable
|
||||
|
||||
final TypeOneToManyRootExpand retreiveRootExpand1 = this.da.get(TypeOneToManyRootExpand.class, insertedRoot.id);
|
||||
final TypeOneToManyRootExpand retreiveRootExpand1 = ConfigureDb.da.get(TypeOneToManyRootExpand.class,
|
||||
insertedRoot.id);
|
||||
Assertions.assertEquals(retreiveRootExpand1.otherData, insertedRoot.otherData);
|
||||
Assertions.assertNotNull(retreiveRootExpand1.remotes);
|
||||
Assertions.assertEquals(2, retreiveRootExpand1.remotes.size());
|
||||
@ -132,7 +124,7 @@ public class TestOneToMany {
|
||||
Assertions.assertEquals(insertedRemote11.rootId, retreiveRootExpand1.remotes.get(1).rootId);
|
||||
Assertions.assertEquals(insertedRemote11.data, retreiveRootExpand1.remotes.get(1).data);
|
||||
|
||||
final TypeOneToManyRootExpand retreiveRootExpand2 = this.da.get(TypeOneToManyRootExpand.class,
|
||||
final TypeOneToManyRootExpand retreiveRootExpand2 = ConfigureDb.da.get(TypeOneToManyRootExpand.class,
|
||||
insertedRoot2.id);
|
||||
Assertions.assertEquals(retreiveRootExpand2.otherData, insertedRoot2.otherData);
|
||||
Assertions.assertNotNull(retreiveRootExpand2.remotes);
|
||||
@ -150,13 +142,13 @@ public class TestOneToMany {
|
||||
|
||||
final TypeOneToManyUUIDRoot root = new TypeOneToManyUUIDRoot();
|
||||
root.otherData = "plouf";
|
||||
final TypeOneToManyUUIDRoot insertedRoot = this.da.insert(root);
|
||||
final TypeOneToManyUUIDRoot insertedRoot = ConfigureDb.da.insert(root);
|
||||
Assertions.assertEquals(insertedRoot.otherData, root.otherData);
|
||||
Assertions.assertNull(insertedRoot.remoteIds);
|
||||
|
||||
final TypeOneToManyUUIDRoot root2 = new TypeOneToManyUUIDRoot();
|
||||
root2.otherData = "plouf 2";
|
||||
final TypeOneToManyUUIDRoot insertedRoot2 = this.da.insert(root2);
|
||||
final TypeOneToManyUUIDRoot insertedRoot2 = ConfigureDb.da.insert(root2);
|
||||
Assertions.assertEquals(insertedRoot2.otherData, root2.otherData);
|
||||
Assertions.assertNull(insertedRoot2.remoteIds);
|
||||
|
||||
@ -165,34 +157,34 @@ public class TestOneToMany {
|
||||
final TypeOneToManyUUIDRemote remote10 = new TypeOneToManyUUIDRemote();
|
||||
remote10.data = "remote10";
|
||||
remote10.rootUuid = insertedRoot.uuid;
|
||||
final TypeOneToManyUUIDRemote insertedRemote10 = this.da.insert(remote10);
|
||||
final TypeOneToManyUUIDRemote insertedRemote10 = ConfigureDb.da.insert(remote10);
|
||||
Assertions.assertEquals(insertedRemote10.data, remote10.data);
|
||||
Assertions.assertEquals(insertedRemote10.rootUuid, remote10.rootUuid);
|
||||
|
||||
final TypeOneToManyUUIDRemote remote11 = new TypeOneToManyUUIDRemote();
|
||||
remote11.data = "remote11";
|
||||
remote11.rootUuid = insertedRoot.uuid;
|
||||
final TypeOneToManyUUIDRemote insertedRemote11 = this.da.insert(remote11);
|
||||
final TypeOneToManyUUIDRemote insertedRemote11 = ConfigureDb.da.insert(remote11);
|
||||
Assertions.assertEquals(insertedRemote11.data, remote11.data);
|
||||
Assertions.assertEquals(insertedRemote11.rootUuid, remote11.rootUuid);
|
||||
|
||||
final TypeOneToManyUUIDRemote remote20 = new TypeOneToManyUUIDRemote();
|
||||
remote20.data = "remote20";
|
||||
remote20.rootUuid = insertedRoot2.uuid;
|
||||
final TypeOneToManyUUIDRemote insertedRemote20 = this.da.insert(remote20);
|
||||
final TypeOneToManyUUIDRemote insertedRemote20 = ConfigureDb.da.insert(remote20);
|
||||
Assertions.assertEquals(insertedRemote20.data, remote20.data);
|
||||
Assertions.assertEquals(insertedRemote20.rootUuid, remote20.rootUuid);
|
||||
|
||||
// Check remote are inserted
|
||||
|
||||
final TypeOneToManyUUIDRoot retreiveRoot1 = this.da.get(TypeOneToManyUUIDRoot.class, insertedRoot.uuid);
|
||||
final TypeOneToManyUUIDRoot retreiveRoot1 = ConfigureDb.da.get(TypeOneToManyUUIDRoot.class, insertedRoot.uuid);
|
||||
Assertions.assertEquals(retreiveRoot1.otherData, insertedRoot.otherData);
|
||||
Assertions.assertNotNull(retreiveRoot1.remoteIds);
|
||||
Assertions.assertEquals(2, retreiveRoot1.remoteIds.size());
|
||||
Assertions.assertEquals(insertedRemote10.uuid, retreiveRoot1.remoteIds.get(0));
|
||||
Assertions.assertEquals(insertedRemote11.uuid, retreiveRoot1.remoteIds.get(1));
|
||||
|
||||
final TypeOneToManyUUIDRoot retreiveRoot2 = this.da.get(TypeOneToManyUUIDRoot.class, insertedRoot2.uuid);
|
||||
final TypeOneToManyUUIDRoot retreiveRoot2 = ConfigureDb.da.get(TypeOneToManyUUIDRoot.class, insertedRoot2.uuid);
|
||||
Assertions.assertEquals(retreiveRoot2.otherData, insertedRoot2.otherData);
|
||||
Assertions.assertNotNull(retreiveRoot2.remoteIds);
|
||||
Assertions.assertEquals(1, retreiveRoot2.remoteIds.size());
|
||||
@ -200,7 +192,7 @@ public class TestOneToMany {
|
||||
|
||||
// Check remote are inserted and expandable
|
||||
|
||||
final TypeOneToManyUUIDRootExpand retreiveRootExpand1 = this.da.get(TypeOneToManyUUIDRootExpand.class,
|
||||
final TypeOneToManyUUIDRootExpand retreiveRootExpand1 = ConfigureDb.da.get(TypeOneToManyUUIDRootExpand.class,
|
||||
insertedRoot.uuid);
|
||||
Assertions.assertEquals(retreiveRootExpand1.otherData, insertedRoot.otherData);
|
||||
Assertions.assertNotNull(retreiveRootExpand1.remotes);
|
||||
@ -212,7 +204,7 @@ public class TestOneToMany {
|
||||
Assertions.assertEquals(insertedRemote11.rootUuid, retreiveRootExpand1.remotes.get(1).rootUuid);
|
||||
Assertions.assertEquals(insertedRemote11.data, retreiveRootExpand1.remotes.get(1).data);
|
||||
|
||||
final TypeOneToManyUUIDRootExpand retreiveRootExpand2 = this.da.get(TypeOneToManyUUIDRootExpand.class,
|
||||
final TypeOneToManyUUIDRootExpand retreiveRootExpand2 = ConfigureDb.da.get(TypeOneToManyUUIDRootExpand.class,
|
||||
insertedRoot2.uuid);
|
||||
Assertions.assertEquals(retreiveRootExpand2.otherData, insertedRoot2.otherData);
|
||||
Assertions.assertNotNull(retreiveRootExpand2.remotes);
|
||||
|
@ -11,14 +11,11 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.dataAccess.model.TypesTable;
|
||||
@ -28,8 +25,6 @@ import test.kar.archidata.dataAccess.model.TypesTable;
|
||||
public class TestRawQuery {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypes.class);
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
@ -40,18 +35,11 @@ public class TestRawQuery {
|
||||
ConfigureDb.clear();
|
||||
}
|
||||
|
||||
public TestRawQuery() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
LOGGER.error("lkjddlkj");
|
||||
}
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
if (ConfigureDb.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
@ -62,30 +50,30 @@ public class TestRawQuery {
|
||||
@Order(2)
|
||||
@Test
|
||||
public void testGet() throws Exception {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
if (ConfigureDb.da instanceof final DBAccessSQL daSQL) {
|
||||
|
||||
final TypesTable test = new TypesTable();
|
||||
test.intData = 95;
|
||||
test.floatData = 1.0F;
|
||||
this.da.insert(test);
|
||||
ConfigureDb.da.insert(test);
|
||||
test.intData = 96;
|
||||
test.floatData = 2.0F;
|
||||
this.da.insert(test);
|
||||
ConfigureDb.da.insert(test);
|
||||
test.intData = 97;
|
||||
test.floatData = 3.0F;
|
||||
this.da.insert(test);
|
||||
ConfigureDb.da.insert(test);
|
||||
test.intData = 98;
|
||||
test.floatData = 4.0F;
|
||||
this.da.insert(test);
|
||||
ConfigureDb.da.insert(test);
|
||||
test.intData = 99;
|
||||
test.floatData = 5.0F;
|
||||
this.da.insert(test);
|
||||
ConfigureDb.da.insert(test);
|
||||
test.intData = 99;
|
||||
test.floatData = 6.0F;
|
||||
this.da.insert(test);
|
||||
ConfigureDb.da.insert(test);
|
||||
test.intData = 99;
|
||||
test.floatData = 7.0F;
|
||||
this.da.insert(test);
|
||||
ConfigureDb.da.insert(test);
|
||||
{
|
||||
final String query = """
|
||||
SELECT *
|
||||
|
@ -14,15 +14,12 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.dataAccess.model.SimpleTable;
|
||||
@ -36,8 +33,6 @@ public class TestSimpleTable {
|
||||
private static Long idOfTheObject = null;
|
||||
private static Timestamp startAction = null;
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
// Clear the static test:
|
||||
@ -51,16 +46,12 @@ public class TestSimpleTable {
|
||||
ConfigureDb.clear();
|
||||
}
|
||||
|
||||
public TestSimpleTable() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testTableInsertAndRetrieve() throws Exception {
|
||||
TestSimpleTable.startAction = Timestamp.from(Instant.now());
|
||||
final List<String> sqlCommand = DataFactory.createTable(SimpleTable.class);
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
if (ConfigureDb.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
@ -68,14 +59,14 @@ public class TestSimpleTable {
|
||||
}
|
||||
final SimpleTable test = new SimpleTable();
|
||||
test.data = TestSimpleTable.DATA_INJECTED;
|
||||
final SimpleTable insertedData = this.da.insert(test);
|
||||
final SimpleTable insertedData = ConfigureDb.da.insert(test);
|
||||
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final SimpleTable retrieve = this.da.get(SimpleTable.class, insertedData.id);
|
||||
final SimpleTable retrieve = ConfigureDb.da.get(SimpleTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -90,7 +81,7 @@ public class TestSimpleTable {
|
||||
@Test
|
||||
public void testReadAllValuesUnreadable() throws Exception {
|
||||
// check the full values
|
||||
final SimpleTable retrieve = this.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||
final SimpleTable retrieve = ConfigureDb.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||
QueryOptions.READ_ALL_COLOMN);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
@ -113,8 +104,8 @@ public class TestSimpleTable {
|
||||
// Delete the entry:
|
||||
final SimpleTable test = new SimpleTable();
|
||||
test.data = TestSimpleTable.DATA_INJECTED_2;
|
||||
this.da.update(test, TestSimpleTable.idOfTheObject, List.of("data"));
|
||||
final SimpleTable retrieve = this.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||
ConfigureDb.da.update(test, TestSimpleTable.idOfTheObject, List.of("data"));
|
||||
final SimpleTable retrieve = ConfigureDb.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||
QueryOptions.READ_ALL_COLOMN);
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -130,8 +121,8 @@ public class TestSimpleTable {
|
||||
@Test
|
||||
public void testDeleteTheObject() throws Exception {
|
||||
// Delete the entry:
|
||||
this.da.delete(SimpleTable.class, TestSimpleTable.idOfTheObject);
|
||||
final SimpleTable retrieve = this.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject);
|
||||
ConfigureDb.da.delete(SimpleTable.class, TestSimpleTable.idOfTheObject);
|
||||
final SimpleTable retrieve = ConfigureDb.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject);
|
||||
Assertions.assertNull(retrieve);
|
||||
}
|
||||
|
||||
@ -140,7 +131,7 @@ public class TestSimpleTable {
|
||||
public void testReadDeletedObject() throws Exception {
|
||||
|
||||
// check if we set get deleted element
|
||||
final SimpleTable retrieve = this.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||
final SimpleTable retrieve = ConfigureDb.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||
QueryOptions.ACCESS_DELETED_ITEMS);
|
||||
Assertions.assertNull(retrieve);
|
||||
|
||||
@ -150,7 +141,7 @@ public class TestSimpleTable {
|
||||
@Test
|
||||
public void testReadAllValuesUnreadableOfDeletedObject() throws Exception {
|
||||
// check if we set get deleted element with all data
|
||||
final SimpleTable retrieve = this.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||
final SimpleTable retrieve = ConfigureDb.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||
QueryOptions.ACCESS_DELETED_ITEMS, QueryOptions.READ_ALL_COLOMN);
|
||||
Assertions.assertNull(retrieve);
|
||||
|
||||
|
@ -14,16 +14,13 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.dataAccess.model.SimpleTableSoftDelete;
|
||||
@ -37,8 +34,6 @@ public class TestSimpleTableSoftDelete {
|
||||
private static Long idOfTheObject = null;
|
||||
private static Timestamp startAction = null;
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
// Clear the static test:
|
||||
@ -53,16 +48,12 @@ public class TestSimpleTableSoftDelete {
|
||||
ConfigureDb.clear();
|
||||
}
|
||||
|
||||
public TestSimpleTableSoftDelete() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testTableInsertAndRetrieve() throws Exception {
|
||||
TestSimpleTableSoftDelete.startAction = Timestamp.from(Instant.now());
|
||||
final List<String> sqlCommand = DataFactory.createTable(SimpleTableSoftDelete.class);
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
if (ConfigureDb.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
@ -70,14 +61,14 @@ public class TestSimpleTableSoftDelete {
|
||||
}
|
||||
final SimpleTableSoftDelete test = new SimpleTableSoftDelete();
|
||||
test.data = TestSimpleTableSoftDelete.DATA_INJECTED;
|
||||
final SimpleTableSoftDelete insertedData = this.da.insert(test);
|
||||
final SimpleTableSoftDelete insertedData = ConfigureDb.da.insert(test);
|
||||
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final SimpleTableSoftDelete retrieve = this.da.get(SimpleTableSoftDelete.class, insertedData.id);
|
||||
final SimpleTableSoftDelete retrieve = ConfigureDb.da.get(SimpleTableSoftDelete.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -93,7 +84,7 @@ public class TestSimpleTableSoftDelete {
|
||||
@Test
|
||||
public void testReadAllValuesUnreadable() throws Exception {
|
||||
// check the full values
|
||||
final SimpleTableSoftDelete retrieve = this.da.get(SimpleTableSoftDelete.class,
|
||||
final SimpleTableSoftDelete retrieve = ConfigureDb.da.get(SimpleTableSoftDelete.class,
|
||||
TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.READ_ALL_COLOMN);
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -119,8 +110,8 @@ public class TestSimpleTableSoftDelete {
|
||||
// Delete the entry:
|
||||
final SimpleTableSoftDelete test = new SimpleTableSoftDelete();
|
||||
test.data = TestSimpleTableSoftDelete.DATA_INJECTED_2;
|
||||
this.da.update(test, TestSimpleTableSoftDelete.idOfTheObject, List.of("data"));
|
||||
final SimpleTableSoftDelete retrieve = this.da.get(SimpleTableSoftDelete.class,
|
||||
ConfigureDb.da.update(test, TestSimpleTableSoftDelete.idOfTheObject, List.of("data"));
|
||||
final SimpleTableSoftDelete retrieve = ConfigureDb.da.get(SimpleTableSoftDelete.class,
|
||||
TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS,
|
||||
QueryOptions.READ_ALL_COLOMN);
|
||||
Assertions.assertNotNull(retrieve);
|
||||
@ -144,8 +135,8 @@ public class TestSimpleTableSoftDelete {
|
||||
Thread.sleep(Duration.ofMillis(15));
|
||||
}
|
||||
// Delete the entry:
|
||||
this.da.delete(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject);
|
||||
final SimpleTableSoftDelete retrieve = this.da.get(SimpleTableSoftDelete.class,
|
||||
ConfigureDb.da.delete(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject);
|
||||
final SimpleTableSoftDelete retrieve = ConfigureDb.da.get(SimpleTableSoftDelete.class,
|
||||
TestSimpleTableSoftDelete.idOfTheObject);
|
||||
Assertions.assertNull(retrieve);
|
||||
}
|
||||
@ -155,7 +146,7 @@ public class TestSimpleTableSoftDelete {
|
||||
public void testReadDeletedObject() throws Exception {
|
||||
|
||||
// check if we set get deleted element
|
||||
final SimpleTableSoftDelete retrieve = this.da.get(SimpleTableSoftDelete.class,
|
||||
final SimpleTableSoftDelete retrieve = ConfigureDb.da.get(SimpleTableSoftDelete.class,
|
||||
TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS);
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -171,7 +162,7 @@ public class TestSimpleTableSoftDelete {
|
||||
@Test
|
||||
public void testReadAllValuesUnreadableOfDeletedObject() throws Exception {
|
||||
// check if we set get deleted element with all data
|
||||
final SimpleTableSoftDelete retrieve = this.da.get(SimpleTableSoftDelete.class,
|
||||
final SimpleTableSoftDelete retrieve = ConfigureDb.da.get(SimpleTableSoftDelete.class,
|
||||
TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS,
|
||||
QueryOptions.READ_ALL_COLOMN);
|
||||
Assertions.assertNotNull(retrieve);
|
||||
|
@ -11,14 +11,11 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.dataAccess.model.Enum1ForTest;
|
||||
@ -29,8 +26,6 @@ import test.kar.archidata.dataAccess.model.TypesEnum1;
|
||||
public class TestTypeEnum1 {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypeEnum1.class);
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
@ -41,15 +36,11 @@ public class TestTypeEnum1 {
|
||||
ConfigureDb.clear();
|
||||
}
|
||||
|
||||
public TestTypeEnum1() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesEnum1.class);
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
if (ConfigureDb.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
@ -63,13 +54,13 @@ public class TestTypeEnum1 {
|
||||
|
||||
final TypesEnum1 test = new TypesEnum1();
|
||||
test.data = Enum1ForTest.ENUM_VALUE_3;
|
||||
final TypesEnum1 insertedData = this.da.insert(test);
|
||||
final TypesEnum1 insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesEnum1 retrieve = this.da.get(TypesEnum1.class, insertedData.id);
|
||||
final TypesEnum1 retrieve = ConfigureDb.da.get(TypesEnum1.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -77,6 +68,6 @@ public class TestTypeEnum1 {
|
||||
Assertions.assertNotNull(retrieve.data);
|
||||
Assertions.assertEquals(insertedData.data, retrieve.data);
|
||||
|
||||
this.da.delete(TypesEnum1.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesEnum1.class, insertedData.id);
|
||||
}
|
||||
}
|
||||
|
@ -11,14 +11,11 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.dataAccess.model.Enum2ForTest;
|
||||
@ -29,8 +26,6 @@ import test.kar.archidata.dataAccess.model.TypesEnum2;
|
||||
public class TestTypeEnum2 {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypeEnum2.class);
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
@ -41,15 +36,11 @@ public class TestTypeEnum2 {
|
||||
ConfigureDb.clear();
|
||||
}
|
||||
|
||||
public TestTypeEnum2() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesEnum2.class);
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
if (ConfigureDb.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
@ -63,13 +54,13 @@ public class TestTypeEnum2 {
|
||||
|
||||
final TypesEnum2 test = new TypesEnum2();
|
||||
test.data = Enum2ForTest.ENUM_VALUE_4;
|
||||
final TypesEnum2 insertedData = this.da.insert(test);
|
||||
final TypesEnum2 insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
TypesEnum2 retrieve = this.da.get(TypesEnum2.class, insertedData.id);
|
||||
TypesEnum2 retrieve = ConfigureDb.da.get(TypesEnum2.class, insertedData.id);
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||
@ -78,22 +69,22 @@ public class TestTypeEnum2 {
|
||||
|
||||
// Update data to null
|
||||
retrieve.data = null;
|
||||
long ret = this.da.update(retrieve, retrieve.id);
|
||||
long ret = ConfigureDb.da.update(retrieve, retrieve.id);
|
||||
Assertions.assertEquals(1L, ret);
|
||||
|
||||
// get new data
|
||||
retrieve = this.da.get(TypesEnum2.class, insertedData.id);
|
||||
retrieve = ConfigureDb.da.get(TypesEnum2.class, insertedData.id);
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||
Assertions.assertNull(retrieve.data);
|
||||
|
||||
// Remove the data
|
||||
ret = this.da.delete(TypesEnum2.class, insertedData.id);
|
||||
ret = ConfigureDb.da.delete(TypesEnum2.class, insertedData.id);
|
||||
Assertions.assertEquals(1L, ret);
|
||||
|
||||
// Get the removed data:
|
||||
retrieve = this.da.get(TypesEnum2.class, insertedData.id);
|
||||
retrieve = ConfigureDb.da.get(TypesEnum2.class, insertedData.id);
|
||||
Assertions.assertNull(retrieve);
|
||||
}
|
||||
|
||||
@ -103,19 +94,19 @@ public class TestTypeEnum2 {
|
||||
|
||||
final TypesEnum2 test = new TypesEnum2();
|
||||
test.data = null;
|
||||
final TypesEnum2 insertedData = this.da.insert(test);
|
||||
final TypesEnum2 insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesEnum2 retrieve = this.da.get(TypesEnum2.class, insertedData.id);
|
||||
final TypesEnum2 retrieve = ConfigureDb.da.get(TypesEnum2.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||
Assertions.assertNull(retrieve.data);
|
||||
|
||||
this.da.delete(TypesEnum2.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesEnum2.class, insertedData.id);
|
||||
}
|
||||
}
|
||||
|
@ -16,14 +16,11 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.dataAccess.model.TypesTable;
|
||||
@ -33,8 +30,6 @@ import test.kar.archidata.dataAccess.model.TypesTable;
|
||||
public class TestTypes {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypes.class);
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
@ -45,15 +40,11 @@ public class TestTypes {
|
||||
ConfigureDb.clear();
|
||||
}
|
||||
|
||||
public TestTypes() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
if (ConfigureDb.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
@ -67,13 +58,13 @@ public class TestTypes {
|
||||
|
||||
final TypesTable test = new TypesTable();
|
||||
test.intData = 95;
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -81,7 +72,7 @@ public class TestTypes {
|
||||
Assertions.assertNotNull(retrieve.intData);
|
||||
Assertions.assertEquals(insertedData.intData, retrieve.intData);
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(3)
|
||||
@ -90,13 +81,13 @@ public class TestTypes {
|
||||
|
||||
final TypesTable test = new TypesTable();
|
||||
test.longData = 541684354354L;
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -104,7 +95,7 @@ public class TestTypes {
|
||||
Assertions.assertNotNull(retrieve.longData);
|
||||
Assertions.assertEquals(insertedData.longData, retrieve.longData);
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(4)
|
||||
@ -113,13 +104,13 @@ public class TestTypes {
|
||||
|
||||
final TypesTable test = new TypesTable();
|
||||
test.floatData = 153154.0f;
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -127,7 +118,7 @@ public class TestTypes {
|
||||
Assertions.assertNotNull(retrieve.floatData);
|
||||
Assertions.assertEquals(insertedData.floatData, retrieve.floatData);
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(5)
|
||||
@ -136,13 +127,13 @@ public class TestTypes {
|
||||
|
||||
final TypesTable test = new TypesTable();
|
||||
test.doubleData = 153152654654.0;
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -150,7 +141,7 @@ public class TestTypes {
|
||||
Assertions.assertNotNull(retrieve.doubleData);
|
||||
Assertions.assertEquals(insertedData.doubleData, retrieve.doubleData);
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(6)
|
||||
@ -159,13 +150,13 @@ public class TestTypes {
|
||||
|
||||
final TypesTable test = new TypesTable();
|
||||
test.textData = "lkjlkjlkjmlkqjsdùkljqsùmckljvùwxmckvmwlkdnfqmsjdvnmclkwsjdn;vbcm <wkdjncvm<wk:dnxcm<lwkdnc mqs<wdn:cx,<nm wlx!k:cn<;wmlx:!c;,<wmlx!:c;n<wm ldx:;c,<nwmlx:c,;<wmlx!:c;,< w";
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -173,7 +164,7 @@ public class TestTypes {
|
||||
Assertions.assertNotNull(retrieve.textData);
|
||||
Assertions.assertEquals(insertedData.textData, retrieve.textData);
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(7)
|
||||
@ -182,13 +173,13 @@ public class TestTypes {
|
||||
|
||||
final TypesTable test = new TypesTable();
|
||||
test.varcharData = "123456789123456789";
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -196,7 +187,7 @@ public class TestTypes {
|
||||
Assertions.assertNotNull(retrieve.varcharData);
|
||||
Assertions.assertEquals(insertedData.varcharData, retrieve.varcharData);
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(8)
|
||||
@ -205,13 +196,13 @@ public class TestTypes {
|
||||
|
||||
final TypesTable test = new TypesTable();
|
||||
test.booleanData = true;
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -219,7 +210,7 @@ public class TestTypes {
|
||||
Assertions.assertNotNull(retrieve.booleanData);
|
||||
Assertions.assertEquals(insertedData.booleanData, retrieve.booleanData);
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(9)
|
||||
@ -228,13 +219,13 @@ public class TestTypes {
|
||||
|
||||
final TypesTable test = new TypesTable();
|
||||
test.booleanData = false;
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -242,7 +233,7 @@ public class TestTypes {
|
||||
Assertions.assertNotNull(retrieve.booleanData);
|
||||
Assertions.assertEquals(insertedData.booleanData, retrieve.booleanData);
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(10)
|
||||
@ -252,13 +243,13 @@ public class TestTypes {
|
||||
final TypesTable test = new TypesTable();
|
||||
test.timeStampData = Timestamp.from(Instant.now());
|
||||
LOGGER.debug("Timestamp = {}", test.timeStampData);
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -270,7 +261,7 @@ public class TestTypes {
|
||||
Assertions.assertEquals(insertedData.timeStampData.toInstant().toEpochMilli(),
|
||||
retrieve.timeStampData.toInstant().toEpochMilli());
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(11)
|
||||
@ -280,13 +271,13 @@ public class TestTypes {
|
||||
final TypesTable test = new TypesTable();
|
||||
test.dateFullData = Date.from(Instant.now());
|
||||
LOGGER.debug("Date = {}", test.dateFullData);
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -295,7 +286,7 @@ public class TestTypes {
|
||||
Assertions.assertNotNull(retrieve.dateFullData);
|
||||
Assertions.assertEquals(insertedData.dateFullData, retrieve.dateFullData);
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(12)
|
||||
@ -305,13 +296,13 @@ public class TestTypes {
|
||||
final TypesTable test = new TypesTable();
|
||||
test.dateData = LocalDate.now();
|
||||
LOGGER.debug("LocalDate = {}", test.dateData);
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -320,7 +311,7 @@ public class TestTypes {
|
||||
Assertions.assertNotNull(retrieve.dateData);
|
||||
Assertions.assertEquals(insertedData.dateData, retrieve.dateData);
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(13)
|
||||
@ -330,13 +321,13 @@ public class TestTypes {
|
||||
final TypesTable test = new TypesTable();
|
||||
test.timeData = LocalTime.now();
|
||||
LOGGER.debug("LocalTime = {}", test.timeData);
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -347,7 +338,7 @@ public class TestTypes {
|
||||
Assertions.assertEquals(insertedData.timeData.getMinute(), retrieve.timeData.getMinute());
|
||||
Assertions.assertEquals(insertedData.timeData.getSecond(), retrieve.timeData.getSecond());
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(14)
|
||||
@ -358,13 +349,13 @@ public class TestTypes {
|
||||
test.textData = "test 1";
|
||||
test.booleanData = null;
|
||||
test.varcharData = "plop";
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -379,11 +370,11 @@ public class TestTypes {
|
||||
retrieve.textData = "test 2";
|
||||
retrieve.booleanData = true;
|
||||
retrieve.varcharData = null;
|
||||
final long nbUpdate = this.da.update(retrieve, insertedData.id);
|
||||
final long nbUpdate = ConfigureDb.da.update(retrieve, insertedData.id);
|
||||
Assertions.assertEquals(1L, nbUpdate);
|
||||
|
||||
// Get new data
|
||||
final TypesTable retrieve2 = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve2 = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve2);
|
||||
Assertions.assertNotNull(retrieve2.id);
|
||||
@ -398,11 +389,11 @@ public class TestTypes {
|
||||
retrieve.textData = "test 3";
|
||||
retrieve.booleanData = false;
|
||||
retrieve.varcharData = "test3";
|
||||
final long nbUpdate2 = this.da.update(retrieve, insertedData.id, List.of("textData"));
|
||||
final long nbUpdate2 = ConfigureDb.da.update(retrieve, insertedData.id, List.of("textData"));
|
||||
Assertions.assertEquals(1L, nbUpdate2);
|
||||
|
||||
// Get new data
|
||||
final TypesTable retrieve3 = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve3 = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve3);
|
||||
Assertions.assertNotNull(retrieve3.id);
|
||||
@ -414,7 +405,7 @@ public class TestTypes {
|
||||
Assertions.assertEquals(retrieve2.booleanData, retrieve3.booleanData);
|
||||
Assertions.assertNull(retrieve3.varcharData);
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
@Order(15)
|
||||
@ -425,13 +416,13 @@ public class TestTypes {
|
||||
test.textData = "test 1";
|
||||
test.booleanData = null;
|
||||
test.varcharData = "plop";
|
||||
final TypesTable insertedData = this.da.insert(test);
|
||||
final TypesTable insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final TypesTable retrieve = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
@ -450,11 +441,11 @@ public class TestTypes {
|
||||
"varcharData": null
|
||||
}
|
||||
""";
|
||||
final long nbUpdate = this.da.updateWithJson(TypesTable.class, insertedData.id, jsonData);
|
||||
final long nbUpdate = ConfigureDb.da.updateWithJson(TypesTable.class, insertedData.id, jsonData);
|
||||
Assertions.assertEquals(1L, nbUpdate);
|
||||
|
||||
// Get new data
|
||||
final TypesTable retrieve2 = this.da.get(TypesTable.class, insertedData.id);
|
||||
final TypesTable retrieve2 = ConfigureDb.da.get(TypesTable.class, insertedData.id);
|
||||
|
||||
Assertions.assertNotNull(retrieve2);
|
||||
Assertions.assertNotNull(retrieve2.id);
|
||||
@ -465,7 +456,7 @@ public class TestTypes {
|
||||
Assertions.assertEquals(true, retrieve2.booleanData);
|
||||
Assertions.assertNull(retrieve2.varcharData);
|
||||
|
||||
this.da.delete(TypesTable.class, insertedData.id);
|
||||
ConfigureDb.da.delete(TypesTable.class, insertedData.id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,15 +10,12 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.db.DbConfig;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.kar.archidata.migration.MigrationEngine;
|
||||
import org.kar.archidata.migration.MigrationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
|
||||
@ -28,12 +25,6 @@ import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
|
||||
public class TestMigrationFail {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestMigrationFirstInit.class);
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
public TestMigrationFail() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
@ -47,14 +38,14 @@ public class TestMigrationFail {
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testInitializeTable() throws Exception {
|
||||
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
||||
// add initialization:
|
||||
migrationEngine.setInit(new InitializationFirst());
|
||||
migrationEngine.migrateErrorThrow(new DbConfig());
|
||||
|
||||
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
|
||||
test.testData = 95.0;
|
||||
final TypesMigrationInitialisationFirst insertedData = this.da.insert(test);
|
||||
final TypesMigrationInitialisationFirst insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertEquals(95.0, insertedData.testData);
|
||||
}
|
||||
@ -62,7 +53,7 @@ public class TestMigrationFail {
|
||||
@Order(2)
|
||||
@Test
|
||||
public void testUpdateTwoMigration() throws Exception {
|
||||
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
||||
// add initialization:
|
||||
migrationEngine.setInit(new InitializationCurrent());
|
||||
migrationEngine.add(new Migration1());
|
||||
|
@ -10,14 +10,11 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.db.DbConfig;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.kar.archidata.migration.MigrationEngine;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
|
||||
@ -28,12 +25,6 @@ import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
|
||||
public class TestMigrationFirstInit {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestMigrationFail.class);
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
public TestMigrationFirstInit() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
@ -47,14 +38,14 @@ public class TestMigrationFirstInit {
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testInitialMigration() throws Exception {
|
||||
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
||||
// add initialization:
|
||||
migrationEngine.setInit(new InitializationFirst());
|
||||
migrationEngine.migrateErrorThrow(new DbConfig());
|
||||
|
||||
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
|
||||
test.testData = 95.0;
|
||||
final TypesMigrationInitialisationFirst insertedData = this.da.insert(test);
|
||||
final TypesMigrationInitialisationFirst insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertEquals(95.0, insertedData.testData);
|
||||
}
|
||||
@ -62,14 +53,14 @@ public class TestMigrationFirstInit {
|
||||
@Order(2)
|
||||
@Test
|
||||
public void testInitialMigrationReopen() throws Exception {
|
||||
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
||||
// add initialization:
|
||||
migrationEngine.setInit(new InitializationFirst());
|
||||
migrationEngine.migrateErrorThrow(new DbConfig());
|
||||
|
||||
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
|
||||
test.testData = 99.0;
|
||||
final TypesMigrationInitialisationFirst insertedData = this.da.insert(test);
|
||||
final TypesMigrationInitialisationFirst insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertEquals(99.0, insertedData.testData);
|
||||
}
|
||||
@ -77,7 +68,7 @@ public class TestMigrationFirstInit {
|
||||
@Order(3)
|
||||
@Test
|
||||
public void testUpdateTwoMigration() throws Exception {
|
||||
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
||||
// add initialization:
|
||||
migrationEngine.setInit(new InitializationCurrent());
|
||||
migrationEngine.add(new Migration1());
|
||||
@ -86,7 +77,7 @@ public class TestMigrationFirstInit {
|
||||
|
||||
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
|
||||
test.testDataMigration2 = 125.0;
|
||||
final TypesMigrationInitialisationCurrent insertedData = this.da.insert(test);
|
||||
final TypesMigrationInitialisationCurrent insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertEquals(125.0, insertedData.testDataMigration2);
|
||||
}
|
||||
@ -94,7 +85,7 @@ public class TestMigrationFirstInit {
|
||||
@Order(4)
|
||||
@Test
|
||||
public void testUpdateTwoMigrationReopen() throws Exception {
|
||||
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
||||
// add initialization:
|
||||
migrationEngine.setInit(new InitializationCurrent());
|
||||
migrationEngine.add(new Migration1());
|
||||
@ -103,7 +94,7 @@ public class TestMigrationFirstInit {
|
||||
|
||||
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
|
||||
test.testDataMigration2 = 2563.0;
|
||||
final TypesMigrationInitialisationCurrent insertedData = this.da.insert(test);
|
||||
final TypesMigrationInitialisationCurrent insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertEquals(2563.0, insertedData.testDataMigration2);
|
||||
}
|
||||
|
@ -11,15 +11,12 @@ 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.dataAccess.DBAccess;
|
||||
import org.kar.archidata.db.DbConfig;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.kar.archidata.migration.MigrationEngine;
|
||||
import org.kar.archidata.migration.model.Migration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
import test.kar.archidata.ConfigureDb;
|
||||
import test.kar.archidata.StepwiseExtension;
|
||||
import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
|
||||
@ -29,12 +26,6 @@ import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
|
||||
public class TestMigrationFirstInitWithMigration {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestMigrationFirstInitWithMigration.class);
|
||||
|
||||
private DBAccess da = null;
|
||||
|
||||
public TestMigrationFirstInitWithMigration() throws InternalServerErrorException, IOException, DataAccessException {
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
@ -48,7 +39,7 @@ public class TestMigrationFirstInitWithMigration {
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testInitialMigration() throws Exception {
|
||||
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
||||
// add initialization:
|
||||
migrationEngine.setInit(new InitializationCurrent());
|
||||
// add migration for old version
|
||||
@ -58,11 +49,11 @@ public class TestMigrationFirstInitWithMigration {
|
||||
|
||||
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
|
||||
test.testDataMigration2 = 95.0;
|
||||
final TypesMigrationInitialisationCurrent insertedData = this.da.insert(test);
|
||||
final TypesMigrationInitialisationCurrent insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertEquals(95.0, insertedData.testDataMigration2);
|
||||
|
||||
final List<Migration> elements = this.da.gets(Migration.class);
|
||||
final List<Migration> elements = ConfigureDb.da.gets(Migration.class);
|
||||
LOGGER.info("List of migrations:");
|
||||
for (final Migration elem : elements) {
|
||||
LOGGER.info(" - {} => {}", elem.id, elem.name);
|
||||
@ -72,7 +63,7 @@ public class TestMigrationFirstInitWithMigration {
|
||||
@Order(2)
|
||||
@Test
|
||||
public void testInitialMigrationReopen() throws Exception {
|
||||
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
||||
// add initialization:
|
||||
migrationEngine.setInit(new InitializationCurrent());
|
||||
// add migration for old version
|
||||
@ -82,7 +73,7 @@ public class TestMigrationFirstInitWithMigration {
|
||||
|
||||
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
|
||||
test.testDataMigration2 = 99.0;
|
||||
final TypesMigrationInitialisationCurrent insertedData = this.da.insert(test);
|
||||
final TypesMigrationInitialisationCurrent insertedData = ConfigureDb.da.insert(test);
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertEquals(99.0, insertedData.testDataMigration2);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user