Example #1
0
  /**
   * Add a new environment and one EnvironmentProperty for each defined property
   *
   * @param application
   * @param environmentName
   * @return
   * @throws ValidationException
   */
  @Override
  public Environment addEnvironment(Application application, String environmentName)
      throws ValidationException {
    Application app = applicationDAO.findById(application.getId());

    if (app == null) {
      String[] inserts = new String[] {application.getId().toString()};
      throw validationException(INVALID_APPLICATION_MESSAGE, inserts);
    }

    for (Environment e : app.getEnvironmentList()) {
      if (e.getName().equals(environmentName)) {
        String[] inserts = new String[] {environmentName, app.getName()};
        throw validationException(DUPLICATE_ENVIRONMENT_MESSAGE, inserts);
      }
    }

    Environment e = new Environment();
    e.setName(environmentName);
    app.addEnvironment(e);
    e = environmentDAO.create(e);

    for (Property p : app.getPropertyList()) {
      EnvironmentProperty ep = new EnvironmentProperty();
      ep.setEnvironment(e);
      ep.setProperty(p);
      environmentPropertyDAO.create(ep);
    }

    return e;
  }
Example #2
0
  @Test
  public void testIsNetworkFederated() {

    ProductRelease productRelease = new ProductRelease("product", "2.0");
    List<ProductRelease> productReleases = new ArrayList<ProductRelease>();
    productReleases.add(productRelease);

    Tier tier = new Tier("name1", new Integer(1), new Integer(5), new Integer(1), productReleases);
    tier.setRegion("region1");
    tier.addNetwork(new Network("uno", VDC, REGION));

    Tier tier2 = new Tier("name2", new Integer(1), new Integer(5), new Integer(1), productReleases);
    tier2.setRegion("region2");
    tier2.addNetwork(new Network("uno", VDC, REGION));

    Set<Tier> tiers = new HashSet<Tier>();
    tiers.add(tier);
    tiers.add(tier2);

    Environment envResult = new Environment("environemntName", tiers, "description", "ORG", VDC);
    envResult.setName("environemntName");
    envResult.setTiers(tiers);

    boolean result = envResult.isNetworkFederated();
    assertEquals(result, true);
    assertEquals(envResult.getDescription(), "description");
    assertEquals(envResult.getVdc(), VDC);
    assertEquals(envResult.getOrg(), "ORG");
  }
Example #3
0
  @Test
  public void testCreateEnvironment() throws Exception {

    ProductRelease productRelease = new ProductRelease("product", "2.0");
    List<ProductRelease> productReleases = new ArrayList<ProductRelease>();
    productReleases.add(productRelease);

    Tier tier = new Tier();
    tier.setInitialNumberInstances(new Integer(1));
    tier.setMaximumNumberInstances(new Integer(5));
    tier.setMinimumNumberInstances(new Integer(1));
    tier.setName("tierName");
    tier.setProductReleases(productReleases);
    tier.setFlavour("3");
    tier.setFloatingip("true");
    tier.setImage("image");

    Tier tier2 =
        new Tier(
            "name",
            new Integer(1),
            new Integer(1),
            new Integer(1),
            productReleases,
            "4",
            "image2",
            "icone2");

    Set<Tier> tiers = new HashSet<Tier>();
    tiers.add(tier);
    tiers.add(tier2);

    Environment envResult = new Environment();
    envResult.setName("environemntName");
    envResult.addTier(tier2);
    envResult.addTier(tier);
    // envResult.setTiers(tiers);

    EnvironmentDto envDto = envResult.toDto();
    Environment env2 = envDto.fromDto();
    assertEquals(env2, envResult);

    assertEquals(envResult.getTiers().size(), 2);
  }
Example #4
0
  @Test
  public void testIsDifferentRegions() {
    Tier tier = new Tier("name1", new Integer(1), new Integer(5), new Integer(1), null);
    tier.setRegion("region1");

    Tier tier2 = new Tier("name2", new Integer(1), new Integer(5), new Integer(1), null);
    tier.setRegion("region2");

    Set<Tier> tiers = new HashSet<Tier>();
    tiers.add(tier);
    tiers.add(tier2);

    Environment env = new Environment();

    env.setName("environmentName");
    env.addTier(tier);
    env.addTier(tier2);

    boolean result = env.isDifferentRegions();
    assertEquals(result, true);
  }