use of jakarta.validation.ConstraintViolation in project spring-cloud-config by spring-cloud.
the class SshPropertyValidatorTest method supportedParametersSuccesful.
@Test
public void supportedParametersSuccesful() throws Exception {
MultipleJGitEnvironmentProperties validSettings = new MultipleJGitEnvironmentProperties();
validSettings.setUri(SSH_URI);
validSettings.setIgnoreLocalSshSettings(true);
validSettings.setPrivateKey(VALID_PRIVATE_KEY);
validSettings.setHostKey(VALID_HOST_KEY);
validSettings.setHostKeyAlgorithm("ssh-rsa");
Set<ConstraintViolation<MultipleJGitEnvironmentProperties>> constraintViolations = validator.validate(validSettings);
assertThat(constraintViolations).hasSize(0);
}
use of jakarta.validation.ConstraintViolation in project spring-cloud-config by spring-cloud.
the class SshPropertyValidatorTest method unsupportedAlgoFails.
@Test
public void unsupportedAlgoFails() throws Exception {
MultipleJGitEnvironmentProperties unsupportedAlgo = new MultipleJGitEnvironmentProperties();
unsupportedAlgo.setUri(SSH_URI);
unsupportedAlgo.setIgnoreLocalSshSettings(true);
unsupportedAlgo.setPrivateKey(VALID_PRIVATE_KEY);
unsupportedAlgo.setHostKey("some_host_key");
unsupportedAlgo.setHostKeyAlgorithm("unsupported");
Set<ConstraintViolation<MultipleJGitEnvironmentProperties>> constraintViolations = validator.validate(unsupportedAlgo);
assertThat(constraintViolations).hasSize(1);
}
use of jakarta.validation.ConstraintViolation in project hibernate-orm by hibernate.
the class HibernateTraversableResolverTest method testEmbedded.
@Test
public void testEmbedded() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Screen screen = new Screen();
PowerSupply ps = new PowerSupply();
screen.setPowerSupply(ps);
Button button = new Button();
button.setName(null);
button.setSize(3);
screen.setStopButton(button);
try {
s.persist(screen);
s.flush();
fail("@NotNull on embedded property is not evaluated");
} catch (ConstraintViolationException e) {
assertEquals(1, e.getConstraintViolations().size());
ConstraintViolation<?> cv = e.getConstraintViolations().iterator().next();
assertEquals(Screen.class, cv.getRootBeanClass());
// toString works since hibernate validator's Path implementation works accordingly. Should do a Path comparison though
assertEquals("stopButton.name", cv.getPropertyPath().toString());
}
tx.rollback();
s.close();
}
use of jakarta.validation.ConstraintViolation in project hibernate-orm by hibernate.
the class HibernateTraversableResolverTest method testEmbeddedCollection.
@Test
public void testEmbeddedCollection() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Screen screen = new Screen();
PowerSupply ps = new PowerSupply();
screen.setPowerSupply(ps);
DisplayConnector conn = new DisplayConnector();
conn.setNumber(0);
screen.getConnectors().add(conn);
try {
s.persist(screen);
s.flush();
fail("Collection of embedded objects should be validated");
} catch (ConstraintViolationException e) {
assertEquals(1, e.getConstraintViolations().size());
final ConstraintViolation constraintViolation = e.getConstraintViolations().iterator().next();
assertEquals(Screen.class, constraintViolation.getRootBeanClass());
// toString works since hibernate validator's Path implementation works accordingly. Should do a Path comparison though
assertEquals("connectors[].number", constraintViolation.getPropertyPath().toString());
}
tx.rollback();
s.close();
}
use of jakarta.validation.ConstraintViolation in project hibernate-orm by hibernate.
the class HibernateTraversableResolverTest method testToOneAssocNotValidated.
@Test
public void testToOneAssocNotValidated() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Screen screen = new Screen();
PowerSupply ps = new PowerSupply();
ps.setPosition("1");
ps.setPower(new BigDecimal(350));
screen.setPowerSupply(ps);
try {
s.persist(screen);
s.flush();
fail("Associated objects should not be validated");
} catch (ConstraintViolationException e) {
assertEquals(1, e.getConstraintViolations().size());
final ConstraintViolation constraintViolation = e.getConstraintViolations().iterator().next();
assertEquals(PowerSupply.class, constraintViolation.getRootBeanClass());
}
tx.rollback();
s.close();
}
Aggregations