Search in sources :

Example 51 with ConstraintViolationException

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());
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) LocalMode(com.datatorrent.api.LocalMode) ConstraintViolationException(javax.validation.ConstraintViolationException) Test(org.junit.Test)

Example 52 with ConstraintViolationException

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);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) LocalMode(com.datatorrent.api.LocalMode) ConstraintViolationException(javax.validation.ConstraintViolationException) IOException(java.io.IOException) ConstraintViolationException(javax.validation.ConstraintViolationException) Test(org.junit.Test)

Example 53 with ConstraintViolationException

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);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) TreeSet(java.util.TreeSet) Set(java.util.Set) ResourceException(javax.resource.ResourceException) EjbTransactionUtil.handleApplicationException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) NamingException(javax.naming.NamingException) ApplicationException(org.apache.openejb.ApplicationException) OpenEJBException(org.apache.openejb.OpenEJBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConstraintViolationException(javax.validation.ConstraintViolationException) SystemException(org.apache.openejb.SystemException) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) TreeSet(java.util.TreeSet) ActivationSpec(javax.resource.spi.ActivationSpec) ConstraintViolationException(javax.validation.ConstraintViolationException) NamingException(javax.naming.NamingException) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Validator(javax.validation.Validator)

Example 54 with ConstraintViolationException

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);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JdbcResource(org.glassfish.jdbc.config.JdbcResource) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) HashMap(java.util.HashMap) ConstraintViolationException(javax.validation.ConstraintViolationException) ConfigBean(org.jvnet.hk2.config.ConfigBean) Domain(com.sun.enterprise.config.serverbeans.Domain) HashMap(java.util.HashMap) Map(java.util.Map) ConfigApiTest(org.glassfish.jdbcruntime.config.ConfigApiTest) Test(org.junit.Test)

Example 55 with ConstraintViolationException

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);
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) AdminService(com.sun.enterprise.config.serverbeans.AdminService) ConstraintViolationException(javax.validation.ConstraintViolationException) ConfigApiTest(com.sun.enterprise.configapi.tests.ConfigApiTest) Test(org.junit.Test)

Aggregations

ConstraintViolationException (javax.validation.ConstraintViolationException)87 Test (org.junit.Test)67 LocalMode (com.datatorrent.api.LocalMode)35 Configuration (org.apache.hadoop.conf.Configuration)34 File (java.io.File)16 ConstraintViolation (javax.validation.ConstraintViolation)15 Session (org.hibernate.Session)11 Transaction (org.hibernate.Transaction)11 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)9 Map (java.util.Map)9 BigDecimal (java.math.BigDecimal)7 HashMap (java.util.HashMap)7 Set (java.util.Set)6 StramLocalCluster (com.datatorrent.stram.StramLocalCluster)5 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)5 HashSet (java.util.HashSet)5 ValidationException (javax.validation.ValidationException)5 Validator (javax.validation.Validator)5 Response (javax.ws.rs.core.Response)5 Path (org.apache.hadoop.fs.Path)5