@Test public void testIsValidWhenBothAlertsThenFalse() { List<String> timeHostGroups = Arrays.asList("hdfs1", "compute1", "hdfs3"); List<String> loadHostGroups = Arrays.asList("compute2", "hdfs1", "hdfs3"); boolean underTestValid = underTest .isValid(getTestRequest(timeHostGroups, loadHostGroups, Optional.empty()), validatorContext); assertFalse("Cluster can be configured with only one type of autoscale policy", underTestValid); }
@Override public boolean isValid(DistroXAutoscaleClusterRequest request, ConstraintValidatorContext context) { if (!request.getLoadAlertRequests().isEmpty() && !request.getTimeAlertRequests().isEmpty()) { ValidatorUtil.addConstraintViolation(context, messagesService.getMessage(VALIDATION_SINGLE_TYPE), "autoscalingPolicy") .disableDefaultConstraintViolation(); return false; } if (!request.getLoadAlertRequests().isEmpty()) { return isValidLoadAlertRequests(request, context); } if (!request.getTimeAlertRequests().isEmpty()) { return isValidTimeAlertRequests(request, context); } return true; }
DistroXAutoscaleRequestValidator implements ConstraintValidator<ValidDistroXAutoscaleRequest, DistroXAutoscaleClusterRequest> { @Override public boolean isValid(DistroXAutoscaleClusterRequest request, ConstraintValidatorContext context) { if (!request.getLoadAlertRequests().isEmpty() && !request.getTimeAlertRequests().isEmpty()) { ValidatorUtil.addConstraintViolation(context, messagesService.getMessage(VALIDATION_SINGLE_TYPE), "autoscalingPolicy") .disableDefaultConstraintViolation(); return false; } if (!request.getLoadAlertRequests().isEmpty()) { return isValidLoadAlertRequests(request, context); } if (!request.getTimeAlertRequests().isEmpty()) { return isValidTimeAlertRequests(request, context); } return true; } }
DistroXAutoscaleRequestValidator implements ConstraintValidator<ValidDistroXAutoscaleRequest, DistroXAutoscaleClusterRequest> { @Override public boolean isValid(DistroXAutoscaleClusterRequest request, ConstraintValidatorContext context) { if (!request.getLoadAlertRequests().isEmpty() && !request.getTimeAlertRequests().isEmpty()) { ValidatorUtil.addConstraintViolation(context, messagesService.getMessage(VALIDATION_SINGLE_TYPE), "autoscalingPolicy") .disableDefaultConstraintViolation(); return false; } if (!request.getLoadAlertRequests().isEmpty()) { return isValidLoadAlertRequests(request, context); } if (!request.getTimeAlertRequests().isEmpty()) { return isValidTimeAlertRequests(request, context); } return true; }  }
DistroXAutoscaleRequestValidator implements ConstraintValidator<ValidDistroXAutoscaleRequest, DistroXAutoscaleClusterRequest> { @Override public boolean isValid(DistroXAutoscaleClusterRequest request, ConstraintValidatorContext context) { if (!request.getLoadAlertRequests().isEmpty() && !request.getTimeAlertRequests().isEmpty()) { ValidatorUtil.addConstraintViolation(context, messagesService.getMessage(VALIDATION_SINGLE_TYPE), "autoscalingPolicy") .disableDefaultConstraintViolation(); return false; } if (!request.getLoadAlertRequests().isEmpty()) { return isValidLoadAlertRequests(request, context); } if (!request.getTimeAlertRequests().isEmpty()) { return isValidTimeAlertRequests(request, context); } return true; }  @Override boolean isValid(DistroXAutoscaleClusterRequest request, ConstraintValidatorContext context); }
DistroXAutoscaleRequestValidator implements ConstraintValidator<ValidDistroXAutoscaleRequest, DistroXAutoscaleClusterRequest> { @Override public boolean isValid(DistroXAutoscaleClusterRequest request, ConstraintValidatorContext context) { if (!request.getLoadAlertRequests().isEmpty() && !request.getTimeAlertRequests().isEmpty()) { ValidatorUtil.addConstraintViolation(context, messagesService.getMessage(VALIDATION_SINGLE_TYPE), "autoscalingPolicy") .disableDefaultConstraintViolation(); return false; } if (!request.getLoadAlertRequests().isEmpty()) { return isValidLoadAlertRequests(request, context); } if (!request.getTimeAlertRequests().isEmpty()) { return isValidTimeAlertRequests(request, context); } return true; }  @Override boolean isValid(DistroXAutoscaleClusterRequest request, ConstraintValidatorContext context);  }