Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Update unit tests to use ES6 import for the test/assert module #642

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Assert } from 'test/assert';

var db = $.db;
var assertTrue = require('test/assert').assertTrue;

var connection = db.getConnection();

Expand Down Expand Up @@ -63,4 +64,4 @@ call.setTimestamp(15, timestampInput);

call.setTinyInt(16, 1);

assertTrue(true);
Assert.assertTrue(true);
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Assert } from 'test/assert';

var db = $.db;
var assertTrue = require('test/assert').assertTrue;
// tests isClosed() too
function close(){
var connection = db.getConnection();
Expand All @@ -26,4 +27,4 @@ function prepareStatement(){
return statement.constructor.name == "XscPreparedStatement"
}

assertTrue(close() && prepareCall() && prepareStatement());
Assert.assertTrue(close() && prepareCall() && prepareStatement());
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Assert } from 'test/assert';

var db = $.db;
var assertTrue = require('test/assert').assertTrue;
var connection = db.getConnection();

assertTrue(connection != null && connection != undefined);
Assert.assertTrue(connection != null && connection != undefined);
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Assert } from 'test/assert';

var db = $.db;

var createTable = "CREATE TABLE TEST_USERS (NAME varchar(255), STEPS integer, SALARY decimal, RATING decimal, IS_ADMIN boolean, BIO varchar(255), AVG_GRADE decimal, LUCKY_NUMBER integer)";
Expand All @@ -15,7 +17,6 @@ connection.prepareCall(createTable).execute();
var statement = connection.prepareStatement(insert);
var parameterMetaData = statement.getParameterMetaData();
var count = parameterMetaData.getParameterCount();
var assertTrue = require('test/assert').assertTrue;

