Esempio n. 1
0
  /** @throws DSLException . */
  @Test
  public void testBasicExtendParsing() throws DSLException {

    final File testParsingBaseDslFile =
        new File(TEST_PARSING_RESOURCE_PATH + "test_parsing_base-service.groovy");
    final File testParsingBaseWorkDir = new File(TEST_PARSING_RESOURCE_PATH);
    final Service baseService =
        ServiceReader.getServiceFromFile(testParsingBaseDslFile, testParsingBaseWorkDir)
            .getService();
    Assert.assertFalse(baseService.getName().equals("test parsing extend"));
    final ServiceLifecycle baseLifecycle = baseService.getLifecycle();
    Assert.assertFalse(baseLifecycle.getInit().equals("test_parsing_extend_install.groovy"));
    Assert.assertNull(baseLifecycle.getStop());

    final File testParsingExtendDslFile =
        new File(TEST_PARSING_RESOURCE_PATH + "test_parsing_extend-service.groovy");
    final File testParsingExtendWorkDir = new File(TEST_PARSING_RESOURCE_PATH);
    final Service service =
        ServiceReader.getServiceFromFile(testParsingExtendDslFile, testParsingExtendWorkDir)
            .getService();
    Assert.assertEquals("test parsing extend", service.getName());
    final ServiceLifecycle lifecycle = service.getLifecycle();
    Assert.assertEquals(ExecutableDSLEntryType.STRING, lifecycle.getInit().getEntryType());
    Assert.assertEquals(
        "test_parsing_extend_install.groovy",
        ((StringExecutableEntry) lifecycle.getInit()).getCommand());
    Assert.assertNotNull(lifecycle.getStart());
    Assert.assertNotNull(lifecycle.getPostStart());
    Assert.assertNotNull(lifecycle.getPreStop());
    Assert.assertNotNull(lifecycle.getStop());
    Assert.assertEquals(1, service.getExtendedServicesPaths().size());
    Assert.assertEquals(
        new File(TEST_PARSING_RESOURCE_PATH, "test_parsing_base-service.groovy").getAbsolutePath(),
        service.getExtendedServicesPaths().getFirst());
  }
 @Test
 public void testMissingTemplate() throws IOException, DSLException, PackagingException {
   Cloud cloud = ServiceReader.readCloud(new File(CLOUD_FILE_PATH));
   Service service = ServiceReader.readService(new File(NOT_EXIST_TEMPLATE_SERVICE_GROOVY));
   testValidator(
       cloud,
       service,
       service.getCompute().getTemplate(),
       CloudifyMessageKeys.MISSING_TEMPLATE.getName());
 }
  public void testService(
      String serviceFolderPath, String overrideServiceName, final int timeoutMins)
      throws IOException, InterruptedException, RestException, PackagingException, DSLException {
    LogUtils.log("Reading Service from file : " + serviceFolderPath);
    Service service = ServiceReader.readService(new File(serviceFolderPath));
    LogUtils.log("Succesfully read Service : " + service);

    serviceName = service.getName();

    if (overrideServiceName != null) {
      LogUtils.log("Overriding service name with " + overrideServiceName);
      serviceName = overrideServiceName;
    }

    installServiceAndWait(serviceFolderPath, serviceName, timeoutMins);
    String restUrl = getRestUrl();
    GSRestClient client =
        new GSRestClient("", "", new URL(restUrl), PlatformVersion.getVersionNumber());
    Map<String, Object> entriesJsonMap =
        client.getAdminData("ProcessingUnits/Names/default." + serviceName + "/Status");
    String serviceStatus = (String) entriesJsonMap.get(STATUS_PROPERTY);

    AssertUtils.assertTrue("service is not intact", serviceStatus.equalsIgnoreCase("INTACT"));

    uninstallServiceAndWait(serviceName);
  }
