@Test public void aggregateSingleValidations() { FormValidation ok = FormValidation.ok(); FormValidation warning = FormValidation.warning(""); FormValidation error = FormValidation.error(""); assertEquals(ok, aggregate(ok)); assertEquals(warning, aggregate(warning)); assertEquals(error, aggregate(error)); }
/** * Check that the releaseVersion field is not empty. * * @param releaseVersion The release version of the package. * @param project The project name * @return Ok if not empty, error otherwise. */ public FormValidation doCheckReleaseVersion( @QueryParameter String releaseVersion, @QueryParameter String project) { setGlobalConfiguration(); releaseVersion = releaseVersion.trim(); if (project == null || project.isEmpty()) { return FormValidation.warning(PROJECT_RELEASE_VALIDATION_MESSAGE); } com.octopusdeploy.api.Project p; try { p = api.getProjectByName(project); if (p == null) { return FormValidation.warning(PROJECT_RELEASE_VALIDATION_MESSAGE); } } catch (Exception ex) { return FormValidation.warning(PROJECT_RELEASE_VALIDATION_MESSAGE); } OctopusValidator validator = new OctopusValidator(api); return validator.validateRelease( releaseVersion, p.getId(), OctopusValidator.ReleaseExistenceRequirement.MustExist); }
public FormValidation doCheckPollingThreadCount(@QueryParameter String value) { if (value != null && "".equals(value.trim())) { return FormValidation.ok(); } return FormValidation.validateNonNegativeInteger(value); }
@Test public void aggregateSeveralValidations() { FormValidation ok = FormValidation.ok("ok_message"); FormValidation warning = FormValidation.warning("warning_message"); FormValidation error = FormValidation.error("error_message"); final FormValidation ok_ok = aggregate(ok, ok); assertEquals(FormValidation.Kind.OK, ok_ok.kind); assertTrue(ok_ok.renderHtml().contains(ok.getMessage())); final FormValidation ok_warning = aggregate(ok, warning); assertEquals(FormValidation.Kind.WARNING, ok_warning.kind); assertTrue(ok_warning.renderHtml().contains(ok.getMessage())); assertTrue(ok_warning.renderHtml().contains(warning.getMessage())); final FormValidation ok_error = aggregate(ok, error); assertEquals(FormValidation.Kind.ERROR, ok_error.kind); assertTrue(ok_error.renderHtml().contains(ok.getMessage())); assertTrue(ok_error.renderHtml().contains(error.getMessage())); final FormValidation warninig_error = aggregate(warning, error); assertEquals(FormValidation.Kind.ERROR, warninig_error.kind); assertTrue(warninig_error.renderHtml().contains(error.getMessage())); assertTrue(warninig_error.renderHtml().contains(warning.getMessage())); }
@Test public void aggregateZeroValidations() { assertEquals(FormValidation.ok(), aggregate()); }
// @Bug(7438) @Test public void testMessage() { assertEquals("test msg", FormValidation.errorWithMarkup("test msg").getMessage()); }
@Test public void testValidateRequired_Empty() { FormValidation actual = FormValidation.validateRequired(" "); assertNotNull(actual); assertEquals(FormValidation.Kind.ERROR, actual.kind); }
@Test public void testValidateRequired_OK() { FormValidation actual = FormValidation.validateRequired("Name"); assertEquals(FormValidation.ok(), actual); }
private FormValidation aggregate(FormValidation... fvs) { return FormValidation.aggregate(Arrays.asList(fvs)); }