public DownloadTargets apply(DownloadRequirement req) {
    Boolean enabled = config.getConfig(CLOUDSOFT_REPO_ENABLED);
    String baseUrl = config.getConfig(CLOUDSOFT_REPO_URL);
    String url = String.format(CLOUDSOFT_REPO_URL_PATTERN, baseUrl);

    if (enabled) {
      Map<String, ?> subs = DownloadSubstituters.getBasicSubstitutions(req);
      String result = DownloadSubstituters.substitute(url, subs);
      return BasicDownloadTargets.builder().addPrimary(result).build();

    } else {
      return BasicDownloadTargets.empty();
    }
  }
 @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));
 }
 @Test
 public void testSubstitutionUsesDriverBean() throws Exception {
   String entityid = entity.getId();
   String pattern = "id=${driver.entity.id}";
   BasicDownloadRequirement req = new BasicDownloadRequirement(driver);
   String result = DownloadSubstituters.substitute(req, pattern);
   assertEquals(result, String.format("id=%s", entityid));
 }
 @Test
 public void testSubstitutionDoesMultipleMatches() throws Exception {
   String simpleType = TestEntity.class.getSimpleName();
   String pattern = "simpletype=${simpletype},simpletype=${simpletype}";
   BasicDownloadRequirement req = new BasicDownloadRequirement(driver);
   String result = DownloadSubstituters.substitute(req, pattern);
   assertEquals(result, String.format("simpletype=%s,simpletype=%s", simpleType, simpleType));
 }
 @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 testThrowsIfUnmatchedSubstitutions() throws Exception {
   String pattern = "nothere=${nothere}";
   BasicDownloadRequirement req = new BasicDownloadRequirement(driver);
   try {
     String result = DownloadSubstituters.substitute(req, pattern);
     fail("Should have failed, but got " + result);
   } catch (IllegalArgumentException e) {
     if (!e.toString().contains("${nothere}")) throw e;
   }
 }
 @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()));
 }