Esempio n. 4
0
  @Test
  public void testServiceWithDSLLogger() throws Exception {
    final Logger logger = Logger.getLogger(BaseDslScript.class.getName());
    final DSLLoggerHandler handler = new DSLLoggerHandler();
    logger.addHandler(handler);

    final File dir = new File(TEST_PARSING_RESOURCE_BASE + "logger");
    final Service service = ServiceReader.getServiceFromDirectory(dir).getService();
    Assert.assertNotNull(service);

    Assert.assertTrue(
        "Println logger not found", handler.getMessages().contains("println logger call"));
    Assert.assertTrue(
        "Print logger not found", handler.getMessages().contains("print logger call"));
    Assert.assertTrue(
        "Class println not found", handler.getMessages().contains("Test Class println"));
    Assert.assertTrue("Class print not found", handler.getMessages().contains("Test Class print"));

    Assert.assertFalse(
        "preInstall event message appeared before expected",
        handler.getMessages().contains("This is the preInstall event"));

    final ExecutableDSLEntry preInstall = service.getLifecycle().getPreInstall();
    final ClosureExecutableEntry preInstallClosureEntry = (ClosureExecutableEntry) preInstall;
    preInstallClosureEntry.getCommand().call();

    Assert.assertTrue(
        "preInstall event message not found",
        handler.getMessages().contains("This is the preInstall event"));
  }
Esempio n. 5
0
 @Test
 public void testStorageDetailsParsing() throws Exception {
   final File serviceFile = new File(TEST_PARSING_RESOURCE_PATH3 + "simpleStorage-service.groovy");
   final Service service = ServiceReader.getServiceFromFile(serviceFile);
   Assert.assertNotNull(service.getStorage());
   Assert.assertNotNull(service.getStorage().getTemplate());
   Assert.assertNotNull(service.getStorage().getTemplate().equals("SMALL_BLOCK"));
 }
Esempio n. 6
0
  /** @throws Exception . */
  @Test
  public void testExternalScalingRules() throws Exception {
    final File dir = new File(TEST_PARSING_RESOURCE_PATH2 + "loadScalingRules");

    final Service service = ServiceReader.getServiceFromDirectory(dir).getService();

    Assert.assertTrue(service.getScalingRules().size() > 0);
  }
 @Test
 public void minConfigedGroovy() throws Exception {
   final File cassandraDslFile =
       new File(CORRUPTED_RESOURCES_PATH + "cassandra_bare_essentials-service.groovy");
   final File cassandraWorkDir = new File(CORRUPTED_RESOURCES_PATH);
   final Service service =
       ServiceReader.getServiceFromFile(cassandraDslFile, cassandraWorkDir).getService();
   assertNotNull(service);
   ServiceTestUtil.validateName(service, nameInGroovy);
 }
Esempio n. 8
0
 /**
  * *********** Pack a service recipe folder into a zip file.
  *
  * @param recipeDirOrFile the recipe directory or recipe file.
  * @return the packed file.
  * @throws IOException .
  * @throws PackagingException .
  * @throws DSLException .
  */
 public static File pack(final File recipeDirOrFile)
     throws IOException, PackagingException, DSLException {
   // Locate recipe file
   final File recipeFile =
       recipeDirOrFile.isDirectory()
           ? DSLReader.findDefaultDSLFile(DSLReader.SERVICE_DSL_FILE_NAME_SUFFIX, recipeDirOrFile)
           : recipeDirOrFile;
   // Parse recipe into service
   final Service service = ServiceReader.readService(recipeFile);
   return Packager.pack(recipeFile, service);
 }
Esempio n. 9
0
  @Test
  public void testServiceWithMapMerge() throws Exception {
    final File serviceFile =
        new File(TEST_PARSING_AMP_MERGE_RESOURCE_PATH3 + "/mapMerge/b/b-service.groovy");
    final Service service = ServiceReader.getServiceFromFile(serviceFile);

    Assert.assertNotNull(service);
    Assert.assertNotNull(service.getLifecycle());
    Assert.assertNotNull(service.getCustomCommands());
    Assert.assertEquals(2, service.getCustomCommands().size());
  }
 @Test
 public void uiOmmitedConfigGroovy() throws Exception {
   final File cassandraDslFile =
       new File(CORRUPTED_RESOURCES_PATH + "cassandra_UI_ommited-service.groovy");
   final File cassandraWorkDir = new File(CORRUPTED_RESOURCES_PATH);
   final Service service =
       ServiceReader.getServiceFromFile(cassandraDslFile, cassandraWorkDir).getService();
   assertNotNull(service);
   assertNull(service.getUserInterface());
   ServiceTestUtil.validateName(service, nameInGroovy);
   ServiceTestUtil.validateIcon(service, CORRUPTED_RESOURCES_PATH);
 }
