Skip to content

Commit

Permalink
Merge pull request ballerina-platform#410 from niveathika/master
Browse files Browse the repository at this point in the history
Migrate to testng
  • Loading branch information
niveathika authored Oct 18, 2021
2 parents 48f82dc + fb9a644 commit 49d0d48
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 65 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ githubSpotbugsVersion=4.1.0
githubJohnrengelmanShadowVersion=5.2.0
underCouchDownloadVersion=4.0.4
researchgateReleaseVersion=2.8.0
junitVersion=5.7.1
testngVersion=7.4.0
ballerinaGradlePluginVersion=0.11.0

ballerinaLangVersion=2.0.0-beta.3
Expand Down
17 changes: 6 additions & 11 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ dependencies {
implementation group: 'io.ballerina.stdlib', name: 'time-native', version: "${stdlibTimeVersion}"
implementation group: 'com.zaxxer', name: 'HikariCP', version: "${hikkariLibVersion}"
implementation group: 'com.atomikos', name: 'transactions-jdbc', version: "${atomikosLibVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"

implementation group: 'org.testng', name: 'testng', version: "${testngVersion}"
}

tasks.withType(JavaCompile) {
Expand All @@ -54,11 +54,12 @@ jacoco {
}

test {
useTestNG() {
suites 'src/test/resources/testng.xml'
}
testLogging.showStandardStreams = true
testLogging {
showStackTraces = true
showStandardStreams = true
events "PASSED", "FAILED", "SKIPPED"
exceptionFormat "full"
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
Expand All @@ -68,12 +69,6 @@ test {
}
}
}
jacoco {
enabled = true
includeNoLocationClasses = false
excludes = ['jdk.internal.*']
useJUnitPlatform()
}
finalizedBy jacocoTestReport
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* under the License.
*/

package io.ballerina.stdlib.sql.tests;
package io.ballerina.stdlib.sql;

import io.ballerina.runtime.api.Module;
import io.ballerina.runtime.api.PredefinedTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@
* under the License.
*/

package io.ballerina.stdlib.sql.tests.datasource;
package io.ballerina.stdlib.sql.datasource;

import io.ballerina.runtime.api.values.BMap;
import io.ballerina.runtime.api.values.BString;
import io.ballerina.runtime.api.values.BValue;
import io.ballerina.runtime.internal.values.MapValueImpl;
import io.ballerina.stdlib.sql.datasource.PoolKey;
import io.ballerina.stdlib.sql.tests.TestUtils;
import org.junit.jupiter.api.Test;
import io.ballerina.stdlib.sql.TestUtils;
import org.testng.annotations.Test;

import static io.ballerina.runtime.api.utils.StringUtils.fromString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

/**
* PoolKey class test.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@
* under the License.
*/

package io.ballerina.stdlib.sql.tests.exception;
package io.ballerina.stdlib.sql.exception;

import io.ballerina.stdlib.sql.exception.ApplicationError;
import io.ballerina.stdlib.sql.exception.ConversionError;
import io.ballerina.stdlib.sql.exception.FieldMismatchError;
import io.ballerina.stdlib.sql.exception.TypeMismatchError;
import io.ballerina.stdlib.sql.exception.UnsupportedTypeError;
import org.junit.jupiter.api.Test;
import org.testng.annotations.Test;

import java.sql.SQLException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.testng.Assert.assertEquals;

/**
* ApplicationError class test.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@
* under the License.
*/

package io.ballerina.stdlib.sql.tests.nativeimpl;
package io.ballerina.stdlib.sql.nativeimpl;

import io.ballerina.runtime.api.PredefinedTypes;
import io.ballerina.runtime.api.values.BMap;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.api.values.BString;
import io.ballerina.stdlib.sql.Constants;
import io.ballerina.stdlib.sql.nativeimpl.OutParameterProcessor;
import io.ballerina.stdlib.sql.TestUtils;
import io.ballerina.stdlib.sql.parameterprocessor.DefaultResultParameterProcessor;
import io.ballerina.stdlib.sql.tests.TestUtils;
import org.junit.jupiter.api.Test;
import org.testng.annotations.Test;

import static io.ballerina.runtime.api.utils.StringUtils.fromString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;

/**
* QueryProcessor class test.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* under the License.
*/

package io.ballerina.stdlib.sql.tests.parameterprocessor;
package io.ballerina.stdlib.sql.parameterprocessor;

import io.ballerina.runtime.api.PredefinedTypes;
import io.ballerina.runtime.api.utils.TypeUtils;
Expand All @@ -25,12 +25,11 @@
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.api.values.BString;
import io.ballerina.runtime.internal.values.MapValueImpl;
import io.ballerina.stdlib.sql.TestUtils;
import io.ballerina.stdlib.sql.exception.ApplicationError;
import io.ballerina.stdlib.sql.exception.DataError;
import io.ballerina.stdlib.sql.parameterprocessor.DefaultResultParameterProcessor;
import io.ballerina.stdlib.sql.tests.TestUtils;
import io.ballerina.stdlib.sql.utils.PrimitiveTypeColumnDefinition;
import org.junit.jupiter.api.Test;
import org.testng.annotations.Test;

import java.math.BigDecimal;
import java.sql.SQLException;
Expand All @@ -40,10 +39,10 @@
import java.util.Date;

import static io.ballerina.runtime.api.utils.StringUtils.fromString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.fail;

/**
* DefaultResultParameterProcessor class test.
Expand Down Expand Up @@ -271,8 +270,8 @@ void convertStructTest9() {
Types.STRUCT, TestUtils.getRecordStructRecord());
BMap<BString, Object> map = (BMap<BString, Object>) object;
MapValueImpl mapValue = (MapValueImpl) map.get(fromString("value0"));
assertEquals(mapValue.getBooleanValue(fromString("value2")), true);
assertEquals(mapValue.getBooleanValue(fromString("value1")), false);
assertEquals(mapValue.getBooleanValue(fromString("value2")), Boolean.TRUE);
assertEquals(mapValue.getBooleanValue(fromString("value1")), Boolean.FALSE);
} catch (Exception ignored) {
fail("Exception received");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@
* specific language governing permissions and limitations
* under the License.
*/
package io.ballerina.stdlib.sql.tests.parameterprocessor;
package io.ballerina.stdlib.sql.parameterprocessor;

import io.ballerina.runtime.api.PredefinedTypes;
import io.ballerina.runtime.api.values.BString;
import io.ballerina.stdlib.sql.TestUtils;
import io.ballerina.stdlib.sql.exception.ApplicationError;
import io.ballerina.stdlib.sql.parameterprocessor.DefaultStatementParameterProcessor;
import io.ballerina.stdlib.sql.tests.TestUtils;
import org.junit.jupiter.api.Test;
import org.testng.annotations.Test;

import java.sql.SQLException;
import java.sql.Struct;
import java.util.ArrayList;

import static io.ballerina.runtime.api.utils.StringUtils.fromString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.fail;

/**
* DefaultStatementParameterProcessor class test.
Expand Down Expand Up @@ -496,7 +495,7 @@ void getBitValueArrayDataBStringTest() {
try {
Object[] objects = testClass.testGetBitValueArrayDataBString();
Boolean[] array = (Boolean[]) objects[0];
assertEquals(array[0], true);
assertEquals(array[0], Boolean.TRUE);
} catch (Exception e) {
fail("Exception received");
}
Expand All @@ -508,7 +507,7 @@ void getBitValueArrayDataIntegerTest() {
try {
Object[] objects = testClass.testGetBitValueArrayDataInteger(1);
Boolean[] array = (Boolean[]) objects[0];
assertEquals(array[0], true);
assertEquals(array[0], Boolean.TRUE);
} catch (Exception e) {
fail("Exception received");
}
Expand All @@ -520,7 +519,7 @@ void getBitValueArrayDataIntegerTest2() {
try {
Object[] objects = testClass.testGetBitValueArrayDataInteger(12);
Boolean[] array = (Boolean[]) objects[0];
assertEquals(array[0], true);
assertEquals(array[0], Boolean.TRUE);
} catch (Exception e) {
assertEquals(e.getMessage(), "Only 1 or 0 can be passed for BIT SQL Type, but found :12");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
* under the License.
*/

package io.ballerina.stdlib.sql.tests.transaction;
package io.ballerina.stdlib.sql.transaction;

import io.ballerina.stdlib.sql.tests.TestUtils;
import io.ballerina.stdlib.sql.transaction.SQLTransactionContext;
import org.junit.jupiter.api.Test;
import io.ballerina.stdlib.sql.TestUtils;
import org.testng.annotations.Test;

import java.sql.Connection;

import javax.transaction.xa.XAResource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.testng.Assert.assertEquals;

/**
* SQLTransactionContext class test.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@
* under the License.
*/

package io.ballerina.stdlib.sql.tests.utils;
package io.ballerina.stdlib.sql.utils;

import io.ballerina.runtime.api.types.StructureType;
import io.ballerina.runtime.api.utils.TypeUtils;
import io.ballerina.stdlib.sql.tests.TestUtils;
import io.ballerina.stdlib.sql.utils.PrimitiveTypeColumnDefinition;
import io.ballerina.stdlib.sql.utils.Utils;
import org.junit.jupiter.api.Test;
import io.ballerina.stdlib.sql.TestUtils;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.testng.Assert.assertEquals;

/**
* Utils class test.
Expand Down
35 changes: 35 additions & 0 deletions native/src/test/resources/testng.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="SQL test suite" parallel="false">

<test name="SQL Tests" parallel="false">
<classes>
<class name="io.ballerina.stdlib.sql.datasource.PoolKeyTest"/>
<class name="io.ballerina.stdlib.sql.exception.ApplicationErrorTest"/>
<class name="io.ballerina.stdlib.sql.nativeimpl.OutParameterProcessorTest"/>
<class name="io.ballerina.stdlib.sql.parameterprocessor.DefaultResultParameterProcessorTest"/>
<class name="io.ballerina.stdlib.sql.parameterprocessor.DefaultStatementParameterProcessorTest"/>
<class name="io.ballerina.stdlib.sql.transaction.SQLTransactionContextTest"/>
<class name="io.ballerina.stdlib.sql.utils.UtilsTest"/>
</classes>
</test>
</suite>

0 comments on commit 49d0d48

Please sign in to comment.