-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/w 10673625 #193
base: main
Are you sure you want to change the base?
Fix/w 10673625 #193
Changes from all commits
61ccac9
3f0381f
f48a61f
5e33dbe
1293584
0cbb1b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,22 +6,22 @@ | |
*/ | ||
package org.mule.test.extension.file.common; | ||
|
||
import static org.mule.extension.file.common.api.util.UriUtils.createUri; | ||
import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assume.assumeTrue; | ||
import static org.mule.extension.file.common.api.util.UriUtils.createUri; | ||
|
||
import org.mule.extension.file.common.api.AbstractFileAttributes; | ||
|
||
import java.net.URI; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.junit.Test; | ||
|
||
public class AbstractFileAttributesTestCase { | ||
|
||
private static final String TEST_FILENAME = "test.txt"; | ||
private static String path; | ||
|
||
@Test | ||
|
@@ -135,13 +135,117 @@ public void bothConstructorAssignEqualFileNamesForParentDirectoryWithTrailingSla | |
assertFileName(path); | ||
} | ||
|
||
@Test | ||
public void bothConstructorAssignAnEmptyBasePath() { | ||
ConcreteFileAttributes uriAttributes = new ConcreteFileAttributes(createUri("", TEST_FILENAME)); | ||
assertThat(uriAttributes.getPath(), equalTo(TEST_FILENAME)); | ||
} | ||
|
||
@Test | ||
public void bothConstructorAssignAnEmptyFilePath() { | ||
path = "/test"; | ||
ConcreteFileAttributes uriAttributes = new ConcreteFileAttributes(createUri(path, "")); | ||
assertThat(uriAttributes.getPath(), equalTo(path)); | ||
} | ||
|
||
@Test | ||
public void bothConstructorAssignAnEmptyFilePathWithoutDash() { | ||
ConcreteFileAttributes uriAttributes = new ConcreteFileAttributes(createUri(TEST_FILENAME, "")); | ||
assertThat(uriAttributes.getPath(), equalTo(TEST_FILENAME)); | ||
} | ||
|
||
private void assertFileName(String path) { | ||
ConcreteFileAttributes pathAttributes = new ConcreteFileAttributes(Paths.get(path)); | ||
ConcreteFileAttributes uriAttributes = new ConcreteFileAttributes(createUri(path)); | ||
|
||
assertThat(pathAttributes.getName(), equalTo(uriAttributes.getName())); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAssignInSpecificFolderWithSeparator2() { | ||
ConcreteFileAttributes pathAttributes = new ConcreteFileAttributes(Paths.get("/myFile.txt")); | ||
// Basepath parameter will be ignored when tne filepath is absolute (when it start with slash) | ||
ConcreteFileAttributes uriAttributes = new ConcreteFileAttributes(createUri("/root/", "/myFile.txt")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in this case I would expect the result as "/root/myfile.txt", the condition to check if the path is absolute checks only that the filePath started with a "/" but that doesn't mean that the path is absolute right? in Unix I would expect a "~/" to determine that the path is absolute and in Windows I would expect a "X:" |
||
assertThat(pathAttributes.getName(), equalTo(uriAttributes.getName())); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathInHome() { | ||
assertBasePathAndFileName("~", "myFile.txt"); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAssignInCurrent() { | ||
assertBasePathAndFileName(".", "myFile.txt"); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAssignInSpecificFolder() { | ||
assertBasePathAndFileName("/root", "myFile.txt"); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAssignInSpecificFolderWithSeparator() { | ||
assertBasePathAndFileName("/root/", "myFile.txt"); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAssignInSpecificFolderWithoutSeparators() { | ||
assertBasePathAndFileName("root", "myFile.txt"); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAssignInSpecificFoldersWithoutSeparators() { | ||
assertBasePathAndFileName("root/test", "myFile.txt"); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAssignInRoot() { | ||
assertBasePathAndFileName("/", "myFile.txt"); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAssignInParent() { | ||
assertBasePathAndFileName("..", "myFile.txt"); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAssignInParentSpeficFolder() { | ||
assertBasePathAndFileName("/root", "../myFile.txt"); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAEmpty() { | ||
assertBasePathAndFileName("", "myFile.txt"); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAEmptyAndSeparator() { | ||
assertBasePathAndFileName("", "/myFile.txt"); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAEmptyAndRelativePathFile() { | ||
assertBasePathAndFileName("", "~/myFile.txt"); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathAEmptyAndFilePathEmpty() { | ||
assertBasePathAndFileName("", ""); | ||
} | ||
|
||
@Test | ||
public void bothConstructorWithBasePathWithSpaceAndFilePathEmpty() { | ||
assertBasePathAndFileName(" ", ""); | ||
} | ||
|
||
private void assertBasePathAndFileName(String basePath, String filePath) { | ||
ConcreteFileAttributes pathAttributes = new ConcreteFileAttributes(Paths.get(basePath, filePath)); | ||
ConcreteFileAttributes uriAttributes = new ConcreteFileAttributes(createUri(basePath, filePath)); | ||
assertThat(pathAttributes.getName(), equalTo(uriAttributes.getName())); | ||
assertThat(pathAttributes.getPath(), equalTo(uriAttributes.getPath())); | ||
} | ||
|
||
private class ConcreteFileAttributes extends AbstractFileAttributes { | ||
|
||
public ConcreteFileAttributes(Path path) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what will happen if the filePath is not an absolute path and the basePath is empty? will the URI constructor throw an exception?