Esempio n. 11
0
  /** @throws Exception . */
  @Test
  public void testLocationAwareParsing() throws Exception {
    final File testParsingBaseDslFile =
        new File(TEST_PARSING_RESOURCE_PATH + "test_location-aware-service.groovy");
    final File testParsingBaseWorkDir = new File(TEST_PARSING_RESOURCE_PATH);
    final Service service =
        ServiceReader.getServiceFromFile(testParsingBaseDslFile, testParsingBaseWorkDir)
            .getService();

    Assert.assertTrue(
        "service.isLocationAware() returned false even though locationAware property is set to true",
        service.isLocationAware());
  }
Esempio n. 12
0
 @Test
 public void testBasicExtendIllegalNestedPropertyLocation() {
   final File testParsingExtendDslFile =
       new File(TEST_PARSING_RESOURCE_PATH + "test_parsing_extend_illegal_nested-service.groovy");
   final File testParsingExtendWorkDir = new File(TEST_PARSING_RESOURCE_PATH);
   try {
     ServiceReader.getServiceFromFile(testParsingExtendDslFile, testParsingExtendWorkDir)
         .getService();
     Assert.fail("No exception thrown while extend resides in illegal place");
   } catch (final Exception e) {
     // ignore
   }
 }
Esempio n. 13
0
  @Test
  public void testServiceWithMapOverride() throws Exception {
    final File serviceFile =
        new File(TEST_PARSING_AMP_MERGE_RESOURCE_PATH3 + "/mapOverride/b/b-service.groovy");
    final Service service = ServiceReader.getServiceFromFile(serviceFile);

    Assert.assertNotNull(service);
    Assert.assertNotNull(service.getLifecycle());
    Assert.assertNotNull(service.getCustomCommands());
    Assert.assertEquals(1, service.getCustomCommands().size());
    Assert.assertTrue(service.getCustomCommands().containsKey("cmdA"));
    Assert.assertTrue(service.getCustomCommands().get("cmdA") == null);
  }
Esempio n. 14
0
 /** @throws DSLException . */
 @Test
 public void testDuplicateServicePropertyParsing() throws DSLException {
   final File testParsingBaseDslFile =
       new File(
           TEST_PARSING_RESOURCE_PATH
               + "test_parsing_on_duplicate_property_in_service_class-service.groovy");
   final File testParsingBaseWorkDir = new File(TEST_PARSING_RESOURCE_PATH);
   try {
     ServiceReader.getServiceFromFile(testParsingBaseDslFile, testParsingBaseWorkDir).getService();
   } catch (final IllegalArgumentException e) {
     System.out.println("Test passed. found duplication: " + e.getMessage());
   }
 }
Esempio n. 15
0
  @Test
  public void testServiceWithGrab() throws Exception {
    final File serviceFile =
        new File(TEST_PARSING_RESOURCE_PATH3 + "serviceWithGrab-service.groovy");
    final File serviceDir = serviceFile.getParentFile();

    final Service service = ServiceReader.getServiceFromFile(serviceFile);

    Assert.assertNotNull(service);
    Assert.assertNotNull(service.getLifecycle());
    // check that the @grab annotation worked.
    Assert.assertEquals("Tomcat", service.getName());
  }
Esempio n. 16
0
  @Test
  public void testInvalidProperties() {

    final File serviceDir = new File(TEST_PARSING_RESOURCE_BASE + "invalidProperties");

    try {
      Service service = ServiceReader.getServiceFromDirectory(serviceDir).getService();
      System.out.println(service);
      System.out.println("retries: " + service.getRetries());
      Assert.fail("Expected parsing to fail");
    } catch (Exception e) {
      Assert.assertTrue("Invalid error message", e.getMessage().contains("Error converting from"));
    }
  }
 @Test
 public void nameFieldCorruptedGroovy() {
   final File cassandraDslFile =
       new File(CORRUPTED_RESOURCES_PATH + "cassandra_name_field_corrupted-service.groovy");
   final File cassandraWorkDir = new File(CORRUPTED_RESOURCES_PATH);
   try {
     final Service service =
         ServiceReader.getServiceFromFile(cassandraDslFile, cassandraWorkDir).getService();
     assertTrue("No exception was thrown due to Name field corruption", false);
   } catch (final Throwable t) {
     // getServiceFromFile should throw something informative due to corruption
     assertTrue(
         "Throwable isn't informative enought", t.getMessage().toLowerCase().contains("nae"));
   }
 }