var assertions = [];
for (var i = 1; i <= count; i++) {
Expand All @@ -32,4 +33,4 @@ for (var i = 1; i <= count; i++) {
statement.close();
connection.close();

assertTrue(assertions.every((assertion) => assertion));
Assert.assertTrue(assertions.every((assertion) => assertion));
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Assert } from 'test/assert';

var db = $.db;
var assertTrue = require('test/assert').assertTrue;
var connection;
try{
connection = db.getConnection();
Expand Down Expand Up @@ -45,7 +46,7 @@ try{
closeAssertion = false;
} catch {}

assertTrue(batchExecutes == 2 && !executeResult && closeAssertion && updatedRows == 3 && metadataAssertion && moreResultsAssertion && parameterMetaDataAssertion && isClosedAssertion && closeAssertion);
Assert.assertTrue(batchExecutes == 2 && !executeResult && closeAssertion && updatedRows == 3 && metadataAssertion && moreResultsAssertion && parameterMetaDataAssertion && isClosedAssertion && closeAssertion);
} finally {
if(connection){
connection.commit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Assert } from 'test/assert';

var db = $.db;
var assertTrue = require('test/assert').assertTrue;

var connection;
try{
Expand Down Expand Up @@ -44,7 +45,7 @@ try{
closeAssertion = false;
} catch {}

assertTrue(bigIntAssertion && dateAssertion && decAssertion && doubleAssertion && intAssertion && stringAssertion && timeAssertion && timestampAssertion && closeAssertion && isClosedAssertion);
Assert.assertTrue(bigIntAssertion && dateAssertion && decAssertion && doubleAssertion && intAssertion && stringAssertion && timeAssertion && timestampAssertion && closeAssertion && isClosedAssertion);
} finally {
if(connection){
connection.commit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Assert } from 'test/assert';

var db = $.db;
var assertTrue = require('test/assert').assertTrue;

var connection;
try {
Expand Down Expand Up @@ -35,7 +36,7 @@ try {

var tableNameAssertion = metadata.getTableName(1) == "TEST_USERS";

assertTrue(columnCountAssertion && labelAssertion && nameAssertion && typeAssertion && typeNameAssertion && precisionAssertion && scaleAssertion && tableNameAssertion);
Assert.assertTrue(columnCountAssertion && labelAssertion && nameAssertion && typeAssertion && typeNameAssertion && precisionAssertion && scaleAssertion && tableNameAssertion);
} finally {
if(connection){
connection.commit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { query } from 'sdk/db'

var assert = require('test/assert');
import { Assert } from 'test/assert';

export function assertEquals(expected, actual, message) {
assert.assertEquals(expected, actual, message
Assert.assertEquals(expected, actual, message
+ "\nExpected: " + expected
+ "\nActual: " + actual);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Assert } from 'test/assert';

var hdb = $.hdb;
var response = require('http/response');
var assertTrue = require('test/assert').assertTrue;

var conn = hdb.getConnection();
conn.executeUpdate('CREATE SCHEMA EXAMPLE');
Expand Down Expand Up @@ -38,4 +39,4 @@ for (var i = 0; i < columnCount; i++) {
response.contentType = "text/plain";
response.println(body);

assertTrue(conn != null&& resultSet != null && columnCount !=null && body != null && lastColumnName ==="WEIGHT"&& lastColumnTypeName==="DOUBLE PRECISION");
Assert.assertTrue(conn != null&& resultSet != null && columnCount !=null && body != null && lastColumnName ==="WEIGHT"&& lastColumnTypeName==="DOUBLE PRECISION");
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Assert } from 'test/assert';

var database = $.hdb;
var response = require('http/response');
var assertTrue = require('test/assert').assertTrue;

try {
var connection = database.getConnection();
Expand Down Expand Up @@ -30,4 +31,4 @@ try {
response.flush();
response.close();

assertTrue(resultSet[0]["FIRSTNAME"] == "IVAN" && resultSet2.length.toString() == 2);
Assert.assertTrue(resultSet[0]["FIRSTNAME"] == "IVAN" && resultSet2.length.toString() == 2);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
let assertTrue = require('test/assert').assertTrue;
import { Assert } from 'test/assert';

let connection;
try{
connection = $.hdb.getConnection();
Expand All @@ -8,7 +9,7 @@
let updateStatement = "UPDATE EXAMPLE.TEST_USERS SET WEIGHT=? WHERE ID = 4";
let updateResult = connection.executeUpdate(updateStatement, 75);

assertTrue(insertResult ===1 && updateResult > 0);
Assert.assertTrue(insertResult ===1 && updateResult > 0);
} finally {
if(connection){
connection.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Assert } from 'test/assert';

var hdb = $.hdb;
var response = require('http/response');
var assertTrue = require('test/assert').assertTrue;

try {
var connection = hdb.getConnection();
Expand Down Expand Up @@ -28,4 +29,4 @@ try {
connection.close();
}

assertTrue(row0['FIRSTNAME'] === "IVAN" && row0['LASTNAME']==="VOLKOV" && row0['AGE']===29);
Assert.assertTrue(row0['FIRSTNAME'] === "IVAN" && row0['LASTNAME']==="VOLKOV" && row0['AGE']===29);
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Assert } from 'test/assert';

var db = $.hdb;
var response = require('http/response');
var assertTrue = require('test/assert').assertTrue;

var connection = db.getConnection();
var result = connection.executeQuery('SELECT * FROM EXAMPLE.TEST_USERS');
Expand All @@ -10,4 +11,4 @@ var metadata = result.metadata;
// conn.executeUpdate('DROP SCHEMA EXAMPLE');
response.println(JSON.stringify(metadata));

assertTrue(metadata != null);
Assert.assertTrue(metadata != null);
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Assert } from 'test/assert';

let http = $.net.http;
var assertTrue = require('test/assert').assertTrue;
let client = new http.Client();
let request = new http.Request(http.GET, "/");
let destination = http.readDestination("test", "test-destination");
Expand All @@ -9,4 +10,4 @@ client.setTimeout(10);
client.request(request, destination);
let response = client.getResponse();

assertTrue(response.status === http.OK && response.cookies != null && response.headers != null && response.body != null);
Assert.assertTrue(response.status === http.OK && response.cookies != null && response.headers != null && response.body != null);
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Assert } from 'test/assert';

// Importing xsjs lib and adding the module to the $ object.
$.import("test.kronos.import.sap.test.lib", "basic");
var assertTrue = require('test/assert').assertTrue;
// Assigning the module to a variable from the $ object.
var mathbasic = $.test.kronos.import.sap.test.lib.basic;

Expand All @@ -17,5 +18,5 @@ var multiply = mathlib.multiply(4, 9);
var division = mathlib.division(9, 3);

// Verifying the results.
assertTrue(square === 36 && multiply === 36 && division === 3 && sum === 10 && sub === 5);
Assert.assertTrue(square === 36 && multiply === 36 && division === 3 && sum === 10 && sub === 5);

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Assert } from 'test/assert';

let net = $.net;
var assertTrue = require('test/assert').assertTrue;
let mail = new net.Mail({
sender: {address: "sender@sap.com"},
to: [{name: "John Doe", address: "john.doe@sap.com", nameEncoding: "US-ASCII"}, {name: "Jane Doe", address: "jane.doe@sap.com"}],
Expand All @@ -21,4 +22,4 @@ let to = mail.to.map(e => e.address)
let cc = mail.cc.map(e => e.address)
let bcc = mail.bcc.map(e => e.address)

assertTrue(to !== "" && to !== undefined && cc !== "" && cc !== undefined && bcc !== "" && bcc !== undefined && smtp.isClosed());
Assert.assertTrue(to !== "" && to !== undefined && cc !== "" && cc !== undefined && bcc !== "" && bcc !== undefined && smtp.isClosed());
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var assertTrue = require('test/assert').assertTrue;
import { Assert } from 'test/assert';

let username = $.session.getUsername()
let appPrivileges = $.session.hasAppPrivilege("Developer")
if (appPrivileges) {
Expand Down Expand Up @@ -26,4 +27,4 @@ $.response.setBody("Timeout: " +timeout);
$.response.setBody("Token: " +token);
$.response.setBody("Auth Type: " +authType);

assertTrue(username === "TestUser" && appPrivileges !== null && sysPrivileges != null && timeout !== null && authType !== null && token != null);
Assert.assertTrue(username === "TestUser" && appPrivileges !== null && sysPrivileges != null && timeout !== null && authType !== null && token != null);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var assertTrue = require('test/assert').assertTrue;
import { Assert } from 'test/assert';

let trace = $.trace;

let debugBool = trace.isDebugEnabled();
Expand All @@ -23,4 +24,4 @@ if (warnBool) {
trace.warning("Warning message!");
}

assertTrue(debugBool && errorBool && fatalBool && infoBool && warnBool);
Assert.assertTrue(debugBool && errorBool && fatalBool && infoBool && warnBool);
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
var assertTrue = require('test/assert').assertTrue;
import { Assert } from 'test/assert';

var codec = $.util.codec;
var util = $.util;

var encodedHex = codec.encodeHex("dirigible as hex");
var decodedHex = codec.decodeHex(encodedHex);
var valueFromHex = util.stringify(decodedHex);



var encodedToBase64 = codec.encodeBase64("dirigible as base64");
var decodedBase64 = codec.decodeBase64(encodedToBase64);
var valueFromBase64 = util.stringify(decodedBase64);



assertTrue(valueFromHex === "dirigible as hex" && valueFromBase64 ==="dirigible as base64");
Assert.assertTrue(valueFromHex === "dirigible as hex" && valueFromBase64 ==="dirigible as base64");
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var assertTrue = require('test/assert').assertTrue;
import { Assert } from 'test/assert';

var util = $.util;
var response = require('http/response');
var random1 = util.createUuid();
Expand All @@ -17,7 +18,7 @@ var zip1ArrayBuffer = zip1.asArrayBuffer();

var zip2 = new util.Zip({source: zipSource});

assertTrue(random1 != random2 &&
Assert.assertTrue(random1 != random2 &&
convertedBuff === "This is a Uint8Array converted to a string" &&
JSON.stringify(zip1ArrayBuffer) === JSON.stringify(zipSource) &&
zip2['kronos.txt'] === 'This is Kronos'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,15 @@ private void mockGetTablesFailWhenSynonym() throws Exception {
}

/**
* Mock get table.
*
* @throws Exception the exception
*/
private void mockGetTable() throws Exception {
//when(mockDataSource.getConnection()).thenReturn(mockConnection);
when(mockConnection.prepareStatement(anyString())).thenReturn(mockPreparedStatement);
//when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
}
* Mock get table.
*
* @throws Exception the exception
*/
private void mockGetTable() throws Exception {
// when(mockDataSource.getConnection()).thenReturn(mockConnection);
when(mockConnection.prepareStatement(anyString())).thenReturn(mockPreparedStatement);
// when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
}

/**
* Mock DB artifacts by name missing.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codbex.platform</groupId>
<artifactId>codbex-platform-parent</artifactId>
<version>1.0.35</version>
<version>1.0.36</version>

</parent>

Expand Down
Loading