ParameterParser { public EnumSet<CreateFlag> createFlag() { String cf = ""; if (param(CreateFlagParam.NAME) != null) { QueryStringDecoder decoder = new QueryStringDecoder( param(CreateFlagParam.NAME), StandardCharsets.UTF_8); cf = decoder.path(); } return new CreateFlagParam(cf).getValue(); } ParameterParser(QueryStringDecoder decoder, Configuration conf); boolean createParent(); EnumSet<CreateFlag> createFlag();  }
@Test public void testCreateFlag() { final String path = "/test1?createflag=append,sync_block"; Configuration conf = new Configuration(); QueryStringDecoder decoder = new QueryStringDecoder( WebHdfsHandler.WEBHDFS_PREFIX + path); ParameterParser testParser = new ParameterParser(decoder, conf); EnumSet<CreateFlag> actual = testParser.createFlag(); EnumSet<CreateFlag> expected = EnumSet.of(CreateFlag.APPEND, CreateFlag.SYNC_BLOCK); Assert.assertEquals(expected.toString(), actual.toString()); final String path1 = "/test1?createflag=append"; decoder = new QueryStringDecoder( WebHdfsHandler.WEBHDFS_PREFIX + path1); testParser = new ParameterParser(decoder, conf); actual = testParser.createFlag(); expected = EnumSet.of(CreateFlag.APPEND); Assert.assertEquals(expected, actual); final String path2 = "/test1"; decoder = new QueryStringDecoder( WebHdfsHandler.WEBHDFS_PREFIX + path2); testParser = new ParameterParser(decoder, conf); actual = testParser.createFlag(); Assert.assertEquals(0, actual.size()); final String path3 = "/test1?createflag=create,overwrite"; decoder = new QueryStringDecoder( WebHdfsHandler.WEBHDFS_PREFIX + path3); testParser = new ParameterParser(decoder, conf); actual = testParser.createFlag(); expected = EnumSet.of(CreateFlag.CREATE, CreateFlag .OVERWRITE); Assert.assertEquals(expected.toString(), actual.toString()); final String path4 = "/test1?createflag="; decoder = new QueryStringDecoder( WebHdfsHandler.WEBHDFS_PREFIX + path4); testParser = new ParameterParser(decoder, conf); actual = testParser.createFlag(); Assert.assertEquals(0, actual.size()); try { final String path5 = "/test1?createflag=overwrite,"; decoder = new QueryStringDecoder( WebHdfsHandler.WEBHDFS_PREFIX + path5); testParser = new ParameterParser(decoder, conf); actual = testParser.createFlag(); fail("It should throw Illegal Argument Exception"); } catch (Exception e) { GenericTestUtils .assertExceptionContains("No enum constant", e); } try { final String path6 = "/test1?createflag=,"; decoder = new QueryStringDecoder( WebHdfsHandler.WEBHDFS_PREFIX + path6); testParser = new ParameterParser(decoder, conf); actual = testParser.createFlag(); fail("It should throw Illegal Argument Exception"); } catch (Exception e) { GenericTestUtils .assertExceptionContains("No enum constant", e); } }