Esempio n. 18
0
  private boolean isNotHAManagementSpace() throws IOException, DSLException {
    if (cloudFileName != null && !cloudFileName.trim().isEmpty()) {
      File cloudFile = new File(cloudFileName);

      final Cloud cloud = ServiceReader.readCloud(cloudFile);
      if (cloud != null) {
        if (cloud.getProvider() != null) {
          final int numberOfManagementMachines =
              cloud.getProvider().getNumberOfManagementMachines();
          return numberOfManagementMachines < 2;
        }
      }
    }
    return true;
  }
Esempio n. 19
0
  @Test
  public void testStopDetectionWithScript() {

    final File serviceFile =
        new File(TEST_PARSING_RESOURCE_BASE + "misc/stopDetectionScript-service.groovy");

    try {
      ServiceReader.getServiceFromFile(serviceFile);
      Assert.fail("Expected parsing to fail");
    } catch (PackagingException e) {
      Assert.assertTrue(
          "Unexpected error message: " + e.getMessage(),
          e.getMessage().contains("The stop detection field only supports execution of closures"));
    }
  }
Esempio n. 20
0
 /** @throws DSLException . */
 @Test
 public void testPropertyInCustomCommand() throws DSLException {
   final File testParsingExtendDslFile =
       new File(TEST_PARSING_RESOURCE_PATH + "test_property_in_custom_command-service.groovy");
   final File testParsingExtendWorkDir = new File(TEST_PARSING_RESOURCE_PATH);
   final Service service =
       ServiceReader.getServiceFromFile(testParsingExtendDslFile, testParsingExtendWorkDir)
           .getService();
   final Closure<?> customCommand =
       ((ClosureExecutableEntry) service.getCustomCommands().get("custom_command")).getCommand();
   final String[] params = new String[2];
   params[0] = "name";
   params[1] = "port";
   customCommand.call((Object[]) params);
   customCommand.call((Object[]) params);
 }
Esempio n. 21
0
  /**
   * @throws DSLException .
   * @throws UnknownHostException .
   */
  @Test
  public void testFeaturesParsing() throws DSLException, UnknownHostException {
    final File testParsingBaseDslFile =
        new File(TEST_PARSING_RESOURCE_PATH + "test_features-service.groovy");
    final File testParsingBaseWorkDir = new File(TEST_PARSING_RESOURCE_PATH);
    final Service service =
        ServiceReader.getServiceFromFile(testParsingBaseDslFile, testParsingBaseWorkDir)
            .getService();
    Assert.assertEquals("test features", service.getName());
    Assert.assertEquals(
        "http://" + InetAddress.getLocalHost().getHostName() + ":8080", service.getUrl());
    final ServiceLifecycle lifecycle = service.getLifecycle();

    Assert.assertNotNull(lifecycle.getStart());
    Assert.assertNotNull(lifecycle.getPostStart());
    Assert.assertNotNull(lifecycle.getPreStop());
  }
Esempio n. 22
0
  /** @throws Exception . */
  @Test
  public void testNoLocatorsParsing() throws Exception {
    final File testParsingBaseDslFile =
        new File(TEST_PARSING_RESOURCE_PATH + "test_no_locators_statement-service.groovy");
    final File testParsingBaseWorkDir = new File(TEST_PARSING_RESOURCE_PATH);
    final Service service =
        ServiceReader.getServiceFromFile(testParsingBaseDslFile, testParsingBaseWorkDir)
            .getService();

    Assert.assertNotNull("Lifecycle should not be null", service.getLifecycle());
    Assert.assertNotNull("Lifecycle should not be null", service.getLifecycle().getLocator());
    final Object result =
        ((ClosureExecutableEntry) service.getLifecycle().getLocator()).getCommand().call();
    Assert.assertNotNull("locators result should not be null", result);
    final List<Long> list = (List<Long>) result;
    Assert.assertEquals("Expected empty list", 0, list.size());
  }
