### Question:
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);  }### Answer:
@Test public void testIsValidWhenValidLoadAlertsThenTrue() { List<String> loadHostGroups = Arrays.asList("compute2"); boolean underTestValid = underTest .isValid(getTestRequest(List.of(), loadHostGroups, Optional.empty()), validatorContext); assertTrue("Valid Load Alert Autoscale Policy", underTestValid); }
@Test public void testIsValidWhenValidTimeAlertsThenTrue() { List<String> timeHostGroups = Arrays.asList("compute2", "hdfs1", "hdfs3"); boolean underTestValid = underTest .isValid(getTestRequest(timeHostGroups, List.of(), Optional.empty()), validatorContext); assertTrue("Valid Time Alert Autoscale Policy", underTestValid); }
@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); }
@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); }
@Test public void testIsValidWhenDuplicateLoadAlertHostGroupThenFalse() { List<String> loadHostGroups = Arrays.asList("compute2", "compute2", "hdfs3"); boolean underTestValid = underTest .isValid(getTestRequest(List.of(), loadHostGroups, Optional.empty()), validatorContext); assertFalse("Cluster can be configured with only one type of autoscale policy", underTestValid); }
@Test public void testIsValidWhenLoadAlertWithInvalidAdjustmentTypeThenFalse() { List<String> loadHostGroups = Arrays.asList("compute2", "compute2", "hdfs3"); boolean underTestValid = underTest .isValid(getTestRequest(List.of(), loadHostGroups, Optional.of(AdjustmentType.NODE_COUNT)), validatorContext); assertFalse("Cluster can be configured with only one type of autoscale policy", underTestValid); }