use of javax.validation.ConstraintViolationException in project apex-malhar by apache.
the class ApplicationTest method testApplication.
@Test
public void testApplication() throws IOException, Exception {
try {
LocalMode lma = LocalMode.newInstance();
Configuration conf = new Configuration(false);
conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
lma.prepareDAG(new Application(), conf);
LocalMode.Controller lc = lma.getController();
// runs for 5 seconds and quits
lc.run(5000);
} catch (ConstraintViolationException e) {
Assert.fail("constraint violations: " + e.getConstraintViolations());
}
}
use of javax.validation.ConstraintViolationException in project apex-malhar by apache.
the class StreamEndpointTest method testApplicationWithPortEndpoint.
@Test
public void testApplicationWithPortEndpoint() {
try {
LocalMode lma = LocalMode.newInstance();
Configuration conf = new Configuration(false);
lma.prepareDAG(new KafkaPortApplication(kafka.getBroker(), testTopicData0, testTopicResult), conf);
LocalMode.Controller lc = lma.getController();
lc.runAsync();
kafka.publish(testTopicData0, Arrays.asList("15/02/2016 10:15:00 +0000,1,paint1,11", "15/02/2016 10:16:00 +0000,2,paint2,12", "15/02/2016 10:17:00 +0000,3,paint3,13", "15/02/2016 10:18:00 +0000,4,paint4,14", "15/02/2016 10:19:00 +0000,5,paint5,15", "15/02/2016 10:10:00 +0000,6,abcde6,16"));
// TODO: Workaround to add \r\n char to test results because of bug in CsvFormatter which adds new line char.
String[] expectedLines = new String[] { "15/02/2016 10:18:00 +0000,15/02/2016 00:00:00 +0000,OILPAINT4\r\n", "15/02/2016 10:19:00 +0000,15/02/2016 00:00:00 +0000,OILPAINT5\r\n" };
List<String> consume = kafka.consume(testTopicResult, 30000);
Assert.assertTrue(Arrays.deepEquals(consume.toArray(new String[consume.size()]), expectedLines));
lc.shutdown();
} catch (ConstraintViolationException e) {
Assert.fail("constraint violations: " + e.getConstraintViolations());
} catch (Exception e) {
Assert.fail("Exception: " + e);
}
}
use of javax.validation.ConstraintViolationException in project tomee by apache.
the class MdbPoolContainer method createActivationSpec.
private ActivationSpec createActivationSpec(final BeanContext beanContext) throws OpenEJBException {
try {
// initialize the object recipe
final ObjectRecipe objectRecipe = new ObjectRecipe(activationSpecClass);
objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
objectRecipe.disallow(Option.FIELD_INJECTION);
final Map<String, String> activationProperties = beanContext.getActivationProperties();
for (final Map.Entry<String, String> entry : activationProperties.entrySet()) {
objectRecipe.setMethodProperty(entry.getKey(), entry.getValue());
}
objectRecipe.setMethodProperty("beanClass", beanContext.getBeanClass());
// create the activationSpec
final ActivationSpec activationSpec = (ActivationSpec) objectRecipe.create(activationSpecClass.getClassLoader());
// verify all properties except "destination" and "destinationType" were consumed
final Set<String> unusedProperties = new TreeSet<String>(objectRecipe.getUnsetProperties().keySet());
unusedProperties.remove("destination");
unusedProperties.remove("destinationType");
unusedProperties.remove("destinationLookup");
unusedProperties.remove("connectionFactoryLookup");
unusedProperties.remove("beanClass");
unusedProperties.remove("MdbActiveOnStartup");
unusedProperties.remove("MdbJMXControl");
unusedProperties.remove("DeliveryActive");
if (!unusedProperties.isEmpty()) {
final String text = "No setter found for the activation spec properties: " + unusedProperties;
if (failOnUnknownActivationSpec) {
throw new IllegalArgumentException(text);
} else {
logger.warning(text);
}
}
// validate the activation spec
try {
activationSpec.validate();
} catch (final UnsupportedOperationException uoe) {
logger.info("ActivationSpec does not support validate. Implementation of validate is optional");
}
// also try validating using Bean Validation if there is a Validator available in the context.
try {
final Validator validator = (Validator) beanContext.getJndiContext().lookup("comp/Validator");
final Set generalSet = validator.validate(activationSpec);
if (!generalSet.isEmpty()) {
throw new ConstraintViolationException("Constraint violation for ActivationSpec " + activationSpecClass.getName(), generalSet);
}
} catch (final NamingException e) {
logger.debug("No Validator bound to JNDI context");
}
// set the resource adapter into the activation spec
activationSpec.setResourceAdapter(resourceAdapter);
return activationSpec;
} catch (final Exception e) {
throw new OpenEJBException("Unable to create activation spec", e);
}
}
use of javax.validation.ConstraintViolationException in project Payara by payara.
the class ReferenceConstrainTest method doChangeToInValidPool.
@Test
public void doChangeToInValidPool() throws TransactionFailure {
Domain domain = habitat.getService(Domain.class);
// Find JdbcResource to chenge its values
Iterator<JdbcResource> iterator = domain.getResources().getResources(JdbcResource.class).iterator();
JdbcResource jdbc = null;
while (iterator.hasNext()) {
JdbcResource res = iterator.next();
if ("DerbyPool".equals(res.getPoolName())) {
jdbc = res;
break;
}
}
assertNotNull(jdbc);
ConfigBean poolConfig = (ConfigBean) ConfigBean.unwrap(jdbc);
Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("pool-name", "WrongPointer");
changes.put(poolConfig, configChanges);
try {
ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
cs.apply(changes);
fail("Can not reach this point");
} catch (TransactionFailure tf) {
ConstraintViolationException cv = findConstrViolation(tf);
// cv.printStackTrace(System.out);
assertNotNull(cv);
}
}
use of javax.validation.ConstraintViolationException in project Payara by payara.
the class FieldsValidationTest method testNotNullField.
@Test
public void testNotNullField() {
AdminService admin = super.getHabitat().getService(AdminService.class);
Assert.assertNotNull(admin);
try {
ConfigSupport.apply(new SingleConfigCode<AdminService>() {
@Override
public Object run(AdminService wAdmin) throws PropertyVetoException, TransactionFailure {
wAdmin.setDasConfig(null);
return null;
}
}, admin);
Assert.fail("Exception not raised when setting a @NotNull annotated field with null");
} catch (TransactionFailure e) {
if (e.getCause() != null) {
Assert.assertTrue(e.getCause() instanceof ConstraintViolationException);
}
}
}
Aggregations