Esempio n. 23
0
  /**
   * @throws DSLException .
   * @throws UnknownHostException .
   */
  @Test
  public void testDebugParsing() throws DSLException, UnknownHostException {
    final File testDebugPath = new File(TEST_PARSING_DEBUG);

    final Service service = ServiceReader.getServiceFromDirectory(testDebugPath).getService();

    // Assert.assertEquals("test features", service.getName());
    // Assert.assertEquals("http://"
    // + InetAddress.getLocalHost().getHostName() + ":8080",
    // service.getUrl());
    // final ServiceLifecycle lifecycle = service.getLifecycle();
    //
    // Assert.assertNotNull(lifecycle.getStart());
    // Assert.assertNotNull(lifecycle.getPostStart());
    // Assert.assertNotNull(lifecycle.getPreStop());
    // System.out.println(service);
  }
Esempio n. 24
0
 /** @throws DSLException . */
 @Test
 public void testBasicParsing() throws DSLException {
   final File testParsingBaseDslFile =
       new File(TEST_PARSING_RESOURCE_PATH + "test_parsing_base-service.groovy");
   final File testParsingBaseWorkDir = new File(TEST_PARSING_RESOURCE_PATH);
   final Service service =
       ServiceReader.getServiceFromFile(testParsingBaseDslFile, testParsingBaseWorkDir)
           .getService();
   Assert.assertEquals("test parsing base", service.getName());
   final ServiceLifecycle lifecycle = service.getLifecycle();
   Assert.assertEquals(ExecutableDSLEntryType.STRING, lifecycle.getInit().getEntryType());
   Assert.assertEquals(
       "test_parsing_base_install.groovy",
       ((StringExecutableEntry) lifecycle.getInit()).getCommand());
   Assert.assertNotNull(lifecycle.getStart());
   Assert.assertNotNull(lifecycle.getPostStart());
   Assert.assertNotNull(lifecycle.getPreStop());
 }
Esempio n. 25
0
  @Test
  public void testCloudWithOverridesFile()
      throws IllegalAccessException, InvocationTargetException, NoSuchMethodException,
          DSLException {

    Cloud cloud = ServiceReader.readCloudFromDirectory(EC2_CLOUD_WITH_FILE_PATH);
    // overriden props
    Assert.assertEquals("OverridesTestUser", cloud.getUser().getUser());
    Assert.assertEquals("OverridesTestApiKey", cloud.getUser().getApiKey());
    Assert.assertEquals(
        "OverridesTestKeyPair",
        (String)
            cloud.getCloudCompute().getTemplates().get("SMALL_LINUX").getOptions().get("keyPair"));
    Assert.assertEquals(
        "OverridesTestImageId",
        cloud.getCloudCompute().getTemplates().get("SMALL_LINUX").getImageId());

    // not overrides, taken from .properties file
    Assert.assertEquals(
        "TestKeyFile.pem", cloud.getCloudCompute().getTemplates().get("SMALL_LINUX").getKeyFile());
  }
Esempio n. 26
0
  @Test
  public void testCloudWithOverridesScript() throws DSLException, IOException {

    Cloud cloud =
        ServiceReader.readCloudFromDirectory(
            EC2_CLOUD_WITH_SCRIPT_PATH,
            FileUtils.readFileToString(new File(EC2_CLOUD_WITH_FILE_OVERRIDES_PATH)));
    // overriden props
    Assert.assertEquals("OverridesTestUser", cloud.getUser().getUser());
    Assert.assertEquals("OverridesTestApiKey", cloud.getUser().getApiKey());
    Assert.assertEquals(
        "OverridesTestKeyPair",
        (String)
            cloud.getCloudCompute().getTemplates().get("SMALL_LINUX").getOptions().get("keyPair"));
    Assert.assertEquals(
        "OverridesTestImageId",
        cloud.getCloudCompute().getTemplates().get("SMALL_LINUX").getImageId());

    // not overrides, taken from .properties file
    Assert.assertEquals(
        "TestKeyFile.pem", cloud.getCloudCompute().getTemplates().get("SMALL_LINUX").getKeyFile());
  }
