コード例 #1
0
  @Test
  public void testValidateWithValidator_fail() throws Exception {

    Properties properties = new Properties();
    properties.put("p1", "v1");

    Configuration ambariConfig = new Configuration(properties);

    ViewConfig config = ViewConfigTest.getConfig(xml_invalid_instance);
    ViewEntity viewEntity =
        ViewRegistryTest.getViewEntity(config, ambariConfig, getClass().getClassLoader(), "");
    ViewInstanceEntity viewInstanceEntity =
        ViewRegistryTest.getViewInstanceEntity(viewEntity, config.getInstances().get(0));

    ViewEntityTest.TestValidator validator = new ViewEntityTest.TestValidator();
    validator.result = new ValidationResultImpl(false, "detail");
    viewEntity.setValidator(validator);

    try {
      viewInstanceEntity.validate(viewEntity, Validator.ValidationContext.PRE_CREATE);
      Assert.fail("Expected an IllegalStateException");
    } catch (ValidationException e) {
      // expected
    }
  }
コード例 #2
0
  @Test
  public void testGetValidationResult() throws Exception {

    Properties properties = new Properties();
    properties.put("p1", "v1");

    Configuration ambariConfig = new Configuration(properties);

    ViewConfig config = ViewConfigTest.getConfig(xml_valid_instance);
    ViewEntity viewEntity =
        ViewRegistryTest.getViewEntity(config, ambariConfig, getClass().getClassLoader(), "");
    ViewInstanceEntity viewInstanceEntity =
        ViewRegistryTest.getViewInstanceEntity(viewEntity, config.getInstances().get(0));

    ViewEntityTest.TestValidator validator = new ViewEntityTest.TestValidator();
    validator.result = new ValidationResultImpl(true, "detail");
    viewEntity.setValidator(validator);

    InstanceValidationResultImpl result =
        viewInstanceEntity.getValidationResult(viewEntity, Validator.ValidationContext.PRE_CREATE);

    Map<String, ValidationResult> propertyResults = result.getPropertyResults();

    junit.framework.Assert.assertEquals(2, propertyResults.size());
    junit.framework.Assert.assertTrue(propertyResults.containsKey("p1"));
    junit.framework.Assert.assertTrue(propertyResults.containsKey("p2"));

    junit.framework.Assert.assertTrue(propertyResults.get("p1").isValid());
    junit.framework.Assert.assertTrue(propertyResults.get("p2").isValid());
  }
コード例 #3
0
  @Test
  public void testValidateWithValidator() throws Exception {

    Properties properties = new Properties();
    properties.put("p1", "v1");

    Configuration ambariConfig = new Configuration(properties);

    ViewConfig config = ViewConfigTest.getConfig(xml_valid_instance);
    ViewEntity viewEntity =
        ViewRegistryTest.getViewEntity(config, ambariConfig, getClass().getClassLoader(), "");
    ViewInstanceEntity viewInstanceEntity =
        ViewRegistryTest.getViewInstanceEntity(viewEntity, config.getInstances().get(0));

    ViewEntityTest.TestValidator validator = new ViewEntityTest.TestValidator();
    validator.result = new ValidationResultImpl(true, "detail");
    viewEntity.setValidator(validator);

    viewInstanceEntity.validate(viewEntity, Validator.ValidationContext.PRE_CREATE);
  }