@Test
 public void testIsValidShouldReturnTrueWhenStatusIsUpdated() {
   UpdateStackJson updateStackJson = new UpdateStackJson();
   updateStackJson.setInstanceGroupAdjustment(null);
   updateStackJson.setStatus(StatusRequest.STARTED);
   boolean valid = underTest.isValid(updateStackJson, constraintValidatorContext);
   assertTrue(valid);
 }
  @Test
  public void testIsValidShouldReturnFalseWhenRequestContainsOnlyNulls() {

    UpdateStackJson updateStackJson = new UpdateStackJson();
    updateStackJson.setInstanceGroupAdjustment(null);
    updateStackJson.setStatus(null);
    boolean valid = underTest.isValid(updateStackJson, constraintValidatorContext);
    assertFalse(valid);
  }
 @Test
 public void testIsValidShouldReturnFalseWhenRequestContainsNodeCountAndStatus() {
   UpdateStackJson updateStackJson = new UpdateStackJson();
   InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
   instanceGroupAdjustmentJson.setScalingAdjustment(4);
   instanceGroupAdjustmentJson.setInstanceGroup("slave_1");
   updateStackJson.setStatus(StatusRequest.STARTED);
   updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
   boolean valid = underTest.isValid(updateStackJson, constraintValidatorContext);
   assertFalse(valid);
 }
 @Test
 public void testIsValidShouldReturnTrueWhenNodeCountIsUpdated() {
   UpdateStackJson updateStackJson = new UpdateStackJson();
   InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
   instanceGroupAdjustmentJson.setScalingAdjustment(12);
   instanceGroupAdjustmentJson.setInstanceGroup("slave_1");
   updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
   updateStackJson.setStatus(null);
   boolean valid = underTest.isValid(updateStackJson, constraintValidatorContext);
   assertTrue(valid);
 }
 @Test
 public void testInValidShouldReturnTrueWhenNodeCountIsLowerThanOneUpdatedAndWithClusterEvent() {
   UpdateStackJson updateStackJson = new UpdateStackJson();
   InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
   instanceGroupAdjustmentJson.setScalingAdjustment(-1);
   instanceGroupAdjustmentJson.setWithClusterEvent(true);
   instanceGroupAdjustmentJson.setInstanceGroup("slave_1");
   updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
   updateStackJson.setStatus(null);
   boolean valid = underTest.isValid(updateStackJson, constraintValidatorContext);
   assertFalse(valid);
 }
Ejemplo n.º 6
0
 @ApiOperation(
     value = StackOpDescription.PUT_BY_ID,
     produces = ContentType.JSON,
     notes = Notes.STACK_NOTES)
 @RequestMapping(value = "stacks/{id}", method = RequestMethod.PUT)
 @ResponseBody
 public ResponseEntity<String> updateStack(
     @ModelAttribute("user") CbUser user,
     @PathVariable Long id,
     @Valid @RequestBody UpdateStackJson updateRequest) {
   MDCBuilder.buildUserMdcContext(user);
   if (updateRequest.getStatus() != null) {
     stackService.updateStatus(id, updateRequest.getStatus());
     return new ResponseEntity<>(HttpStatus.NO_CONTENT);
   } else {
     Integer scalingAdjustment = updateRequest.getInstanceGroupAdjustment().getScalingAdjustment();
     validateAccountPreferences(id, scalingAdjustment);
     stackService.updateNodeCount(id, updateRequest.getInstanceGroupAdjustment());
     return new ResponseEntity<>(HttpStatus.NO_CONTENT);
   }
 }