PropertyUtils { public static String replacePropertiesInString(String line, Resource propertyResource) { Properties properties = new Properties(); try { properties.load(propertyResource.getInputStream()); } catch (IOException e) { return line; } return replacePropertiesInString(line, properties); } private  PropertyUtils(); static String replacePropertiesInString(String line, Resource propertyResource); static String replacePropertiesInString(final String line, Properties properties);  }
@Test public void testPropertyReplacementSingleProperty() { Properties props = new Properties(); props.put("test.name", "MyTest"); String content = "This test has the name @test.name@!"; String result = PropertyUtils.replacePropertiesInString(content, props); Assert.assertEquals("This test has the name MyTest!", result); }
@Test public void testPropertyReplacementStartingWithProperty() { Properties props = new Properties(); props.put("test.name", "MyTest"); String content = "@test.name@ is the test's name!"; String result = PropertyUtils.replacePropertiesInString(content, props); Assert.assertEquals("MyTest is the test's name!", result); }
@Test public void testPropertyReplacementMultipleProperties() { Properties props = new Properties(); props.put("test.name", "MyTest"); props.put("test.author", "Mickey Mouse"); String content = "This test has the name @test.name@ and its author is @test.author@"; String result = PropertyUtils.replacePropertiesInString(content, props); Assert.assertEquals("This test has the name MyTest and its author is Mickey Mouse", result); }
@Test(expectedExceptions = {CitrusRuntimeException.class}) public void testPropertyReplacementUnknownProperty() { Properties props = new Properties(); props.put("test.name", "MyTest"); String content = "This test has the name @test.name@ and its author is @test.author@"; PropertyUtils.replacePropertiesInString(content, props); }
@Test public void testPropertyMarkerEscaping() { Properties props = new Properties(); props.put("test.name", "MyTest"); props.put("test.author", "Mickey Mouse (mail:mickey@mouse.de)"); props.put("test.coauthor", "Donald Duck (mail:donald@duck.de)"); String content = "This test has the name @test.name@ and its author is @test.author@ and @test.coauthor@"; String result = PropertyUtils.replacePropertiesInString(content, props); Assert.assertEquals("This test has the name MyTest and its author is Mickey Mouse (mail:mickey@mouse.de) and Donald Duck (mail:donald@duck.de)", result); }
@Test public void testPropertyMarkerEscapingInContent() { Properties props = new Properties(); props.put("test.name", "MyTest"); props.put("test.author", "Mickey Mouse"); String content = "This \\@test\\@ has the name @test.name@ and its author is @test.author@"; String result = PropertyUtils.replacePropertiesInString(content, props); Assert.assertEquals("This @test@ has the name MyTest and its author is Mickey Mouse", result); }
@Test public void testPropertyMarkerEscapingInDirectNeighbourhood() { Properties props = new Properties(); props.put("test.name", "MyTest"); props.put("test.author", "Mickey Mouse"); String content = "This \\@test\\@ has the name \\@@test.name@\\@ and its author is @test.author@"; String result = PropertyUtils.replacePropertiesInString(content, props); Assert.assertEquals("This @test@ has the name @MyTest@ and its author is Mickey Mouse", result); }