Ejemplo n.º 1
0
  @DirtiesContext
  @Test
  public void testCountDietElement1() {

    try {
      {
        String infra = "infrastructure/3D-5N-3G-3L.xml";
        InputStream inputStreamInfra = getClass().getClassLoader().getResourceAsStream(infra);
        String outputString = StringUtils.streamToString(inputStreamInfra);

        godiet.getXmlHelpService().registerInfrastructureElements(outputString);
      }

      {
        // Load Diet scenarii
        String testCaseFile = "diet/1MA-3LA-10SED.xml";
        InputStream inputStream = getClass().getClassLoader().getResourceAsStream(testCaseFile);
        String outputString = StringUtils.streamToString(inputStream);

        godiet.getXmlHelpService().registerDietElements(outputString);
      }

      InfrastructureManager platform = rm.getInfrastructureModel();
      // if (platform.getClusters().size() != 0)
      // Assert.fail();
      if (platform.getDomains().size() != 4) Assert.fail();
      // if (platform.getFrontends().size() != 0)
      // Assert.fail();

      if (platform.getLinks().size() != 0) Assert.fail();
      if (platform.getNodes().size() != 5) Assert.fail(platform.getNodes().size() + " != 5");

      DietManager diet = rm.getDietModel();
      if (diet.getMasterAgents().size() != 1) Assert.fail();
      if (diet.getLocalAgents().size() != 3) Assert.fail();
      if (diet.getSeds().size() != 10) Assert.fail();

      // check if all Diet are pluged on physical resources
      for (SoftwareInterface<MasterAgent> ma : diet.getMasterAgents()) {
        if (ma.getPluggedOn() == null) Assert.fail();
      }
      for (SoftwareInterface<LocalAgent> la : diet.getLocalAgents()) {
        if (la.getPluggedOn() == null) Assert.fail();
      }

      for (SoftwareInterface<Sed> sed : diet.getSeds()) {
        if (sed.getPluggedOn() == null) Assert.fail();
      }

    } catch (Exception e) {
      Assert.fail(e.getMessage());
      log.error("", e);
    }
  }
Ejemplo n.º 2
0
  @Before
  public void init() throws IncubateException {

    {
      // Loading configuration
      String configurationFile = "configuration/configuration.xml";

      InputStream inputStream = getClass().getClassLoader().getResourceAsStream(configurationFile);

      try {
        String outputString = StringUtils.streamToString(inputStream);

        godiet.getXmlHelpService().registerConfigurationFile(outputString);
      } catch (IOException e) {
        log.error("", e);
        Assert.fail(e.getMessage());
      } catch (XMLParseException e) {
        log.error("", e);
        Assert.fail(e.getMessage());
      } catch (GoDietConfigurationException e) {
        log.error("", e);
        Assert.fail(e.getMessage());
      }
    }
  }
Ejemplo n.º 3
0
  @DirtiesContext
  @Test
  public void testCommand() {
    List<String> testCaseFiles =
        Arrays.asList(
            new String[] {
              "diet/2MA-1LA-6SED.xml",
              // "diet/1MA-3LA-10SED.xml",
              // "diet/1MA-3SED.xml"
            });
    String infraCaseFiles = "infrastructure/3D-5N-3G-3L.xml";

    InputStream inputStreamPlatform =
        getClass().getClassLoader().getResourceAsStream(infraCaseFiles);
    try {
      String outputString = StringUtils.streamToString(inputStreamPlatform);

      godiet.getXmlHelpService().registerInfrastructureElements(outputString);
    } catch (IOException e) {
      log.error("", e);
      Assert.fail(e.getMessage());
    } catch (XMLParseException e) {
      log.error("", e);
      Assert.fail(e.getMessage());
    } catch (ResourceAddException e) {
      log.error("", e);
      Assert.fail(e.getMessage());
    } catch (GraphDataException e) {
      log.error("", e);
      Assert.fail(e.getMessage());
    }

    for (String testCaseFile : testCaseFiles) {
      // Retry with the same config

      try {

        InputStream inputStream = getClass().getClassLoader().getResourceAsStream(testCaseFile);
        String outputString = StringUtils.streamToString(inputStream);

        godiet.getXmlHelpService().registerDietElements(outputString);
      } catch (Exception e) {
        log.error("Test fail for file: " + testCaseFile, e);
        Assert.fail();
      }
    }
  }
Ejemplo n.º 4
0
  @Test
  public void testFileNotFound() {
    String testCaseFile = "filefromMars.xml";
    InputStream inputStream = getClass().getClassLoader().getResourceAsStream(testCaseFile);
    XmlScannerJaxbImpl scanner = new XmlScannerJaxbImpl();

    try {
      String outputString = StringUtils.streamToString(inputStream);

      scanner.buildDietModel(outputString);
    } catch (IOException e) {
      log.error("", e);
      Assert.fail();
    } catch (XMLParseException e) {
      // Cool
    }
  }