diff --git a/.github/workflows/Jirabot.yml b/.github/workflows/Jirabot.yml index 1c2b16d0c..a0c295916 100644 --- a/.github/workflows/Jirabot.yml +++ b/.github/workflows/Jirabot.yml @@ -39,28 +39,22 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GHUB_JIRA_USER_MAP: ${{ vars.GHUB_JIRA_USER_MAP }} JIRA_ISSUE_PROPERTY_MAP: ${{ vars.JIRA_ISSUE_PROPERTY_MAP }} + JIRA_ISSUE_TRANSITION_MAP: ${{ vars.JIRA_ISSUE_TRANSITION_MAP }} run: | import os import re import json from jira.client import JIRA - def updateIssue(jira, issue, prAuthor: str, propertyMap: dict, pull_url: str) -> str: + def updateIssue(jira, issue, prAuthorEmail : str, transitionMap: dict, propertyMap: dict, pull_url: str) -> str: result = '' statusName = str(issue.fields.status) - if statusName == 'Open': - transition = 'Start Progress' - elif statusName == 'In Progress': - transition = '' - elif statusName == 'Resolved': - transition = 'Reopen Issue' - elif statusName == 'Closed': - transition = 'Reopen Issue' - else: - transition = '' + transition = transitionMap.get(statusName, None) - if transition != '': + if transition == None: + print('Error: Unable to find transition for status: ' + statusName) + elif transition != '': try: jira.transition_issue(issue, transition) result += 'Workflow Transition: ' + transition + '\n' @@ -81,13 +75,17 @@ jobs: elif currentPR is not None and currentPR != pull_url: result += 'Additional PR: ' + pull_url + '\n' - if prAuthor: + if prAuthorEmail: if issue.fields.assignee is None: - jira.assign_issue(issue, prAuthor) - result += 'Assigning user: ' + prAuthor + '\n' - elif issue.fields.assignee is not None and issue.fields.assignee.name.lower() != prAuthor.lower(): - result += 'Changing assignee from: ' + issue.fields.assignee.name + ' to: ' + prAuthor + '\n' - jira.assign_issue(issue, prAuthor) + jira.assign_issue(issue, prAuthorEmail) + result += 'Assigning user: ' + prAuthorEmail + '\n' + else: + assigneeEmail = None + if issue.fields.assignee: + assigneeEmail = issue.fields.assignee.emailAddress + if assigneeEmail is None or assigneeEmail.lower() != assigneeEmail.lower(): + result += 'Changing assignee from: ' + assigneeEmail + ' to: ' + prAuthorEmail + '\n' + jira.assign_issue(issue, prAuthorEmail) return result @@ -122,24 +120,41 @@ jobs: jira = JIRA(options=options, basic_auth=(jirabot_user, jirabot_pass)) - # Check if prAuthor exists in Jira - try: + # Need to change how we find users for Jira Cloud, unfortunately the API doesn't provide this information. + # At the moment checking if the URL contains atlassian.net appears to be the easiest way to determine if it's Jira Cloud. + isJiraCloud = False + if jira_url.find('atlassian.net') > 0: + isJiraCloud = True + + if isJiraCloud: + res = jira.search_users(query=prAuthor) + if res and len(res) > 0: + jiraUser = res[0] + else: jiraUser = jira.user(prAuthor) - if jiraUser is None: - prAuthor = None - print('Error: Unable to find Jira user: ' + prAuthor + ' continuing without assigning') - except Exception as error: - prAuthor = None - print('Error: Unable to find Jira user: ' + prAuthor + ' with error: ' + str(error) + ' continuing without assigning') + + jiraUserEmail = None + if jiraUser is None: + print('Error: Unable to find Jira user: ' + prAuthor + ' continuing without assigning') + else: + jiraUserEmail = jiraUser.emailAddress + + print("Jira User Email:" + str(jiraUserEmail)) issue = jira.issue(issue_name) result = 'Jirabot Action Result:\n' + transitionMap = json.loads(os.environ['JIRA_ISSUE_TRANSITION_MAP']) + if not isinstance(transitionMap, dict): + print('Error: JIRA_ISSUE_TRANSITION_MAP is not a valid JSON object, ignoring.') + transitionMap = {} + jiraIssuePropertyMap = json.loads(os.environ['JIRA_ISSUE_PROPERTY_MAP']) if not isinstance(jiraIssuePropertyMap, dict): + print('Error: JIRA_ISSUE_PROPERTY_MAP is not a valid JSON object, ignoring.') jiraIssuePropertyMap = {} - result += updateIssue(jira, issue, prAuthor, jiraIssuePropertyMap, pull_url) + result += updateIssue(jira, issue, jiraUserEmail, transitionMap, jiraIssuePropertyMap, pull_url) jira.add_comment(issue, result) else: print('Unable to find Jira issue name in title') diff --git a/dfsclient/src/main/java/org/hpccsystems/dfs/client/HpccRemoteFileReader.java b/dfsclient/src/main/java/org/hpccsystems/dfs/client/HpccRemoteFileReader.java index ade51a57e..dad69ec3a 100644 --- a/dfsclient/src/main/java/org/hpccsystems/dfs/client/HpccRemoteFileReader.java +++ b/dfsclient/src/main/java/org/hpccsystems/dfs/client/HpccRemoteFileReader.java @@ -22,6 +22,7 @@ import java.util.Iterator; /** + * Remote file reader the reads the data represented by a @see org.hpccsystems.dfs.client.DataPartition * Remote file reader the reads the data represented by a @see org.hpccsystems.dfs.client.DataPartition * and constructs records via the provided @see org.hpccsystems.dfs.client#IRecordBuilder. */ @@ -78,7 +79,7 @@ public HpccRemoteFileReader(DataPartition dp, FieldDef originalRD, IRecordBuilde * @param recBuilder * the IRecordBuilder used to construct records * @param connectTimeout - * the connection timeout in milliseconds, -1 for default + * the connection timeout in seconds, -1 for default * @throws Exception * the exception */ @@ -118,7 +119,7 @@ public HpccRemoteFileReader(DataPartition dp, FieldDef originalRD, IRecordBuilde * @param recBuilder * the IRecordBuilder used to construct records * @param connectTimeout - * the connection timeout in milliseconds, -1 for default + * the connection timeout in seconds, -1 for default * @param limit * the maximum number of records to read from the provided data partition, -1 specifies no limit * @param createPrefetchThread @@ -130,7 +131,7 @@ public HpccRemoteFileReader(DataPartition dp, FieldDef originalRD, IRecordBuilde */ public HpccRemoteFileReader(DataPartition dp, FieldDef originalRD, IRecordBuilder recBuilder, int connectTimeout, int limit, boolean createPrefetchThread, int readSizeKB) throws Exception { - this(dp, originalRD, recBuilder, connectTimeout, limit, true, DEFAULT_READ_SIZE_OPTION, null); + this(dp, originalRD, recBuilder, connectTimeout, limit, createPrefetchThread, readSizeKB, null); } /** @@ -143,7 +144,7 @@ public HpccRemoteFileReader(DataPartition dp, FieldDef originalRD, IRecordBuilde * @param recBuilder * the IRecordBuilder used to construct records * @param connectTimeout - * the connection timeout in milliseconds, -1 for default + * the connection timeout in seconds, -1 for default * @param limit * the maximum number of records to read from the provided data partition, -1 specifies no limit * @param createPrefetchThread @@ -157,7 +158,7 @@ public HpccRemoteFileReader(DataPartition dp, FieldDef originalRD, IRecordBuilde */ public HpccRemoteFileReader(DataPartition dp, FieldDef originalRD, IRecordBuilder recBuilder, int connectTimeout, int limit, boolean createPrefetchThread, int readSizeKB, FileReadResumeInfo resumeInfo) throws Exception { - this(dp, originalRD, recBuilder, connectTimeout, limit, true, readSizeKB, resumeInfo, RowServiceInputStream.DEFAULT_SOCKET_OP_TIMEOUT_MS); + this(dp, originalRD, recBuilder, connectTimeout, limit, createPrefetchThread, readSizeKB, resumeInfo, RowServiceInputStream.DEFAULT_SOCKET_OP_TIMEOUT_MS); } /** diff --git a/dfsclient/src/test/java/org/hpccsystems/dfs/client/DFSReadWriteTest.java b/dfsclient/src/test/java/org/hpccsystems/dfs/client/DFSReadWriteTest.java index eb3f2a2fa..9ea4ea0a5 100644 --- a/dfsclient/src/test/java/org/hpccsystems/dfs/client/DFSReadWriteTest.java +++ b/dfsclient/src/test/java/org/hpccsystems/dfs/client/DFSReadWriteTest.java @@ -63,8 +63,8 @@ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DFSReadWriteTest extends BaseRemoteTest { - private static final String[] datasets = { "~benchmark::integer::20kb", "~benchmark::all_types::200kb"}; - private static final int[] expectedCounts = { 1250, 5600 }; + private static final String[] datasets = { "~benchmark::integer::20kb", "~unit_test::all_types::thor", "~unit_test::all_types::xml", "~unit_test::all_types::json", "~unit_test::all_types::csv" }; + private static final int[] expectedCounts = { 1250, 10000, 10000, 10000, 10000, 10000}; private static final Version newProtocolVersion = new Version(8,12,10); @@ -183,6 +183,7 @@ public void integrationReadWriteBackTest() throws Exception HPCCFile file = new HPCCFile(datasets[i], connString, hpccUser, hpccPass); file.setProjectList(""); + System.out.println("Reading dataset: " + datasets[i]); List records = readFile(file, connTO, false); if (records.size() != expectedCounts[i]) { @@ -190,7 +191,8 @@ public void integrationReadWriteBackTest() throws Exception } // Write the dataset back - String copyFileName = datasets[i] + "-copy13"; + String copyFileName = datasets[i] + "-copy"; + System.out.println("Writing dataset: " + copyFileName); writeFile(records, copyFileName, file.getProjectedRecordDefinition(),connTO); // Read and compare to original dataset @@ -203,7 +205,7 @@ public void integrationReadWriteBackTest() throws Exception } //read out a projected layout, confirm that this works - List projectedfields=new ArrayList(); + List projectedfields = new ArrayList(); for (int j=0; j < file.getRecordDefinition().getNumDefs()-1;j++) { projectedfields.add(file.getRecordDefinition().getDef(j).getFieldName()); @@ -211,7 +213,6 @@ public void integrationReadWriteBackTest() throws Exception file=new HPCCFile(copyFileName, connString , hpccUser, hpccPass); - FieldDef recdef=file.getRecordDefinition(); file.setProjectList(String.join(",", projectedfields)); List recs=readFile(file, connTO, false); if (recs.get(0).getNumFields() != file.getRecordDefinition().getNumDefs()-1) diff --git a/dfsclient/src/test/resources/generate-datasets.ecl b/dfsclient/src/test/resources/generate-datasets.ecl index fed129a15..4e333ab9b 100644 --- a/dfsclient/src/test/resources/generate-datasets.ecl +++ b/dfsclient/src/test/resources/generate-datasets.ecl @@ -2,13 +2,12 @@ IMPORT Std; unique_keys := 100000; // Should be less than number of records unique_values := 10212; // Should be less than number of records -dataset_name := '~benchmark::all_types::200KB'; -totalrecs1 := 5600; +totalrecs1 := 10000; childRec := {STRING8 childField1, INTEGER8 childField2, REAL8 childField3}; -rec := {INTEGER8 int8, UNSIGNED8 uint8, INTEGER4 int4, UNSIGNED4 uint4, - INTEGER2 int2, UNSIGNED2 uint2, +rec := { INTEGER8 int8, UNSIGNED8 uint8, INTEGER4 int4, UNSIGNED4 uint4, + INTEGER2 int2, UNSIGNED2 uint2, REAL8 r8, REAL4 r4, DECIMAL16_8 dec16, DECIMAL15_8 dec15, @@ -19,7 +18,7 @@ rec := {INTEGER8 int8, UNSIGNED8 uint8, INTEGER4 int4, UNSIGNED4 uint4, STRING str, VARSTRING varStr, VARSTRING varStr8, - UTF8 utfStr, + UTF8 utfStr, UNICODE8 uni8, UNICODE uni, VARUNICODE varUni, @@ -52,10 +51,65 @@ ds := DATASET(totalrecs1, transform(rec, self.int1Set := [1,2,3]; ), DISTRIBUTED); +dataset_name := '~unit_test::all_types::thor'; IF(~Std.File.FileExists(dataset_name), OUTPUT(ds,,dataset_name,overwrite)); -key_name := '~benchmark::all_types::200KB::key'; -Ptbl := DATASET(dataset_name, {rec,UNSIGNED8 RecPtr {virtual(fileposition)}}, FLAT); +// For the text files there appears to be an issue with reading sets from the datasets +// So, for those file formats create datasets wwith all types except SETs +recWithoutSet := { INTEGER8 int8, UNSIGNED8 uint8, INTEGER4 int4, UNSIGNED4 uint4, + INTEGER2 int2, UNSIGNED2 uint2, + REAL8 r8, REAL4 r4, + DECIMAL16_8 dec16, + DECIMAL15_8 dec15, + UDECIMAL16_8 udec16, + UDECIMAL15_8 udec15, + QSTRING qStr, + STRING8 fixStr8, + STRING str, + VARSTRING varStr, + VARSTRING varStr8, + UTF8 utfStr, + UNICODE8 uni8, + UNICODE uni, + VARUNICODE varUni, + DATASET(childRec) childDataset, + }; +dsWithoutSet := DATASET(totalrecs1, transform(recWithoutSet, + self.int8 := (INTEGER)(random() % unique_keys); + self.uint8 := (INTEGER)(random() % unique_values); + self.int4 := (INTEGER)(random() % unique_values); + self.uint4 := (INTEGER)(random() % unique_values); + self.int2 := (INTEGER)(random() % unique_values); + self.uint2 := (INTEGER)(random() % unique_values); + self.r8 := (REAL)(random() % unique_values); + self.r4 := (REAL)(random() % unique_values); + self.dec16 := (REAL)(random() % unique_values); + self.dec15 := (REAL)(random() % unique_values); + self.udec16 := (REAL)(random() % unique_values); + self.udec15 := (REAL)(random() % unique_values); + self.qStr := (STRING)(random() % unique_values); + self.fixStr8 := (STRING)(random() % unique_values); + self.str := (STRING)(random() % unique_values); + self.varStr := (STRING)(random() % unique_values); + self.varStr8 := (STRING)(random() % unique_values); + self.utfStr := (STRING)(random() % unique_values); + self.uni8 := (STRING)(random() % unique_values); + self.uni := (STRING)(random() % unique_values); + self.varUni := (STRING)(random() % unique_values); + self.childDataset := DATASET([{'field1',2,3},{'field1',2,3}],childRec); + ), DISTRIBUTED); + +xml_dataset_name := '~unit_test::all_types::xml'; +IF(~Std.File.FileExists(xml_dataset_name), OUTPUT(dsWithoutSet,,xml_dataset_name,XML,overwrite)); + +json_dataset_name := '~unit_test::all_types::json'; +IF(~Std.File.FileExists(json_dataset_name), OUTPUT(dsWithoutSet,,json_dataset_name,JSON,overwrite)); + +csv_dataset_name := '~unit_test::all_types::csv'; +IF(~Std.File.FileExists(csv_dataset_name), OUTPUT(dsWithoutSet,,csv_dataset_name,CSV,overwrite)); + +key_name := '~unit_test::all_types::key'; +Ptbl := DATASET('~unit_test::all_types::thor', {rec,UNSIGNED8 RecPtr {virtual(fileposition)}}, FLAT); indexds := INDEX(Ptbl, {int8, uint8, int4, uint4, int2, uint2, udec16, fixStr8, RecPtr},key_name); IF(~Std.File.FileExists(key_name), BUILDINDEX(indexds, overwrite)); diff --git a/wsclient/src/main/java/org/hpccsystems/ws/client/HPCCFileSprayClient.java b/wsclient/src/main/java/org/hpccsystems/ws/client/HPCCFileSprayClient.java index 87d0c5d61..a7283a6cd 100644 --- a/wsclient/src/main/java/org/hpccsystems/ws/client/HPCCFileSprayClient.java +++ b/wsclient/src/main/java/org/hpccsystems/ws/client/HPCCFileSprayClient.java @@ -1004,9 +1004,8 @@ public ProgressResponseWrapper sprayVariable(DelimitedDataOptions options, DropZ if (targetDropZone == null) throw new Exception("TargetDropZone object not available!"); SprayVariable request = new SprayVariable(); - request.setSourceIP(targetDropZone.getNetAddress()); - request.setSourcePath(targetDropZone.getPath() + "/" + sourceFileName); + request.setSourcePath(Utils.ensureTrailingPathSlash(targetDropZone.getPath()) + sourceFileName); request.setDestGroup(destGroup); request.setDestLogicalName(targetFileName); request.setOverwrite(overwrite); @@ -1162,7 +1161,7 @@ public ProgressResponseWrapper sprayXML(DropZoneWrapper targetDropZone, String s request.setDestGroup(destGroup); request.setSourceIP(targetDropZone.getNetAddress()); - request.setSourcePath(targetDropZone.getPath() + "/" + sourceFileName); + request.setSourcePath(Utils.ensureTrailingPathSlash(targetDropZone.getPath()) + sourceFileName); request.setDestLogicalName(targetFileName); request.setOverwrite(overwrite); request.setSourceFormat(format.getValue()); @@ -1318,7 +1317,7 @@ public ProgressResponseWrapper sprayFixed(DropZoneWrapper targetDropZone, String request.setDestGroup(destGroup); request.setSourceRecordSize(recordSize); request.setSourceIP(targetDropZone.getNetAddress()); - request.setSourcePath(targetDropZone.getPath() + "/" + sourceFileName); + request.setSourcePath(Utils.ensureTrailingPathSlash(targetDropZone.getPath()) + sourceFileName); request.setDestLogicalName(targetFileLabel); request.setOverwrite(overwrite); request.setPrefix(prefix); @@ -1488,15 +1487,11 @@ public boolean uploadLargeFile(File uploadFile, DropZoneWrapper dropZone) return false; } - uploadurlbuilder += "&NetAddress=" + dropZone.getNetAddress() + "&Path=" + dropZone.getPath(); + uploadurlbuilder += "&NetAddress=" + dropZone.getNetAddress() + "&Path=" + Utils.ensureTrailingPathSlash(dropZone.getPath()); if (!dropZone.getName().isEmpty()) uploadurlbuilder += "&DropZoneName=" + dropZone.getName(); - String path = dropZone.getPath().trim(); - if (!path.endsWith("/")) - path += "/"; - uploadurlbuilder += "&Path=" + path; uploadurlbuilder += "&OS=" + (dropZone.getLinux().equalsIgnoreCase("true") ? "2" : "1"); uploadurlbuilder += "&rawxml_=1"; WritableByteChannel outchannel = null; diff --git a/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java b/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java index f33d83cf1..df7a56162 100644 --- a/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java +++ b/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java @@ -1061,21 +1061,64 @@ public static DocumentBuilder newSafeXMLDocBuilder() throws ParserConfigurationE return safeXMLDocBuilder; } + /** + * Ensures the given path contains a trailing path delimiter. + * Does not introduce duplicate trailing path delimiter if one already exists. + * Defaults to Linux style separator if the given path either contains a Linux style separator, or the path is empty. + * Strips all trailing white space character + * @param path The path to be postfixed + * @return original path with proper trailing path delimiter + */ public static String ensureTrailingPathSlash(String path) { return ensureTrailingPathSlash(path, (path.contains(Character.toString(LINUX_SEP)) || path.length() == 0) ? LINUX_SEP : WIN_SEP); } + /** + * Ensures the given path contains a trailing path delimiter. + * Does not introduce duplicate trailing path delimiter if one already exists. + * Uses Linux style path separator 'useLinuxSep' == "true", otherwise uses windows style path separator + * Strips all trailing white space character + * @param path path The path to be postfixed + * @param useLinuxSep String, if "true" linux styled path delimiter will be used + * @return original path with proper trailing path delimiter + */ public static String ensureTrailingPathSlash(String path, String useLinuxSep) { return ensureTrailingPathSlash(path, useLinuxSep.equalsIgnoreCase("true") ? LINUX_SEP : WIN_SEP); } + /** + * Ensures the given path contains a trailing path delimiter. + * Does not introduce duplicate trailing path delimiter if one already exists. + * Uses provided 'slash' as trailing path delimiter + * Strips all trailing white space character + * @param path The path to be postfixed + * @param slash The character to append + * @return original path with proper trailing path delimiter + */ public static String ensureTrailingPathSlash(String path, char slash) { + path = trimTrailing(path); + if (path.length() == 0 || path.charAt(path.length()-1) != slash) path = path + slash; return path; } + + /** + * Removes trailing whitespace characters from a string. + * + * @param originalStr the original string from which trailing whitespace should be removed + * @return a new string with the same characters as the original string, minus any trailing whitespace + */ + public static String trimTrailing(String originalStr) + { + int strIndex = originalStr.length()-1; + while(strIndex >= 0 && Character.isWhitespace(originalStr.charAt(strIndex))) + strIndex--; + + return originalStr.substring(0,strIndex+1); + } } diff --git a/wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java b/wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java index 1ff309ebf..eef268e47 100644 --- a/wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java +++ b/wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java @@ -8,59 +8,75 @@ public class UtilsTest { + @Test + public void testEnsureTrailingSlashTrailingWhiteSpace() + { + assertEquals(Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash("")); + assertEquals(Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.LINUX_SEP)+ " ")); + assertEquals(Character.toString(Utils.WIN_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP) + " ")); + assertEquals(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP)+"\t")); + assertEquals("C:\\some\\Path\\", Utils.ensureTrailingPathSlash("C:\\some\\Path ")); + assertEquals("C:\\some\\Path\\", Utils.ensureTrailingPathSlash("C:\\some\\Path\\ ")); + assertEquals("/another/path/", Utils.ensureTrailingPathSlash("/another/path ")); + assertEquals("/another/path/", Utils.ensureTrailingPathSlash("/another/path/\t\t")); + assertEquals("/another/path/", Utils.ensureTrailingPathSlash("/another/path/\n")); + assertEquals("/another/path/", Utils.ensureTrailingPathSlash("/another/path/" + '\u005Cn')); + assertEquals("/another/path/", Utils.ensureTrailingPathSlash("/another/path/ " + '\u005Ct')); + } + @Test public void testEnsureTrailingSlashNoSlashSpecified() { - assertEquals(Utils.ensureTrailingPathSlash(""), Character.toString(Utils.LINUX_SEP)); //no sep in path, default to lin sep - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.LINUX_SEP)), Character.toString(Utils.LINUX_SEP));//no change expected - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP)), Character.toString(Utils.WIN_SEP)); //no change expected - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP)), Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP));//no change expected - assertEquals(Utils.ensureTrailingPathSlash("C:\\some\\Path"), "C:\\some\\Path\\"); - assertEquals(Utils.ensureTrailingPathSlash("C:\\some\\Path\\"), "C:\\some\\Path\\"); - assertEquals(Utils.ensureTrailingPathSlash("/another/path"), "/another/path/"); - assertEquals(Utils.ensureTrailingPathSlash("/another/path/"), "/another/path/"); + assertEquals(Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash("")); //no sep in path, default to lin sep + assertEquals(Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.LINUX_SEP)));//no change expected + assertEquals(Character.toString(Utils.WIN_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP))); //no change expected + assertEquals(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP)));//no change expected + assertEquals("C:\\some\\Path\\", Utils.ensureTrailingPathSlash("C:\\some\\Path")); + assertEquals("C:\\some\\Path\\", Utils.ensureTrailingPathSlash("C:\\some\\Path\\")); + assertEquals("/another/path/", Utils.ensureTrailingPathSlash("/another/path")); + assertEquals("/another/path/", Utils.ensureTrailingPathSlash("/another/path/")); } @Test public void testEnsureTrailingSlashSlashSpecified() { - assertEquals(Utils.ensureTrailingPathSlash("", Utils.LINUX_SEP), Character.toString(Utils.LINUX_SEP)); - assertEquals(Utils.ensureTrailingPathSlash("", Utils.WIN_SEP), Character.toString(Utils.WIN_SEP)); - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.LINUX_SEP), Utils.WIN_SEP), Character.toString(Utils.LINUX_SEP)+Utils.WIN_SEP); - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.LINUX_SEP), Utils.LINUX_SEP), Character.toString(Utils.LINUX_SEP)); - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP), Utils.WIN_SEP), Character.toString(Utils.WIN_SEP)); - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP), Utils.LINUX_SEP), Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP)); - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), Utils.LINUX_SEP), Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP)); - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), Utils.WIN_SEP), Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP)+Character.toString(Utils.WIN_SEP)); - assertEquals(Utils.ensureTrailingPathSlash("C:\\some\\Path", Utils.LINUX_SEP), "C:\\some\\Path\\"+Utils.LINUX_SEP); - assertEquals(Utils.ensureTrailingPathSlash("C:\\some\\Path", Utils.WIN_SEP), "C:\\some\\Path\\"+Utils.WIN_SEP); - assertEquals(Utils.ensureTrailingPathSlash("C:\\some\\Path\\", Utils.LINUX_SEP), "C:\\some\\Path\\" + Utils.LINUX_SEP); - assertEquals(Utils.ensureTrailingPathSlash("C:\\some\\Path\\", Utils.WIN_SEP), "C:\\some\\Path\\"); - assertEquals(Utils.ensureTrailingPathSlash("/another/path", Utils.LINUX_SEP), "/another/path" + Utils.LINUX_SEP); - assertEquals(Utils.ensureTrailingPathSlash("/another/path", Utils.WIN_SEP), "/another/path/"+ Utils.WIN_SEP); - assertEquals(Utils.ensureTrailingPathSlash("/another/path/", Utils.LINUX_SEP), "/another/path/"); - assertEquals(Utils.ensureTrailingPathSlash("/another/path/", Utils.WIN_SEP), "/another/path/"+Utils.WIN_SEP); + assertEquals(Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash("", Utils.LINUX_SEP)); + assertEquals(Character.toString(Utils.WIN_SEP), Utils.ensureTrailingPathSlash("", Utils.WIN_SEP)); + assertEquals(Character.toString(Utils.LINUX_SEP)+Utils.WIN_SEP, Utils.ensureTrailingPathSlash(Character.toString(Utils.LINUX_SEP), Utils.WIN_SEP)); + assertEquals(Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.LINUX_SEP), Utils.LINUX_SEP)); + assertEquals(Character.toString(Utils.WIN_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP), Utils.WIN_SEP)); + assertEquals(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP), Utils.LINUX_SEP)); + assertEquals(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), Utils.LINUX_SEP)); + assertEquals(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP)+Character.toString(Utils.WIN_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), Utils.WIN_SEP)); + assertEquals("C:\\some\\Path\\"+Utils.LINUX_SEP, Utils.ensureTrailingPathSlash("C:\\some\\Path", Utils.LINUX_SEP)); + assertEquals("C:\\some\\Path\\"+Utils.WIN_SEP, Utils.ensureTrailingPathSlash("C:\\some\\Path", Utils.WIN_SEP)); + assertEquals("C:\\some\\Path\\" + Utils.LINUX_SEP, Utils.ensureTrailingPathSlash("C:\\some\\Path\\", Utils.LINUX_SEP)); + assertEquals("C:\\some\\Path\\", Utils.ensureTrailingPathSlash("C:\\some\\Path\\", Utils.WIN_SEP)); + assertEquals("/another/path" + Utils.LINUX_SEP, Utils.ensureTrailingPathSlash("/another/path", Utils.LINUX_SEP)); + assertEquals("/another/path/"+ Utils.WIN_SEP, Utils.ensureTrailingPathSlash("/another/path", Utils.WIN_SEP)); + assertEquals("/another/path/", Utils.ensureTrailingPathSlash("/another/path/", Utils.LINUX_SEP)); + assertEquals("/another/path/"+Utils.WIN_SEP, Utils.ensureTrailingPathSlash("/another/path/", Utils.WIN_SEP)); } @Test public void testEnsureTrailingSlashUseLinuxBoolTest() { - assertEquals(Utils.ensureTrailingPathSlash("", "true"), Character.toString(Utils.LINUX_SEP)); - assertEquals(Utils.ensureTrailingPathSlash("", "false"), Character.toString(Utils.WIN_SEP)); - assertEquals(Utils.ensureTrailingPathSlash("", "xyz"), Character.toString(Utils.WIN_SEP)); - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.LINUX_SEP), "false"), Character.toString(Utils.LINUX_SEP)+Utils.WIN_SEP); - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.LINUX_SEP), "true"), Character.toString(Utils.LINUX_SEP)); - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP), "false"), Character.toString(Utils.WIN_SEP)); - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP), "true"), Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP)); - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), "true"), Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP)); - assertEquals(Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), "false"), Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP)+Character.toString(Utils.WIN_SEP)); - assertEquals(Utils.ensureTrailingPathSlash("C:\\some\\Path", "true"), "C:\\some\\Path\\"+Utils.LINUX_SEP); - assertEquals(Utils.ensureTrailingPathSlash("C:\\some\\Path", "false"), "C:\\some\\Path\\"+Utils.WIN_SEP); - assertEquals(Utils.ensureTrailingPathSlash("C:\\some\\Path\\", "true"), "C:\\some\\Path\\" + Utils.LINUX_SEP); - assertEquals(Utils.ensureTrailingPathSlash("C:\\some\\Path\\", "false"), "C:\\some\\Path\\"); - assertEquals(Utils.ensureTrailingPathSlash("/another/path", "TRUE"), "/another/path" + Utils.LINUX_SEP); - assertEquals(Utils.ensureTrailingPathSlash("/another/path", "FALSE"), "/another/path/"+ Utils.WIN_SEP); - assertEquals(Utils.ensureTrailingPathSlash("/another/path/", "TrUe"), "/another/path/"); - assertEquals(Utils.ensureTrailingPathSlash("/another/path/", "FalSe"), "/another/path/"+Utils.WIN_SEP); + assertEquals(Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash("", "true")); + assertEquals(Character.toString(Utils.WIN_SEP), Utils.ensureTrailingPathSlash("", "false")); + assertEquals(Character.toString(Utils.WIN_SEP), Utils.ensureTrailingPathSlash("", "xyz")); + assertEquals(Character.toString(Utils.LINUX_SEP)+Utils.WIN_SEP, Utils.ensureTrailingPathSlash(Character.toString(Utils.LINUX_SEP), "false")); + assertEquals(Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.LINUX_SEP), "true")); + assertEquals(Character.toString(Utils.WIN_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP), "false")); + assertEquals(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP), "true")); + assertEquals(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), "true")); + assertEquals(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP)+Character.toString(Utils.WIN_SEP), Utils.ensureTrailingPathSlash(Character.toString(Utils.WIN_SEP)+Character.toString(Utils.LINUX_SEP), "false")); + assertEquals("C:\\some\\Path\\"+Utils.LINUX_SEP, Utils.ensureTrailingPathSlash("C:\\some\\Path", "true")); + assertEquals("C:\\some\\Path\\"+Utils.WIN_SEP, Utils.ensureTrailingPathSlash("C:\\some\\Path", "false")); + assertEquals("C:\\some\\Path\\" + Utils.LINUX_SEP, Utils.ensureTrailingPathSlash("C:\\some\\Path\\", "true")); + assertEquals("C:\\some\\Path\\", Utils.ensureTrailingPathSlash("C:\\some\\Path\\", "false")); + assertEquals("/another/path" + Utils.LINUX_SEP, Utils.ensureTrailingPathSlash("/another/path", "TRUE")); + assertEquals("/another/path/"+ Utils.WIN_SEP, Utils.ensureTrailingPathSlash("/another/path", "FALSE")); + assertEquals("/another/path/", Utils.ensureTrailingPathSlash("/another/path/", "TrUe")); + assertEquals("/another/path/"+Utils.WIN_SEP, Utils.ensureTrailingPathSlash("/another/path/", "FalSe")); } }