@Test public void testSimpleSubstitution() throws Exception { entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); String pattern = "mykey1=${mykey1},mykey2=${mykey2}"; String result = DownloadSubstituters.substitute( pattern, ImmutableMap.of("mykey1", "myval1", "mykey2", "myval2")); assertEquals(result, "mykey1=myval1,mykey2=myval2"); }
@Test public void testSubstitutionUsesOverrides() throws Exception { entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); String pattern = "version=${version},mykey1=${mykey1}"; BasicDownloadRequirement req = new BasicDownloadRequirement( driver, ImmutableMap.of("version", "overriddenversion", "mykey1", "myval1")); String result = DownloadSubstituters.substitute(req, pattern); assertEquals(result, "version=overriddenversion,mykey1=myval1"); }
@Test public void testSubstitutionIncludesDefaultSubs() throws Exception { entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); String pattern = "version=${version},type=${type},simpletype=${simpletype}"; BasicDownloadRequirement req = new BasicDownloadRequirement(driver); String result = DownloadSubstituters.substitute(req, pattern); assertEquals( result, String.format( "version=%s,type=%s,simpletype=%s", "myversion", TestEntity.class.getName(), TestEntity.class.getSimpleName())); }
@Test public void testSubstituter() throws Exception { entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); String baseurl = "version=${version},type=${type},simpletype=${simpletype}"; Map<String, Object> subs = DownloadSubstituters.getBasicEntitySubstitutions(driver); DownloadTargets result = DownloadSubstituters.substituter(Functions.constant(baseurl), Functions.constant(subs)) .apply(new BasicDownloadRequirement(driver)); String expected = String.format( "version=%s,type=%s,simpletype=%s", "myversion", TestEntity.class.getName(), TestEntity.class.getSimpleName()); assertEquals(result.getPrimaryLocations(), ImmutableList.of(expected)); }