コード例 #1
0
  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();
    }
  }
コード例 #2
0
 @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));
 }
コード例 #3
0
 @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));
 }
コード例 #4
0
 @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));
 }
コード例 #5
0
 @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");
 }
コード例 #6
0
 @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");
 }
コード例 #7
0
 @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;
   }
 }
コード例 #8
0
 @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()));
 }