@@ -311,12 +311,67 @@ public void testRenameNotFoundBlobToEmptyRoot() throws Exception {
311311 *
312312 * @throws Exception if an error occurs during test execution
313313 */
314- @ Test ( expected = IOException . class )
315- public void testRenameBlobToDstWithColonInPath () throws Exception {
314+ @ Test
315+ public void testRenameBlobToDstWithColonInSourcePath () throws Exception {
316316 AzureBlobFileSystem fs = getFileSystem ();
317317 assumeBlobServiceType ();
318+ fs .create (new Path ("/src:/file" ));
319+ Assertions .assertThat (
320+ fs .rename (new Path ("/src:" ),
321+ new Path ("/dst" ))
322+ ).isTrue ();
323+ }
324+
325+ /**
326+ * Tests renaming a source path to a destination path that contains a colon in the path.
327+ * This verifies that the rename operation handles paths with special characters like a colon.
328+ *
329+ * The test creates a source directory and renames it to a destination path that includes a colon,
330+ * ensuring that the operation succeeds without errors.
331+ *
332+ * @throws Exception if an error occurs during test execution
333+ */
334+ @ Test
335+ public void testRenameWithColonInDestinationPath () throws Exception {
336+ AzureBlobFileSystem fs = getFileSystem ();
318337 fs .create (new Path ("/src" ));
319- fs .rename (new Path ("/src" ), new Path ("/dst:file" ));
338+ Assertions .assertThat (
339+ fs .rename (new Path ("/src" ),
340+ new Path ("/dst:" ))
341+ ).isTrue ();
342+ }
343+
344+ @ Test
345+ public void testRenameWithColonInSourcePath () throws Exception {
346+ AzureBlobFileSystem fs = getFileSystem ();
347+ String sourceDirectory = "/src:" ;
348+ String destinationDirectory = "/dst" ;
349+ String fileName = "file" ;
350+ fs .create (new Path (sourceDirectory , fileName ));
351+ fs .create (new Path (sourceDirectory + "/Test:" , fileName ));
352+ // Rename from source to destination
353+ Assertions .assertThat (
354+ fs .rename (new Path (sourceDirectory ),
355+ new Path (destinationDirectory ))
356+ ).isTrue ();
357+ Assertions .assertThat (
358+ fs .exists (new Path (sourceDirectory , fileName )))
359+ .isFalse ();
360+ Assertions .assertThat (
361+ fs .exists (new Path (destinationDirectory , fileName )))
362+ .isTrue ();
363+
364+ // Rename from destination to source
365+ Assertions .assertThat (
366+ fs .rename (new Path (destinationDirectory ),
367+ new Path (sourceDirectory ))
368+ ).isTrue ();
369+ Assertions .assertThat (
370+ fs .exists (new Path (sourceDirectory , fileName )))
371+ .isTrue ();
372+ Assertions .assertThat (
373+ fs .exists (new Path (destinationDirectory , fileName )))
374+ .isFalse ();
320375 }
321376
322377 /**
@@ -1883,64 +1938,64 @@ public void testRenameDeleteFailureInBetween() throws Exception {
18831938 }
18841939 }
18851940
1886- // /**
1887- // * Tests renaming a file or directory when the destination path contains
1888- // * a colon (":"). The test ensures that:
1889- // * - The source directory exists before the rename.
1890- // * - The file is successfully renamed to the destination path.
1891- // * - The old source directory no longer exists after the rename.
1892- // * - The new destination directory exists after the rename.
1893- // *
1894- // * @throws Exception if an error occurs during file system operations
1895- // */
1896- // @Test
1897- // public void testRenameWhenDestinationPathContainsColon() throws Exception {
1898- // AzureBlobFileSystem fs = getFileSystem();
1899- // fs.setWorkingDirectory(new Path(ROOT_PATH));
1900- // String fileName = "file";
1901- // Path src = new Path("/test1/");
1902- // Path dst = new Path("/test1:/");
1903- //
1904- // // Create the file
1905- // fs.create(new Path(src, fileName));
1906- //
1907- // // Perform the rename operation and validate the results
1908- // performRenameAndValidate(fs, src, dst, fileName);
1909- // }
1910-
1911- // /**
1912- // * Performs the rename operation and validates the existence of the directories and files.
1913- // *
1914- // * @param fs the AzureBlobFileSystem instance
1915- // * @param src the source path to be renamed
1916- // * @param dst the destination path for the rename
1917- // * @param fileName the name of the file to be renamed
1918- // */
1919- // private void performRenameAndValidate(AzureBlobFileSystem fs, Path src, Path dst, String fileName)
1920- // throws IOException {
1921- // // Assert the source directory exists
1922- // Assertions.assertThat(fs.exists(src))
1923- // .describedAs("Old directory should exist before rename")
1924- // .isTrue();
1925- //
1926- // // Perform rename
1927- // fs.rename(src, dst);
1928- //
1929- // // Assert the destination directory and file exist after rename
1930- // Assertions.assertThat(fs.exists(new Path(dst, fileName)))
1931- // .describedAs("Rename should be successful")
1932- // .isTrue();
1933- //
1934- // // Assert the source directory no longer exists
1935- // Assertions.assertThat(fs.exists(src))
1936- // .describedAs("Old directory should not exist")
1937- // .isFalse();
1938- //
1939- // // Assert the new destination directory exists
1940- // Assertions.assertThat(fs.exists(dst))
1941- // .describedAs("New directory should exist")
1942- // .isTrue();
1943- // }
1941+ /**
1942+ * Tests renaming a file or directory when the destination path contains
1943+ * a colon (":"). The test ensures that:
1944+ * - The source directory exists before the rename.
1945+ * - The file is successfully renamed to the destination path.
1946+ * - The old source directory no longer exists after the rename.
1947+ * - The new destination directory exists after the rename.
1948+ *
1949+ * @throws Exception if an error occurs during file system operations
1950+ */
1951+ @ Test
1952+ public void testRenameWhenDestinationPathContainsColon () throws Exception {
1953+ AzureBlobFileSystem fs = getFileSystem ();
1954+ fs .setWorkingDirectory (new Path (ROOT_PATH ));
1955+ String fileName = "file" ;
1956+ Path src = new Path ("/test1/" );
1957+ Path dst = new Path ("/test1:/" );
1958+
1959+ // Create the file
1960+ fs .create (new Path (src , fileName ));
1961+
1962+ // Perform the rename operation and validate the results
1963+ performRenameAndValidate (fs , src , dst , fileName );
1964+ }
1965+
1966+ /**
1967+ * Performs the rename operation and validates the existence of the directories and files.
1968+ *
1969+ * @param fs the AzureBlobFileSystem instance
1970+ * @param src the source path to be renamed
1971+ * @param dst the destination path for the rename
1972+ * @param fileName the name of the file to be renamed
1973+ */
1974+ private void performRenameAndValidate (AzureBlobFileSystem fs , Path src , Path dst , String fileName )
1975+ throws IOException {
1976+ // Assert the source directory exists
1977+ Assertions .assertThat (fs .exists (src ))
1978+ .describedAs ("Old directory should exist before rename" )
1979+ .isTrue ();
1980+
1981+ // Perform rename
1982+ fs .rename (src , dst );
1983+
1984+ // Assert the destination directory and file exist after rename
1985+ Assertions .assertThat (fs .exists (new Path (dst , fileName )))
1986+ .describedAs ("Rename should be successful" )
1987+ .isTrue ();
1988+
1989+ // Assert the source directory no longer exists
1990+ Assertions .assertThat (fs .exists (src ))
1991+ .describedAs ("Old directory should not exist" )
1992+ .isFalse ();
1993+
1994+ // Assert the new destination directory exists
1995+ Assertions .assertThat (fs .exists (dst ))
1996+ .describedAs ("New directory should exist" )
1997+ .isTrue ();
1998+ }
19441999
19452000 /**
19462001 * Tests the behavior of the atomic rename key for the root folder
0 commit comments