Esempio n. 27
0
  private static File createZippedPu(
      final Service service, final File puFolderToZip, final File recipeFile)
      throws IOException, PackagingException {
    logger.finer("trying to zip " + puFolderToZip.getAbsolutePath());
    final String serviceName =
        service.getName() != null ? service.getName() : recipeFile.getParentFile().getName();

    // create a temp dir under the system temp dir
    final File tmpFile = File.createTempFile("ServicePackage", null);
    tmpFile.delete();
    tmpFile.mkdir();

    final File zipFile = new File(tmpFile, serviceName + ".zip");

    // files will be deleted in reverse order
    tmpFile.deleteOnExit();
    zipFile.deleteOnExit();

    ServiceReader.validateFolderSize(puFolderToZip, service.getMaxJarSize());
    ZipUtils.zip(puFolderToZip, zipFile);
    logger.finer("zipped folder successfully to " + zipFile.getAbsolutePath());
    return zipFile;
  }
Esempio n. 28
0
  /**
   * Unzips a given file.
   *
   * @param inputFile The zip file to extract
   * @return The new folder, containing the extracted content of the zip file
   * @throws IOException Reporting a failure to extract the zipped file or close it afterwards
   */
  private static File unzipFile(final File inputFile) throws IOException {

    ZipFile zipFile = null;
    try {
      final File baseDir = TestRecipe.createTempDir();
      zipFile = new ZipFile(inputFile);
      final Enumeration<? extends ZipEntry> entries = zipFile.entries();

      while (entries.hasMoreElements()) {
        final ZipEntry entry = entries.nextElement();

        if (entry.isDirectory()) {

          logger.fine("Extracting directory: " + entry.getName());
          final File dir = new File(baseDir, entry.getName());
          dir.mkdir();
          continue;
        }

        logger.finer("Extracting file: " + entry.getName());
        final File file = new File(baseDir, entry.getName());
        file.getParentFile().mkdirs();
        ServiceReader.copyInputStream(
            zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(file)));
      }
      return baseDir;

    } finally {
      if (zipFile != null) {
        try {
          zipFile.close();
        } catch (final IOException e) {
          logger.log(Level.SEVERE, "Failed to close zip file after unzipping zip contents", e);
        }
      }
    }
  }
Esempio n. 29
0
 /**
  * Verifies the service configuration is valid.
  *
  * @param serviceFolder The Folder holding the service configuration files
  * @throws CLIException Reporting a failure to find or parse the configuration files
  */
 private void isServiceLifecycleNotNull(final File serviceFolder) throws CLIException {
   Service service;
   try {
     final File serviceFileDir = new File(serviceFolder, "ext");
     service =
         ServiceReader.getServiceFromDirectory(
                 serviceFileDir, CloudifyConstants.DEFAULT_APPLICATION_NAME)
             .getService();
     if (service.getLifecycle() == null) {
       throw new CLIException(getFormattedMessage("test_recipe_service_lifecycle_missing"));
     }
   } catch (final FileNotFoundException e) {
     logger.log(Level.SEVERE, "Service configuration file not found " + e.getMessage(), e);
     throw new CLIException("Failed to locate service configuration file. " + e.getMessage(), e);
   } catch (final PackagingException e) {
     logger.log(Level.SEVERE, "Packaging failed: " + e.getMessage(), e);
     e.printStackTrace();
     throw new CLIException("Packaging failed: " + e.getMessage(), e);
   } catch (final DSLException e) {
     logger.log(Level.SEVERE, "DSL Parsing failed: " + e.getMessage(), e);
     e.printStackTrace();
     throw new CLIException("Packaging failed: " + e.getMessage(), e);
   }
 }
