Skip to content

Commit

Permalink
Nexial 4.6
Browse files Browse the repository at this point in the history
- minor tweak to jenkins-related styling
- updated 3rd party library (xalan)
- updated code to Java 17 syntax (more to come...)
  • Loading branch information
mikeliucc committed May 30, 2023
1 parent ac67d61 commit 87e2a82
Show file tree
Hide file tree
Showing 37 changed files with 1,044 additions and 1,414 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ dependencies {
implementation("net.sourceforge.jregex:jregex:+")
implementation("org.aspectj:aspectjweaver:+")
implementation("jaxen:jaxen:+")
implementation("xalan:xalan:+")
implementation("xalan:xalan:2.7.3")
implementation("xalan:serializer:2.7.3")
implementation("io.jsonwebtoken:jjwt:+")
implementation("org.thymeleaf:thymeleaf:${thymeleafVersion}")
implementation("javax.media:jmf:+")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mongoDriverVersion=3.12.+
msal4jVersion=1.+
pdfboxVersion=2.0.+
#poiVersion=5.+ ==> too many breaking changes
poiVersion=3.+
poiVersion=3.17
#seleniumVersion=4.3.+ ==> too many breaking changes
seleniumVersion=3.141.59
servletApiVersion=4.0.1
Expand Down
106 changes: 25 additions & 81 deletions src/main/java/org/nexial/commons/utils/TextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1164,17 +1164,14 @@ public static Map<String, Map<String, String>> loadProperties(String propFile,
Map<String, String> maps = properties.get(section);
if (maps.containsKey(key)) {
switch (duplicateKeyStrategy) {
case NotAllowed:
throw new InvalidInputRuntimeException(RB.Abort.text("dupProjectProperties",
propPath,
key));
case FavorFirst:
ConsoleUtils.log(RB.Commons.text("dupProjectProperties.first", propPath, key));
break;
case FavorLast:
case NotAllowed -> throw new InvalidInputRuntimeException(
RB.Abort.text("dupProjectProperties", propPath, key));
case FavorFirst -> ConsoleUtils.log(
RB.Commons.text("dupProjectProperties.first", propPath, key));
case FavorLast -> {
ConsoleUtils.log(RB.Commons.text("dupProjectProperties.last", propPath, key));
maps.put(key, value);
break;
}
}
} else {
maps.put(key, value);
Expand Down Expand Up @@ -1225,66 +1222,20 @@ public static String sanitizePhoneNumber(String phoneNumber) {
if (Character.isLetter(ch)) {
ch = Character.toUpperCase(ch);
switch (ch) {
case 'A':
case 'B':
case 'C': {
phone.append('2');
break;
}
case 'D':
case 'E':
case 'F': {
phone.append('3');
break;
}
case 'G':
case 'H':
case 'I': {
phone.append('4');
break;
}
case 'J':
case 'K':
case 'L': {
phone.append('5');
break;
}
case 'M':
case 'N':
case 'O': {
phone.append('6');
break;
}
case 'P':
case 'Q':
case 'R':
case 'S': {
phone.append('7');
break;
}
case 'T':
case 'U':
case 'V': {
phone.append('8');
break;
}
case 'W':
case 'X':
case 'Y':
case 'Z': {
phone.append('9');
break;
}
default: {
break;
}
case 'A', 'B', 'C' -> phone.append('2');
case 'D', 'E', 'F' -> phone.append('3');
case 'G', 'H', 'I' -> phone.append('4');
case 'J', 'K', 'L' -> phone.append('5');
case 'M', 'N', 'O' -> phone.append('6');
case 'P', 'Q', 'R', 'S' -> phone.append('7');
case 'T', 'U', 'V' -> phone.append('8');
case 'W', 'X', 'Y', 'Z' -> phone.append('9');
default -> { }
}
continue;
}

if (ch == '*' || ch == '#') {
phone.append(ch);
}
if (ch == '*' || ch == '#') { phone.append(ch); }
}

phoneNumber = phone.toString();
Expand Down Expand Up @@ -1592,22 +1543,15 @@ public static boolean polyMatch(String actual, String expected, boolean trim) {
}

private static boolean polyMatcherNumeric(String comparator, double actual, double expected, String polyMatcher) {
switch (comparator) {
case ">":
return actual > expected;
case ">=":
return actual >= expected;
case "<":
return actual < expected;
case "<=":
return actual <= expected;
case "=":
return actual == expected;
case "!=":
return actual != expected;
default:
throw new IllegalArgumentException("Unknown comparator in PolyMatcher: " + polyMatcher);
}
return switch (comparator) {
case ">" -> actual > expected;
case ">=" -> actual >= expected;
case "<" -> actual < expected;
case "<=" -> actual <= expected;
case "=" -> actual == expected;
case "!=" -> actual != expected;
default -> throw new IllegalArgumentException("Unknown comparator in PolyMatcher: " + polyMatcher);
};
}

private static Map<String, String> initDefaultEscapeHtmlMapping() {
Expand Down
38 changes: 16 additions & 22 deletions src/main/java/org/nexial/core/ExecutionInputPrep.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

package org.nexial.core;

import java.io.File;
import java.io.IOException;
import java.util.*;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.io.FileUtils;
Expand All @@ -39,6 +35,10 @@
import org.nexial.core.utils.ExecUtils;
import org.nexial.core.utils.OutputFileUtils;

import java.io.File;
import java.io.IOException;
import java.util.*;

import static java.io.File.separator;
import static org.apache.poi.ss.usermodel.Row.MissingCellPolicy.CREATE_NULL_AS_BLANK;
import static org.nexial.core.NexialConst.Data.SHEET_MERGED_DATA;
Expand Down Expand Up @@ -79,7 +79,7 @@ public static Excel prep(String runId, ExecutionDefinition execDef, int iteratio
String filename = testScript.getName();

// since tmp file is local, the merge work with test data would be faster
// add random alphanum to avoid collision in parallel processing
// add random alphanumeric to avoid collision in parallel processing
// String tmpFilePath = SystemUtils.getJavaIoTmpDir().getAbsolutePath() + separator +
// RandomStringUtils.randomAlphabetic(5) + separator +
// filename;
Expand All @@ -89,7 +89,8 @@ public static Excel prep(String runId, ExecutionDefinition execDef, int iteratio
// 2.1. decorate output file name based on runtime information
String outputFileName = StringUtils.appendIfMissing(outBase, separator) + filename;
outputFileName = OutputFileUtils.addStartDateTime(outputFileName, new Date());
outputFileName = OutputFileUtils.addIteration(outputFileName, StringUtils.leftPad(iterationIndex + "", 3, "0"));
outputFileName = OutputFileUtils.addIteration(outputFileName,
StringUtils.leftPad(String.valueOf(iterationIndex), 3, "0"));

// if script are executed as part of test plan, then the naming convention is:
// [test plan file name w/o ext][SEP][test plan sheet name][SEP][sequence#][SEP][test script name w/o ext][SEP][start date yyyyMMdd_HHmmss][SEP][iteration#].xlsx
Expand Down Expand Up @@ -121,23 +122,16 @@ public static Excel prep(String runId, ExecutionDefinition execDef, int iteratio
outputExcel = new Excel(outputFile, false, true);
}

// merge macros
/* // todo: better instantiation so that we can reuse in-class cache (inside MacroMerger)
MacroMerger macroMerger = new MacroMerger();
macroMerger.setCurrentIteration(iterationIndex);
macroMerger.setExecDef(execDef);
macroMerger.setProject(execDef.getProject());
macroMerger.setExcel(outputExcel);
// macroMerger.mergeMacro();*/

// 4. merge expanded test data to output file
// this is necessary since the output directory (and final output file) could be remote
// merging test data to remote output file could be time-consuming
ConsoleUtils.log(runId, "merging test data to tmp file " + outputFile);

// we are no longer concerned with remote file access. The best practice to follow is NOT to use remote fs
TestData testData = execDef.getTestData();
if (testData == null || testData.getSettingAsBoolean(REFETCH_DATA_FILE)) {testData = execDef.getTestData(true);}
if (testData == null || testData.getSettingAsBoolean(REFETCH_DATA_FILE)) {
testData = execDef.getTestData(true);
}
if (!ExecUtils.isRunningInZeroTouchEnv()) {
testData = new ExecutionVariableConsole().processRuntimeVariables(testData, iterationIndex);
}
Expand All @@ -154,7 +148,7 @@ public static Excel prep(String runId, ExecutionDefinition execDef, int iteratio
if (StringUtils.isNotBlank(jitBatchSource) && FileUtil.isFileReadable(jitBatchSource, 800)) {
String jitBatchTarget = StringUtils.appendIfMissing(outBase, separator) + "nexial.sh";
if (!FileUtil.isFileReadable(jitBatchTarget, 800)) {
// didn't copy the file yet.. time to do so
// didn't copy the file yet... time to do so
ConsoleUtils.log(runId, "copying just-in-time batch script to output");
FileUtils.copyFile(new File(jitBatchSource), new File(jitBatchTarget));
}
Expand Down Expand Up @@ -235,14 +229,14 @@ private static Excel mergeTestData(Excel excel, TestData testData, int iteration
int iterationRef = iterationManager.getIterationRef(iterationIndex - 1);

data.putAll(testData.getAllValue(iterationRef));
testData.getAllSettings().forEach(data::put);
data.putAll(testData.getAllSettings());
data.putAll(ExecUtils.deriveJavaOpts());

data.put(CURR_ITERATION, iterationIndex + "");
if (iterationRef != -1) { data.put(CURR_ITERATION_ID, iterationRef + ""); }
data.put(CURR_ITERATION, String.valueOf(iterationIndex));
if (iterationRef != -1) { data.put(CURR_ITERATION_ID, String.valueOf(iterationRef)); }
if (iterationIndex > 1) {
int lastIterationRef = iterationManager.getIterationRef(iterationIndex - 2);
if (lastIterationRef != -1) { data.put(LAST_ITERATION, lastIterationRef + ""); }
if (lastIterationRef != -1) { data.put(LAST_ITERATION, String.valueOf(lastIterationRef)); }
data.put(IS_FIRST_ITERATION, "false");
} else {
data.put(IS_FIRST_ITERATION, "true");
Expand Down Expand Up @@ -280,7 +274,7 @@ private static Excel mergeTestData(Excel excel, TestData testData, int iteration
dataSheet.autoSizeColumn(1);

// save output file with expanded data
// (2018/10/18,automike): skip saving because it'll need to be saved later anyways
// (2018/10/18,automike): skip saving because it'll need to be saved later anyway
// excel.save();

return excel;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/nexial/core/ExecutionThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
* {@link Nexial} as the initiator has the option to wait on thread complete or to launch another set of
* tests in parallel. This class will track all the test artifacts such as test scenarios, test steps, test data
* and test results within its own thread context. No sharing of such data between parallel test executions.
* However test results will be consolidated at the end of the entire run.
* However, test results will be consolidated at the end of the entire run.
*
* @see Nexial
* @see ExecutionDefinition
Expand Down Expand Up @@ -130,7 +130,7 @@ public void run() {

ExecutionThread.set(context);

// in case there were fail-immediate condition from previous script.. or end-immediate condition
// in case there were fail-immediate condition from previous script... or end-immediate condition
if (shouldFailNow(context) || BooleanUtils.toBoolean(System.getProperty(END_SCRIPT_IMMEDIATE, "false"))) {
return;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ public void run() {
File testScriptFile = null;
if (testScript == null) {
// possibly the script prep/parsing routine failed (ie ExecutionInputPrep.prep()), but the output
// file might already generated. If so then we should use the generated output file and generate
// file might already be generated. If so then we should use the generated output file and generate
// output (as much as possible).
String scriptOutputFullPath = context.getStringData(OPT_INPUT_EXCEL_FILE);
if (StringUtils.isNotBlank(scriptOutputFullPath)) {testScriptFile = new File(scriptOutputFullPath);}
Expand Down Expand Up @@ -282,7 +282,7 @@ protected boolean shouldFailNow(ExecutionContext context) {

if (execDef.isFailFast() && !context.getBooleanData(OPT_LAST_OUTCOME)) {
if (context.getBooleanData(RESET_FAIL_FAST, getDefaultBool(RESET_FAIL_FAST))) {
// reset and pretend nothing's wrong. Current script will be executed..
// reset and pretend nothing's wrong. Current script will be executed...
context.setData(OPT_LAST_OUTCOME, true);
} else {
logger.error(context, RB.Abort.text("scenario.failFast"));
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/nexial/core/NexialConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,6 @@ public static final class CLI {
public static final String SUBPLANS = "subplans";
public static final String OUTPUT = "output";
public static final String OVERRIDE = "override";
public static final String ANNOUNCE = "ready";
public static final String READY = "ready";
public static final String INTERACTIVE = "interactive";
public static final Options OPTIONS = initCmdOptions();
Expand Down
Loading

0 comments on commit 87e2a82

Please sign in to comment.