@Test public void testIsValidWhenNegativeTargeTimeAlertsThenFalse() { List<String> timeHostGroups = Arrays.asList("compute2", "hdfs1", "hdfs3"); DistroXAutoscaleClusterRequest request = getTestRequest(timeHostGroups, List.of(), Optional.empty()); request.getTimeAlertRequests().stream() .forEach(timeAlertRequest -> timeAlertRequest.getScalingPolicy().setScalingAdjustment(-10)); boolean underTestValid = underTest.isValid(request, validatorContext); assertFalse("Target for Time Alert with Exact Adjustment cannot be negative.", 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);  }