From 47922b42e24581de4b3f0da3786132ca94b5809a Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Tue, 3 Dec 2024 03:02:17 +0100 Subject: [PATCH] Refactor jballerina integration tests to use more Paths instead of Strings --- .../runtime/internal/BalRuntime.java | 1 + .../internal/scheduling/Scheduler.java | 1 - .../runtime/internal/scheduling/Strand.java | 1 + .../debugadapter/JBallerinaDebugServer.java | 96 +++++++++------- .../debugadapter/variable/types/BRecord.java | 31 ++--- .../org/ballerinalang/test/context/BMain.java | 25 ++-- .../test/context/BMainInstance.java | 100 ++++++++-------- .../ballerinalang/test/context/BServer.java | 23 ++-- .../test/context/BServerInstance.java | 59 +++++----- .../ballerinalang/test/context/BalServer.java | 36 +++--- .../org/ballerinalang/test/context/Utils.java | 4 +- .../debugger/test/utils/DebugTestRunner.java | 2 +- .../test/utils/client/DAPClientConnector.java | 14 +-- .../ProcessStreamConnectionProvider.java | 10 +- .../SocketStreamConnectionProvider.java | 3 +- .../debugger/test/BaseTestCase.java | 4 +- .../remote/BallerinaRunRemoteDebugTest.java | 8 +- .../remote/BallerinaTestRemoteDebugTest.java | 2 +- .../test/async/AsyncFunctionsTest.java | 16 +-- .../test/bindgen/BindgenTestCase.java | 4 +- .../test/configurables/ConfigurableTest.java | 108 +++++++++--------- .../TypeIdViaDifferentVersionsTest.java | 13 +-- .../ForwardReferenceListenerVarTest.java | 4 +- .../identifier/IdentifierLiteralTest.java | 20 ++-- .../IsolatedInferenceWithTestsTest.java | 5 +- .../test/packaging/MavenTestCase.java | 6 +- .../packaging/ModuleExecutionFlowTests.java | 28 ++--- .../packaging/MultipleModuleVersionTests.java | 13 +-- .../test/profiler/ProfilerTest.java | 35 +++--- ...nlyIntersectionViaMultipleModulesTest.java | 13 +-- ...lyIntersectionViaMultipleModulesTest2.java | 13 +-- ...lyIntersectionViaMultipleModulesTest3.java | 13 +-- .../run/BalRunFunctionNegativeTestCase.java | 2 +- .../run/BalRunFunctionPositiveTestCase.java | 2 +- .../test/run/BasicJavaJarRunTestCase.java | 2 +- .../test/runtime/api/RuntimeAPITest.java | 32 +++--- .../test/semver/SemverValidatorBaseTest.java | 6 +- .../test/testarina/TestarinaTestCase.java | 2 +- .../test/troubleshoot/StrandDumpTest.java | 58 +++++----- .../testerina/test/BasicCasesTest.java | 6 +- .../test/CodeCoverageReportTest.java | 8 +- .../test/CodegenCodeCoverageTest.java | 8 +- .../test/ConfigurableCliArgsTest.java | 10 +- .../testerina/test/DataProviderTest.java | 38 +++--- .../testerina/test/DisableTestsTestCase.java | 5 +- .../EscapedIdentifiersValidationTest.java | 4 +- .../test/ExcludeFromCodeCoverageTest.java | 9 +- .../test/FunctionNameValidationTest.java | 4 +- .../testerina/test/GroupingTest.java | 7 +- .../testerina/test/ImportTest.java | 4 +- .../testerina/test/MockTest.java | 30 +++-- .../test/ModuleExecutionFlowTest.java | 6 +- .../testerina/test/ModuleExecutionTest.java | 6 +- ...uleExecutionWithInitStartFailuresTest.java | 6 +- .../test/ModuleGracefulStopTest.java | 6 +- .../testerina/test/PathVerificationTest.java | 5 +- .../testerina/test/RerunFailedTest.java | 8 +- .../testerina/test/SelectedFunctionTest.java | 5 +- ...ngleTestExecutionWithInitFailuresTest.java | 5 +- .../test/SourcelessTestExecutionTests.java | 5 +- .../TestExecutionWithInitFailuresTest.java | 6 +- .../testerina/test/TestReportTest.java | 4 +- .../test/TestparallelizationTest.java | 5 +- .../InvalidConfigurableCliArgsTestCase.java | 6 +- .../negative/InvalidDataProviderTestCase.java | 6 +- .../InvalidFunctionMockingTestCase.java | 25 ++-- .../InvalidTestDefinitionsTestCase.java | 5 +- .../negative/MissingFunctionsTestCase.java | 5 +- .../test/negative/SkipTestsTestCase.java | 5 +- .../negative/UnusedVarWithErrorTestCase.java | 5 +- 70 files changed, 538 insertions(+), 534 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BalRuntime.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BalRuntime.java index ef19a17acfee..711af93abfcb 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BalRuntime.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BalRuntime.java @@ -34,6 +34,7 @@ import io.ballerina.runtime.internal.scheduling.RuntimeRegistry; import io.ballerina.runtime.internal.scheduling.Scheduler; import io.ballerina.runtime.internal.values.FutureValue; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java index 2959a656e06e..a7b657dceba5 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java @@ -41,7 +41,6 @@ import io.ballerina.runtime.internal.values.FutureValue; import io.ballerina.runtime.internal.values.ObjectValue; import io.ballerina.runtime.internal.values.ValueCreator; -import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java index 9239304a9a93..e494924c65a7 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.internal.utils.ErrorUtils; import io.ballerina.runtime.transactions.TransactionLocalContext; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java index f16e20832380..f1cdaa97b3c9 100755 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java @@ -966,13 +966,14 @@ private void prepareFor(DebugInstruction instruction, int threadId) { private Variable[] computeGlobalScopeVariables(VariablesArguments requestArgs) { int stackFrameReference = requestArgs.getVariablesReference(); - String classQName = PackageUtils.getQualifiedClassName(suspendedContext, INIT_CLASS_NAME); - List cls = suspendedContext.getAttachedVm().classesByName(classQName); + String classQName = PackageUtils.getQualifiedClassName( + Objects.requireNonNull(suspendedContext), INIT_CLASS_NAME); + List cls = Objects.requireNonNull(suspendedContext).getAttachedVm().classesByName(classQName); if (cls.size() != 1) { return new Variable[0]; } List> scheduledVariables = new ArrayList<>(); - ReferenceType initClassReference = cls.get(0); + ReferenceType initClassReference = cls.getFirst(); for (Field field : initClassReference.allFields()) { String fieldName = Utils.decodeIdentifier(field.name()); if (!field.isPublic() || !field.isStatic() || fieldName.startsWith(GENERATED_VAR_PREFIX)) { @@ -1080,16 +1081,19 @@ private CompletableFuture fetchLocalVariablesFromMap(VariablesArgume private CompletableFuture computeVariableAsync(String name, Value value, Integer stackFrameRef) { return CompletableFuture.supplyAsync(() -> { BVariable variable = VariableFactory.getVariable(suspendedContext, name, value); - if (variable == null) { - return null; - } - if (variable instanceof BSimpleVariable) { - variable.getDapVariable().setVariablesReference(0); - } else if (variable instanceof BCompoundVariable) { - int variableReference = nextVarReference.getAndIncrement(); - variable.getDapVariable().setVariablesReference(variableReference); - loadedCompoundVariables.put(variableReference, (BCompoundVariable) variable); - updateVariableToStackFrameMap(stackFrameRef, variableReference); + switch (variable) { + case null -> { + return null; + } + case BSimpleVariable bSimpleVariable -> bSimpleVariable.getDapVariable().setVariablesReference(0); + case BCompoundVariable bCompoundVariable -> { + int variableReference = nextVarReference.getAndIncrement(); + variable.getDapVariable().setVariablesReference(variableReference); + loadedCompoundVariables.put(variableReference, bCompoundVariable); + updateVariableToStackFrameMap(stackFrameRef, variableReference); + } + default -> { + } } return variable.getDapVariable(); }, variableExecutor); @@ -1135,15 +1139,19 @@ private Variable[] createVariableArrayFrom(VariablesArguments args, Map { + return null; + } + case BSimpleVariable bSimpleVariable -> bSimpleVariable.getDapVariable().setVariablesReference(0); + case BCompoundVariable bCompoundVariable -> { + int variableReference = nextVarReference.getAndIncrement(); + variable.getDapVariable().setVariablesReference(variableReference); + loadedCompoundVariables.put(variableReference, bCompoundVariable); + updateVariableToStackFrameMap(args.getVariablesReference(), variableReference); + } + default -> { + } } return variable.getDapVariable(); }).filter(Objects::nonNull).toArray(Variable[]::new); @@ -1156,15 +1164,19 @@ private Variable[] createVariableArrayFrom(VariablesArguments args, List return varMap.stream().map(value -> { String name = String.format("[%d]", index.getAndIncrement()); BVariable variable = VariableFactory.getVariable(suspendedContext, name, value); - if (variable == null) { - return null; - } else if (variable instanceof BSimpleVariable) { - variable.getDapVariable().setVariablesReference(0); - } else if (variable instanceof BCompoundVariable) { - int variableReference = nextVarReference.getAndIncrement(); - variable.getDapVariable().setVariablesReference(variableReference); - loadedCompoundVariables.put(variableReference, (BCompoundVariable) variable); - updateVariableToStackFrameMap(args.getVariablesReference(), variableReference); + switch (variable) { + case null -> { + return null; + } + case BSimpleVariable bSimpleVariable -> bSimpleVariable.getDapVariable().setVariablesReference(0); + case BCompoundVariable bCompoundVariable -> { + int variableReference = nextVarReference.getAndIncrement(); + variable.getDapVariable().setVariablesReference(variableReference); + loadedCompoundVariables.put(variableReference, bCompoundVariable); + updateVariableToStackFrameMap(args.getVariablesReference(), variableReference); + } + default -> { + } } return variable.getDapVariable(); }).filter(Objects::nonNull).toArray(Variable[]::new); @@ -1178,15 +1190,19 @@ private Variable[] createVariableArrayFrom(VariablesArguments args, List */ private EvaluateResponse constructEvaluateResponse(EvaluateArguments args, BVariable evaluationResult) { EvaluateResponse response = new EvaluateResponse(); - if (evaluationResult == null) { - return response; - } else if (evaluationResult instanceof BSimpleVariable) { - evaluationResult.getDapVariable().setVariablesReference(0); - } else if (evaluationResult instanceof BCompoundVariable) { - int variableReference = nextVarReference.getAndIncrement(); - evaluationResult.getDapVariable().setVariablesReference(variableReference); - loadedCompoundVariables.put(variableReference, (BCompoundVariable) evaluationResult); - updateVariableToStackFrameMap(args.getFrameId(), variableReference); + switch (evaluationResult) { + case null -> { + return response; + } + case BSimpleVariable bSimpleVariable -> bSimpleVariable.getDapVariable().setVariablesReference(0); + case BCompoundVariable bCompoundVariable -> { + int variableReference = nextVarReference.getAndIncrement(); + evaluationResult.getDapVariable().setVariablesReference(variableReference); + loadedCompoundVariables.put(variableReference, bCompoundVariable); + updateVariableToStackFrameMap(args.getFrameId(), variableReference); + } + default -> { + } } Variable dapVariable = evaluationResult.getDapVariable(); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BRecord.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BRecord.java index 6f2ff4381f2a..524ee4fef653 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BRecord.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BRecord.java @@ -88,7 +88,7 @@ public Map computeChildVariables() { @Nullable private Map getRecordFields() { try { - loadAllKeys(); + ArrayReference loadedKeys = loadAllKeys(); Map recordFields = new LinkedHashMap<>(); if (loadedKeys == null) { return null; @@ -105,19 +105,22 @@ private Map getRecordFields() { } } - private void loadAllKeys() { - if (loadedKeys == null) { - try { - Optional getKeysMethod = VariableUtils.getMethod(jvmValue, METHOD_GET_KEYS, - GETKEYS_METHOD_SIGNATURE_PATTERN); - Value keyArray = ((ObjectReference) jvmValue).invokeMethod( - context.getOwningThread().getThreadReference(), getKeysMethod.get(), Collections.emptyList(), - ObjectReference.INVOKE_SINGLE_THREADED); - loadedKeys = (ArrayReference) keyArray; - } catch (Exception ignored) { - loadedKeys = null; - } + @Nullable + private ArrayReference loadAllKeys() { + if (loadedKeys != null) { + return loadedKeys; + } + try { + Optional getKeysMethod = VariableUtils.getMethod(jvmValue, METHOD_GET_KEYS, + GETKEYS_METHOD_SIGNATURE_PATTERN); + Value keyArray = ((ObjectReference) jvmValue).invokeMethod( + context.getOwningThread().getThreadReference(), getKeysMethod.get(), Collections.emptyList(), + ObjectReference.INVOKE_SINGLE_THREADED); + loadedKeys = (ArrayReference) keyArray; + } catch (Exception ignored) { + loadedKeys = null; } + return loadedKeys; } @Nullable @@ -140,7 +143,7 @@ public int getChildrenCount() { if (!(jvmValue instanceof ObjectReference)) { return 0; } - loadAllKeys(); + ArrayReference loadedKeys = loadAllKeys(); return loadedKeys == null ? 0 : loadedKeys.length(); } catch (Exception ignored) { return 0; diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BMain.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BMain.java index 195a2051c823..d1604ab61ac9 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BMain.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BMain.java @@ -18,6 +18,7 @@ package org.ballerinalang.test.context; +import java.nio.file.Path; import java.util.Map; /** @@ -34,7 +35,7 @@ public interface BMain { * @param balFile bal file path * @throws BallerinaTestException if any exception is thrown when running the main function */ - void runMain(String balFile) throws BallerinaTestException; + void runMain(Path balFile) throws BallerinaTestException; /** * Run ballerina main function provided .bal file. @@ -43,7 +44,7 @@ public interface BMain { * @param leechers log leechers to check the log if any * @throws BallerinaTestException if any exception is thrown when running the main function */ - void runMain(String balFile, LogLeecher[] leechers) throws BallerinaTestException; + void runMain(Path balFile, LogLeecher[] leechers) throws BallerinaTestException; /** * Run ballerina main function provided .bal file. @@ -53,7 +54,7 @@ public interface BMain { * @param args arguments to pass * @throws BallerinaTestException if any exception is thrown when running the main function */ - void runMain(String balFile, String[] flags, String[] args) throws BallerinaTestException; + void runMain(Path balFile, String[] flags, String[] args) throws BallerinaTestException; /** * Run ballerina main function provided .bal file. @@ -64,7 +65,7 @@ public interface BMain { * @param leechers log leechers to check the log if any * @throws BallerinaTestException if any exception is thrown when running the main function */ - void runMain(String balFile, String[] flags, String[] args, LogLeecher[] leechers) throws BallerinaTestException; + void runMain(Path balFile, String[] flags, String[] args, LogLeecher[] leechers) throws BallerinaTestException; /** * Run ballerina main function provided .bal file. @@ -76,7 +77,7 @@ public interface BMain { * @param clientArgs arguments which program expects * @throws BallerinaTestException if any exception is thrown when running the main function */ - void runMain(String balFile, String[] flags, String[] args, Map envProperties, + void runMain(Path balFile, String[] flags, String[] args, Map envProperties, String[] clientArgs) throws BallerinaTestException; /** @@ -90,7 +91,7 @@ void runMain(String balFile, String[] flags, String[] args, Map * @param leechers log leechers to check the log if any * @throws BallerinaTestException if any exception is thrown when running the main function */ - void runMain(String balFile, String[] flags, String[] args, Map envProperties, + void runMain(Path balFile, String[] flags, String[] args, Map envProperties, String[] clientArgs, LogLeecher[] leechers) throws BallerinaTestException; // ********************* End bal file run methods. ******************* @@ -103,7 +104,7 @@ void runMain(String balFile, String[] flags, String[] args, Map * @param packagePath package path * @throws BallerinaTestException if any exception is thrown when running the main function */ - void runMain(String sourceRoot, String packagePath) throws BallerinaTestException; + void runMain(Path sourceRoot, String packagePath) throws BallerinaTestException; /** * Run ballerina main function provided bal package. @@ -113,7 +114,7 @@ void runMain(String balFile, String[] flags, String[] args, Map * @param leechers log leechers to check the log if any * @throws BallerinaTestException if any exception is thrown when running the main function */ - void runMain(String sourceRoot, String packagePath, LogLeecher[] leechers) throws BallerinaTestException; + void runMain(Path sourceRoot, String packagePath, LogLeecher[] leechers) throws BallerinaTestException; /** * Run ballerina main function provided bal package. @@ -124,7 +125,7 @@ void runMain(String balFile, String[] flags, String[] args, Map * @param args arguments to parse * @throws BallerinaTestException if any exception is thrown when running the main function */ - void runMain(String sourceRoot, String packagePath, String[] flags, String[] args) throws BallerinaTestException; + void runMain(Path sourceRoot, String packagePath, String[] flags, String[] args) throws BallerinaTestException; /** * Run ballerina main function provided bal package. @@ -136,7 +137,7 @@ void runMain(String balFile, String[] flags, String[] args, Map * @param leechers log leechers to check the log if any * @throws BallerinaTestException if any exception is thrown when running the main function */ - void runMain(String sourceRoot, String packagePath, String[] flags, String[] args, + void runMain(Path sourceRoot, String packagePath, String[] flags, String[] args, LogLeecher[] leechers) throws BallerinaTestException; /** @@ -150,7 +151,7 @@ void runMain(String sourceRoot, String packagePath, String[] flags, String[] arg * @param clientArgs arguments which program expects * @throws BallerinaTestException if any exception is thrown when running the main function */ - void runMain(String sourceRoot, String packagePath, String[] flags, String[] args, + void runMain(Path sourceRoot, String packagePath, String[] flags, String[] args, Map envProperties, String[] clientArgs) throws BallerinaTestException; /** @@ -165,7 +166,7 @@ void runMain(String sourceRoot, String packagePath, String[] flags, String[] arg * @param leechers log leechers to check the log if any * @throws BallerinaTestException if any exception is thrown when running the main function */ - void runMain(String sourceRoot, String packagePath, + void runMain(Path sourceRoot, String packagePath, String[] flags, String[] args, Map envProperties, String[] clientArgs, LogLeecher[] leechers) throws BallerinaTestException; // ********************* End bal package run methods. ******************* diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BMainInstance.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BMainInstance.java index bd8c39a7b755..15a473ba7e96 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BMainInstance.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BMainInstance.java @@ -93,42 +93,42 @@ private void initialize() { private void configureAgentArgs() { // add jacoco agent - String jacocoArgLine = "-javaagent:" + Path.of(balServer.getServerHome(), "bre/lib/jacocoagent.jar") + String jacocoArgLine = "-javaagent:" + balServer.getServerHome().resolve("bre/lib/jacocoagent.jar") + "=destfile=" + Path.of(System.getProperty("user.dir"), "build/jacoco/test.exec"); agentArgs = jacocoArgLine + " "; } @Override - public void runMain(String balFile) throws BallerinaTestException { + public void runMain(Path balFile) throws BallerinaTestException { runMain(balFile, new String[]{}, new String[]{}); } @Override - public void runMain(String balFile, LogLeecher[] leechers) throws BallerinaTestException { + public void runMain(Path balFile, LogLeecher[] leechers) throws BallerinaTestException { runMain(balFile, new String[]{}, new String[]{}, leechers); } @Override - public void runMain(String balFile, String[] flags, String[] args) throws BallerinaTestException { + public void runMain(Path balFile, String[] flags, String[] args) throws BallerinaTestException { runMain(balFile, flags, args, null, null); } @Override - public void runMain(String balFile, @Nullable String[] flags, + public void runMain(Path balFile, @Nullable String[] flags, String[] args, LogLeecher[] leechers) throws BallerinaTestException { runMain(balFile, flags, args, new HashMap<>(), new String[]{}, leechers); } @Override - public void runMain(String balFile, String[] flags, String[] args, @Nullable Map envProperties, + public void runMain(Path balFile, String[] flags, String[] args, @Nullable Map envProperties, @Nullable String[] clientArgs) throws BallerinaTestException { runMain(balFile, flags, args, envProperties, clientArgs, null); } @Override - public void runMain(String balFile, String[] flags, String[] args, Map envProperties, + public void runMain(Path balFile, String[] flags, String[] args, Map envProperties, String[] clientArgs, @Nullable LogLeecher[] leechers) throws BallerinaTestException { - if (balFile == null || balFile.isEmpty()) { + if (balFile == null) { throw new IllegalArgumentException("Invalid ballerina program file name provided, name - " + balFile); } @@ -144,44 +144,45 @@ public void runMain(String balFile, String[] flags, String[] args, Map(); } - runMain("build", new String[]{balFile}, envProperties, null, leechers, balServer.getServerHome()); + runMain("build", new String[]{ + balFile.toAbsolutePath().toString()}, envProperties, null, leechers, balServer.getServerHome()); runJar(balFile, ArrayUtils.addAll(flags, args), envProperties, clientArgs, leechers, balServer.getServerHome()); } @Override - public void runMain(String sourceRoot, String packagePath) throws BallerinaTestException { + public void runMain(Path sourceRoot, String packagePath) throws BallerinaTestException { runMain(sourceRoot, packagePath, new String[]{}, new String[]{}); } @Override - public void runMain(String sourceRoot, String packagePath, LogLeecher[] leechers) throws BallerinaTestException { + public void runMain(Path sourceRoot, String packagePath, LogLeecher[] leechers) throws BallerinaTestException { runMain(sourceRoot, packagePath, new String[]{}, new String[]{}, leechers); } @Override - public void runMain(String sourceRoot, String packagePath, + public void runMain(Path sourceRoot, String packagePath, String[] flags, String[] args) throws BallerinaTestException { runMain(sourceRoot, packagePath, flags, args, null, null); } @Override - public void runMain(String sourceRoot, String packagePath, String[] flags, String[] args, + public void runMain(Path sourceRoot, String packagePath, String[] flags, String[] args, LogLeecher[] leechers) throws BallerinaTestException { runMain(sourceRoot, packagePath, flags, args, null, new String[]{}, leechers); } @Override - public void runMain(String sourceRoot, String packagePath, String[] flags, String[] args, + public void runMain(Path sourceRoot, String packagePath, String[] flags, String[] args, @Nullable Map envProperties, @Nullable String[] clientArgs ) throws BallerinaTestException { runMain(sourceRoot, packagePath, flags, args, envProperties, clientArgs, null); } @Override - public void runMain(String sourceRoot, String packagePath, + public void runMain(Path sourceRoot, String packagePath, @Nullable String[] flags, String[] args, @Nullable Map envProperties, @Nullable String[] clientArgs, @Nullable LogLeecher[] leechers) throws BallerinaTestException { - if (sourceRoot == null || sourceRoot.isEmpty() || packagePath == null || packagePath.isEmpty()) { + if (sourceRoot == null || packagePath == null) { throw new IllegalArgumentException("Invalid ballerina program file provided, sourceRoot - " + sourceRoot + " packagePath - " + packagePath); } @@ -198,7 +199,7 @@ public void runMain(String sourceRoot, String packagePath, envProperties = new HashMap<>(); } runMain("build", new String[]{packagePath}, envProperties, null, leechers, sourceRoot); - runJar(Path.of(sourceRoot, packagePath).toString(), packagePath, ArrayUtils.addAll(flags, args), + runJar(sourceRoot.resolve(packagePath), packagePath, ArrayUtils.addAll(flags, args), envProperties, clientArgs, leechers, sourceRoot); } @@ -218,7 +219,7 @@ public synchronized void addJavaAgents(Map envProperties) { } public String getBalServerHome() { - return Path.of(balServer.getServerHome()).toString(); + return balServer.getServerHome().toString(); } /** @@ -234,7 +235,7 @@ public String getBalServerHome() { */ public void runMain(String command, String[] args, @Nullable Map envProperties, @Nullable String[] clientArgs, - @Nullable LogLeecher[] leechers, String commandDir) throws BallerinaTestException { + @Nullable LogLeecher[] leechers, Path commandDir) throws BallerinaTestException { String scriptName = Constant.BALLERINA_SERVER_SCRIPT_NAME; String[] cmdArray; try { @@ -248,7 +249,7 @@ public void runMain(String command, String[] args, @Nullable Map } String[] cmdArgs = Stream.concat(Arrays.stream(cmdArray), Arrays.stream(args)).toArray(String[]::new); - ProcessBuilder processBuilder = new ProcessBuilder(cmdArgs).directory(new File(commandDir)); + ProcessBuilder processBuilder = new ProcessBuilder(cmdArgs).directory(commandDir.toAbsolutePath().toFile()); if (envProperties != null) { Map env = processBuilder.environment(); env.putAll(envProperties); @@ -302,19 +303,19 @@ public void runMain(String command, String[] args, @Nullable Map * @throws BallerinaTestException if starting services failed */ public Process runCommandAndGetProcess(String command, String[] args, Map envProperties, - String commandDir) throws BallerinaTestException { + Path commandDir) throws BallerinaTestException { String scriptName = Constant.BALLERINA_SERVER_SCRIPT_NAME; String[] cmdArray; try { if (Utils.isWindowsOS()) { - cmdArray = new String[]{"cmd.exe", "/c", balServer.getServerHome() + - File.separator + "bin" + File.separator + scriptName + ".bat", command}; + cmdArray = new String[]{"cmd.exe", "/c", + balServer.getServerHome().resolve("bin/" + scriptName + ".bat").toString(), command}; } else { - cmdArray = new String[]{"bash", balServer.getServerHome() + - File.separator + "bin/" + scriptName, command}; + cmdArray = new String[]{"bash", + balServer.getServerHome().resolve("bin/" + scriptName).toString(), command}; } String[] cmdArgs = Stream.concat(Arrays.stream(cmdArray), Arrays.stream(args)).toArray(String[]::new); - ProcessBuilder processBuilder = new ProcessBuilder(cmdArgs).directory(new File(commandDir)); + ProcessBuilder processBuilder = new ProcessBuilder(cmdArgs).directory(commandDir.toAbsolutePath().toFile()); if (envProperties != null) { Map env = processBuilder.environment(); env.putAll(envProperties); @@ -347,7 +348,7 @@ public void waitForLeechers(List logLeechers, int timeout) throws Ba */ public Process debugMain(String command, String[] args, @Nullable Map envProperties, String[] clientArgs, - LogLeecher[] leechers, String commandDir, int timeout, boolean isAttachMode) + LogLeecher[] leechers, Path commandDir, int timeout, boolean isAttachMode) throws BallerinaTestException { String scriptName = Constant.BALLERINA_SERVER_SCRIPT_NAME; String[] cmdArray; @@ -368,7 +369,7 @@ public Process debugMain(String command, String[] args, @Nullable Map env = processBuilder.environment(); env.putAll(envProperties); @@ -461,7 +462,7 @@ public Process debugMain(String command, String[] args, @Nullable Map envProperties, @Nullable String[] clientArgs, - LogLeecher[] leechers, String commandDir, int timeout) throws BallerinaTestException { + LogLeecher[] leechers, Path commandDir, int timeout) throws BallerinaTestException { boolean isAttachMode = false; debugMain(command, args, envProperties, clientArgs, leechers, commandDir, timeout, isAttachMode); } @@ -523,9 +524,9 @@ public void terminateProcessWithDescendants(@Nullable Process process) { * @param commandDir where to execute the command * @throws BallerinaTestException if starting services failed */ - private void runJar(String sourceRoot, String packageName, String[] args, Map envProperties, - String[] clientArgs, LogLeecher[] leechers, String commandDir) throws BallerinaTestException { - executeJarFile(Path.of(sourceRoot, "target", "bin", packageName + ".jar").toFile().getPath(), + private void runJar(Path sourceRoot, String packageName, String[] args, Map envProperties, + String[] clientArgs, LogLeecher[] leechers, Path commandDir) throws BallerinaTestException { + executeJarFile(sourceRoot.resolve("target/bin/" + packageName + ".jar"), args, envProperties, clientArgs, leechers, commandDir); } @@ -540,11 +541,10 @@ private void runJar(String sourceRoot, String packageName, String[] args, Map envProperties, String[] clientArgs, - LogLeecher[] leechers, String commandDir) throws BallerinaTestException { - String balFileName = Path.of(balFile).getFileName().toString(); - String jarPath = Path.of(Path.of(commandDir).toString(), balFileName.substring(0, balFileName.length() - - 4) + ".jar").toString(); + private void runJar(Path balFile, String[] args, Map envProperties, String[] clientArgs, + LogLeecher[] leechers, Path commandDir) throws BallerinaTestException { + String balFileName = balFile.getFileName().toString(); + Path jarPath = commandDir.resolve(balFileName.substring(0, balFileName.length() - 4) + ".jar"); executeJarFile(jarPath, args, envProperties, clientArgs, leechers, commandDir); } @@ -559,8 +559,8 @@ private void runJar(String balFile, String[] args, Map envProper * @param commandDir where to execute the command * @throws BallerinaTestException if starting services failed */ - private void executeJarFile(String jarPath, String[] args, Map envProperties, String[] clientArgs, - LogLeecher[] leechers, String commandDir) throws BallerinaTestException { + private void executeJarFile(Path jarPath, String[] args, Map envProperties, String[] clientArgs, + LogLeecher[] leechers, Path commandDir) throws BallerinaTestException { try { List runCmdSet = new ArrayList<>(); runCmdSet.add("java"); @@ -568,13 +568,13 @@ private void executeJarFile(String jarPath, String[] args, Map e if (envProperties.containsKey(JAVA_OPTS)) { runCmdSet.add(envProperties.get(JAVA_OPTS).trim()); } - String tempBalHome = new File("src" + File.separator + "test" + File.separator + - "resources" + File.separator + "ballerina.home").getAbsolutePath(); + String tempBalHome = Path.of("src/test/resources/ballerina.home").toString(); runCmdSet.add("-Dballerina.home=" + tempBalHome); - runCmdSet.addAll(Arrays.asList("-jar", jarPath)); + runCmdSet.addAll(Arrays.asList("-jar", jarPath.toAbsolutePath().toString())); runCmdSet.addAll(Arrays.asList(args)); - ProcessBuilder processBuilder = new ProcessBuilder(runCmdSet).directory(new File(commandDir)); + ProcessBuilder processBuilder = new ProcessBuilder(runCmdSet).directory( + commandDir.toAbsolutePath().toFile()); Map env = processBuilder.environment(); env.putAll(envProperties); Process process = processBuilder.start(); @@ -620,7 +620,7 @@ private void executeJarFile(String jarPath, String[] args, Map e * @return logs printed to std out * @throws BallerinaTestException if starting services failed or if an error occurs when reading the stdout */ - public String runMainAndReadStdOut(String command, String[] args, String commandDir) throws BallerinaTestException { + public String runMainAndReadStdOut(String command, String[] args, Path commandDir) throws BallerinaTestException { return runMainAndReadStdOut(command, args, new HashMap<>(), commandDir, false); } @@ -636,7 +636,7 @@ public String runMainAndReadStdOut(String command, String[] args, String command * @throws BallerinaTestException if starting services failed or if an error occurs when reading the stdout */ public String runMainAndReadStdOut(String command, String[] args, Map envProperties, - String commandDir, boolean readErrStream) throws BallerinaTestException { + Path commandDir, boolean readErrStream) throws BallerinaTestException { String scriptName = Constant.BALLERINA_SERVER_SCRIPT_NAME; String[] cmdArray; @@ -651,8 +651,8 @@ public String runMainAndReadStdOut(String command, String[] args, Map env = processBuilder.environment(); env.putAll(envProperties); @@ -701,9 +701,9 @@ private void writeClientArgsToProcess(String[] clientArgs, Process process) thro writer.close(); } - public void compilePackageAndPushToLocal(String packagPath, String balaFileName) throws BallerinaTestException { - String targetBala = Path.of("target/bala/" + balaFileName + ".bala").toString(); - LogLeecher buildLeecher = new LogLeecher(targetBala); + public void compilePackageAndPushToLocal(Path packagPath, String balaFileName) throws BallerinaTestException { + Path targetBala = Path.of("target/bala/" + balaFileName + ".bala"); + LogLeecher buildLeecher = new LogLeecher(targetBala.toString()); LogLeecher pushLeecher = new LogLeecher("Successfully pushed " + targetBala + " to 'local' repository."); this.runMain("pack", new String[]{}, null, null, new LogLeecher[]{buildLeecher}, packagPath); buildLeecher.waitForText(5000); diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BServer.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BServer.java index ed2089a39997..4a08967a3459 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BServer.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BServer.java @@ -18,6 +18,7 @@ package org.ballerinalang.test.context; +import java.nio.file.Path; import java.util.Map; /** @@ -33,7 +34,7 @@ public interface BServer { * @param balFile bal file path * @throws BallerinaTestException if services start fails */ - void startServer(String balFile) throws BallerinaTestException; + void startServer(Path balFile) throws BallerinaTestException; /** * Start ballerina server passing provided .bal files. @@ -42,7 +43,7 @@ public interface BServer { * @param useBallerinaRunCommand flag to use ballerina run to execute program. * @throws BallerinaTestException if services start fails */ - void startServer(String balFile, boolean useBallerinaRunCommand) throws BallerinaTestException; + void startServer(Path balFile, boolean useBallerinaRunCommand) throws BallerinaTestException; /** * Start ballerina server passing provided .bal files. @@ -51,7 +52,7 @@ public interface BServer { * @param requiredPorts ports required for the server instance * @throws BallerinaTestException if services start fails */ - void startServer(String balFile, int[] requiredPorts) throws BallerinaTestException; + void startServer(Path balFile, int[] requiredPorts) throws BallerinaTestException; /** * Start ballerina server passing provided .bal files. @@ -62,7 +63,7 @@ public interface BServer { * @param requiredPorts ports required for the server instance * @throws BallerinaTestException if services start fails */ - void startServer(String balFile, String[] buildArgs, String[] runtimeArgs, int[] requiredPorts) + void startServer(Path balFile, String[] buildArgs, String[] runtimeArgs, int[] requiredPorts) throws BallerinaTestException; /** @@ -75,7 +76,7 @@ void startServer(String balFile, String[] buildArgs, String[] runtimeArgs, int[] * @param requiredPorts ports required for the server instance * @throws BallerinaTestException if services start fails */ - void startServer(String balFile, String[] buildArgs, String[] runtimeArgs, Map envProperties, + void startServer(Path balFile, String[] buildArgs, String[] runtimeArgs, Map envProperties, int[] requiredPorts) throws BallerinaTestException; /** @@ -89,7 +90,7 @@ void startServer(String balFile, String[] buildArgs, String[] runtimeArgs, Map envProperties, + void startServer(Path balFile, String[] buildArgs, String[] runtimeArgs, Map envProperties, int[] requiredPorts, boolean useBallerinaRunCommand) throws BallerinaTestException; /** @@ -99,7 +100,7 @@ void startServer(String balFile, String[] buildArgs, String[] runtimeArgs, Map envProperties, int[] requiredPorts, boolean useBallerinaRunCommand) throws BallerinaTestException; @@ -151,7 +152,7 @@ void startServer(String sourceRoot, String packagePath, String[] buildArgs, Stri * @param requiredPorts ports required for the server instance * @throws BallerinaTestException if starting fails */ - void startServer(String sourceRoot, String packagePath, String[] buildArgs, String[] runtimeArgs, + void startServer(Path sourceRoot, String packagePath, String[] buildArgs, String[] runtimeArgs, Map envProperties, int[] requiredPorts) throws BallerinaTestException; /** diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BServerInstance.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BServerInstance.java index 53f377ba88d8..98aed587fbf0 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BServerInstance.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BServerInstance.java @@ -98,47 +98,47 @@ private void configureAgentArgs() throws BallerinaTestException { + ",exitStatus=1,timeout=15000,killStatus=5 "; // add jacoco agent - String jacocoArgLine = "-javaagent:" + Path.of(balServer.getServerHome(), "bre/lib/jacocoagent.jar") + String jacocoArgLine = "-javaagent:" + balServer.getServerHome().resolve("bre/lib/jacocoagent.jar") + "=destfile=" + Path.of(System.getProperty("user.dir"), "build/jacoco/test.exec"); agentArgs = jacocoArgLine + " " + agentArgs + " "; } @Override - public void startServer(String balFile) throws BallerinaTestException { + public void startServer(Path balFile) throws BallerinaTestException { startServer(balFile, new int[]{}); } @Override - public void startServer(String balFile, boolean useBallerinaRunCommand) throws BallerinaTestException { + public void startServer(Path balFile, boolean useBallerinaRunCommand) throws BallerinaTestException { assert requiredPorts.length < 20 : "test try to open too many ports : " + requiredPorts.length; startServer(balFile, new String[] {}, null, null, requiredPorts, true); } @Override - public void startServer(String balFile, int[] requiredPorts) throws BallerinaTestException { + public void startServer(Path balFile, int[] requiredPorts) throws BallerinaTestException { assert requiredPorts.length < 20 : "test try to open too many ports : " + requiredPorts.length; startServer(balFile, new String[] { }, null, requiredPorts); } @Override - public void startServer(String balFile, String[] buildArgs, @Nullable String[] runtimeArgs, int[] requiredPorts) + public void startServer(Path balFile, String[] buildArgs, @Nullable String[] runtimeArgs, int[] requiredPorts) throws BallerinaTestException { startServer(balFile, buildArgs, runtimeArgs, null, requiredPorts); } @Override - public void startServer(String balFile, @Nullable String[] buildArgs, @Nullable String[] runtimeArgs, + public void startServer(Path balFile, @Nullable String[] buildArgs, @Nullable String[] runtimeArgs, @Nullable Map envProperties, int[] requiredPorts ) throws BallerinaTestException { startServer(balFile, buildArgs, runtimeArgs, envProperties, requiredPorts, false); } @Override - public void startServer(String balFile, String[] buildArgs, @Nullable String[] runtimeArgs, + public void startServer(Path balFile, String[] buildArgs, @Nullable String[] runtimeArgs, @Nullable Map envProperties, int[] requiredPorts, boolean useBallerinaRunCommand) throws BallerinaTestException { - if (balFile == null || balFile.isEmpty()) { + if (balFile == null) { throw new IllegalArgumentException("Invalid ballerina program file name provided, name - " + balFile); } @@ -154,7 +154,7 @@ public void startServer(String balFile, String[] buildArgs, @Nullable String[] r envProperties = new HashMap<>(); } - String[] newArgs = {balFile}; + String[] newArgs = {balFile.toAbsolutePath().toString()}; newArgs = ArrayUtils.addAll(buildArgs, newArgs); addJavaAgents(envProperties); @@ -167,34 +167,34 @@ public void startServer(String balFile, String[] buildArgs, @Nullable String[] r } @Override - public void startServer(String sourceRoot, String packagePath) throws BallerinaTestException { + public void startServer(Path sourceRoot, String packagePath) throws BallerinaTestException { startServer(sourceRoot, packagePath, new int[]{}); } @Override - public void startServer(String sourceRoot, String packagePath, int[] requiredPorts) throws BallerinaTestException { + public void startServer(Path sourceRoot, String packagePath, int[] requiredPorts) throws BallerinaTestException { startServer(sourceRoot, packagePath, new String[]{}, new String[]{}, requiredPorts); } @Override - public void startServer(String sourceRoot, String packagePath, @Nullable String[] buildArgs, + public void startServer(Path sourceRoot, String packagePath, @Nullable String[] buildArgs, @Nullable String[] runtimeArgs, int @Nullable [] requiredPorts) throws BallerinaTestException { startServer(sourceRoot, packagePath, buildArgs, runtimeArgs, null, requiredPorts); } @Override - public void startServer(String sourceRoot, String packagePath, String[] buildArgs, String[] runtimeArgs, + public void startServer(Path sourceRoot, String packagePath, String[] buildArgs, String[] runtimeArgs, @Nullable Map envProperties, int[] requiredPorts ) throws BallerinaTestException { startServer(sourceRoot, packagePath, buildArgs, runtimeArgs, envProperties, requiredPorts, false); } @Override - public void startServer(String sourceRoot, String packagePath, String[] buildArgs, String[] runtimeArgs, + public void startServer(Path sourceRoot, String packagePath, String[] buildArgs, String[] runtimeArgs, Map envProperties, int[] requiredPorts, boolean useBallerinaRunCommand) throws BallerinaTestException { - if (sourceRoot == null || sourceRoot.isEmpty()) { + if (sourceRoot == null) { throw new IllegalArgumentException("Invalid ballerina program file provided, sourceRoot - " + sourceRoot); } @@ -211,7 +211,7 @@ public void startServer(String sourceRoot, String packagePath, String[] buildArg } addJavaAgents(envProperties); - String[] newArgs = new String[] { sourceRoot }; + String[] newArgs = new String[]{sourceRoot.toAbsolutePath().toString()}; newArgs = ArrayUtils.addAll(buildArgs, newArgs); if (useBallerinaRunCommand) { runBalSource(newArgs, envProperties); @@ -292,7 +292,7 @@ private synchronized void addJavaAgents(Map envProperties) { * * @return absolute path of the server location */ - public String getServerHome() { + public Path getServerHome() { return balServer.getServerHome(); } @@ -376,7 +376,7 @@ private void runBuildTool(String command, String[] args, @Nullable Map envProperties) * @param requiredPorts ports required for the server instance * @throws BallerinaTestException if starting services failed */ - private void runJar(String sourceRoot, String packageName, String[] args, Map envProperties, + private void runJar(Path sourceRoot, String packageName, String[] args, Map envProperties, int[] requiredPorts) throws BallerinaTestException { - File commandDir = new File(balServer.getServerHome()); - executeJarFile(Path.of(sourceRoot, "target", "bin", packageName + ".jar").toFile().getPath(), + Path commandDir = balServer.getServerHome(); + executeJarFile(sourceRoot.resolve("target/bin/" + packageName + ".jar"), args, envProperties, commandDir, requiredPorts); } @@ -454,12 +454,11 @@ private void runJar(String sourceRoot, String packageName, String[] args, Map envProperties, int[] requiredPorts) + private void runJar(Path balFile, String[] args, Map envProperties, int[] requiredPorts) throws BallerinaTestException { - File commandDir = new File(balServer.getServerHome()); - String balFileName = Path.of(balFile).getFileName().toString(); - String jarPath = Path.of(commandDir.getAbsolutePath(), balFileName.substring(0, balFileName.length() - - 4) + ".jar").toString(); + Path commandDir = balServer.getServerHome(); + String balFileName = balFile.getFileName().toString(); + Path jarPath = commandDir.resolve(balFileName.substring(0, balFileName.length() - 4) + ".jar"); executeJarFile(jarPath, args, envProperties, commandDir, requiredPorts); } @@ -473,8 +472,8 @@ private void runJar(String balFile, String[] args, Map envProper * @param requiredPorts ports required for the server instance * @throws BallerinaTestException if starting services failed */ - private void executeJarFile(String jarPath, String[] args, Map envProperties, - File commandDir, int[] requiredPorts) throws BallerinaTestException { + private void executeJarFile(Path jarPath, String[] args, Map envProperties, + Path commandDir, int[] requiredPorts) throws BallerinaTestException { try { if (this.requiredPorts == null) { this.requiredPorts = new int[]{}; @@ -498,10 +497,10 @@ private void executeJarFile(String jarPath, String[] args, Map e String tempBalHome = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "ballerina.home").getAbsolutePath(); runCmdSet.add("-Dballerina.home=" + tempBalHome); - runCmdSet.addAll(Arrays.asList("-jar", jarPath)); + runCmdSet.addAll(Arrays.asList("-jar", jarPath.toAbsolutePath().toString())); runCmdSet.addAll(Arrays.asList(args)); - ProcessBuilder processBuilder = new ProcessBuilder(runCmdSet).directory(commandDir); + ProcessBuilder processBuilder = new ProcessBuilder(runCmdSet).directory(commandDir.toFile()); Map env = processBuilder.environment(); env.putAll(envProperties); process = processBuilder.start(); diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BalServer.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BalServer.java index b899dda443c5..cda45064e6de 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BalServer.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BalServer.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Path; /** * This class hold the server location and manage the a server location. @@ -30,12 +31,12 @@ */ public class BalServer { private static final Logger log = LoggerFactory.getLogger(BalServer.class); - private String serverHome; + private Path serverHome; /** * The parent directory which the ballerina runtime will be extracted to. */ - private String extractDir; + private Path extractDir; /** * This will unzip a new Ballerina server and create a new server location. @@ -43,11 +44,11 @@ public class BalServer { * @throws BallerinaTestException if something fails */ public BalServer() throws BallerinaTestException { - this(System.getProperty(Constant.SYSTEM_PROP_SERVER_ZIP)); + this(Path.of(System.getProperty(Constant.SYSTEM_PROP_SERVER_ZIP))); } - public BalServer(String serverZipFile) throws BallerinaTestException { - setUpServerHome(serverZipFile); + public BalServer(Path serverZipFile) throws BallerinaTestException { + setUpServerHome(serverZipFile.toAbsolutePath()); log.info("Server Home " + serverHome); } @@ -59,28 +60,21 @@ public BalServer(String serverZipFile) throws BallerinaTestException { * @param serverZipFile server zip file location * @throws BallerinaTestException if setting up the server fails */ - private void setUpServerHome(String serverZipFile) throws BallerinaTestException { - - int indexOfZip = serverZipFile.lastIndexOf(".zip"); - if (indexOfZip == -1) { + private void setUpServerHome(Path serverZipFile) throws BallerinaTestException { + if (!serverZipFile.getFileName().toString().endsWith(".zip")) { throw new IllegalArgumentException(serverZipFile + " is not a zip file"); } - String fileSeparator = (File.separator.equals("\\")) ? "\\" : "/"; - if (fileSeparator.equals("\\")) { - serverZipFile = serverZipFile.replace("/", "\\"); - } - String extractedBalDir = serverZipFile.substring(serverZipFile.lastIndexOf(fileSeparator) + 1, indexOfZip); - String baseDir = (System.getProperty("libdir", ".")); + String extractedBalDir = serverZipFile.getFileName().toString().replace(".zip", ""); + String baseDir = System.getProperty("libdir", "."); - extractDir = new File(baseDir).getAbsolutePath() + - File.separator + "ballerinatmp" + System.currentTimeMillis(); + extractDir = Path.of(baseDir, "ballerinatmp" + System.currentTimeMillis()); log.info("Extracting ballerina zip file.. "); try { - Utils.extractFile(serverZipFile, extractDir); + Utils.extractFile(serverZipFile.toFile(), extractDir.toFile()); - this.serverHome = extractDir + File.separator + extractedBalDir; + this.serverHome = extractDir.resolve(extractedBalDir); } catch (IOException e) { throw new BallerinaTestException("Error extracting server zip file", e); } @@ -98,7 +92,7 @@ public void cleanup() { * * @return absolute path of the server location */ - public String getServerHome() { + public Path getServerHome() { return serverHome; } @@ -106,7 +100,7 @@ public String getServerHome() { * Delete the working directory with the extracted ballerina instance to cleanup data after execution is complete. */ private void deleteWorkDir() { - File workDir = new File(extractDir); + File workDir = extractDir.toFile(); Utils.deleteFolder(workDir); } } diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/Utils.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/Utils.java index ff1a971cf7ba..4dcc15e0cd70 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/Utils.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/Utils.java @@ -161,7 +161,7 @@ private static boolean isPortOpen(int port, InetAddress address) { * @throws IOException if an i/o exception occurs when extracting the file * @throws BallerinaTestException if ballerina test exception occurs when extracting the file */ - public static void extractFile(String sourceFilePath, String extractedDir) throws IOException, + public static void extractFile(File sourceFilePath, File extractedDir) throws IOException, BallerinaTestException { FileOutputStream fileoutputstream = null; @@ -182,7 +182,7 @@ public static void extractFile(String sourceFilePath, String extractedDir) throw int n; File newFile = new File(entryName); - if (!newFile.getCanonicalPath().startsWith(new File(extractedDir).getCanonicalPath())) { + if (!newFile.getCanonicalPath().startsWith(extractedDir.getCanonicalPath())) { throw new BallerinaTestException("Arbitrary File Write attack attempted via an archive file. " + "File name: " + newFile.getName()); } diff --git a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java index 716f407db91e..354a8483208a 100644 --- a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java +++ b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java @@ -133,7 +133,7 @@ public boolean isSoftAssertionsEnabled() { return assertionMode == AssertionMode.SOFT_ASSERT; } - public void runDebuggeeProgram(String projectPath, int port) throws BallerinaTestException { + public void runDebuggeeProgram(Path projectPath, int port) throws BallerinaTestException { String msg = "Listening for transport dt_socket at address: " + port; LogLeecher clientLeecher = new LogLeecher(msg); balClient = new BMainInstance(balServer); diff --git a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/DAPClientConnector.java b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/DAPClientConnector.java index 31b23ca111c9..7d43e6583758 100644 --- a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/DAPClientConnector.java +++ b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/DAPClientConnector.java @@ -51,7 +51,7 @@ public class DAPClientConnector { private static final Logger LOGGER = LoggerFactory.getLogger(DAPClientConnector.class); - private final String balHome; + private final Path balHome; private final Path projectPath; private final Path entryFilePath; private final String host; @@ -75,12 +75,12 @@ public class DAPClientConnector { private static final String OFFLINE_CMD_OPTION = "--offline"; - public DAPClientConnector(String balHome, Path projectPath, Path entryFilePath, int port, + public DAPClientConnector(Path balHome, Path projectPath, Path entryFilePath, int port, boolean supportsRunInTerminalRequest) { this(balHome, projectPath, entryFilePath, "localhost", port, supportsRunInTerminalRequest); } - public DAPClientConnector(String balHome, Path projectPath, Path entryFilePath, String host, int port, + public DAPClientConnector(Path balHome, Path projectPath, Path entryFilePath, String host, int port, boolean supportsRunInTerminalRequest) { this.balHome = balHome; this.projectPath = projectPath; @@ -181,7 +181,7 @@ public void launchServer(DebugUtils.DebuggeeExecutionKind launchKind, Map processArgs = new ArrayList<>(); if (Utils.getOSName().toLowerCase(Locale.ENGLISH).contains("windows")) { processArgs.add("cmd.exe"); processArgs.add("/c"); - processArgs.add(Path.of(balHome, "bin", Constant.BALLERINA_SERVER_SCRIPT_NAME + ".bat").toString()); + processArgs.add(balHome.resolve("bin/" + Constant.BALLERINA_SERVER_SCRIPT_NAME + ".bat").toString()); } else { processArgs.add("bash"); - processArgs.add(Path.of(balHome, "bin", Constant.BALLERINA_SERVER_SCRIPT_NAME).toString()); + processArgs.add(balHome.resolve("bin/" + Constant.BALLERINA_SERVER_SCRIPT_NAME).toString()); } processArgs.add(DebugUtils.JBAL_DEBUG_CMD_NAME); diff --git a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/ProcessStreamConnectionProvider.java b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/ProcessStreamConnectionProvider.java index 20c59f394bef..00e27b4f3939 100644 --- a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/ProcessStreamConnectionProvider.java +++ b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/ProcessStreamConnectionProvider.java @@ -39,14 +39,14 @@ public class ProcessStreamConnectionProvider implements StreamConnectionProvider private final List commands; private final String workingDir; - private final String balHome; + private final Path balHome; private static final String ENV_JAVA_OPTS = "JAVA_OPTS"; private static final String ENV_DEBUGGER_TEST_MODE = "BAL_DEBUGGER_TEST"; private static final String JACOCO_AGENT_ARGS = " -javaagent:%s=destfile=%s "; private static final Logger LOG = LoggerFactory.getLogger(ProcessStreamConnectionProvider.class); - public ProcessStreamConnectionProvider(List commands, String workingDir, String balHome) { + public ProcessStreamConnectionProvider(List commands, String workingDir, Path balHome) { this.commands = commands; this.workingDir = workingDir; this.balHome = balHome; @@ -81,9 +81,9 @@ private ProcessBuilder createProcessBuilder() { * Injects jacoco agent args into the debug server VM environment. */ private void configureJacocoAgentArgs(Map envProperties) { - Path jacocoAgentPath = Path.of(balHome).resolve("bre").resolve("lib").resolve("jacocoagent.jar"); - Path destinationFile = Path.of(System.getProperty("user.dir")).resolve("build").resolve("jacoco") - .resolve("debugger-core-test.exec"); + Path jacocoAgentPath = balHome.resolve("bre/lib/jacocoagent.jar"); + Path destinationFile = Path.of(System.getProperty("user.dir")) + .resolve("build/jacoco/debugger-core-test.exec"); String agentArgs = String.format(JACOCO_AGENT_ARGS, jacocoAgentPath, destinationFile); String javaOpts = ""; diff --git a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/SocketStreamConnectionProvider.java b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/SocketStreamConnectionProvider.java index 5a73f58b444a..4510c8f5c346 100644 --- a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/SocketStreamConnectionProvider.java +++ b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/SocketStreamConnectionProvider.java @@ -27,6 +27,7 @@ import java.io.OutputStream; import java.net.Socket; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import java.util.List; import java.util.Objects; import java.util.concurrent.CompletableFuture; @@ -51,7 +52,7 @@ public class SocketStreamConnectionProvider extends ProcessStreamConnectionProvi private OutputStream outputStream; public SocketStreamConnectionProvider(List commands, String workingDir, String address, int port, - String balHome) { + Path balHome) { super(commands, workingDir, balHome); this.address = address; this.port = port; diff --git a/tests/jballerina-debugger-integration-test/src/test/java/org/ballerinalang/debugger/test/BaseTestCase.java b/tests/jballerina-debugger-integration-test/src/test/java/org/ballerinalang/debugger/test/BaseTestCase.java index 4fc6ad92dbdf..3a4d48f00c83 100644 --- a/tests/jballerina-debugger-integration-test/src/test/java/org/ballerinalang/debugger/test/BaseTestCase.java +++ b/tests/jballerina-debugger-integration-test/src/test/java/org/ballerinalang/debugger/test/BaseTestCase.java @@ -46,8 +46,8 @@ public abstract class BaseTestCase { @BeforeSuite(alwaysRun = true) public void initialize() throws BallerinaTestException, IOException { - Path projectResourcePath = Path.of("src", "test", "resources", "project-based-tests").toAbsolutePath(); - Path singleFileResourcePath = Path.of("src", "test", "resources", "single-file-tests").toAbsolutePath(); + Path projectResourcePath = Path.of("src/test/resources/project-based-tests").toAbsolutePath(); + Path singleFileResourcePath = Path.of("src/test/resources/single-file-tests").toAbsolutePath(); DebugTestRunner.initialize(projectResourcePath, singleFileResourcePath); } diff --git a/tests/jballerina-debugger-integration-test/src/test/java/org/ballerinalang/debugger/test/remote/BallerinaRunRemoteDebugTest.java b/tests/jballerina-debugger-integration-test/src/test/java/org/ballerinalang/debugger/test/remote/BallerinaRunRemoteDebugTest.java index 66139328a5a5..b1b12fa1069d 100644 --- a/tests/jballerina-debugger-integration-test/src/test/java/org/ballerinalang/debugger/test/remote/BallerinaRunRemoteDebugTest.java +++ b/tests/jballerina-debugger-integration-test/src/test/java/org/ballerinalang/debugger/test/remote/BallerinaRunRemoteDebugTest.java @@ -58,7 +58,7 @@ public void testSuspendOnBallerinaModuleRun() throws BallerinaTestException { String msg = REMOTE_DEBUG_LISTENING + port; LogLeecher clientLeecher = new LogLeecher(msg); balClient.debugMain("run", new String[]{"--debug", String.valueOf(port)}, null, null, - new LogLeecher[]{clientLeecher}, debugTestRunner.testProjectPath.toString(), 15); + new LogLeecher[]{clientLeecher}, debugTestRunner.testProjectPath, 15); clientLeecher.waitForText(20000); } @@ -69,7 +69,7 @@ public void testSuspendOnBallerinaFileRun() throws BallerinaTestException { LogLeecher clientLeecher = new LogLeecher(msg); balClient.debugMain("run", new String[]{"--debug", String.valueOf(port), debugTestRunner.testEntryFilePath .toString()}, null, null, new LogLeecher[]{clientLeecher}, - debugTestRunner.testProjectPath.toString(), 15); + debugTestRunner.testProjectPath, 15); clientLeecher.waitForText(20000); } @@ -90,7 +90,7 @@ public void testBalJarInDebugMode(String... debugOptions) throws BallerinaTestEx .toFile().getPath(); LogLeecher clientLeecher = new LogLeecher(executablePath); balClient.runMain("build", new String[0], null, null, new LogLeecher[]{clientLeecher}, - debugTestRunner.testProjectPath.toString()); + debugTestRunner.testProjectPath); clientLeecher.waitForText(20000); String port = debugOptions[0].contains("=") ? debugOptions[0].split("=")[1] : debugOptions[1]; @@ -99,7 +99,7 @@ public void testBalJarInDebugMode(String... debugOptions) throws BallerinaTestEx List debugOptionsList = new ArrayList<>(Arrays.asList(debugOptions)); debugOptionsList.add(executablePath); balClient.debugMain("run", debugOptionsList.toArray(new String[0]), null, null, new LogLeecher[]{clientLeecher}, - debugTestRunner.testProjectPath.toString(), 15); + debugTestRunner.testProjectPath, 15); clientLeecher.waitForText(20000); } diff --git a/tests/jballerina-debugger-integration-test/src/test/java/org/ballerinalang/debugger/test/remote/BallerinaTestRemoteDebugTest.java b/tests/jballerina-debugger-integration-test/src/test/java/org/ballerinalang/debugger/test/remote/BallerinaTestRemoteDebugTest.java index bdb209b6e85b..c84bdc4421a4 100644 --- a/tests/jballerina-debugger-integration-test/src/test/java/org/ballerinalang/debugger/test/remote/BallerinaTestRemoteDebugTest.java +++ b/tests/jballerina-debugger-integration-test/src/test/java/org/ballerinalang/debugger/test/remote/BallerinaTestRemoteDebugTest.java @@ -51,7 +51,7 @@ public void testSuspendOnBallerinaModuleTest() throws BallerinaTestException { String msg = "Listening for transport dt_socket at address: " + port; LogLeecher clientLeecher = new LogLeecher(msg); balClient.debugMain("test", new String[]{"--debug", String.valueOf(port)}, null, null, - new LogLeecher[]{clientLeecher}, debugTestRunner.testProjectPath.toString(), 15); + new LogLeecher[]{clientLeecher}, debugTestRunner.testProjectPath, 15); clientLeecher.waitForText(20000); } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/async/AsyncFunctionsTest.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/async/AsyncFunctionsTest.java index e51dd2ea1a7f..b270f32e1cd6 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/async/AsyncFunctionsTest.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/async/AsyncFunctionsTest.java @@ -31,26 +31,26 @@ */ public class AsyncFunctionsTest extends BaseTest { - private static final String testFileLocation = Path.of("src/test/resources/async").toAbsolutePath().toString(); + private static final Path testFileLocation = Path.of("src/test/resources/async"); private BMainInstance bMainInstance; @BeforeClass public void setup() throws BallerinaTestException { bMainInstance = new BMainInstance(balServer); - - String targetBala = Path.of("target/bala/testOrg-functionsLib-java21-0.1.0.bala").toString(); + + Path targetBala = Path.of("target/bala/testOrg-functionsLib-java21-0.1.0.bala"); // Build and push config Lib project. - LogLeecher buildLeecher = new LogLeecher(targetBala); + LogLeecher buildLeecher = new LogLeecher(targetBala.toString()); LogLeecher pushLeecher = new LogLeecher("Successfully pushed " + targetBala + " to 'local' repository."); LogLeecher runLeecher = new LogLeecher("Run the library package to fix code coverage"); - bMainInstance.runMain(testFileLocation + "/", "functionsLib", null, new String[]{}, null, null, + bMainInstance.runMain(testFileLocation, "functionsLib", null, new String[]{}, null, null, new LogLeecher[]{runLeecher}); runLeecher.waitForText(5000); bMainInstance.runMain("pack", new String[]{}, null, null, new LogLeecher[]{buildLeecher}, - testFileLocation + "/functionsLib"); + testFileLocation.resolve("functionsLib")); buildLeecher.waitForText(5000); bMainInstance.runMain("push", new String[]{"--repository=local"}, null, null, new LogLeecher[]{pushLeecher}, - testFileLocation + "/functionsLib"); + testFileLocation.resolve("functionsLib")); pushLeecher.waitForText(5000); } @@ -58,7 +58,7 @@ public void setup() throws BallerinaTestException { public void testRunFunctionsFromDifferentPackageAsynchronously() throws BallerinaTestException { String testsPassed = "Tests passed"; LogLeecher logLeecher = new LogLeecher(testsPassed); - bMainInstance.runMain(testFileLocation + "/", "asyncFunctionPackage", null, new String[]{}, null, null, + bMainInstance.runMain(testFileLocation, "asyncFunctionPackage", null, new String[]{}, null, null, new LogLeecher[]{logLeecher}); logLeecher.waitForText(5000); } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/bindgen/BindgenTestCase.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/bindgen/BindgenTestCase.java index 83eb44bc2bce..539b660c4e26 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/bindgen/BindgenTestCase.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/bindgen/BindgenTestCase.java @@ -72,7 +72,7 @@ public void bindgenTest() throws BallerinaTestException { String[] args = {"-mvn=org.yaml:snakeyaml:2.0", "-o=.", "org.yaml.snakeyaml.Yaml"}; try { balClient.runMain("bindgen", args, null, new String[]{}, - new LogLeecher[]{bindgenLeecher1, bindgenLeecher2}, tempProjectsDir.toString()); + new LogLeecher[]{bindgenLeecher1, bindgenLeecher2}, tempProjectsDir); throw new BallerinaTestException("Contains classes not generated."); } catch (BallerinaTestException e) { if (bindgenLeecher1.isTextFound()) { @@ -83,7 +83,7 @@ public void bindgenTest() throws BallerinaTestException { } balClient.runMain("build", new String[]{}, null, new String[]{}, - new LogLeecher[]{buildLeecher}, tempProjectsDir.toString()); + new LogLeecher[]{buildLeecher}, tempProjectsDir); buildLeecher.waitForText(5000); } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/configurables/ConfigurableTest.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/configurables/ConfigurableTest.java index 0243cddcca6a..1baddea245d5 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/configurables/ConfigurableTest.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/configurables/ConfigurableTest.java @@ -33,7 +33,9 @@ import java.util.Map; import static io.ballerina.cli.utils.OsUtils.isWindows; -import static io.ballerina.runtime.internal.configurable.providers.toml.TomlConstants.*; +import static io.ballerina.runtime.internal.configurable.providers.toml.TomlConstants.CONFIG_DATA_ENV_VARIABLE; +import static io.ballerina.runtime.internal.configurable.providers.toml.TomlConstants.CONFIG_FILES_ENV_VARIABLE; +import static io.ballerina.runtime.internal.configurable.providers.toml.TomlConstants.ENV_VAR_PREFIX; import static org.ballerinalang.test.context.LogLeecher.LeecherType.ERROR; /** @@ -41,8 +43,7 @@ */ public class ConfigurableTest extends BaseTest { - private static final String testFileLocation = Path.of("src/test/resources/configurables") - .toAbsolutePath().toString(); + private static final Path testFileLocation = Path.of("src/test/resources/configurables").toAbsolutePath(); private BMainInstance bMainInstance; private final String testsPassed = "Tests passed"; @@ -50,7 +51,7 @@ public class ConfigurableTest extends BaseTest { public void setup() throws BallerinaTestException { bMainInstance = new BMainInstance(balServer); // Build and push config Lib project. - bMainInstance.compilePackageAndPushToLocal(Path.of(testFileLocation, "configLibProject").toString(), + bMainInstance.compilePackageAndPushToLocal(testFileLocation.resolve("configLibProject"), "testOrg-configLib-java21-0.1.0"); } @@ -59,20 +60,21 @@ public void testConfigurableBalRun() throws BallerinaTestException { // bal run package with configurables LogLeecher logLeecher1 = new LogLeecher(testsPassed); bMainInstance.runMain("run", new String[]{"main"}, null, new String[]{}, - new LogLeecher[]{logLeecher1}, testFileLocation + "/configurableProject"); + new LogLeecher[]{logLeecher1}, testFileLocation.resolve("configurableProject")); logLeecher1.waitForText(5000); // bal run single bal file with configurables LogLeecher logLeecher2 = new LogLeecher(testsPassed); - bMainInstance.runMain("run", new String[]{testFileLocation + "/SingleBalFile/configTest.bal"}, null, - new String[]{}, new LogLeecher[]{logLeecher2}, testFileLocation + "/SingleBalFile"); + bMainInstance.runMain("run", + new String[]{testFileLocation.resolve("SingleBalFile/configTest.bal").toString()}, null, + new String[]{}, new LogLeecher[]{logLeecher2}, testFileLocation.resolve("SingleBalFile")); logLeecher2.waitForText(5000); } @Test public void testConfigurableVariablesWithCliArgs() throws BallerinaTestException { LogLeecher logLeecher = new LogLeecher(testsPassed); - bMainInstance.runMain(testFileLocation + "/configurableSimpleProject", "main", null, + bMainInstance.runMain(testFileLocation.resolve("configurableSimpleProject"), "main", null, new String[]{"-CintVar=42", "-CbyteVar=22", "-CstringVar=waru=na", "-CbooleanVar=true", "-CxmlVar=The Lost World", "-CtestOrg.main.floatVar=3.5", "-Cmain.decimalVar=24.87", "-Cmain.color=RED", "-Cmain.countryCode=Sri Lanka", @@ -96,13 +98,13 @@ public void testConfigurableVariablesWithEnvVars() throws BallerinaTestException Map.entry(ENV_VAR_PREFIX + "FILES", "pqr-1.toml"), Map.entry(ENV_VAR_PREFIX + "DATA", "intVar=bbb") ); - executeBalCommand("/configurableSimpleProject", "main", + executeBalCommand("configurableSimpleProject", "main", addEnvironmentVariables(envVariables)); } @Test public void testConfigurableWithJavaJarRun() throws BallerinaTestException { - executeBalCommand("/configurableProject", "main", null); + executeBalCommand("configurableProject", "main", null); } @Test @@ -110,7 +112,7 @@ public void testBallerinaTestAPIWithConfigurableVariables() throws BallerinaTest LogLeecher testLog1 = new LogLeecher("5 passing"); LogLeecher testLog2 = new LogLeecher("4 passing"); bMainInstance.runMain("test", new String[]{"configPkg"}, null, new String[]{}, - new LogLeecher[]{testLog1, testLog2}, testFileLocation + "/testProject"); + new LogLeecher[]{testLog1, testLog2}, testFileLocation.resolve("testProject")); testLog1.waitForText(5000); testLog2.waitForText(5000); @@ -120,8 +122,9 @@ public void testBallerinaTestAPIWithConfigurableVariables() throws BallerinaTest String errorLocationMsg = "\tat testOrg/configPkg:0.1.0(tests/main_test.bal:19)"; LogLeecher errorLog = new LogLeecher(errorMsg, ERROR); LogLeecher errorLocationLog = new LogLeecher(errorLocationMsg, ERROR); - bMainInstance.runMain("test", new String[]{"configPkg"}, null, new String[]{}, - new LogLeecher[]{errorLog, errorLocationLog}, testFileLocation + "/testErrorProject"); + bMainInstance.runMain("test", + new String[]{"configPkg"}, null, new String[]{}, + new LogLeecher[]{errorLog, errorLocationLog}, testFileLocation.resolve("testErrorProject")); errorLog.waitForText(5000); } @@ -130,7 +133,7 @@ public void testConfigurableModuleStructureWithTestAPI() throws BallerinaTestExc LogLeecher testLog1 = new LogLeecher("5 passing"); LogLeecher testLog2 = new LogLeecher("4 passing"); bMainInstance.runMain("test", new String[]{"configPkg"}, null, new String[]{}, - new LogLeecher[]{testLog1, testLog2}, testFileLocation + "/testModuleStructureProject"); + new LogLeecher[]{testLog1, testLog2}, testFileLocation.resolve("testModuleStructureProject")); testLog1.waitForText(5000); testLog2.waitForText(5000); } @@ -139,10 +142,10 @@ public void testConfigurableModuleStructureWithTestAPI() throws BallerinaTestExc public void testFileEnvVariableBasedConfigurable() throws BallerinaTestException { // test config file location through `BAL_CONFIG_FILES` env variable - String configFilePaths = Path.of(testFileLocation, "config_files", "Config-A.toml") + - File.pathSeparator + Path.of(testFileLocation, "config_files", "Config-B.toml"); + String configFilePaths = testFileLocation.resolve("config_files/Config-A.toml") + + File.pathSeparator + testFileLocation.resolve("config_files/Config-B.toml"); executeBalCommand("", "envVarPkg", - addEnvironmentVariables(Map.ofEntries(Map.entry(CONFIG_FILES_ENV_VARIABLE, configFilePaths)))); + addEnvironmentVariables(Map.of(CONFIG_FILES_ENV_VARIABLE, configFilePaths))); } @Test @@ -167,7 +170,7 @@ public void testDataEnvVariableBasedConfigurableNegative() throws BallerinaTestE String configData = "[envVarPkg] intVar = 42 floatVar = 3.5 stringVar = \"abc\" booleanVar = true " + "decimalVar = 24.87 intArr = [1,2,3] floatArr = [9.0, 5.6]"; bMainInstance.runMain(testFileLocation, "envVarPkg", null, new String[]{}, - addEnvironmentVariables(Map.ofEntries(Map.entry(CONFIG_DATA_ENV_VARIABLE, configData))), null, + addEnvironmentVariables(Map.of(CONFIG_DATA_ENV_VARIABLE, configData)), null, new LogLeecher[]{errorLeecher1, errorLeecher2, errorLeecher3, errorLeecher4, errorLeecher5, errorLeecher6, errorLeecher7, errorLeecher8, errorLeecher9, errorLeecher10, errorLeecher11, errorLeecher12}); @@ -200,50 +203,51 @@ public void testDataEnvVariableBasedConfigurableWithNewLine() throws BallerinaTe booleanArr = [true, false,false, true] decimalArr = [8.9, 4.5, 6.2]"""; executeBalCommand("", "envVarPkg", - addEnvironmentVariables(Map.ofEntries(Map.entry(CONFIG_DATA_ENV_VARIABLE, configData)))); + addEnvironmentVariables(Map.of(CONFIG_DATA_ENV_VARIABLE, configData))); configData = "[envVarPkg]\\nintVar = 42\\nfloatVar = 3.5\\nstringVar = \"abc\"\\nbooleanVar = true\\n" + "decimalVar = 24.87\\nintArr = [1,2,3]\\nfloatArr = [9.0, 5.6]\\n" + "stringArr = [\"red\", \"yellow\", \"green\"]\\nbooleanArr = [true, false,false, true]\\n" + "decimalArr = [8.9, 4.5, 6.2]"; executeBalCommand("", "envVarPkg", - addEnvironmentVariables(Map.ofEntries(Map.entry(CONFIG_DATA_ENV_VARIABLE, configData)))); + addEnvironmentVariables(Map.of(CONFIG_DATA_ENV_VARIABLE, configData))); configData = "[envVarPkg]\\n\\rintVar = 42\\n\\rfloatVar = 3.5\\n\\rstringVar = \"abc\"\\n\\r" + "booleanVar = true\\n\\rdecimalVar = 24.87\\n\\rintArr = [1,2,3]\\n\\r" + "floatArr = [9.0, 5.6]\\n\\rstringArr = [\"red\", \"yellow\", \"green\"]\\n\\r" + "booleanArr = [true, false,false, true]\\n\\rdecimalArr = [8.9, 4.5, 6.2]"; executeBalCommand("", "envVarPkg", - addEnvironmentVariables(Map.ofEntries(Map.entry(CONFIG_DATA_ENV_VARIABLE, configData)))); + addEnvironmentVariables(Map.of(CONFIG_DATA_ENV_VARIABLE, configData))); } @Test public void testConfigOverriding() throws BallerinaTestException { // Check multiple cases of TOML values getting overridden - String configFilePath1 = Path.of(testFileLocation, "config_files", "Config.toml").toString(); - String configFilePath2 = Path.of(testFileLocation, "config_files", "Config-override.toml").toString(); + String configFilePath1 = testFileLocation.resolve("config_files/Config.toml").toString(); + String configFilePath2 = testFileLocation.resolve("config_files/Config-override.toml").toString(); // test config file overriding another config file - Map envVarMap = Map.ofEntries( - Map.entry(CONFIG_FILES_ENV_VARIABLE, configFilePath1 + File.pathSeparator + configFilePath2)); + Map envVarMap = Map.of( + CONFIG_FILES_ENV_VARIABLE, configFilePath1 + File.pathSeparator + configFilePath2); executeBalCommand("", "envVarPkg", addEnvironmentVariables(envVarMap)); // test config file overriding config content - String configData = "[envVarPkg] " + - "booleanVar = false " + - "decimalVar = 12.34 " + - "floatVar = 23.1 " + - "intVar = 22 " + - "stringVar = \"this should get overridden\" " + - "booleanArr = [true, false, false, true] " + - "decimalArr = [9.1, 8.2, 7.3] " + - "floatArr = [1.9, 2.8, 3.7] " + - "intArr = [1, 9, 2, 8] " + - "stringArr = [\"this\", \"should\", \"get\", \"overridden\"]"; - envVarMap = Map.ofEntries( - Map.entry(CONFIG_FILES_ENV_VARIABLE, configFilePath1), - Map.entry(CONFIG_DATA_ENV_VARIABLE, configData)); + String configData = """ + [envVarPkg] + booleanVar = false + decimalVar = 12.34 + floatVar = 23.1 + intVar = 22 + stringVar = "this should get overridden" + booleanArr = [true, false, false, true] + decimalArr = [9.1, 8.2, 7.3] + floatArr = [1.9, 2.8, 3.7] + intArr = [1, 9, 2, 8] + stringArr = ["this", "should", "get", "overridden"]"""; + envVarMap = Map.of( + CONFIG_FILES_ENV_VARIABLE, configFilePath1, + CONFIG_DATA_ENV_VARIABLE, configData); executeBalCommand("", "envVarPkg", addEnvironmentVariables(envVarMap)); // test configuration using default path @@ -252,17 +256,17 @@ public void testConfigOverriding() throws BallerinaTestException { @Test public void testRecordValueWithModuleClash() throws BallerinaTestException { - executeBalCommand("/recordModuleProject", "main", null); + executeBalCommand("recordModuleProject", "main", null); } @Test() public void testConfigurableUnionTypes() throws BallerinaTestException { - executeBalCommand("/configUnionTypesProject", "configUnionTypes", null); + executeBalCommand("configUnionTypesProject", "configUnionTypes", null); } @Test public void testMultipleTomlModuleSections() throws BallerinaTestException { - executeBalCommand("/multipleTomlModuleSectionsProject", "test_module", null); + executeBalCommand("multipleTomlModuleSectionsProject", "test_module", null); } /** Negative test cases. */ @@ -291,7 +295,7 @@ public void testConfigurableVariablesWithInvalidCliArgs() throws BallerinaTestEx "=true", "-CxmlVar=123 envProperties) throws BallerinaTestException { LogLeecher logLeecher = new LogLeecher(testsPassed); bMainInstance.runMain( - Path.of(testFileLocation, projectPath).toString(), packageName, null, new String[]{}, envProperties, null, + testFileLocation.resolve(projectPath), packageName, null, new String[]{}, envProperties, null, new LogLeecher[]{logLeecher}); logLeecher.waitForText(5000); } @@ -380,7 +384,7 @@ private void executeBalCommand(String projectPath, String packageName, @Test(dataProvider = "structured-project-provider") public void testStructuredTypeConfigurable(String packageName, String configFile) throws BallerinaTestException { executeBalCommand("configStructuredTypesProject", packageName, - addEnvironmentVariables(Map.ofEntries(Map.entry(CONFIG_FILES_ENV_VARIABLE, configFile)))); + addEnvironmentVariables(Map.of(CONFIG_FILES_ENV_VARIABLE, configFile))); } @DataProvider(name = "structured-project-provider") @@ -418,7 +422,7 @@ public void testModuleAmbiguityWithModuleNameAsBallerina() throws BallerinaTestE "with an imported organization name. Please provide the module name as '[ballerina.ballerina]'", ERROR); bMainInstance.runMain("run", new String[]{}, null, new String[]{}, new LogLeecher[]{errorLog}, - Path.of(testFileLocation, "testAmbiguousCases", "moduleNamedBallerina").toString()); + testFileLocation.resolve("testAmbiguousCases/moduleNamedBallerina")); errorLog.waitForText(5000); } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/distinct/TypeIdViaDifferentVersionsTest.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/distinct/TypeIdViaDifferentVersionsTest.java index 44ab6b881870..d3f8373e1a8e 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/distinct/TypeIdViaDifferentVersionsTest.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/distinct/TypeIdViaDifferentVersionsTest.java @@ -35,23 +35,22 @@ */ public class TypeIdViaDifferentVersionsTest extends BaseTest { - private static final String testFileLocation = Path.of("src/test/resources/packaging/distinct") - .toAbsolutePath().toString(); + private static final Path testFileLocation = Path.of("src/test/resources/packaging/distinct"); private BMainInstance bMainInstance; @BeforeClass public void setup() throws BallerinaTestException { bMainInstance = new BMainInstance(balServer); // Build and push down stream packages. - compilePackageAndPushToLocal(Path.of(testFileLocation, "test_project_distinct_foo").toString(), + compilePackageAndPushToLocal(testFileLocation.resolve("test_project_distinct_foo"), "testorg-distinct_foo-any-1.0.0"); - compilePackageAndPushToLocal(Path.of(testFileLocation, "test_project_distinct_bar").toString(), + compilePackageAndPushToLocal(testFileLocation.resolve("test_project_distinct_bar"), "testorg-distinct_bar-any-1.0.0"); // Triggers caching the BIR for foo 1.0.0. buildPackage("baz"); } - private void compilePackageAndPushToLocal(String packagePath, String balaFileName) throws BallerinaTestException { + private void compilePackageAndPushToLocal(Path packagePath, String balaFileName) throws BallerinaTestException { String targetBala = Path.of("target/bala/" + balaFileName + ".bala").toString(); LogLeecher buildLeecher = new LogLeecher(targetBala); LogLeecher pushLeecher = new LogLeecher("Successfully pushed " + targetBala + " to 'local' repository."); @@ -65,7 +64,7 @@ private void compilePackageAndPushToLocal(String packagePath, String balaFileNam @Test public void testTypeIDsViaDifferentVersions() throws BallerinaTestException { - compilePackageAndPushToLocal(Path.of(testFileLocation, "test_project_distinct_foo_patch").toString(), + compilePackageAndPushToLocal(testFileLocation.resolve("test_project_distinct_foo_patch"), "testorg-distinct_foo-any-1.0.1"); buildPackage("qux"); @@ -75,7 +74,7 @@ private void buildPackage(String name) throws BallerinaTestException { LogLeecher buildLeecher = new LogLeecher( Path.of("target/bala/testorg-distinct_" + name + "-any-1.0.0.bala").toString()); bMainInstance.runMain("pack", new String[]{}, null, null, new LogLeecher[]{buildLeecher}, - Path.of(testFileLocation, "test_project_distinct_" + name).toString()); + testFileLocation.resolve("test_project_distinct_" + name)); buildLeecher.waitForText(5000); } } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/forwardreference/ForwardReferenceListenerVarTest.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/forwardreference/ForwardReferenceListenerVarTest.java index 0df948d6d1f9..3502e40de143 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/forwardreference/ForwardReferenceListenerVarTest.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/forwardreference/ForwardReferenceListenerVarTest.java @@ -43,8 +43,8 @@ public class ForwardReferenceListenerVarTest extends BaseTest { @BeforeClass private void setup() throws Exception { serverInstance = new BServerInstance(balServer); - String balFile = Path.of("src/test/resources/forwardreference/forward_ref_service.bal") - .toAbsolutePath().toString(); + Path balFile = Path.of("src/test/resources/forwardreference/forward_ref_service.bal") + .toAbsolutePath(); serverInstance.startServer(balFile, new int[SERVICE_PORT]); } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/identifier/IdentifierLiteralTest.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/identifier/IdentifierLiteralTest.java index 8f1ba7e1769d..e6596e9ea4da 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/identifier/IdentifierLiteralTest.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/identifier/IdentifierLiteralTest.java @@ -25,7 +25,6 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import java.io.File; import java.nio.file.Path; import java.util.HashMap; @@ -35,24 +34,23 @@ * @since 2.0.0 */ public class IdentifierLiteralTest extends BaseTest { - - private static final String testFileLocation = Path.of("src/test/resources/identifier") - .toAbsolutePath().toString(); + + private static final Path testFileLocation = Path.of("src/test/resources/identifier"); private BMainInstance bMainInstance; @BeforeClass public void setup() throws BallerinaTestException { bMainInstance = new BMainInstance(balServer); - bMainInstance.compilePackageAndPushToLocal(Path.of(testFileLocation, "testProject").toString(), + bMainInstance.compilePackageAndPushToLocal(testFileLocation.resolve("testProject"), "a_b-foo-any-0.1.0"); } @Test(description = "Test clashes in module names contain '.' and '_'") public void testModuleIdentifierClash() throws BallerinaTestException { - Path projectPath = Path.of(testFileLocation, "ModuleNameClashProject").toAbsolutePath(); + Path projectPath = testFileLocation.resolve("ModuleNameClashProject"); LogLeecher runLeecher = new LogLeecher("1 passing"); bMainInstance.runMain("test", new String[0], new HashMap<>(), new String[0], - new LogLeecher[]{runLeecher}, projectPath.toString()); + new LogLeecher[]{runLeecher}, projectPath); runLeecher.waitForText(5000); } @@ -60,7 +58,7 @@ public void testModuleIdentifierClash() throws BallerinaTestException { public void testPackageIDClash() throws BallerinaTestException { LogLeecher runLeecher = new LogLeecher("Tests passed"); bMainInstance.runMain("run", new String[0], null, new String[0], new LogLeecher[]{runLeecher}, - testFileLocation + File.separator + "PackageNameClashProject"); + testFileLocation.resolve("PackageNameClashProject")); runLeecher.waitForText(5000); } @@ -71,7 +69,7 @@ public void testUserDefinedIdentifierClash() throws BallerinaTestException { // Run and see output String msg = "Tests passed"; LogLeecher runLeecher = new LogLeecher(msg); - String runCommandPath = testFileLocation + File.separator + testBalFile; + String runCommandPath = testFileLocation.resolve(testBalFile).toAbsolutePath().toString(); bMainInstance.runMain("run", new String[]{runCommandPath}, new HashMap<>(), new String[0], new LogLeecher[]{runLeecher}, testFileLocation); runLeecher.waitForText(5000); @@ -81,12 +79,12 @@ public void testUserDefinedIdentifierClash() throws BallerinaTestException { public void testResourceFunctionCall() throws BallerinaTestException { LogLeecher testLeecher = new LogLeecher("1 passing"); bMainInstance.runMain("test", new String[0], null, new String[0], new LogLeecher[]{testLeecher}, - testFileLocation + File.separator + "ResourceCallProject"); + testFileLocation.resolve("ResourceCallProject")); testLeecher.waitForText(5000); LogLeecher runLeecher = new LogLeecher("Tests passed"); bMainInstance.runMain("run", new String[0], null, new String[0], new LogLeecher[]{runLeecher}, - testFileLocation + File.separator + "ResourceCallProject"); + testFileLocation.resolve("ResourceCallProject")); runLeecher.waitForText(5000); } } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/isolated/IsolatedInferenceWithTestsTest.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/isolated/IsolatedInferenceWithTestsTest.java index cbd94bea2fa4..65a0043e15fb 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/isolated/IsolatedInferenceWithTestsTest.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/isolated/IsolatedInferenceWithTestsTest.java @@ -36,8 +36,7 @@ */ public class IsolatedInferenceWithTestsTest extends BaseTest { - private static final String testFileLocation = - Path.of("src/test/resources/isolated-inference-projects").toAbsolutePath().toString(); + private static final Path testFileLocation = Path.of("src/test/resources/isolated-inference-projects"); private BMainInstance bMainInstance; @BeforeClass @@ -65,7 +64,7 @@ private void testPkg(String pkg, int testCount) throws BallerinaTestException { LogLeecher failedLeecher = new LogLeecher("0 failing"); bMainInstance.runMain("test", new String[0], null, null, new LogLeecher[]{passedLeecher, failedLeecher}, - Path.of(testFileLocation, pkg).toString()); + testFileLocation.resolve(pkg)); passedLeecher.waitForText(5000); failedLeecher.waitForText(5000); } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/MavenTestCase.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/MavenTestCase.java index c077754486c6..6cb58617b717 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/MavenTestCase.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/MavenTestCase.java @@ -66,14 +66,14 @@ public void setUp() throws IOException { public void mavenResolvingTest() throws BallerinaTestException, IOException { String[] args = {"-mvn=org.yaml:snakeyaml:2.0", "org.yaml.snakeyaml.Yaml"}; balClient.runMain("bindgen", args, envVariables, new String[]{}, - new LogLeecher[]{}, projectPath.toString()); + new LogLeecher[]{}, projectPath); // delete the platform lib directory deleteFiles(this.projectPath.resolve("target").resolve("platform-libs")); String mvnBuildMsg = Path.of("target/bin/tests.jar").toString(); LogLeecher mvnBuildLeecher = new LogLeecher(mvnBuildMsg); balClient.runMain("build", new String[]{}, envVariables, new String[]{}, - new LogLeecher[]{mvnBuildLeecher}, projectPath.toString()); + new LogLeecher[]{mvnBuildLeecher}, projectPath); mvnBuildLeecher.waitForText(5000); // delete the platform lib directory deleteFiles(this.projectPath.resolve("target").resolve("platform-libs")); @@ -81,7 +81,7 @@ public void mavenResolvingTest() throws BallerinaTestException, IOException { Path tempFile = projectPath.resolve("temp.txt"); Assert.assertFalse(tempFile.toFile().exists()); balClient.runMain("run", new String[]{"--", tempFile.toString()}, envVariables, new String[]{}, - new LogLeecher[]{}, projectPath.toString()); + new LogLeecher[]{}, projectPath); Assert.assertTrue(tempFile.toFile().exists()); Files.delete(tempFile); } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/ModuleExecutionFlowTests.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/ModuleExecutionFlowTests.java index bc75a006a146..1c62a6b44350 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/ModuleExecutionFlowTests.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/ModuleExecutionFlowTests.java @@ -50,7 +50,7 @@ public void testModuleMainExecutionOrder() throws BallerinaTestException { public void testImportModuleHasListener() throws BallerinaTestException { Path projectPath = Path.of("src/test/resources/packaging/proj2"); BServerInstance serverInstance = new BServerInstance(balServer); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); LogLeecher errLeecherA = new LogLeecher("Stopped module A", LogLeecher.LeecherType.ERROR); serverInstance.addErrorLogLeecher(errLeecherA); @@ -61,7 +61,7 @@ public void testImportModuleHasListener() throws BallerinaTestException { private void runAndAssert(Path projectPath) throws BallerinaTestException { BServerInstance serverInstance = new BServerInstance(balServer); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); LogLeecher errLeecherA = new LogLeecher("Stopped module A", LogLeecher.LeecherType.ERROR); LogLeecher errLeecherB = new LogLeecher("Stopped module B", LogLeecher.LeecherType.ERROR); @@ -80,7 +80,7 @@ private void runAndAssert(Path projectPath) throws BallerinaTestException { public void testModuleDependencyChainForInit() throws BallerinaTestException, InterruptedException { Path projectPath = Path.of("src/test/resources/packaging/module_invocation_project"); BServerInstance serverInstance = new BServerInstance(balServer); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), "module_invocation_project", null, null, + serverInstance.startServer(projectPath, "module_invocation_project", null, null, null); LogLeecher errLeecherCurrent = new LogLeecher("Stopped module current", LogLeecher.LeecherType.ERROR); LogLeecher errLeecherDep1 = new LogLeecher("Stopped module second dependent", LogLeecher.LeecherType.ERROR); @@ -120,7 +120,7 @@ public void testMultipleDynamicListenersWithAsyncCall() throws BallerinaTestExce private void runAssertDynamicListener(Path projectPath) throws BallerinaTestException { BServerInstance serverInstance = new BServerInstance(balServer); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); LogLeecher errLeecherA = new LogLeecher("Stopped module A", LogLeecher.LeecherType.ERROR); serverInstance.addErrorLogLeecher(errLeecherA); @@ -133,7 +133,7 @@ private void runAssertDynamicListener(Path projectPath) throws BallerinaTestExce public void testStopHandlerExecution() throws BallerinaTestException { Path projectPath = Path.of("src/test/resources/packaging/stop_handler_execution"); BServerInstance serverInstance = new BServerInstance(balServer); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); LogLeecher infoLeecher1 = new LogLeecher("Stopped stopHandlerFunc3"); LogLeecher infoLeecher2 = new LogLeecher("Stopped stopHandlerFunc2"); @@ -155,7 +155,7 @@ public void testModuleShutdownRegisteredWithStopHandlers() throws BallerinaTestE Path projectPath = Path.of("src/test/resources/packaging/module_shutdown_order_project"); BServerInstance serverInstance = new BServerInstance(balServer); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); LogLeecher logLeecherA = new LogLeecher("Stopped current module"); LogLeecher logLeecherB = new LogLeecher("Stopped moduleB"); @@ -178,7 +178,7 @@ public void testStopHandlerExecutionOrder() throws BallerinaTestException { Path projectPath = Path.of("src/test/resources/packaging/stop_handler_execution_order_test"); BServerInstance serverInstance = new BServerInstance(balServer); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); LogLeecher logLeecherA = new LogLeecher("StopHandlerFunc3 in current module"); LogLeecher logLeecherB = new LogLeecher("stopHandlerFunc3 in moduleA"); @@ -213,7 +213,7 @@ public void testListenerStopHandlerShutdownOrderWithErrorReturn() throws Balleri Path projectPath = Path.of("src/test/resources/packaging/listener_stophandler_shutdown_order_project"); BServerInstance serverInstance = new BServerInstance(balServer); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); LogLeecher logLeecherA = new LogLeecher("Calling stop for static listener"); LogLeecher logLeecherB = new LogLeecher("error: error during the gracefulStop call of static listener", @@ -258,7 +258,7 @@ public void testListenerStopHandlerAsyncCall() throws BallerinaTestException { serverInstance.addLogLeecher(logLeecherC); serverInstance.addLogLeecher(logLeecherD); serverInstance.addLogLeecher(logLeecherE); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); serverInstance.shutdownServer(); logLeecherA.waitForText(TIMEOUT); @@ -273,7 +273,7 @@ public void testListenerStopHandlerAsyncCall() throws BallerinaTestException { public void testStopHandlerAsyncCall() throws BallerinaTestException { Path projectPath = Path.of("src/test/resources/packaging/stop_handler_async_call_test"); BServerInstance serverInstance = new BServerInstance(balServer); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); LogLeecher infoLeecher1 = new LogLeecher("Stopped stopHandlerFunc3"); LogLeecher infoLeecher2 = new LogLeecher("Stopped stopHandlerFunc4"); @@ -305,7 +305,7 @@ public void testModuleExecuteFunctionOrder() throws BallerinaTestException { serverInstance.addLogLeecher(moduleInitLeecher); serverInstance.addLogLeecher(mainLeecher); serverInstance.addLogLeecher(listenerStartLeecher); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); serverInstance.shutdownServer(); @@ -332,7 +332,7 @@ public void testModuleInitWithBusyWorkerAndListener() throws BallerinaTestExcept serverInstance.addLogLeecher(mainLeecher); serverInstance.addLogLeecher(listenerStartLeecher); serverInstance.addLogLeecher(workerLeecher); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); serverInstance.shutdownServer(); @@ -363,7 +363,7 @@ public void testModuleInitWithBusyWorkerAndDynamicListener() throws BallerinaTes serverInstance.addLogLeecher(listenerInitLeecher); serverInstance.addLogLeecher(listenerStartLeecher); serverInstance.addLogLeecher(listenerStopLeecher); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); serverInstance.shutdownServer(); moduleInitLeecher.waitForText(TIMEOUT); @@ -387,7 +387,7 @@ public void testModuleInitWithBusyWorkerTerminating() throws BallerinaTestExcept serverInstance.addLogLeecher(moduleInitLeecher); serverInstance.addLogLeecher(mainLeecher); serverInstance.addLogLeecher(workerLeecher); - serverInstance.startServer(projectPath.toAbsolutePath().toString(), projectPath.getFileName().toString(), null, + serverInstance.startServer(projectPath, projectPath.getFileName().toString(), null, null, null); serverInstance.shutdownServer(); moduleInitLeecher.waitForText(TIMEOUT); diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/MultipleModuleVersionTests.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/MultipleModuleVersionTests.java index d1d53bdd3f9b..4b9e9ca1341f 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/MultipleModuleVersionTests.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/MultipleModuleVersionTests.java @@ -33,20 +33,19 @@ */ public class MultipleModuleVersionTests extends BaseTest { - private static final String testFileLocation = Path.of("src/test/resources/packaging/versions") - .toAbsolutePath().toString(); + private static final Path testFileLocation = Path.of("src/test/resources/packaging/versions"); private BMainInstance bMainInstance; @BeforeClass public void setup() throws BallerinaTestException { bMainInstance = new BMainInstance(balServer); // Build and push down stream packages. - compilePackageAndPushToLocal(Path.of(testFileLocation, "http1.1.1").toString(), "waruna-http-any-1.1.1"); - compilePackageAndPushToLocal(Path.of(testFileLocation, "http1.1.2").toString(), "waruna-http-any-1.1.2"); - compilePackageAndPushToLocal(Path.of(testFileLocation, "websub").toString(), "waruna-websub-any-1.0.1"); + compilePackageAndPushToLocal(testFileLocation.resolve("http1.1.1"), "waruna-http-any-1.1.1"); + compilePackageAndPushToLocal(testFileLocation.resolve("http1.1.2"), "waruna-http-any-1.1.2"); + compilePackageAndPushToLocal(testFileLocation.resolve("websub"), "waruna-websub-any-1.0.1"); } - private void compilePackageAndPushToLocal(String packagePath, String balaFileName) throws BallerinaTestException { + private void compilePackageAndPushToLocal(Path packagePath, String balaFileName) throws BallerinaTestException { String targetBala = Path.of("target/bala/" + balaFileName + ".bala").toString(); LogLeecher buildLeecher = new LogLeecher(targetBala); LogLeecher pushLeecher = new LogLeecher("Successfully pushed " + targetBala + " to 'local' repository."); @@ -71,7 +70,7 @@ public void testUsageOfNewPackageVersion() throws BallerinaTestException { private void executeBalCommand(String packageName) throws BallerinaTestException { String testsPassed = "Tests passed"; LogLeecher logLeecher = new LogLeecher(testsPassed); - bMainInstance.runMain(testFileLocation + "/", packageName, null, new String[]{}, null, null, + bMainInstance.runMain(testFileLocation, packageName, null, new String[]{}, null, null, new LogLeecher[]{logLeecher}); logLeecher.waitForText(5000); } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/profiler/ProfilerTest.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/profiler/ProfilerTest.java index 1d1d23a362ff..f978a0f6466b 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/profiler/ProfilerTest.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/profiler/ProfilerTest.java @@ -27,7 +27,6 @@ import org.testng.annotations.Test; import org.wso2.ballerinalang.util.Lists; -import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.util.HashMap; @@ -41,7 +40,7 @@ * @since 2201.8.0 */ public class ProfilerTest extends BaseTest { - private static final String testFileLocation = Path.of("src/test/resources/profiler").toAbsolutePath().toString(); + private static final Path testFileLocation = Path.of("src/test/resources/profiler"); private final String outputFile = "ProfilerReport.html"; private BMainInstance bMainInstance; public static final String BALLERINA_HOME = "ballerina.home"; @@ -53,13 +52,13 @@ public void setup() { @Test public void testProfilerExecutionWithBalPackage() throws BallerinaTestException { - String packageName = "projectForProfile" + File.separator + "package_a"; - String sourceRoot = testFileLocation + File.separator; + Path packageName = Path.of("projectForProfile/package_a"); + Path sourceRoot = testFileLocation; Map envProperties = new HashMap<>(); - String htmlFilePath = Path.of(sourceRoot, packageName, "target", "profiler", outputFile).toString(); + Path htmlFilePath = sourceRoot.resolve(packageName).resolve("target/profiler/" + outputFile); List leechers = getProfilerLogLeechers(htmlFilePath); leechers.add(new LogLeecher("Is the array sorted? true")); - bMainInstance.runMain("profile", new String[]{packageName}, envProperties, null, + bMainInstance.runMain("profile", new String[]{packageName.toString()}, envProperties, null, leechers.toArray(new LogLeecher[0]), sourceRoot); for (LogLeecher leecher : leechers) { leecher.waitForText(5000); @@ -68,11 +67,10 @@ public void testProfilerExecutionWithBalPackage() throws BallerinaTestException @Test public void testProfilerExecutionWithConfigurableVars() throws BallerinaTestException { - String packageName = "projectForProfile" + File.separator + "package_b"; - String sourceRoot = testFileLocation + File.separator + packageName; + Path packageName = Path.of("projectForProfile/package_b"); + Path sourceRoot = testFileLocation.resolve(packageName); Map envProperties = new HashMap<>(); - List leechers = getProfilerLogLeechers(packageName + File.separator + "target" + - File.separator + "profiler" + File.separator + outputFile); + List leechers = getProfilerLogLeechers(packageName.resolve("target/profiler/" + outputFile)); leechers.add(new LogLeecher("Tests passed")); bMainInstance.runMain("profile", new String[]{}, envProperties, null, leechers.toArray(new LogLeecher[0]), sourceRoot); @@ -81,7 +79,7 @@ public void testProfilerExecutionWithConfigurableVars() throws BallerinaTestExce } } - private List getProfilerLogLeechers(String htmlFilePath) { + private List getProfilerLogLeechers(Path htmlFilePath) { return Lists.of( new LogLeecher("[1/6] Initializing..."), new LogLeecher("[2/6] Copying executable..."), @@ -93,18 +91,17 @@ private List getProfilerLogLeechers(String htmlFilePath) { new LogLeecher("[6/6] Generating output..."), new LogLeecher(" Execution time: [1-2]?[0-9] seconds ", true, LogLeecher.LeecherType.INFO), new LogLeecher(" Output: "), - new LogLeecher(htmlFilePath)); + new LogLeecher(htmlFilePath.toString())); } @Test public void testProfilerExecutionWithSingleBalFile() throws BallerinaTestException { - String sourceRoot = testFileLocation + File.separator; String fileName = "profiler_single_file.bal"; Map envProperties = new HashMap<>(); envProperties.put(BALLERINA_HOME, bMainInstance.getBalServerHome()); - List leechers = getProfilerLogLeechers(sourceRoot + "profiler" + File.separator + outputFile); + List leechers = getProfilerLogLeechers(testFileLocation.resolve("profiler/" + outputFile)); bMainInstance.runMain("profile", new String[]{fileName}, envProperties, - null, leechers.toArray(new LogLeecher[0]), sourceRoot); + null, leechers.toArray(new LogLeecher[0]), testFileLocation); for (LogLeecher leecher : leechers) { leecher.waitForText(5000); } @@ -112,8 +109,7 @@ public void testProfilerExecutionWithSingleBalFile() throws BallerinaTestExcepti @Test public void testProfilerExecutionWithKillSignal() throws BallerinaTestException { - String sourceRoot = testFileLocation + File.separator; - String packageName = "serviceProjectForProfile" + File.separator + "package_a"; + Path packageName = Path.of("serviceProjectForProfile/package_a"); Map envProperties = new HashMap<>(); bMainInstance.addJavaAgents(envProperties); LogLeecher[] beforeExecleechers = new LogLeecher[]{new LogLeecher("[1/6] Initializing..."), @@ -127,8 +123,9 @@ public void testProfilerExecutionWithKillSignal() throws BallerinaTestException new LogLeecher("[6/6] Generating output..."), new LogLeecher(" Execution time:"), new LogLeecher(" Output: ")}; - Process process = bMainInstance.runCommandAndGetProcess("profile", new String[]{packageName}, - envProperties, sourceRoot); + Process process = bMainInstance.runCommandAndGetProcess("profile", + new String[]{packageName.toString()}, + envProperties, testFileLocation); ServerLogReader serverInfoLogReader = new ServerLogReader("inputStream", process.getInputStream()); addLogLeechers(beforeExecleechers, serverInfoLogReader); try { diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/readonly/ReadOnlyIntersectionViaMultipleModulesTest.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/readonly/ReadOnlyIntersectionViaMultipleModulesTest.java index 62cdc9b8df98..2fcf829657d6 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/readonly/ReadOnlyIntersectionViaMultipleModulesTest.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/readonly/ReadOnlyIntersectionViaMultipleModulesTest.java @@ -35,23 +35,22 @@ */ public class ReadOnlyIntersectionViaMultipleModulesTest extends BaseTest { - private static final String testFileLocation = Path.of("src/test/resources/packaging/readonly/one") - .toAbsolutePath().toString(); + private static final Path testFileLocation = Path.of("src/test/resources/packaging/readonly/one"); private BMainInstance bMainInstance; @BeforeClass public void setup() throws BallerinaTestException { bMainInstance = new BMainInstance(balServer); // Build and push down stream packages. - compilePackageAndPushToLocal(Path.of(testFileLocation, "test_project_immutable_foo").toString(), + compilePackageAndPushToLocal(testFileLocation.resolve("test_project_immutable_foo"), "testorg-selectively_immutable_foo-any-1.0.0"); - compilePackageAndPushToLocal(Path.of(testFileLocation, "test_project_immutable_bar").toString(), + compilePackageAndPushToLocal(testFileLocation.resolve("test_project_immutable_bar"), "testorg-selectively_immutable_bar-any-1.0.0"); - compilePackageAndPushToLocal(Path.of(testFileLocation, "test_project_immutable_baz").toString(), + compilePackageAndPushToLocal(testFileLocation.resolve("test_project_immutable_baz"), "testorg-selectively_immutable_baz-any-1.0.0"); } - private void compilePackageAndPushToLocal(String packagePath, String balaFileName) throws BallerinaTestException { + private void compilePackageAndPushToLocal(Path packagePath, String balaFileName) throws BallerinaTestException { String targetBala = Path.of("target/bala/" + balaFileName + ".bala").toString(); LogLeecher buildLeecher = new LogLeecher(targetBala); LogLeecher pushLeecher = new LogLeecher("Successfully pushed " + targetBala + " to 'local' repository."); @@ -74,7 +73,7 @@ private void buildQux() throws BallerinaTestException { LogLeecher buildLeecher = new LogLeecher( Path.of("target/bala/testorg-selectively_immutable_qux-any-1.0.0.bala").toString()); bMainInstance.runMain("pack", new String[]{}, null, null, new LogLeecher[]{buildLeecher}, - Path.of(testFileLocation, "test_project_immutable_qux").toString()); + testFileLocation.resolve("test_project_immutable_qux")); buildLeecher.waitForText(5000); } } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/readonly/ReadOnlyIntersectionViaMultipleModulesTest2.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/readonly/ReadOnlyIntersectionViaMultipleModulesTest2.java index 8b99345845d7..4f414511f2e9 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/readonly/ReadOnlyIntersectionViaMultipleModulesTest2.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/readonly/ReadOnlyIntersectionViaMultipleModulesTest2.java @@ -35,23 +35,22 @@ */ public class ReadOnlyIntersectionViaMultipleModulesTest2 extends BaseTest { - private static final String testFileLocation = Path.of("src/test/resources/packaging/readonly/two") - .toAbsolutePath().toString(); + private static final Path testFileLocation = Path.of("src/test/resources/packaging/readonly/two"); private BMainInstance bMainInstance; @BeforeClass public void setup() throws BallerinaTestException { bMainInstance = new BMainInstance(balServer); // Build and push down stream packages. - compilePackageAndPushToLocal(Path.of(testFileLocation, "test_project_immutable_foo").toString(), + compilePackageAndPushToLocal(testFileLocation.resolve("test_project_immutable_foo"), "testorg-selectively_immutable_foo2-any-1.0.0"); - compilePackageAndPushToLocal(Path.of(testFileLocation, "test_project_immutable_bar").toString(), + compilePackageAndPushToLocal(testFileLocation.resolve("test_project_immutable_bar"), "testorg-selectively_immutable_bar2-any-1.0.0"); - compilePackageAndPushToLocal(Path.of(testFileLocation, "test_project_immutable_baz").toString(), + compilePackageAndPushToLocal(testFileLocation.resolve("test_project_immutable_baz"), "testorg-selectively_immutable_baz2-any-1.0.0"); } - private void compilePackageAndPushToLocal(String packagePath, String balaFileName) throws BallerinaTestException { + private void compilePackageAndPushToLocal(Path packagePath, String balaFileName) throws BallerinaTestException { String targetBala = Path.of("target/bala/" + balaFileName + ".bala").toString(); LogLeecher buildLeecher = new LogLeecher(targetBala); LogLeecher pushLeecher = new LogLeecher("Successfully pushed " + targetBala + " to 'local' repository."); @@ -74,7 +73,7 @@ private void buildQux() throws BallerinaTestException { LogLeecher buildLeecher = new LogLeecher( Path.of("target/bala/testorg-selectively_immutable_qux2-any-1.0.0.bala").toString()); bMainInstance.runMain("pack", new String[]{}, null, null, new LogLeecher[]{buildLeecher}, - Path.of(testFileLocation, "test_project_immutable_qux").toString()); + testFileLocation.resolve("test_project_immutable_qux")); buildLeecher.waitForText(5000); } } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/readonly/ReadOnlyIntersectionViaMultipleModulesTest3.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/readonly/ReadOnlyIntersectionViaMultipleModulesTest3.java index dd2d66ec0724..1d9cd319acc9 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/readonly/ReadOnlyIntersectionViaMultipleModulesTest3.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/readonly/ReadOnlyIntersectionViaMultipleModulesTest3.java @@ -35,23 +35,22 @@ */ public class ReadOnlyIntersectionViaMultipleModulesTest3 extends BaseTest { - private static final String testFileLocation = Path.of("src/test/resources/packaging/readonly/three") - .toAbsolutePath().toString(); + private static final Path testFileLocation = Path.of("src/test/resources/packaging/readonly/three"); private BMainInstance bMainInstance; @BeforeClass public void setup() throws BallerinaTestException { bMainInstance = new BMainInstance(balServer); // Build and push down stream packages. - compilePackageAndPushToLocal(Path.of(testFileLocation, "test_project_immutable_foo").toString(), + compilePackageAndPushToLocal(testFileLocation.resolve("test_project_immutable_foo"), "testorg-selectively_immutable_foo3-any-1.0.0"); - compilePackageAndPushToLocal(Path.of(testFileLocation, "test_project_immutable_bar").toString(), + compilePackageAndPushToLocal(testFileLocation.resolve("test_project_immutable_bar"), "testorg-selectively_immutable_bar3-any-1.0.0"); - compilePackageAndPushToLocal(Path.of(testFileLocation, "test_project_immutable_baz").toString(), + compilePackageAndPushToLocal(testFileLocation.resolve("test_project_immutable_baz"), "testorg-selectively_immutable_baz3-any-1.0.0"); } - private void compilePackageAndPushToLocal(String packagePath, String balaFileName) throws BallerinaTestException { + private void compilePackageAndPushToLocal(Path packagePath, String balaFileName) throws BallerinaTestException { String targetBala = Path.of("target/bala/" + balaFileName + ".bala").toString(); LogLeecher buildLeecher = new LogLeecher(targetBala); LogLeecher pushLeecher = new LogLeecher("Successfully pushed " + targetBala + " to 'local' repository."); @@ -74,7 +73,7 @@ private void buildQux() throws BallerinaTestException { LogLeecher buildLeecher = new LogLeecher( Path.of("target/bala/testorg-selectively_immutable_qux3-any-1.0.0.bala").toString()); bMainInstance.runMain("pack", new String[]{}, null, null, new LogLeecher[]{buildLeecher}, - Path.of(testFileLocation, "test_project_immutable_qux").toString()); + testFileLocation.resolve("test_project_immutable_qux")); buildLeecher.waitForText(5000); } } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/run/BalRunFunctionNegativeTestCase.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/run/BalRunFunctionNegativeTestCase.java index eb3478c2c0ed..cf004877c947 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/run/BalRunFunctionNegativeTestCase.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/run/BalRunFunctionNegativeTestCase.java @@ -55,7 +55,7 @@ public void testErrorPanicInMain() throws BallerinaTestException { private void executeTest(String message, String fileName, String... args) throws BallerinaTestException { LogLeecher errLogLeecher = new LogLeecher(message, LeecherType.ERROR); - String balFile = Path.of("src/test/resources/run/file", fileName).toAbsolutePath().toString(); + Path balFile = Path.of("src/test/resources/run/file", fileName); BMainInstance bMainInstance = new BMainInstance(balServer); bMainInstance.runMain(balFile, new String[0], args, new LogLeecher[]{errLogLeecher}); errLogLeecher.waitForText(10000); diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/run/BalRunFunctionPositiveTestCase.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/run/BalRunFunctionPositiveTestCase.java index 8cf0c640aaa6..09d92ee5ca20 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/run/BalRunFunctionPositiveTestCase.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/run/BalRunFunctionPositiveTestCase.java @@ -51,7 +51,7 @@ public void testMultipleParam() throws BallerinaTestException { private void executeTest(String[] args, String expected) throws BallerinaTestException { BMainInstance bMainInstance = new BMainInstance(balServer); String output = bMainInstance.runMainAndReadStdOut("run", args, - Path.of("src/test/resources/run/file").toString()); + Path.of("src/test/resources/run/file")); Assert.assertTrue(output.stripTrailing().endsWith(expected.stripTrailing()), output); } } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/run/BasicJavaJarRunTestCase.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/run/BasicJavaJarRunTestCase.java index 1c534e833882..d1e22f9890c1 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/run/BasicJavaJarRunTestCase.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/run/BasicJavaJarRunTestCase.java @@ -48,7 +48,7 @@ public void testMultipleParam() throws BallerinaTestException { private void executeTest(String serverResponse, String fileName, String... args) throws BallerinaTestException { BMainInstance ballerinaClient = new BMainInstance(balServer); - String balFile = Path.of("src/test/resources/run/file", fileName).toAbsolutePath().toString(); + Path balFile = Path.of("src/test/resources/run/file", fileName); LogLeecher clientLeecher = new LogLeecher(serverResponse); ballerinaClient.runMain(balFile, null, args, new LogLeecher[]{clientLeecher}); clientLeecher.waitForText(10000); diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java index 4375d8259604..3c4d84489d96 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java @@ -42,9 +42,8 @@ * @since 2201.9.0 */ public class RuntimeAPITest extends BaseTest { - - private static final String testFileLocation = Path.of("src/test/resources/runtime.api") - .toAbsolutePath().toString(); + + private static final Path testFileLocation = Path.of("src/test/resources/runtime.api").toAbsolutePath(); private static final Path javaSrcLocation = Path.of("src/test/java/org/ballerinalang/test/runtime/api") .toAbsolutePath(); private static final String JAVA_OPTS = "JAVA_OPTS"; @@ -53,9 +52,9 @@ public class RuntimeAPITest extends BaseTest { @BeforeClass public void setup() throws BallerinaTestException { bMainInstance = new BMainInstance(balServer); - Path sourceRoot = Path.of(testFileLocation, "function_invocation").toAbsolutePath(); + Path sourceRoot = testFileLocation.resolve("function_invocation"); bMainInstance.runMain("build", new String[0], new HashMap<>(), new String[0], null, - sourceRoot.toString()); + sourceRoot); } @Test @@ -63,8 +62,7 @@ public void testRuntimeAPIsForBalFunctionInvocation() throws BallerinaTestExcept if (isWindows()) { throw new SkipException("Unzip is not supported in Windows"); } - Path jarPath = Path.of(testFileLocation, "function_invocation/target/bin/function_invocation.jar") - .toAbsolutePath(); + Path jarPath = testFileLocation.resolve("function_invocation/target/bin/function_invocation.jar"); compileJavaSource(jarPath, "targetDir", "RuntimeAPICall.java"); unzipJarFile(jarPath, "targetDir"); createExecutableJar("targetDir", "org.ballerinalang.test.runtime.api.RuntimeAPICall"); @@ -72,7 +70,7 @@ public void testRuntimeAPIsForBalFunctionInvocation() throws BallerinaTestExcept bMainInstance.addJavaAgents(envProperties); // Run the executable jar and assert the output - Path execJarPath = Path.of(javaSrcLocation.toString(), "targetDir/test-exec.jar").toAbsolutePath(); + Path execJarPath = javaSrcLocation.resolve("targetDir/test-exec.jar"); List runCmdSet = new ArrayList<>(); runCmdSet.add("java"); if (envProperties.containsKey(JAVA_OPTS)) { @@ -108,8 +106,7 @@ public void testBalFunctionInvocationAPINegative() throws BallerinaTestException if (isWindows()) { throw new SkipException("Unzip is not supported in Windows"); } - Path jarPath = Path.of(testFileLocation, "function_invocation/target/bin/function_invocation.jar") - .toAbsolutePath(); + Path jarPath = testFileLocation.resolve("function_invocation/target/bin/function_invocation.jar"); compileJavaSource(jarPath, "target-dir-negative", "RuntimeAPICallNegative.java"); unzipJarFile(jarPath, "target-dir-negative"); createExecutableJar("target-dir-negative", @@ -118,8 +115,7 @@ public void testBalFunctionInvocationAPINegative() throws BallerinaTestException bMainInstance.addJavaAgents(envProperties); // Run the executable jar and assert the output - Path execJarPath = Path.of(javaSrcLocation.toString(), "target-dir-negative/test-exec.jar") - .toAbsolutePath(); + Path execJarPath = javaSrcLocation.resolve("target-dir-negative/test-exec.jar"); List runCmdSet = new ArrayList<>(); runCmdSet.add("java"); if (envProperties.containsKey(JAVA_OPTS)) { @@ -165,9 +161,9 @@ public void testBalFunctionInvocationAPINegative() throws BallerinaTestException @AfterClass public void tearDown() { bMainInstance = null; - BFileUtil.deleteDirectory(Path.of(javaSrcLocation.toString(), "targetDir").toFile()); - BFileUtil.deleteDirectory(Path.of(javaSrcLocation.toString(), "target-dir-negative").toFile()); - BFileUtil.deleteDirectory(Path.of(javaSrcLocation.toString(), "start-call-negative").toFile()); + BFileUtil.deleteDirectory(javaSrcLocation.resolve("targetDir").toFile()); + BFileUtil.deleteDirectory(javaSrcLocation.resolve("target-dir-negative").toFile()); + BFileUtil.deleteDirectory(javaSrcLocation.resolve("start-call-negative").toFile()); } private static void compileJavaSource(Path jarPath, String targetDir, String... srcFiles) @@ -179,14 +175,14 @@ private static void compileJavaSource(Path jarPath, String targetDir, String... compileCmdSet.add("-d"); compileCmdSet.add(targetDir); for (String srcFile : srcFiles) { - compileCmdSet.add(Path.of(javaSrcLocation.toString(), srcFile).toString()); + compileCmdSet.add(javaSrcLocation.resolve(srcFile).toString()); } ProcessBuilder compile = new ProcessBuilder(compileCmdSet).directory(javaSrcLocation.toFile()); try { Process process = compile.start(); process.waitFor(); } catch (InterruptedException | IOException e) { - throw new BallerinaTestException("Error occurred while compiling the java file"); + throw new BallerinaTestException("Error occurred while compiling the java file", e); } } @@ -214,7 +210,7 @@ private static void createExecutableJar(String targetDir, String mainClass) thro jarCmdSet.add("test-exec.jar"); jarCmdSet.add(mainClass); jarCmdSet.add("."); - Path targetPath = Path.of(javaSrcLocation.toString(), targetDir).toAbsolutePath(); + Path targetPath = javaSrcLocation.resolve(targetDir); ProcessBuilder jarProcess = new ProcessBuilder(jarCmdSet).inheritIO().directory(targetPath.toFile()); try { Process process = jarProcess.start(); diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/semver/SemverValidatorBaseTest.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/semver/SemverValidatorBaseTest.java index 4e8020292285..8ea0cfcb3274 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/semver/SemverValidatorBaseTest.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/semver/SemverValidatorBaseTest.java @@ -47,10 +47,10 @@ protected void pushPackageToCustomRepo(String packageName) throws BallerinaTestE customRepoEnv.put(HOME_REPO_ENV_KEY, customRepoDir.toAbsolutePath().toString()); balClient.runMain("pack", new String[]{}, customRepoEnv, new String[]{}, new LogLeecher[0], - tempProjectsDir.resolve(packageName).toAbsolutePath().toString()); + tempProjectsDir.resolve(packageName)); balClient.runMain("push", new String[]{"--repository=local"}, customRepoEnv, new String[]{}, - new LogLeecher[0], tempProjectsDir.resolve(packageName).toAbsolutePath().toString()); + new LogLeecher[0], tempProjectsDir.resolve(packageName)); } protected void executeSemverCommand(String packageName, String[] commandArgs, List expectedLogs) @@ -77,7 +77,7 @@ protected void executeSemverCommand(String packageName, String[] commandArgs, Li Path commandDir = packageName != null ? tempProjectsDir.resolve(packageName) : tempProjectsDir; balClient.runMain("semver", commandArgs, customRepoEnv, new String[]{}, leechers, - commandDir.toAbsolutePath().toString()); + commandDir); for (LogLeecher leecher : leechers) { leecher.waitForText(10000); diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/testarina/TestarinaTestCase.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/testarina/TestarinaTestCase.java index a3820b950a1e..638e531b8180 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/testarina/TestarinaTestCase.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/testarina/TestarinaTestCase.java @@ -63,7 +63,7 @@ public void testServiceTesting() throws Exception { LogLeecher clientLeecher2 = new LogLeecher(secondMsg); balClient.runMain("test", new String[]{"--all"}, null, new String[]{}, new LogLeecher[]{clientLeecher1, clientLeecher2}, - serviceProjectPath.toString()); + serviceProjectPath); clientLeecher1.waitForText(20000); clientLeecher2.waitForText(20000); } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/troubleshoot/StrandDumpTest.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/troubleshoot/StrandDumpTest.java index 1535a9351c42..f412857291b8 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/troubleshoot/StrandDumpTest.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/troubleshoot/StrandDumpTest.java @@ -24,10 +24,10 @@ import org.ballerinalang.test.context.LogLeecher; import org.ballerinalang.test.context.ServerLogReader; import org.ballerinalang.test.context.Utils; +import org.testng.SkipException; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -45,8 +45,8 @@ */ public class StrandDumpTest extends BaseTest { - private static final String testFileLocation = Path.of("src/test/resources/troubleshoot/strandDump") - .toAbsolutePath().toString(); + private static final Path testFileLocation = Path.of("src/test/resources/troubleshoot/strandDump") + .toAbsolutePath(); private static final String JAVA_OPTS = "JAVA_OPTS"; private static final int TIMEOUT = 60000; private BMainInstance bMainInstance; @@ -58,17 +58,16 @@ public void setup() { @Test public void testStrandDumpOfBalPackage() throws BallerinaTestException { - Path expectedOutputFilePath = Path.of(testFileLocation, "testOutputs", - "testPackageWithModulesStrandDumpRegEx.txt"); - Path steadyStateOutputFilePath = Path.of(testFileLocation, "testOutputs", - "testPackageWithModulesSteadyState.txt"); - String sourceRoot = testFileLocation + "/"; + Path expectedOutputFilePath = testFileLocation.resolve( + "testOutputs/testPackageWithModulesStrandDumpRegEx.txt"); + Path steadyStateOutputFilePath = testFileLocation.resolve( + "testOutputs/testPackageWithModulesSteadyState.txt"); + Path sourceRoot = testFileLocation; String packageName = "testPackageWithModules"; Map envProperties = new HashMap<>(); bMainInstance.runMain("build", new String[]{packageName}, envProperties, null, null, sourceRoot); - String jarPath = Path.of(Path.of(sourceRoot, packageName).toString(), "target", "bin", - packageName + ".jar").toFile().getPath(); + Path jarPath = sourceRoot.resolve(packageName + "/target/bin/" + packageName + ".jar"); runJarAndVerifyStrandDump(envProperties, jarPath, sourceRoot, expectedOutputFilePath, steadyStateOutputFilePath); } @@ -76,55 +75,52 @@ public void testStrandDumpOfBalPackage() throws BallerinaTestException { @Test public void testStrandDumpDuringBalTest() throws BallerinaTestException { if (Utils.isWindowsOS()) { - return; + throw new SkipException("Currently not working on windows"); } - Path expectedOutputFilePath = Path.of(testFileLocation, "testOutputs", "balTestStrandDumpRegEx.txt"); - Path steadyStateOutputFilePath = Path.of(testFileLocation, "testOutputs", "balTestSteadyState.txt"); - String sourceRoot = testFileLocation + "/"; + Path expectedOutputFilePath = testFileLocation.resolve("testOutputs/balTestStrandDumpRegEx.txt"); + Path steadyStateOutputFilePath = testFileLocation.resolve("testOutputs/balTestSteadyState.txt"); String packageName = "testPackageWithModules"; Map envProperties = new HashMap<>(); bMainInstance.addJavaAgents(envProperties); String[] cmdArgs = new String[]{"bash", balServer.getServerHome() + "/bin/bal", "test", packageName}; - ProcessBuilder processBuilder = new ProcessBuilder(cmdArgs).directory(new File(sourceRoot)); + ProcessBuilder processBuilder = new ProcessBuilder(cmdArgs).directory(testFileLocation.toFile()); startProcessAndVerifyStrandDump(processBuilder, envProperties, expectedOutputFilePath, steadyStateOutputFilePath, false); } @Test public void testStrandDumpOfSingleBalFile() throws BallerinaTestException { - Path expectedOutputFilePath = Path.of(testFileLocation, "testOutputs", "balProgram1StrandDumpRegEx.txt"); - Path steadyStateOutputFilePath = Path.of(testFileLocation, "testOutputs", "balProgram1SteadyStateOutput.txt"); - String commandDir = balServer.getServerHome(); - String balFile = testFileLocation + "/singleBalFiles/balProgram1.bal"; + Path expectedOutputFilePath = testFileLocation.resolve("testOutputs/balProgram1StrandDumpRegEx.txt"); + Path steadyStateOutputFilePath = testFileLocation.resolve("testOutputs/balProgram1SteadyStateOutput.txt"); + Path commandDir = balServer.getServerHome(); + Path balFile = testFileLocation.resolve("singleBalFiles/balProgram1.bal"); Map envProperties = new HashMap<>(); - bMainInstance.runMain("build", new String[]{balFile}, envProperties, null, null, commandDir); + bMainInstance.runMain("build", new String[]{balFile.toString()}, envProperties, null, null, commandDir); - String balFileName = Path.of(balFile).getFileName().toString(); - String jarPath = Path.of(Path.of(commandDir).toString(), - balFileName.substring(0, balFileName.length() - 4) + ".jar").toString(); + String balFileName = balFile.getFileName().toString(); + Path jarPath = commandDir.resolve(balFileName.substring(0, balFileName.length() - 4) + ".jar"); runJarAndVerifyStrandDump(envProperties, jarPath, commandDir, expectedOutputFilePath, steadyStateOutputFilePath); } - private void runJarAndVerifyStrandDump(Map envProperties, String jarPath, String commandDir, + private void runJarAndVerifyStrandDump(Map envProperties, Path jarPath, Path commandDir, Path expectedStrandDumpFilePath, Path steadyStateOutputFilePath) throws BallerinaTestException { if (Utils.isWindowsOS()) { - return; + throw new SkipException("Currently not working on windows"); } List runCmdSet = new ArrayList<>(); bMainInstance.addJavaAgents(envProperties); runCmdSet.add("java"); runCmdSet.add(envProperties.get(JAVA_OPTS).trim()); - String tempBalHome = new File("src" + File.separator + "test" + File.separator + - "resources" + File.separator + "ballerina.home").getAbsolutePath(); + String tempBalHome = Path.of("src/test/resources/ballerina.home").toAbsolutePath().toString(); runCmdSet.add("-Dballerina.home=" + tempBalHome); - runCmdSet.addAll(Arrays.asList("-jar", jarPath)); + runCmdSet.addAll(Arrays.asList("-jar", jarPath.toAbsolutePath().toString())); - ProcessBuilder processBuilder = new ProcessBuilder(runCmdSet).directory(new File(commandDir)); + ProcessBuilder processBuilder = new ProcessBuilder(runCmdSet).directory(commandDir.toAbsolutePath().toFile()); startProcessAndVerifyStrandDump(processBuilder, envProperties, expectedStrandDumpFilePath, steadyStateOutputFilePath, true); } @@ -134,9 +130,7 @@ private void startProcessAndVerifyStrandDump(ProcessBuilder processBuilder, Map< boolean isJar) throws BallerinaTestException { Map env = processBuilder.environment(); - for (Map.Entry entry : envProperties.entrySet()) { - env.put(entry.getKey(), entry.getValue()); - } + env.putAll(envProperties); try { Process process = processBuilder.start(); diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/BasicCasesTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/BasicCasesTest.java index beb987b875fd..64559aac1783 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/BasicCasesTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/BasicCasesTest.java @@ -34,13 +34,13 @@ public class BasicCasesTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass() public void setup() throws IOException { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.toString(); - FileUtils.copyFolder(Path.of("build/libs"), Path.of(projectPath, "runtime-api-tests", "libs")); + projectPath = projectBasedTestsPath; + FileUtils.copyFolder(Path.of("build/libs"), projectPath.resolve("runtime-api-tests/libs")); } @Test diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodeCoverageReportTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodeCoverageReportTest.java index de5b58544759..bb6be2f98006 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodeCoverageReportTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodeCoverageReportTest.java @@ -50,7 +50,7 @@ public class CodeCoverageReportTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; private Path coverageXMLPath; private String multiModuleTestRoot; private String singleModuleTestRoot; @@ -64,7 +64,7 @@ public void setup() { @Test public void singleModulePkgCoverageTest() throws BallerinaTestException { - projectPath = projectBasedTestsPath.resolve(singleModuleTestRoot).toString(); + projectPath = projectBasedTestsPath.resolve(singleModuleTestRoot); coverageXMLPath = projectBasedTestsPath.resolve(singleModuleTestRoot).resolve("target").resolve("report") .resolve("codecov").resolve("coverage-report.xml"); balClient.runMain("test", new String[]{"--code-coverage", "--coverage-format=xml"}, null, @@ -98,7 +98,7 @@ public void singleModulePkgCoverageTest() throws BallerinaTestException { @Test public void multipleModulePkgCoverageTest() throws BallerinaTestException { - projectPath = projectBasedTestsPath.resolve(multiModuleTestRoot).toString(); + projectPath = projectBasedTestsPath.resolve(multiModuleTestRoot); coverageXMLPath = projectBasedTestsPath.resolve(multiModuleTestRoot).resolve("target").resolve("report") .resolve("foo").resolve("coverage-report.xml"); balClient.runMain("test", new String[]{"--code-coverage", "--coverage-format=xml"}, null, @@ -176,7 +176,7 @@ public void multipleModulePkgCoverageTest() throws BallerinaTestException { @Test public void normalizedCoverageClassTest() throws BallerinaTestException { - projectPath = projectBasedTestsPath.resolve(multiModuleTestRoot).toString(); + projectPath = projectBasedTestsPath.resolve(multiModuleTestRoot); balClient.runMain("test", new String[]{"--code-coverage", "--coverage-format=xml"}, null, new String[]{}, new LogLeecher[]{}, projectPath); Path reportRoot = projectBasedTestsPath.resolve(multiModuleTestRoot).resolve("target"). diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodegenCodeCoverageTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodegenCodeCoverageTest.java index 205c94cadaf5..0d2131e55fb7 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodegenCodeCoverageTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodegenCodeCoverageTest.java @@ -60,7 +60,7 @@ public void setup() throws IOException { balClient = new BMainInstance(balServer); FileUtils.copyFolder(Path.of("build/compiler-plugin-jars"), projectBasedTestsPath.resolve("compiler-plugin-jars")); - repoBalaPath = Path.of(balServer.getServerHome(), "repo"); + repoBalaPath = balServer.getServerHome().resolve("repo"); } @DataProvider(name = "provideCoverageData") @@ -117,8 +117,8 @@ public void codegenCoverageTest(String projectName, String compilerPluginName, M } private void publishCompilerPlugin(String compilerPluginName) throws BallerinaTestException, IOException { - String compilerPluginBalaPath = projectBasedTestsPath.resolve("compiler-plugins") - .resolve(compilerPluginName).toString(); + Path compilerPluginBalaPath = projectBasedTestsPath.resolve("compiler-plugins") + .resolve(compilerPluginName); balClient.runMain("pack", new String[]{}, null, null, new LogLeecher[]{}, compilerPluginBalaPath); Path balaPath = projectBasedTestsPath.resolve(compilerPluginBalaPath).resolve("target").resolve("bala") .resolve("samjs-" + compilerPluginName + "-java21-0.1.0.bala"); @@ -197,7 +197,7 @@ private void validateStatus(Map status, JsonObject obj, String private void runCommand(String projectName, String[] args) throws BallerinaTestException { Path projectPath = projectBasedTestsPath.resolve("code-coverage-report-test").resolve(projectName); Path resultsJsonPath = projectPath.resolve("target").resolve("report").resolve("test_results.json"); - balClient.runMain("test", args, null, new String[]{}, new LogLeecher[]{}, projectPath.toString()); + balClient.runMain("test", args, null, new String[]{}, new LogLeecher[]{}, projectPath); Gson gson = new Gson(); try (BufferedReader bufferedReader = Files.newBufferedReader(resultsJsonPath, StandardCharsets.UTF_8)) { resultObj = gson.fromJson(bufferedReader, JsonObject.class); diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ConfigurableCliArgsTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ConfigurableCliArgsTest.java index 6b9b29a06aa0..73e7ba5d01ad 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ConfigurableCliArgsTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ConfigurableCliArgsTest.java @@ -24,6 +24,8 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.nio.file.Path; + /** * Test class containing tests related to configurable cli arguments. * @@ -33,14 +35,14 @@ public class ConfigurableCliArgsTest extends BaseTestCase { private BMainInstance bMainInstance; - private String testFileLocation; - private String singleFileTestLocation; + private Path testFileLocation; + private Path singleFileTestLocation; @BeforeClass public void setup() { bMainInstance = new BMainInstance(balServer); - testFileLocation = projectBasedTestsPath.resolve("configurable-cli-args-test").toString(); - singleFileTestLocation = singleFileTestsPath.resolve("configurable-cli-arguments").toString(); + testFileLocation = projectBasedTestsPath.resolve("configurable-cli-args-test"); + singleFileTestLocation = singleFileTestsPath.resolve("configurable-cli-arguments"); } @Test diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/DataProviderTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/DataProviderTest.java index 3dab86a8c5d3..6acbdb5d7637 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/DataProviderTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/DataProviderTest.java @@ -36,19 +36,17 @@ public class DataProviderTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; @BeforeClass() public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.toString(); } @Test public void testValidDataProvider() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"--tests", "jsonDataProviderTest", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("DataProviderTest-testValidDataProvider.txt", output); } @@ -56,7 +54,7 @@ public void testValidDataProvider() throws BallerinaTestException, IOException { public void testValidDataProviderWithFail() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"--tests", "intDataProviderTest", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; output = CommonUtils.replaceVaryingString(firstString, endString, output); @@ -67,7 +65,7 @@ public void testValidDataProviderWithFail() throws BallerinaTestException, IOExc public void testRerunFailedTest() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"--rerun-failed", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; output = CommonUtils.replaceVaryingString(firstString, endString, output); @@ -79,7 +77,7 @@ public void testValidDataProviderCase() throws BallerinaTestException, IOExcepti String[] args = mergeCoverageArgs(new String[]{"--tests", "dataproviders:jsonDataProviderTest#'json1'", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("DataProviderTest-testValidDataProviderCase.txt", output); } @@ -88,7 +86,7 @@ public void testValidDataProviderCaseWithoutQuotes() throws BallerinaTestExcepti String[] args = mergeCoverageArgs(new String[]{"--tests", "dataproviders:jsonDataProviderTest#json1", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("DataProviderTest-testValidDataProviderCase.txt", output); } @@ -97,7 +95,7 @@ public void testDataProviderWithMixedType() throws BallerinaTestException, IOExc String[] args = mergeCoverageArgs(new String[]{"--tests", "testFunction1#'CaseNew*'", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("DataProviderTest-testDataProviderWithMixedType.txt", output); } @@ -106,7 +104,7 @@ public void testDataProviderWithMixedTypeWithoutQuotes() throws BallerinaTestExc String[] args = mergeCoverageArgs(new String[]{"--tests", "testFunction1#CaseNew*", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("DataProviderTest-testDataProviderWithMixedType.txt", output); } @@ -115,7 +113,7 @@ public void testWithSpecialKeys() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"--tests", "testFunction2", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("DataProviderTest-testWithSpecialKeys.txt", output); } @@ -123,7 +121,7 @@ public void testWithSpecialKeys() throws BallerinaTestException, IOException { public void testArrayDataProviderWithFail() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"--tests", "intArrayDataProviderTest", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; @@ -138,7 +136,7 @@ public void testArrayDataProviderWithFail() throws BallerinaTestException, IOExc public void testArrayDataRerunFailedTest() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"--rerun-failed", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; output = CommonUtils.replaceVaryingString(firstString, endString, output); @@ -149,7 +147,7 @@ public void testArrayDataRerunFailedTest() throws BallerinaTestException, IOExce public void testMultiModuleSingleTestExec() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"--tests", "stringDataProviderMod1Test#1", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("DataProviderTest-testMultiModuleSingleTestExec.txt", output); } @@ -163,7 +161,7 @@ public void testCodeFragmentKeys() throws BallerinaTestException, IOException { for (String key:keys) { String[] args = mergeCoverageArgs(new String[]{"--tests", "testFunction3#" + key, "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("DataProviderTest-testCodeFragmentKeys" + count + ".txt", output); count++; @@ -180,7 +178,7 @@ public void testCodeFragmentKeysWithWildCard() throws BallerinaTestException, IO for (String key:keys) { String[] args = mergeCoverageArgs(new String[]{"--tests", "testFunction3#" + key, "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("DataProviderTest-testCodeFragmentKeysWithWildCard" + count + ".txt", output); count++; @@ -192,7 +190,7 @@ public void testMapValueDataProvider() throws BallerinaTestException, IOExceptio String[] args = mergeCoverageArgs(new String[]{"--tests", "testGetState", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; output = CommonUtils.replaceVaryingString(firstString, endString, output); @@ -204,7 +202,7 @@ public void testMapValueDataProvider() throws BallerinaTestException, IOExceptio public void testValidDataProviderWithBeforeAfterFunctions() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"--tests", "testExecutionOfBeforeAfter", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("DataProviderTest-testValidDataProviderWithBeforeAfterFunctions.txt" , output); } @@ -214,7 +212,7 @@ public void testValidDataProviderWithBeforeFailing() throws BallerinaTestExcepti String[] args = mergeCoverageArgs(new String[]{"--tests", "testDividingValuesWithBeforeFailing,testExecutionOfBeforeFailing", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; output = CommonUtils.replaceVaryingString(firstString, endString, output); @@ -226,7 +224,7 @@ public void testValidDataProviderWithAfterFailing() throws BallerinaTestExceptio String[] args = mergeCoverageArgs(new String[]{"--tests", "testDividingValuesWithAfterFailing,testExecutionOfAfterFailing", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; output = CommonUtils.replaceVaryingString(firstString, endString, output); @@ -238,7 +236,7 @@ public void testDataProviderSingleFailure() throws BallerinaTestException, IOExc String[] args = mergeCoverageArgs(new String[]{"--tests", "testExecutionOfDataValueFailing", "data-providers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; output = CommonUtils.replaceVaryingString(firstString, endString, output); diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/DisableTestsTestCase.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/DisableTestsTestCase.java index ff3b0cbed281..edbe1d2b026f 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/DisableTestsTestCase.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/DisableTestsTestCase.java @@ -24,6 +24,7 @@ import org.testng.annotations.Test; import java.io.IOException; +import java.nio.file.Path; import java.util.HashMap; /** @@ -32,12 +33,12 @@ public class DisableTestsTestCase extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = singleFileTestsPath.resolve("disabled-tests").toString(); + projectPath = singleFileTestsPath.resolve("disabled-tests"); } @Test diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/EscapedIdentifiersValidationTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/EscapedIdentifiersValidationTest.java index e434c56755f6..3935f57ecd83 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/EscapedIdentifiersValidationTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/EscapedIdentifiersValidationTest.java @@ -31,19 +31,17 @@ public class EscapedIdentifiersValidationTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.toString(); } @Test public void validateEscapedIdentifiersTest() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"validate-escaped-identifiers"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, true); + new HashMap<>(), projectBasedTestsPath, true); AssertionUtils.assertOutput("EscapedIdentifiersValidationTest-validateEscapedIdentifiersTest.txt", output); } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ExcludeFromCodeCoverageTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ExcludeFromCodeCoverageTest.java index 036152b49d5d..53561e86f01c 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ExcludeFromCodeCoverageTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ExcludeFromCodeCoverageTest.java @@ -47,8 +47,7 @@ public class ExcludeFromCodeCoverageTest extends BaseTestCase { public void setup() { balClient = new BMainInstance(balServer); projectPath = projectBasedTestsPath.resolve("code-cov-exclusion"); - resultsJsonPath = projectBasedTestsPath.resolve("code-cov-exclusion").resolve("target").resolve("report") - .resolve("test_results.json"); + resultsJsonPath = projectBasedTestsPath.resolve("code-cov-exclusion/target/report/test_results.json"); } @Test(description = "Exclude coverage with relative source paths and wildcards") @@ -72,7 +71,7 @@ public void testExcludingBalFileCoverage() throws BallerinaTestException { String[] args = mergeCoverageArgs(new String[]{"--test-report", "--coverage-format=xml", "--excludes=" + String.join(",", exclusionList)}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath.toString(), false); + new HashMap<>(), projectPath, false); Gson gson = new Gson(); try (BufferedReader bufferedReader = Files.newBufferedReader(resultsJsonPath, StandardCharsets.UTF_8)) { @@ -90,7 +89,7 @@ public void testExcludesSrcFileFromExclusionList() throws BallerinaTestException String[] args = mergeCoverageArgs(new String[]{"--test-report", "--coverage-format=xml", "--excludes=" + String.join(",", exclusionList)}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath.toString(), false); + new HashMap<>(), projectPath, false); Gson gson = new Gson(); try (BufferedReader bufferedReader = Files.newBufferedReader(resultsJsonPath, StandardCharsets.UTF_8)) { @@ -108,7 +107,7 @@ public void testExcludesSrcFolderFromExclusionList() throws BallerinaTestExcepti String[] args = mergeCoverageArgs(new String[]{"--test-report", "--coverage-format=xml", "--excludes=" + String.join(",", exclusionList)}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath.toString(), false); + new HashMap<>(), projectPath, false); Gson gson = new Gson(); try (BufferedReader bufferedReader = Files.newBufferedReader(resultsJsonPath, StandardCharsets.UTF_8)) { diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/FunctionNameValidationTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/FunctionNameValidationTest.java index 87acf171f2ca..3909ff044f0b 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/FunctionNameValidationTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/FunctionNameValidationTest.java @@ -32,19 +32,17 @@ public class FunctionNameValidationTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.toString(); } @Test public void validateFunctionNamesTest() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"validate-function-names"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, true); + new HashMap<>(), projectBasedTestsPath, true); AssertionUtils.assertOutput("FunctionNameValidationTest-validateFunctionNamesTest.txt", output); } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/GroupingTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/GroupingTest.java index 5c503c05df8b..2425c785d893 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/GroupingTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/GroupingTest.java @@ -24,6 +24,7 @@ import org.testng.annotations.Test; import java.io.IOException; +import java.nio.file.Path; import java.util.HashMap; /** @@ -32,12 +33,12 @@ public class GroupingTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = singleFileTestsPath.resolve("grouping").toString(); + projectPath = singleFileTestsPath.resolve("grouping"); } @Test @@ -101,7 +102,7 @@ public void testListingOfTestGroups() throws BallerinaTestException, IOException String[] args = {"--list-groups"}; String output = balClient.runMainAndReadStdOut("test", args, new HashMap<>(), - projectBasedTestsPath.resolve("group-test").toString(), + projectBasedTestsPath.resolve("group-test"), false); AssertionUtils.assertOutput("GroupingTest-testListingOfTestGroups.txt", output); } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ImportTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ImportTest.java index 9a9339002335..eef09d536ed3 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ImportTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ImportTest.java @@ -33,19 +33,17 @@ */ public class ImportTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; @BeforeClass() public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.toString(); } @Test() public void testImportTest() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"predeclared-import-tests"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, true); + new HashMap<>(), projectBasedTestsPath, true); AssertionUtils.assertOutput("ImportTest-testImportTest.txt", output); } } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/MockTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/MockTest.java index 0c6f0e8848f4..abdd0e8e4a72 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/MockTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/MockTest.java @@ -46,16 +46,14 @@ public class MockTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; @BeforeClass public void setup() throws BallerinaTestException, IOException { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.toString(); FileUtils.copyFolder(Path.of("build/libs"), - Path.of(projectPath, "object-mocking-tests", "libs")); + projectBasedTestsPath.resolve("object-mocking-tests/libs")); // Build and push config Lib project. - compilePackageAndPushToLocal(projectBasedTestsPath.resolve("mockLibProject").toString(), + compilePackageAndPushToLocal(projectBasedTestsPath.resolve("mockLibProject"), "testOrg-mockLib-any-0.1.0"); } @@ -63,7 +61,7 @@ public void setup() throws BallerinaTestException, IOException { public void testFunctionMocking() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"function-mocking-tests"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; output = CommonUtils.replaceVaryingString(firstString, endString, output); @@ -74,7 +72,7 @@ public void testFunctionMocking() throws BallerinaTestException, IOException { public void testFunctionMockingLegacy() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"legacy-function-mocking-tests"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("MockTest-testFunctionMockingLegacy.txt", output); } @@ -82,7 +80,7 @@ public void testFunctionMockingLegacy() throws BallerinaTestException, IOExcepti public void testObjectMocking() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"object-mocking-tests"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; output = CommonUtils.replaceVaryingString(firstString, endString, output); @@ -98,7 +96,7 @@ public void testObjectMocking() throws BallerinaTestException, IOException { public void testObjectMockDouble() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"object-mocking-tests2"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("MockTest-testObjectMockDouble.txt", output); } @@ -106,7 +104,7 @@ public void testObjectMockDouble() throws BallerinaTestException, IOException { public void testResourceMocking() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"resource-mocking-tests"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("MockTest-testResourceMocking.txt", output); } @@ -114,7 +112,7 @@ public void testResourceMocking() throws BallerinaTestException, IOException { public void testFunctionMockingModuleLevel() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"function-mocking-tests"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; output = CommonUtils.replaceVaryingString(firstString, endString, output); @@ -125,7 +123,7 @@ public void testFunctionMockingModuleLevel() throws BallerinaTestException, IOEx public void testCoverageWithMocking() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"mocking-coverage-tests"}); String output = balClient.runMainAndReadStdOut("test", args, - new HashMap<>(), projectPath, false); + new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("MockTest-testCoverageWithMocking.txt", output); Path resultsJsonPath = projectBasedTestsPath.resolve("mocking-coverage-tests").resolve("target") .resolve("report").resolve("test_results.json"); @@ -158,14 +156,14 @@ public void testCoverageWithMocking() throws BallerinaTestException, IOException @Test public void testFunctionMockingInMultipleModulesWithDependencies() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"function-mocking-tests-with-dependencies"}); - String output = balClient.runMainAndReadStdOut("test", args, new HashMap<>(), projectPath, false); + String output = balClient.runMainAndReadStdOut("test", args, new HashMap<>(), projectBasedTestsPath, false); AssertionUtils.assertOutput("MockTest-testFuncMockInMultiModulesWDepen.txt", output); } @Test public void testFunctionMockingThenReturnWithNilReturnValue() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"function-mocking-tests-then-return-with-nil-ret-val"}); - String output = balClient.runMainAndReadStdOut("test", args, new HashMap<>(), projectPath, false); + String output = balClient.runMainAndReadStdOut("test", args, new HashMap<>(), projectBasedTestsPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; output = CommonUtils.replaceVaryingString(firstString, endString, output); @@ -179,7 +177,7 @@ public void testObjectMocking_NegativeCases(String message, String test, String String[] args = mergeCoverageArgs(new String[]{"--tests", test}); String output = balClient.runMainAndReadStdOut("test", args, new HashMap<>(), - projectBasedTestsPath.resolve("object-mocking-tests").toString(), false); + projectBasedTestsPath.resolve("object-mocking-tests"), false); String firstString = "Generating Test Report"; String endString = "project-based-tests"; output = CommonUtils.replaceVaryingString(firstString, endString, output); @@ -196,7 +194,7 @@ public void testObjectMocking_NonPublicField() throws BallerinaTestException, IO "non_public_field_mock:testNonPublicMemberFieldMock"}); String output = balClient.runMainAndReadStdOut("test", args, new HashMap<>(), - projectBasedTestsPath.resolve("non-public-field-mock").toString(), false); + projectBasedTestsPath.resolve("non-public-field-mock"), false); String firstString = "Generating Test Report"; String endString = "project-based-tests"; output = CommonUtils.replaceVaryingString(firstString, endString, output); @@ -229,7 +227,7 @@ public static Object[][] negativeCases() { }; } - private void compilePackageAndPushToLocal(String packagPath, String balaFileName) throws BallerinaTestException { + private void compilePackageAndPushToLocal(Path packagPath, String balaFileName) throws BallerinaTestException { LogLeecher buildLeecher = new LogLeecher("target" + File.separator + "bala" + File.separator + balaFileName + ".bala"); LogLeecher pushLeecher = new LogLeecher("Successfully pushed target" + File.separator + "bala" + diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleExecutionFlowTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleExecutionFlowTest.java index cc4813b5f37b..7cf7b27cca17 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleExecutionFlowTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleExecutionFlowTest.java @@ -38,12 +38,12 @@ public class ModuleExecutionFlowTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.resolve("module-execution-flow-tests").toString(); + projectPath = projectBasedTestsPath.resolve("module-execution-flow-tests"); } @Test() @@ -57,7 +57,7 @@ public void testModuleExecutionFlow() throws BallerinaTestException, IOException @AfterMethod public void copyExec() { try { - FileUtils.copyBallerinaExec(Path.of(projectPath), String.valueOf(System.currentTimeMillis())); + FileUtils.copyBallerinaExec(projectPath, String.valueOf(System.currentTimeMillis())); } catch (IOException e) { // ignore exception } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleExecutionTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleExecutionTest.java index 530b1a4b1b4d..90c08e4f1863 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleExecutionTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleExecutionTest.java @@ -37,12 +37,12 @@ public class ModuleExecutionTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.resolve("module-execution-tests").toString(); + projectPath = projectBasedTestsPath.resolve("module-execution-tests"); } @Test() @@ -168,7 +168,7 @@ public void test_Module1_WithGroups() throws BallerinaTestException, IOException @AfterMethod public void copyExec() { try { - FileUtils.copyBallerinaExec(Path.of(projectPath), String.valueOf(System.currentTimeMillis())); + FileUtils.copyBallerinaExec(projectPath, String.valueOf(System.currentTimeMillis())); } catch (IOException e) { // ignore exception } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleExecutionWithInitStartFailuresTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleExecutionWithInitStartFailuresTest.java index f8801eb073e8..df7785ef6e7f 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleExecutionWithInitStartFailuresTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleExecutionWithInitStartFailuresTest.java @@ -41,12 +41,12 @@ public class ModuleExecutionWithInitStartFailuresTest { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.resolve("module-execution-tests-with-init-start-failures").toString(); + projectPath = projectBasedTestsPath.resolve("module-execution-tests-with-init-start-failures"); } @Test() @@ -63,7 +63,7 @@ public void testModuleExecutionFlow() throws BallerinaTestException, IOException @AfterMethod public void copyExec() { try { - FileUtils.copyBallerinaExec(Path.of(projectPath), String.valueOf(System.currentTimeMillis())); + FileUtils.copyBallerinaExec(projectPath, String.valueOf(System.currentTimeMillis())); } catch (IOException e) { // ignore exception } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleGracefulStopTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleGracefulStopTest.java index 6fd0630b6bb2..fc14de5562c4 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleGracefulStopTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/ModuleGracefulStopTest.java @@ -38,12 +38,12 @@ public class ModuleGracefulStopTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.resolve("module-graceful-stop-tests").toString(); + projectPath = projectBasedTestsPath.resolve("module-graceful-stop-tests"); } @Test() @@ -60,7 +60,7 @@ public void testModuleGracefulStop() throws BallerinaTestException, IOException @AfterMethod public void copyExec() { try { - FileUtils.copyBallerinaExec(Path.of(projectPath), String.valueOf(System.currentTimeMillis())); + FileUtils.copyBallerinaExec(projectPath, String.valueOf(System.currentTimeMillis())); } catch (IOException e) { // ignore exception } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/PathVerificationTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/PathVerificationTest.java index a5148969e93f..5b3e6335b8f0 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/PathVerificationTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/PathVerificationTest.java @@ -24,6 +24,7 @@ import org.testng.annotations.Test; import java.io.IOException; +import java.nio.file.Path; import java.util.HashMap; /** @@ -32,12 +33,12 @@ public class PathVerificationTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.toString(); + projectPath = projectBasedTestsPath; } @Test diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/RerunFailedTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/RerunFailedTest.java index cfbecff50d36..796ad239af88 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/RerunFailedTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/RerunFailedTest.java @@ -38,12 +38,12 @@ public class RerunFailedTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.toString(); + projectPath = projectBasedTestsPath; } @Test @@ -101,7 +101,7 @@ public void testRerunFailedTestWithMissingModuleNameInRunTestJson() throws Balle @AfterMethod public void copyExec() { try { - FileUtils.copyBallerinaExec(Path.of(projectPath), String.valueOf(System.currentTimeMillis())); + FileUtils.copyBallerinaExec(projectPath, String.valueOf(System.currentTimeMillis())); } catch (IOException e) { // ignore exception } @@ -110,7 +110,7 @@ public void copyExec() { private void runBalClean(String packageDirName) throws BallerinaTestException { String[] args = new String[]{"--target-dir", packageDirName + "/target"}; Map envProperties = new HashMap<>(); - envProperties.put("user.dir", projectPath); + envProperties.put("user.dir", projectPath.toString()); balClient.runMain("clean", args, envProperties, null, null, projectPath); } } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SelectedFunctionTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SelectedFunctionTest.java index 2202f3b953ea..63f31b2dfd06 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SelectedFunctionTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SelectedFunctionTest.java @@ -24,6 +24,7 @@ import org.testng.annotations.Test; import java.io.IOException; +import java.nio.file.Path; import java.util.HashMap; /** @@ -32,12 +33,12 @@ public class SelectedFunctionTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = singleFileTestsPath.resolve("single-test-execution").toString(); + projectPath = singleFileTestsPath.resolve("single-test-execution"); } @Test diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java index 4be1c6309e69..c476cb033855 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java @@ -25,17 +25,18 @@ import org.testng.annotations.Test; import java.io.IOException; +import java.nio.file.Path; import java.util.HashMap; public class SingleTestExecutionWithInitFailuresTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = singleFileTestsPath.resolve("single-test-execution").toString(); + projectPath = singleFileTestsPath.resolve("single-test-execution"); } @Test diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SourcelessTestExecutionTests.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SourcelessTestExecutionTests.java index 3d47d2f43b26..9402a2ffb313 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SourcelessTestExecutionTests.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SourcelessTestExecutionTests.java @@ -7,6 +7,7 @@ import org.testng.annotations.Test; import java.io.IOException; +import java.nio.file.Path; import java.util.HashMap; /** @@ -15,12 +16,12 @@ public class SourcelessTestExecutionTests extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.resolve("sourceless-test-execution-tests").toString(); + projectPath = projectBasedTestsPath.resolve("sourceless-test-execution-tests"); } // Scenario : Modules only have tests and no sourcefiles. Default module doesnt have sources or tests diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestExecutionWithInitFailuresTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestExecutionWithInitFailuresTest.java index 97b171d7a564..c6febc8e19ef 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestExecutionWithInitFailuresTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestExecutionWithInitFailuresTest.java @@ -37,12 +37,12 @@ public class TestExecutionWithInitFailuresTest { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.resolve("test-execution-with-init-failure").toString(); + projectPath = projectBasedTestsPath.resolve("test-execution-with-init-failure"); } @Test() @@ -59,7 +59,7 @@ public void testModuleExecutionFlow() throws BallerinaTestException, IOException @AfterMethod public void copyExec() { try { - FileUtils.copyBallerinaExec(Path.of(projectPath), String.valueOf(System.currentTimeMillis())); + FileUtils.copyBallerinaExec(projectPath, String.valueOf(System.currentTimeMillis())); } catch (IOException e) { // ignore exception } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestReportTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestReportTest.java index e2ae25cef4d5..804c1c105ba1 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestReportTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestReportTest.java @@ -44,7 +44,7 @@ public class TestReportTest extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; private Path resultsJsonPath; private JsonObject resultObj; @@ -56,7 +56,7 @@ public class TestReportTest extends BaseTestCase { @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.resolve("test-report-tests").toString(); + projectPath = projectBasedTestsPath.resolve("test-report-tests"); resultsJsonPath = projectBasedTestsPath.resolve("test-report-tests").resolve("target").resolve("report") .resolve("test_results.json"); } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestparallelizationTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestparallelizationTest.java index 4c516e9d64ea..1bf6fad4447c 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestparallelizationTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestparallelizationTest.java @@ -22,6 +22,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.nio.file.Path; import java.util.HashMap; /** @@ -32,12 +33,12 @@ public class TestparallelizationTest extends BaseTestCase { public static final String PARALLEL_FLAG = "--parallel"; private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.resolve("parallelisation-test").toString(); + projectPath = projectBasedTestsPath.resolve("parallelisation-test"); } @Test diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidConfigurableCliArgsTestCase.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidConfigurableCliArgsTestCase.java index a8826e647943..2ea6e189b07d 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidConfigurableCliArgsTestCase.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidConfigurableCliArgsTestCase.java @@ -25,6 +25,8 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.nio.file.Path; + import static org.ballerinalang.test.context.LogLeecher.LeecherType.ERROR; /** @@ -35,12 +37,12 @@ public class InvalidConfigurableCliArgsTestCase extends BaseTestCase { private BMainInstance bMainInstance; - private String testFileLocation; + private Path testFileLocation; @BeforeClass public void setup() { bMainInstance = new BMainInstance(balServer); - testFileLocation = projectBasedTestsPath.resolve("configurable-cli-args-test").toString(); + testFileLocation = projectBasedTestsPath.resolve("configurable-cli-args-test"); } @Test diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidDataProviderTestCase.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidDataProviderTestCase.java index 81af85af4792..020cd8ae578e 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidDataProviderTestCase.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidDataProviderTestCase.java @@ -36,14 +36,14 @@ public class InvalidDataProviderTestCase extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; private Path errorlogFile; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = singleFileTestsPath.resolve("invalid-data-providers").toString(); - errorlogFile = Path.of(projectPath).resolve("ballerina-internal.log"); + projectPath = singleFileTestsPath.resolve("invalid-data-providers"); + errorlogFile = projectPath.resolve("ballerina-internal.log"); } @BeforeMethod diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidFunctionMockingTestCase.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidFunctionMockingTestCase.java index efccbf620dcc..89136e59febd 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidFunctionMockingTestCase.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidFunctionMockingTestCase.java @@ -27,6 +27,7 @@ import org.testng.annotations.Test; import java.io.IOException; +import java.nio.file.Path; import java.util.HashMap; /** @@ -42,7 +43,7 @@ public void setup() { @Test public void testMockingNonExistingFunction() throws BallerinaTestException, IOException { - String projectPath = projectBasedTestsPath.resolve("non-existent-function-mock").toString(); + Path projectPath = projectBasedTestsPath.resolve("non-existent-function-mock"); String output = balClient.runMainAndReadStdOut("test", new String[0], new HashMap<>(), projectPath, true); AssertionUtils.assertOutput("InvalidFunctionMockingTestCase-testMockingNonExistingFunction.txt", output.replaceAll("\r\n|\r|\n", "\n")); @@ -50,7 +51,7 @@ public void testMockingNonExistingFunction() throws BallerinaTestException, IOEx @Test public void testLegacyMockingNonExistingFunction() throws BallerinaTestException, IOException { - String projectPath = projectBasedTestsPath.resolve("non-existent-function-legacy-mock").toString(); + Path projectPath = projectBasedTestsPath.resolve("non-existent-function-legacy-mock"); String output = balClient.runMainAndReadStdOut("test", new String[0], new HashMap<>(), projectPath, true); AssertionUtils.assertOutput("InvalidFunctionMockingTestCase-testLegacyMockingNonExistingFunction.txt", output.replaceAll("\r\n|\r|\n", "\n")); @@ -58,7 +59,7 @@ public void testLegacyMockingNonExistingFunction() throws BallerinaTestException @Test public void testMockingWithoutAnnotationRecord() throws BallerinaTestException, IOException { - String projectPath = projectBasedTestsPath.resolve("record-less-annotation-function-mock").toString(); + Path projectPath = projectBasedTestsPath.resolve("record-less-annotation-function-mock"); String output = balClient.runMainAndReadStdOut("test", new String[0], new HashMap<>(), projectPath, true); AssertionUtils.assertOutput("InvalidFunctionMockingTestCase-testMockingWithoutAnnotationRecord.txt", output.replaceAll("\r\n|\r|\n", "\n")); @@ -66,7 +67,7 @@ public void testMockingWithoutAnnotationRecord() throws BallerinaTestException, @Test public void testLegacyMockingWithoutAnnotationRecord() throws BallerinaTestException, IOException { - String projectPath = projectBasedTestsPath.resolve("record-less-annotation-function-legacy-mock").toString(); + Path projectPath = projectBasedTestsPath.resolve("record-less-annotation-function-legacy-mock"); String output = balClient.runMainAndReadStdOut("test", new String[0], new HashMap<>(), projectPath, true); AssertionUtils.assertOutput("InvalidFunctionMockingTestCase-testLegacyMockingWithoutAnnotationRecord.txt", output.replaceAll("\r\n|\r|\n", "\n")); @@ -74,7 +75,7 @@ public void testLegacyMockingWithoutAnnotationRecord() throws BallerinaTestExcep @Test public void testMockingWithEmptyAnnotationRecord() throws BallerinaTestException, IOException { - String projectPath = projectBasedTestsPath.resolve("empty-annotation-record-function-mock").toString(); + Path projectPath = projectBasedTestsPath.resolve("empty-annotation-record-function-mock"); String output = balClient.runMainAndReadStdOut("test", new String[0], new HashMap<>(), projectPath, true); AssertionUtils.assertOutput("InvalidFunctionMockingTestCase-testMockingWithEmptyAnnotationRecord.txt", output.replaceAll("\r\n|\r|\n", "\n")); @@ -82,7 +83,7 @@ public void testMockingWithEmptyAnnotationRecord() throws BallerinaTestException @Test public void testLegacyMockingWithEmptyAnnotationRecord() throws BallerinaTestException, IOException { - String projectPath = projectBasedTestsPath.resolve("empty-annotation-record-function-legacy-mock").toString(); + Path projectPath = projectBasedTestsPath.resolve("empty-annotation-record-function-legacy-mock"); String output = balClient.runMainAndReadStdOut("test", new String[0], new HashMap<>(), projectPath, true); AssertionUtils.assertOutput("InvalidFunctionMockingTestCase-testLegacyMockingWithEmptyAnnotationRecord.txt", output.replaceAll("\r\n|\r|\n", "\n")); @@ -90,7 +91,7 @@ public void testLegacyMockingWithEmptyAnnotationRecord() throws BallerinaTestExc @Test public void testMockingFunctionInNonExistingModule() throws BallerinaTestException, IOException { - String projectPath = projectBasedTestsPath.resolve("non-existent-module-mock").toString(); + Path projectPath = projectBasedTestsPath.resolve("non-existent-module-mock"); String output = balClient.runMainAndReadStdOut("test", new String[0], new HashMap<>(), projectPath, true); AssertionUtils.assertOutput("InvalidFunctionMockingTestCase-testMockingFunctionInNonExistingModule.txt", output.replaceAll("\r\n|\r|\n", "\n")); @@ -98,7 +99,7 @@ public void testMockingFunctionInNonExistingModule() throws BallerinaTestExcepti @Test public void testLegacyMockingFunctionInNonExistingModule() throws BallerinaTestException, IOException { - String projectPath = projectBasedTestsPath.resolve("non-existent-module-legacy-mock").toString(); + Path projectPath = projectBasedTestsPath.resolve("non-existent-module-legacy-mock"); String output = balClient.runMainAndReadStdOut("test", new String[0], new HashMap<>(), projectPath, true); AssertionUtils.assertOutput("InvalidFunctionMockingTestCase-testLegacyMockingFunctionInNonExistingModule.txt", output.replaceAll("\r\n|\r|\n", "\n")); @@ -106,7 +107,7 @@ public void testLegacyMockingFunctionInNonExistingModule() throws BallerinaTestE @Test public void testMockingFunctionWithIncompatibleTypes() throws BallerinaTestException, IOException { - String projectPath = projectBasedTestsPath.resolve("incompatible-type-mock").toString(); + Path projectPath = projectBasedTestsPath.resolve("incompatible-type-mock"); String output = balClient.runMainAndReadStdOut("test", new String[0], new HashMap<>(), projectPath, false); String firstString = "tests.test_execute-generated_"; String endString = "lineNumber"; @@ -117,7 +118,7 @@ public void testMockingFunctionWithIncompatibleTypes() throws BallerinaTestExcep @Test public void testLegacyMockingFunctionWithIncompatibleTypes() throws BallerinaTestException, IOException { - String projectPath = projectBasedTestsPath.resolve("incompatible-type-legacy-mock").toString(); + Path projectPath = projectBasedTestsPath.resolve("incompatible-type-legacy-mock"); String output = balClient.runMainAndReadStdOut("test", new String[0], new HashMap<>(), projectPath, true); AssertionUtils.assertOutput("InvalidFunctionMockingTestCase-testLegacyMockingFunctionWithIncompatibleTypes.txt", output.replaceAll("\r\n|\r|\n", "\n")); @@ -125,7 +126,7 @@ public void testLegacyMockingFunctionWithIncompatibleTypes() throws BallerinaTes @Test public void testMockingFunctionInSingleFileProject() throws BallerinaTestException, IOException { - String projectPath = singleFileTestsPath.resolve("mocking").toString(); + Path projectPath = singleFileTestsPath.resolve("mocking"); String[] args = mergeCoverageArgs(new String[]{"function-mock.bal"}); String output = balClient.runMainAndReadStdOut("test", args, new HashMap<>(), projectPath, true); AssertionUtils.assertOutput("InvalidFunctionMockingTestCase-testMockingFunctionInSingleFileProject.txt", @@ -134,7 +135,7 @@ public void testMockingFunctionInSingleFileProject() throws BallerinaTestExcepti @Test public void testLegacyMockingFunctionInSingleFileProject() throws BallerinaTestException, IOException { - String projectPath = singleFileTestsPath.resolve("mocking").toString(); + Path projectPath = singleFileTestsPath.resolve("mocking"); String[] args = mergeCoverageArgs(new String[]{"function-legacy-mock.bal"}); String output = balClient.runMainAndReadStdOut("test", args, new HashMap<>(), projectPath, true); AssertionUtils.assertOutput("InvalidFunctionMockingTestCase-testLegacyMockingFunctionInSingleFileProject.txt", diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidTestDefinitionsTestCase.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidTestDefinitionsTestCase.java index 5a9c4dc0ffbb..4007c06af63b 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidTestDefinitionsTestCase.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/InvalidTestDefinitionsTestCase.java @@ -24,6 +24,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.nio.file.Path; import java.util.HashMap; /** @@ -34,12 +35,12 @@ public class InvalidTestDefinitionsTestCase extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = singleFileTestsPath.resolve("invalid-test-definitions").toString(); + projectPath = singleFileTestsPath.resolve("invalid-test-definitions"); } @Test diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/MissingFunctionsTestCase.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/MissingFunctionsTestCase.java index 691ef89741fb..5155d9bca732 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/MissingFunctionsTestCase.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/MissingFunctionsTestCase.java @@ -25,6 +25,7 @@ import org.testng.annotations.Test; import java.io.IOException; +import java.nio.file.Path; import java.util.HashMap; /** @@ -33,12 +34,12 @@ public class MissingFunctionsTestCase extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = singleFileTestsPath.resolve("missing-functions").toString(); + projectPath = singleFileTestsPath.resolve("missing-functions"); } @Test diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/SkipTestsTestCase.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/SkipTestsTestCase.java index 91447b0b8cf6..0275280c66b6 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/SkipTestsTestCase.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/SkipTestsTestCase.java @@ -25,6 +25,7 @@ import org.testng.annotations.Test; import java.io.IOException; +import java.nio.file.Path; import java.util.HashMap; /** @@ -33,12 +34,12 @@ public class SkipTestsTestCase extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = singleFileTestsPath.resolve("skip-tests").toString(); + projectPath = singleFileTestsPath.resolve("skip-tests"); } @Test diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/UnusedVarWithErrorTestCase.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/UnusedVarWithErrorTestCase.java index bb0c2584e375..1480c5cd30d1 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/UnusedVarWithErrorTestCase.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/negative/UnusedVarWithErrorTestCase.java @@ -23,6 +23,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.nio.file.Path; import java.util.HashMap; import static org.testng.Assert.assertEquals; @@ -35,12 +36,12 @@ public class UnusedVarWithErrorTestCase extends BaseTestCase { private BMainInstance balClient; - private String projectPath; + private Path projectPath; @BeforeClass public void setup() { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.resolve("unused-var-with-error-test").toString(); + projectPath = projectBasedTestsPath.resolve("unused-var-with-error-test"); } @Test