HerdRestController extends HerdBaseController { @ApiOperation(value = "Validates infrastructure timeouts", hidden = true) @RequestMapping(value = "/timeoutValidation", method = RequestMethod.GET) @Secured(SecurityFunctions.FN_TIMEOUT_VALIDATION_GET) public TimeoutValidationResponse getTimeoutValidation(@RequestParam(value = "waitForSeconds") Integer waitForSeconds) throws InterruptedException { Assert.isTrue(waitForSeconds != null, "waitForSeconds query parameter is required."); Assert.isTrue(waitForSeconds >= 0 && waitForSeconds <= MAX_WAIT_FOR_SECONDS, "Specified value \"" + waitForSeconds +"\" does not fall within the range of 0 to 1800 seconds."); Thread.sleep(waitForSeconds * 1000L); return new TimeoutValidationResponse("Successfully waited for " + waitForSeconds + " seconds."); }  @ApiOperation(value = "Gets the build information") @RequestMapping(value = "/buildInfo", method = RequestMethod.GET) @Secured(SecurityFunctions.FN_BUILD_INFO_GET) BuildInformation getBuildInfo(); @ApiOperation(value = "Validates infrastructure timeouts", hidden = true) @RequestMapping(value = "/timeoutValidation", method = RequestMethod.GET) @Secured(SecurityFunctions.FN_TIMEOUT_VALIDATION_GET) TimeoutValidationResponse getTimeoutValidation(@RequestParam(value = "waitForSeconds") Integer waitForSeconds);  }
@Test public void testGetTimeoutValidation() throws InterruptedException { Integer testSeconds = 1; Date start = new Date(); TimeoutValidationResponse result = herdRestController.getTimeoutValidation(testSeconds); long timeDiff = (new Date().getTime() - start.getTime()) / 1000; assertTrue( timeDiff >= testSeconds); assertEquals("Successfully waited for " + testSeconds + " seconds.", result.getMessage()); }
@Test public void testGetTimeoutValidationNegativeNumber() throws InterruptedException { try { herdRestController.getTimeoutValidation(-1); fail("Expected an IllegalArgumentException to be thrown"); } catch (IllegalArgumentException e) { assertEquals("Specified value \"-1\" does not fall within the range of 0 to 1800 seconds.", e.getMessage()); } }
@Test public void testGetTimeoutValidationTooHighNumber() throws InterruptedException { try { herdRestController.getTimeoutValidation(1900); fail("Expected an IllegalArgumentException to be thrown"); } catch (IllegalArgumentException e) { assertEquals("Specified value \"1900\" does not fall within the range of 0 to 1800 seconds.", e.getMessage()); } }
@Test public void testGetTimeoutValidationNullParameter() throws InterruptedException { try { herdRestController.getTimeoutValidation(null); fail("Expected an IllegalArgumentException to be thrown"); } catch (IllegalArgumentException e) { assertEquals("waitForSeconds query parameter is required.", e.getMessage()); } }