Skip to content

Commit

Permalink
Add db tests
Browse files Browse the repository at this point in the history
  • Loading branch information
javiertuya committed Jun 22, 2024
1 parent 4b683c0 commit 3db3b01
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
if: ${{ matrix.scope != 'Core' }}
run: >
mvn test surefire-report:report -Daggregate=true
-Dtest=Test${{ matrix.scope }}* -pl tdrules-client-rdb,tdrules-store-rdb -am -Dsurefire.failIfNoSpecifiedTests=false
-Dtest=Test${{ matrix.scope }}* -pl tdrules-client-rdb,tdrules-store-rdb,tdrules-store-loader -am -Dsurefire.failIfNoSpecifiedTests=false
-Dmaven.test.failure.ignore=true -U --no-transfer-progress
-Duser.timezone=Europe/Madrid
# NOTE: must specify a timezone to avoid oracle error ORA-01882: timezone region not found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public void testPkInArray() throws IOException {

String actual=dg.getDataAdapter().getAllAsString().replace("\r", "");
FileUtil.fileWrite(TEST_PATH_OUTPUT, fileName + ".txt", actual);
//System.out.println(new MermaidWriter(schema1).getMermaid());
//System.out.println(actual);
String expected=
("'ProductDTORes':{'productId':1,'age':2}\n"
+ "'UserDTORes':{'email':'XXX','name':'202'}\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
//import org.mockserver.client.server.MockServerClient;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.socket.PortFactory;

Expand Down Expand Up @@ -293,7 +292,7 @@ public void testErrorServer() {
// expectation returns error 500
LoaderException exception = assertThrows(LoaderException.class, () -> {
DataLoader dtg = getLiveGenerator();
createErrorExpectationPost("/master", "{'I1':10}", "{'pk1':991,'I1':10}");
createErrorExpectationPost("/master", "{'I1':10}");
dtg.load("master", "pk1,i1", "@km1,10");
});
assertEquals("endWrite: Did not completed properly, response: 500 Internal Server Error - body: Error message"
Expand Down Expand Up @@ -348,7 +347,7 @@ private void createExpectationPostWithAuth(String endpointPath, String requestBo
.withBody(json(responseBody))
);
}
private void createErrorExpectationPost(String endpointPath, String requestBody, String responseBody) {
private void createErrorExpectationPost(String endpointPath, String requestBody) {
mockServer.when(request()
.withMethod("POST")
.withPath("/oatest" + endpointPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,53 @@

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import giis.tdrules.store.rdb.SchemaException;
import giis.portable.util.FileUtil;
import giis.portable.util.Parameters;
import giis.tdrules.store.rdb.JdbcProperties;

/**
* Definiciones comunes para las pruebas de las clases de manejo de datos
* para ser utilizado como clase base de estas pruebas
*/
public class Base {
Logger log = LoggerFactory.getLogger(this.getClass());

// Datos principales para parametrizacion del sgbd usado en el test
// Esta es la referencia, el resto de sgbds son clases heredadas que cambian este valor
protected String dbmsname = "sqlserver";

// nombres de las bases de datos a utilizar
public static final String TEST_DBNAME2 = "tdstorerdb2";

protected Properties config;
protected static final String PLATFORM = Parameters.getPlatformName();
private static final String SETUP_PATH = FileUtil.getPath(Parameters.getProjectRoot(), "..", "setup");
private static final String ENVIRONMENT_PROPERTIES = FileUtil.getPath(SETUP_PATH, "environment.properties");
private static final String DATABASE_PROPERTIES = FileUtil.getPath(SETUP_PATH, "database.properties");

public static final String TEST_DBNAME = "tdstorerdb2";

protected String dbmsname = "sqlserver";

@Rule
public TestName testName = new TestName();

@Before
public void setUp() throws SQLException {
log.debug("*** Running test: {}", testName.getMethodName());
config = new Properties();
try {
config.load(new FileInputStream(new File("../tdrules4.properties")));
} catch (IOException e) {
throw new SchemaException("Can't load test configuration file");
}
}

/**
* Connection user and url are obtained from a properties file,
* password is obtained from environment, if not defined, another properties file is used as fallback
*/
protected Connection getConnection(String database) throws SQLException {
log.debug("Create connection to '{}' database", dbmsname);
String propPrefix = "tdrules." + PLATFORM + "." + TEST_DBNAME + "." + dbmsname;
Connection conn = DriverManager.getConnection(
config.getProperty("tdrules." + dbmsname + "." + database + ".url"),
config.getProperty("tdrules." + dbmsname + "." + database + ".user"),
config.getProperty("tdrules." + dbmsname + "." + database + ".password"));
new JdbcProperties().getProp(DATABASE_PROPERTIES, propPrefix + ".url"),
new JdbcProperties().getProp(DATABASE_PROPERTIES, propPrefix + ".user"),
new JdbcProperties().getEnvVar(ENVIRONMENT_PROPERTIES, "TEST_" + dbmsname.toUpperCase() + "_PWD"));
// Try to avoid lock problems that make flaky tests when running concurrently
// with other tests (mainly for getTableList)
if ("sqlserver".equals(dbmsname))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected String getDateTimeForSql() {
@Override
protected void createTablesAndViews() throws SQLException {
super.createTablesAndViews();
Connection dbt = getConnection(TEST_DBNAME2); // modo conectado para que se cierre la conexion
Connection dbt = getConnection(TEST_DBNAME); // modo conectado para que se cierre la conexion
try {
execute(dbt, "drop sequence seq_ggm");
} catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class TestSqlserverGeneration extends Base {
public void setUp() throws SQLException {
super.setUp();
dropTablesAndViews();
db = getConnection(TEST_DBNAME2);
db = getConnection(TEST_DBNAME);
dbms = new SchemaReaderJdbc(db).getDbmsType();
}

Expand All @@ -69,7 +69,7 @@ protected String getDate2() {
}

protected void createTablesAndViews() throws SQLException {
Connection dbt = getConnection(TEST_DBNAME2);
Connection dbt = getConnection(TEST_DBNAME);
execute(dbt, "create table Gg0 (Pk1 int, I1 int, primary key(Pk1))");
// tabla basica con datos pk, fk y enteros/characteres con alguno nullable,
// fechas en dos formatos, date+time y date, uno nullable y otro no
Expand All @@ -90,7 +90,7 @@ protected void createTablesAndViewsMultipleRelations(boolean useCircularRelation
// relaciones (detalle-maestro): gg0-gg1-ggd-(ggm-gg2-(gg3 | ggd...) | gg1)
// cadena cirucular ggd-ggm-gg2-ggd
// relacion recursiva gg1-ggd-gg2
Connection dbt = getConnection(TEST_DBNAME2);
Connection dbt = getConnection(TEST_DBNAME);
execute(dbt, "create table Gg3 (Pk1 int, primary key(Pk1), Fk1 int)");
execute(dbt, "create table Gg2 (Pk1 int, primary key(Pk1), Fk1 int, Fk2 int)");
String identityType = this.dbms.getDataTypeIdentity("int") + " " + this.dbms.getDataTypeIdentitySuffix();
Expand All @@ -111,7 +111,7 @@ protected void createTablesAndViewsMultipleRelations(boolean useCircularRelation
}

protected void dropTablesAndViews() throws SQLException {
Connection dbt = getConnection(TEST_DBNAME2); // modo conectado para que se cierre la conexion
Connection dbt = getConnection(TEST_DBNAME); // modo conectado para que se cierre la conexion
executeNotThrow(dbt, "alter table gg2 drop constraint FK_GG2_GG3");
executeNotThrow(dbt, "alter table gg2 drop constraint FK_GG2_GGD");
executeNotThrow(dbt, "alter table ggm drop constraint FK_GGM_GG2");
Expand Down Expand Up @@ -214,8 +214,6 @@ public void testGenerateRowUserSpecified2UsingDate() throws SQLException {
execute(db, "alter table gg1 drop column d2");
execute(db, "alter table gg1 add d1 DATE");
execute(db, "alter table gg1 add d2 " + this.dbms.getDataTypeDatetime() + " NOT NULL");
// execute(db, "alter table gg1 alter column d2 " +
// this.dbms.getDataTypeDatetime() + " NOT NULL");
dtg.load("gg1", "pk1=1,i1=10,c1='abc',d1=" + getDate1());
dtg.load("gg1", " pk1 = 2 , i2 = 20 , c2 = 'x' , d2=" + getDate2());
dtg.load("gg1", ""); // una tercera sin indicar ningun valor
Expand Down

0 comments on commit 3db3b01

Please sign in to comment.