From 86f4d1c66c8b541465ff769e5d951305c41c715c Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Tue, 12 Sep 2017 16:51:08 -0500 Subject: [PATCH] HADOOP-14843. Improve FsPermission symbolic parsing unit test coverage. Contributed by Bharat Viswanadham --- .../fs/permission/TestFsPermission.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/permission/TestFsPermission.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/permission/TestFsPermission.java index a22985de50..afddf80a25 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/permission/TestFsPermission.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/permission/TestFsPermission.java @@ -138,6 +138,63 @@ public void testFsPermission() { } } + @Test + public void testFsSymbolicConstructorWithNormalInput() { + + // Test cases for symbolic representation + + //Added both Octal and short representation to show with sticky bit + + assertEquals(777, new FsPermission("+rwx").toOctal()); + assertEquals(0777, new FsPermission("+rwx").toShort()); + + assertEquals(444, new FsPermission("+r").toOctal()); + assertEquals(0444, new FsPermission("+r").toShort()); + + assertEquals(222, new FsPermission("+w").toOctal()); + assertEquals(0222, new FsPermission("+w").toShort()); + + assertEquals(111, new FsPermission("+x").toOctal()); + assertEquals(0111, new FsPermission("+x").toShort()); + + assertEquals(666, new FsPermission("+rw").toOctal()); + assertEquals(0666, new FsPermission("+rw").toShort()); + + assertEquals(333, new FsPermission("+wx").toOctal()); + assertEquals(0333, new FsPermission("+wx").toShort()); + + assertEquals(555, new FsPermission("+rx").toOctal()); + assertEquals(0555, new FsPermission("+rx").toShort()); + + + // Test case is to test with repeated values in mode. + // Repeated value in input will be ignored as duplicate. + + assertEquals(666, new FsPermission("+rwr").toOctal()); + assertEquals(0666, new FsPermission("+rwr").toShort()); + + assertEquals(000, new FsPermission("-rwr").toOctal()); + assertEquals(0000, new FsPermission("-rwr").toShort()); + + assertEquals(1666, new FsPermission("+rwrt").toOctal()); + assertEquals(01666, new FsPermission("+rwrt").toShort()); + + assertEquals(000, new FsPermission("-rwrt").toOctal()); + assertEquals(0000, new FsPermission("-rwrt").toShort()); + + assertEquals(1777, new FsPermission("+rwxt").toOctal()); + assertEquals(01777, new FsPermission("+rwxt").toShort()); + + + assertEquals(000, new FsPermission("-rt").toOctal()); + assertEquals(0000, new FsPermission("-rt").toShort()); + + assertEquals(000, new FsPermission("-rwx").toOctal()); + assertEquals(0000, new FsPermission("-rwx").toShort()); + + } + + @Test public void testSymbolicPermission() { for (int i = 0; i < SYMBOLIC.length; ++i) {