@Test public void testValidation() { assertValidates(new LdapConfig() .setLdapUrl("ldaps://localhost") .setUserBindSearchPattern("uid=${USER},ou=org,dc=test,dc=com") .setUserBaseDistinguishedName("dc=test,dc=com") .setGroupAuthorizationSearchPattern("&(objectClass=user)(memberOf=cn=group)(user=username)")); assertFailsValidation(new LdapConfig().setLdapUrl("ldap://"), "ldapUrl", "LDAP without SSL/TLS unsupported. Expected ldaps://", Pattern.class); assertFailsValidation(new LdapConfig().setLdapUrl("localhost"), "ldapUrl", "LDAP without SSL/TLS unsupported. Expected ldaps://", Pattern.class); assertFailsValidation(new LdapConfig().setLdapUrl("ldaps:/localhost"), "ldapUrl", "LDAP without SSL/TLS unsupported. Expected ldaps://", Pattern.class); assertFailsValidation(new LdapConfig(), "ldapUrl", "may not be null", NotNull.class); assertFailsValidation(new LdapConfig(), "userBindSearchPattern", "may not be null", NotNull.class); } }
public static void assertValidates(Object object, String message) { assertTrue(validate(object).isEmpty(), format("%sexpected:<%s> to pass validation", toMessageString(message), object)); }
@Test public void testTheAssertFailsValidationWithMessageMethodSucceedsWithInvalidObject() { assertFailsValidation(INVALID_OBJECT, "value", "may not be null", NotNull.class, MESSAGE); }
@Test public void testTheAssertFailsValidationMethodThrowsWithValidObject() { boolean ok = false; try { assertFailsValidation(VALID_OBJECT, "value", "may not be null", NotNull.class); } catch (AssertionError e) { ok = true; verifyExceptionMessage(e, null, VALID_OBJECT, "value", NotNull.class); } assertTrue(ok, "Expected AssertionError"); }
@Test public void testAssertValidatesThrowsWithInvalidObject() { boolean ok = false; try { ValidationAssertions.assertValidates(INVALID_OBJECT); } catch (AssertionError e) { ok = true; verifyExceptionMessage(e, null, INVALID_OBJECT, null, null); } assertTrue(ok, "Expected AssertionError"); }
@Test(groups = "aws", parameters = "aws-credentials-file") public void testProvisionAgent(String awsCredentialsFile) throws Exception .setAwsAgentSecurityGroup("default") .setAwsAgentDefaultInstanceType("t1.micro"); assertValidates(awsProvisionerConfig); assertValidates(coordinatorConfig); assertEquals(provisioned.size(), agentCount); System.err.println("provisioned instances: " + provisioned); assertEquals(running.size(), agentCount); System.err.println("running agents: " + running);
@Test public void testAssertValidates() { assertValidates(VALID_OBJECT); assertValidates(VALID_OBJECT, MESSAGE); }
public static void assertValidates(Object object, String message) { assertTrue(VALIDATOR.validate(object).isEmpty(), format("%sexpected:<%s> to pass validation", toMessageString(message), object)); }
public static <T> void assertFailsValidation(T object, String field, String expectedErrorMessage, Class<? extends Annotation> annotation, String message) { Set<ConstraintViolation<T>> violations = validate(object); for (ConstraintViolation<T> violation : violations) { if (annotation.isInstance(violation.getConstraintDescriptor().getAnnotation()) && violation.getPropertyPath().toString().equals(field)) { if (!violation.getMessage().equals(expectedErrorMessage)) { fail(format("%sexpected %s.%s for <%s> to fail validation for %s with message '%s', but message was '%s'", toMessageString(message), object.getClass().getName(), field, message, annotation.getName(), expectedErrorMessage, violation.getMessage())); } return; } } fail(format("%sexpected %s.%s for <%s> to fail validation for %s with message '%s'", toMessageString(message), object.getClass().getName(), field, object, annotation.getName(), expectedErrorMessage)); }
public static <T> void assertFailsValidation(T object, String field, String expectedErrorMessage, Class<? extends Annotation> annotation, String message) { Set<ConstraintViolation<T>> violations = VALIDATOR.validate(object); for (ConstraintViolation<T> violation : violations) { if (annotation.isInstance(violation.getConstraintDescriptor().getAnnotation()) && violation.getPropertyPath().toString().equals(field)) { if (!violation.getMessage().equals(expectedErrorMessage)) { fail(format("%sexpected %s.%s for <%s> to fail validation for %s with message '%s', but message was '%s'", toMessageString(message), object.getClass().getName(), field, message, annotation.getName(), expectedErrorMessage, violation.getMessage())); } return; } } fail(format("%sexpected %s.%s for <%s> to fail validation for %s with message '%s'", toMessageString(message), object.getClass().getName(), field, object, annotation.getName(), expectedErrorMessage)); }
public static <T> void assertFailsValidation(T object, String field, String expectedErrorMessage, Class<? extends Annotation> annotation) { assertFailsValidation(object, field, expectedErrorMessage, annotation, null); }
public static void assertValidates(Object object) { assertValidates(object, null); }
@Test public void testTheAssertFailsValidationMethodSucceedsWithInvalidObject() { assertFailsValidation(INVALID_OBJECT, "value", "may not be null", NotNull.class); }
@Test public void testTheAssertFailsValidationMethodThrowsWithValidObject() { boolean ok = false; try { assertFailsValidation(VALID_OBJECT, "value", "may not be null", NotNull.class); } catch (AssertionError e) { ok = true; verifyExceptionMessage(e, null, VALID_OBJECT, "value", NotNull.class); } assertTrue(ok, "Expected AssertionError"); }
@Test public void testAssertValidatesThrowsWithInvalidObject() { boolean ok = false; try { ValidationAssertions.assertValidates(INVALID_OBJECT); } catch (AssertionError e) { ok = true; verifyExceptionMessage(e, null, INVALID_OBJECT, null, null); } assertTrue(ok, "Expected AssertionError"); }
@Test(groups = "aws", parameters = "aws-credentials-file") public void testProvisionAgent(String awsCredentialsFile) throws Exception .setAwsAgentSecurityGroup("default") .setAwsAgentDefaultInstanceType("t1.micro"); assertValidates(awsProvisionerConfig); assertValidates(coordinatorConfig); assertEquals(provisioned.size(), agentCount); System.err.println("provisioned instances: " + provisioned); assertEquals(running.size(), agentCount); System.err.println("running agents: " + running);
@Test public void testAssertValidates() { assertValidates(VALID_OBJECT); assertValidates(VALID_OBJECT, MESSAGE); }
public static <T> void assertFailsValidation(T object, String field, String expectedErrorMessage, Class<? extends Annotation> annotation, String message) { Set<ConstraintViolation<T>> violations = validate(object); for (ConstraintViolation<T> violation : violations) { if (annotation.isInstance(violation.getConstraintDescriptor().getAnnotation()) && violation.getPropertyPath().toString().equals(field)) { if (!violation.getMessage().equals(expectedErrorMessage)) { fail(format("%sexpected %s.%s for <%s> to fail validation for %s with message '%s', but message was '%s'", toMessageString(message), object.getClass().getName(), field, message, annotation.getName(), expectedErrorMessage, violation.getMessage())); } return; } } fail(format("%sexpected %s.%s for <%s> to fail validation for %s with message '%s'", toMessageString(message), object.getClass().getName(), field, object, annotation.getName(), expectedErrorMessage)); }
public static <T> void assertFailsValidation(T object, String field, String expectedErrorMessage, Class<? extends Annotation> annotation) { assertFailsValidation(object, field, expectedErrorMessage, annotation, null); }
public static void assertValidates(Object object) { assertValidates(object, null); }