Esempio n. 30
0
  /**
   * @throws DSLException .
   * @throws UnknownHostException .
   */
  @Test
  public void testAutoScalingParsing() throws DSLException, UnknownHostException {
    final File testParsingBaseDslFile =
        new File(TEST_PARSING_RESOURCE_PATH + "test_parsing_autoscaling-service.groovy");
    final File testParsingBaseWorkDir = new File(TEST_PARSING_RESOURCE_PATH);
    final Service service =
        ServiceReader.getServiceFromFile(testParsingBaseDslFile, testParsingBaseWorkDir)
            .getService();
    Assert.assertTrue(service.getMinAllowedInstances() > 1);
    Assert.assertTrue(service.getNumInstances() >= service.getMinAllowedInstances());
    Assert.assertTrue(service.getMaxAllowedInstances() >= service.getNumInstances());
    Assert.assertEquals(1, service.getScaleInCooldownInSeconds());
    Assert.assertEquals(1, service.getScaleOutCooldownInSeconds());
    Assert.assertEquals(1, service.getScaleCooldownInSeconds());
    Assert.assertNotNull(service.getSamplingPeriodInSeconds());

    Assert.assertEquals("scalingRules", service.getName());

    final List<ServiceStatisticsDetails> serviceStatistics = service.getServiceStatistics();
    Assert.assertEquals(1, serviceStatistics.size());
    Assert.assertNotNull(serviceStatistics.get(0));
    final String servicestatisticsName = serviceStatistics.get(0).getName();
    Assert.assertNotNull(serviceStatistics.get(0).getMetric());
    Assert.assertNotNull(serviceStatistics.get(0).getInstancesStatistics());
    Assert.assertNotNull(serviceStatistics.get(0).getTimeStatistics());
    Assert.assertNotNull(serviceStatistics.get(0).getMovingTimeRangeInSeconds());

    final List<PerInstanceStatisticsDetails> perInstanceStatistics =
        service.getPerInstanceStatistics();
    Assert.assertEquals(1, perInstanceStatistics.size());
    Assert.assertNotNull(perInstanceStatistics.get(0));
    Assert.assertNotNull(perInstanceStatistics.get(0).getMetric());
    Assert.assertNotNull(perInstanceStatistics.get(0).getInstancesStatistics());
    Assert.assertNotNull(perInstanceStatistics.get(0).getTimeStatistics());
    Assert.assertNotNull(perInstanceStatistics.get(0).getMovingTimeRangeInSeconds());

    final List<ScalingRuleDetails> scalingRules = service.getScalingRules();
    Assert.assertNotNull(scalingRules);
    Assert.assertEquals(2, scalingRules.size());
    Assert.assertNotNull(scalingRules.get(0).getHighThreshold());
    Assert.assertNotNull(scalingRules.get(0).getLowThreshold());
    Assert.assertEquals(servicestatisticsName, scalingRules.get(0).getServiceStatistics());

    final HighThresholdDetails highThreshold = scalingRules.get(0).getHighThreshold();
    Assert.assertNotNull(highThreshold.getValue());
    Assert.assertNotNull(highThreshold.getInstancesIncrease());

    final LowThresholdDetails lowThreshold = scalingRules.get(0).getLowThreshold();
    Assert.assertNotNull(lowThreshold.getValue());
    Assert.assertNotNull(lowThreshold.getInstancesDecrease());

    Assert.assertEquals(
        ((ServiceStatisticsDetails) scalingRules.get(1).getServiceStatistics()).getMetric(),
        serviceStatistics.get(0).getMetric());
    Assert.assertEquals(
        ((ServiceStatisticsDetails) scalingRules.get(1).getServiceStatistics())
            .getInstancesStatistics()
            .createInstancesStatistics(),
        serviceStatistics.get(0).getInstancesStatistics().createInstancesStatistics());
    Assert.assertEquals(
        ((ServiceStatisticsDetails) scalingRules.get(1).getServiceStatistics())
            .getTimeStatistics()
            .createTimeWindowStatistics(1, TimeUnit.MINUTES),
        serviceStatistics
            .get(0)
            .getTimeStatistics()
            .createTimeWindowStatistics(1, TimeUnit.MINUTES));
    Assert.assertEquals(
        ((ServiceStatisticsDetails) scalingRules.get(1).getServiceStatistics())
            .getMovingTimeRangeInSeconds(),
        serviceStatistics.get(0).getMovingTimeRangeInSeconds());

    Assert.assertNotNull(scalingRules.get(1).getHighThreshold());
    Assert.assertNotNull(scalingRules.get(1).getLowThreshold());
  }