Skip to content

Commit

Permalink
add test cases for annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
hasathcharu committed Feb 27, 2024
1 parent 8d31b55 commit 166692c
Show file tree
Hide file tree
Showing 22 changed files with 821 additions and 26 deletions.
52 changes: 32 additions & 20 deletions ballerina/tests/init-tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,37 @@ configurable record {|
@test:BeforeSuite
function initTests() returns error? {
// MySQL
mysql:Client mysqlDbClient = check new (host = mysql.host, user = mysql.user, password = mysql.password, database = mysql.database, port = mysql.port);
_ = check mysqlDbClient->execute(`SET FOREIGN_KEY_CHECKS = 0`);
_ = check mysqlDbClient->execute(`TRUNCATE Employee`);
_ = check mysqlDbClient->execute(`TRUNCATE Workspace`);
_ = check mysqlDbClient->execute(`TRUNCATE Building`);
_ = check mysqlDbClient->execute(`TRUNCATE Department`);
_ = check mysqlDbClient->execute(`TRUNCATE OrderItem`);
_ = check mysqlDbClient->execute(`TRUNCATE AllTypes`);
_ = check mysqlDbClient->execute(`TRUNCATE FloatIdRecord`);
_ = check mysqlDbClient->execute(`TRUNCATE StringIdRecord`);
_ = check mysqlDbClient->execute(`TRUNCATE DecimalIdRecord`);
_ = check mysqlDbClient->execute(`TRUNCATE BooleanIdRecord`);
_ = check mysqlDbClient->execute(`TRUNCATE IntIdRecord`);
_ = check mysqlDbClient->execute(`TRUNCATE AllTypesIdRecord`);
_ = check mysqlDbClient->execute(`TRUNCATE CompositeAssociationRecord`);
_ = check mysqlDbClient->execute(`SET FOREIGN_KEY_CHECKS = 1`);
check mysqlDbClient.close();
check MySQLTests();

//MSSQL
mssql:Client mssqlDbClient = check new (host = mssql.host, user = mssql.user, password = mssql.password, port = mssql.port);
check MSSQLTests();

// PostgreSQL
check PostgreSQLTests();
}

function MySQLTests() returns error? {
mysql:Client mysqlDbClient = check new (host = mysql.host, user = mysql.user, password = mysql.password, database = mysql.database, port = mysql.port);
_ = check mysqlDbClient->execute(`SET FOREIGN_KEY_CHECKS = 0`);
_ = check mysqlDbClient->execute(`TRUNCATE Employee`);
_ = check mysqlDbClient->execute(`TRUNCATE Workspace`);
_ = check mysqlDbClient->execute(`TRUNCATE Building`);
_ = check mysqlDbClient->execute(`TRUNCATE Department`);
_ = check mysqlDbClient->execute(`TRUNCATE OrderItem`);
_ = check mysqlDbClient->execute(`TRUNCATE AllTypes`);
_ = check mysqlDbClient->execute(`TRUNCATE FloatIdRecord`);
_ = check mysqlDbClient->execute(`TRUNCATE StringIdRecord`);
_ = check mysqlDbClient->execute(`TRUNCATE DecimalIdRecord`);
_ = check mysqlDbClient->execute(`TRUNCATE BooleanIdRecord`);
_ = check mysqlDbClient->execute(`TRUNCATE IntIdRecord`);
_ = check mysqlDbClient->execute(`TRUNCATE AllTypesIdRecord`);
_ = check mysqlDbClient->execute(`TRUNCATE CompositeAssociationRecord`);
_ = check mysqlDbClient->execute(`SET FOREIGN_KEY_CHECKS = 1`);
check mysqlDbClient.close();
}

function MSSQLTests() returns error? {
mssql:Client mssqlDbClient = check new (host = mssql.host, user = mssql.user, password = mssql.password, port = mssql.port);
_ = check mssqlDbClient->execute(`DROP DATABASE IF EXISTS test;`);
_ = check mssqlDbClient->execute(`CREATE DATABASE test`);
check mssqlDbClient.close();
Expand Down Expand Up @@ -221,9 +232,10 @@ function initTests() returns error? {
PRIMARY KEY(id)
);
`);
}

// PostgreSQL
postgresql:Client postgresqlDbClient = check new (host = postgresql.host, username = postgresql.user, password = postgresql.password, database = postgresql.database, port = postgresql.port);
function PostgreSQLTests() returns error? {
postgresql:Client postgresqlDbClient = check new (host = postgresql.host, username = postgresql.user, password = postgresql.password, database = postgresql.database, port = postgresql.port);
_ = check postgresqlDbClient->execute(`TRUNCATE "Employee" CASCADE`);
_ = check postgresqlDbClient->execute(`TRUNCATE "Workspace" CASCADE`);
_ = check postgresqlDbClient->execute(`TRUNCATE "Building" CASCADE`);
Expand Down
2 changes: 2 additions & 0 deletions compiler-plugin-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ dependencies {
implementation group: 'org.testng', name: 'testng', version: "${testngVersion}"
testImplementation 'org.testng:testng'
testImplementation group: 'com.google.code.gson', name: 'gson', version: "${gsonVersion}"
implementation group: 'io.ballerina.stdlib', name: 'persist-native', version: "1.2.1-20240222-125000-4a9d764"
implementation group: 'io.ballerina.stdlib', name: 'persist-compiler-plugin', version: "1.2.1-20240222-125000-4a9d764"
}

tasks.withType(JavaCompile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private Package loadPackage(String path) {
return project.currentPackage();
}

@Test
@Test(enabled = true)
public void testCodeModifier() {

Package newPackage = getModifiedPackage("project_1");
Expand Down Expand Up @@ -130,7 +130,7 @@ public void testCodeModifier() {
}
}

@Test
@Test(enabled = true)
public void testCodeModifierWithRelationTables() {

Package newPackage = getModifiedPackage("project_3");
Expand All @@ -155,7 +155,7 @@ public void testCodeModifierWithRelationTables() {
}
}

@Test
@Test(enabled = true)
public void testCodeModifierWhenNameHasEscapeCharacter() {

Package newPackage = getModifiedPackage("project_4");
Expand Down Expand Up @@ -200,7 +200,7 @@ public void testCodeModifierWhenNameHasEscapeCharacter() {
}


@Test
@Test(enabled = true)
public void testCodeModifierWhenFieldIsInTypeDescriptor() {

Package newPackage = getModifiedPackage("project_5");
Expand Down Expand Up @@ -241,7 +241,7 @@ public void testCodeModifierWhenFieldIsInTypeDescriptor() {
}
}

@Test
@Test(enabled = true)
public void testCodeModifierWithDiagnostic() {
Package currentPackage = loadPackage("project_2");
DiagnosticResult diagnosticResult = currentPackage.getCompilation().diagnosticResult();
Expand Down
Loading

0 comments on commit 166692c

Please sign in to comment.