AMImageConfigurationEntryParser { public AMImageConfigurationEntry parse(String s) { if (Validator.isNull(s)) { throw new IllegalArgumentException( "Invalid image adaptive media configuration: " + s); } String[] fields = _fieldSeparatorPattern.split(s); if ((fields.length != 4) && (fields.length != 5)) { throw new IllegalArgumentException( "Invalid image adaptive media configuration: " + s); } String name = fields[0]; name = _http.decodeURL(name); String description = fields[1]; description = _http.decodeURL(description); String uuid = fields[2]; if (Validator.isNull(name) || Validator.isNull(uuid)) { throw new IllegalArgumentException( "Invalid image adaptive media configuration: " + s); } String[] attributes = _attributeSeparatorPattern.split(fields[3]); Map<String, String> properties = new HashMap<>(); for (String attribute : attributes) { String[] keyValuePair = _keyValueSeparatorPattern.split(attribute); properties.put(keyValuePair[0], keyValuePair[1]); } boolean enabled = true; if (fields.length == 5) { String disabledAttribute = fields[4]; Matcher matcher = _disabledSeparatorPattern.matcher( disabledAttribute); if (!matcher.matches()) { throw new IllegalArgumentException( "Invalid image adaptive media configuration: " + s); } enabled = GetterUtil.getBoolean(matcher.group(1)); } return new AMImageConfigurationEntryImpl( name, description, uuid, properties, enabled); } AMImageConfigurationEntryParser(); protected  AMImageConfigurationEntryParser(Http http); String getConfigurationString(
		AMImageConfigurationEntry amImageConfigurationEntry); AMImageConfigurationEntry parse(String s);  }
@Test public void testDisabledValidString() { AMImageConfigurationEntry amImageConfigurationEntry = _amImageConfigurationEntryParser.parse( "test:desc:12345:max-height=100;max-width=200:enabled=false"); Assert.assertEquals("test", amImageConfigurationEntry.getName()); Assert.assertEquals("desc", amImageConfigurationEntry.getDescription()); Assert.assertEquals("12345", amImageConfigurationEntry.getUUID()); Assert.assertFalse(amImageConfigurationEntry.isEnabled()); Map<String, String> properties = amImageConfigurationEntry.getProperties(); Assert.assertEquals("100", properties.get("max-height")); Assert.assertEquals("200", properties.get("max-width")); Assert.assertEquals(properties.toString(), 2, properties.size()); }
@Test(expected = IllegalArgumentException.class) public void testEmptyAttributes() { _amImageConfigurationEntryParser.parse("test:desc:12345:"); }
@Test public void testEmptyDescription() { _amImageConfigurationEntryParser.parse( "test::12345:max-height=100;max-width=200"); }
@Test(expected = IllegalArgumentException.class) public void testEmptyName() { _amImageConfigurationEntryParser.parse( ":desc:12345:max-height=100;max-width=200"); }
@Test(expected = IllegalArgumentException.class) public void testEmptyString() { _amImageConfigurationEntryParser.parse(""); }
@Test(expected = IllegalArgumentException.class) public void testEmptyUUID() { _amImageConfigurationEntryParser.parse( "test:desc::max-height=100;max-width=200"); }
@Test public void testEncodedDescription() { when( URLCodec.encodeURL(Mockito.eq("desc:;")) ).thenReturn( "desc%3A%3B" ); when( _http.decodeURL(Mockito.eq("desc%3A%3B")) ).thenReturn( "desc:;" ); AMImageConfigurationEntry amImageConfigurationEntry = _amImageConfigurationEntryParser.parse( "test:desc%3A%3B:12345:max-height=100;max-width=200"); Assert.assertEquals("test", amImageConfigurationEntry.getName()); Assert.assertEquals( "desc:;", amImageConfigurationEntry.getDescription()); Assert.assertEquals("12345", amImageConfigurationEntry.getUUID()); Map<String, String> properties = amImageConfigurationEntry.getProperties(); Assert.assertEquals("100", properties.get("max-height")); Assert.assertEquals("200", properties.get("max-width")); Assert.assertEquals(properties.toString(), 2, properties.size()); }
@Test public void testEncodedName() { when( URLCodec.encodeURL(Mockito.eq("test:;")) ).thenReturn( "test%3A%3B" ); when( _http.decodeURL(Mockito.eq("test%3A%3B")) ).thenReturn( "test:;" ); AMImageConfigurationEntry amImageConfigurationEntry = _amImageConfigurationEntryParser.parse( "test%3A%3B:desc:12345:max-height=100;max-width=200"); Assert.assertEquals("test:;", amImageConfigurationEntry.getName()); Assert.assertEquals("desc", amImageConfigurationEntry.getDescription()); Assert.assertEquals("12345", amImageConfigurationEntry.getUUID()); Map<String, String> properties = amImageConfigurationEntry.getProperties(); Assert.assertEquals("100", properties.get("max-height")); Assert.assertEquals("200", properties.get("max-width")); Assert.assertEquals(properties.toString(), 2, properties.size()); }
@Test(expected = IllegalArgumentException.class) public void testInvalidEnabledAttribute() { _amImageConfigurationEntryParser.parse( "test:desc:12345:max-height=100;max-width=200:disabled=true"); }
@Test(expected = IllegalArgumentException.class) public void testMissingAttributesField() { _amImageConfigurationEntryParser.parse("test:desc:12345"); }
@Test(expected = IllegalArgumentException.class) public void testMissingDescription() { _amImageConfigurationEntryParser.parse( "12345:max-height=100;max-width=200"); }
@Test public void testMissingEnabledAttributeDefaultsEnabled() { AMImageConfigurationEntry amImageConfigurationEntry = _amImageConfigurationEntryParser.parse( "test:desc:12345:max-height=100;max-width=200"); Assert.assertEquals("test", amImageConfigurationEntry.getName()); Assert.assertEquals("12345", amImageConfigurationEntry.getUUID()); Assert.assertEquals("desc", amImageConfigurationEntry.getDescription()); Assert.assertTrue(amImageConfigurationEntry.isEnabled()); Map<String, String> properties = amImageConfigurationEntry.getProperties(); Assert.assertEquals("100", properties.get("max-height")); Assert.assertEquals("200", properties.get("max-width")); Assert.assertEquals(properties.toString(), 2, properties.size()); }
@Test(expected = IllegalArgumentException.class) public void testMissingName() { _amImageConfigurationEntryParser.parse( "12345:desc:max-height=100;max-width=200"); }
@Test(expected = IllegalArgumentException.class) public void testMissingUUID() { _amImageConfigurationEntryParser.parse( "test:desc:max-height=100;max-width=200"); }
@Test(expected = IllegalArgumentException.class) public void testNullString() { _amImageConfigurationEntryParser.parse(null); }
@Test public void testValidString() { AMImageConfigurationEntry amImageConfigurationEntry = _amImageConfigurationEntryParser.parse( "test:desc:12345:max-height=100;max-width=200:enabled=true"); Assert.assertEquals("test", amImageConfigurationEntry.getName()); Assert.assertEquals("desc", amImageConfigurationEntry.getDescription()); Assert.assertEquals("12345", amImageConfigurationEntry.getUUID()); Assert.assertTrue(amImageConfigurationEntry.isEnabled()); Map<String, String> properties = amImageConfigurationEntry.getProperties(); Assert.assertEquals("100", properties.get("max-height")); Assert.assertEquals("200", properties.get("max-width")); Assert.assertEquals(properties.toString(), 2, properties.size()); }