[ 
https://issues.apache.org/activemq/browse/CAMEL-1537?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Christian Mueller updated CAMEL-1537:
-------------------------------------

    Attachment: CAMEL-1537.patch

I spend some hous to understand the camel-core components. I have now finished 
the first of tree steps, implementing the validation DSL for regular 
expressions. I attached the patch and hope that someone could give me a 
feedback whether or not I'm on the right way. The unit test shows best what you 
can now do:

{code}
public class ValidateRegExpTest extends ContextTestSupport {
    
    private Endpoint startEndpoint;
    private MockEndpoint resultEndpoint;
    
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        
        startEndpoint = resolveMandatoryEndpoint("direct:start", 
Endpoint.class);
        resultEndpoint = resolveMandatoryEndpoint("mock:result", 
MockEndpoint.class);
    }

    public void testSendMatchingMessage() throws Exception {
        resultEndpoint.expectedMessageCount(1);

        template.sendBody(startEndpoint, "01.01.2010");
        
        resultEndpoint.assertIsSatisfied();
    }

    public void testSendNotMatchingMessage() throws Exception {
        resultEndpoint.expectedMessageCount(0);

        try {
            template.sendBody(startEndpoint, "1.1.2010");
            fail("CamelExecutionException expected");
        } catch (CamelExecutionException e) {
            // expected
            assertTrue(e.getCause() instanceof RegExpValidationException);
            String message = ((RegExpValidationException) 
e.getCause()).getMessage();
            assertEquals("Validation failed for 
Predicate[{bodyAs[java.lang.String]}.matches('^\\d{2}\\.\\d{2}\\.\\d{4}$')]. 
Exchange[Message: 1.1.2010]", message);
        }

        resultEndpoint.assertIsSatisfied();
    }


    protected RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() {
                from("direct:start")
                
.validate(body(String.class)).regex("^\\d{2}\\.\\d{2}\\.\\d{4}$")
                .to("mock:result");
            }
        };
    }
}
{code}

Thanks,
Christian

> Predicate for validation 
> -------------------------
>
>                 Key: CAMEL-1537
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-1537
>             Project: Apache Camel
>          Issue Type: New Feature
>    Affects Versions: 2.0-M1
>            Reporter: Claus Ibsen
>            Assignee: Christian Mueller
>            Priority: Minor
>             Fix For: Future
>
>         Attachments: CAMEL-1537.patch
>
>
> The current validator is a component and its a bit clumsy as it throws an 
> exception if validation error.
> So if we have a nice Predicate for it, it can be like a xpath predicate or 
> the likes.
> [17:58]  <jstrachan> http://camel.apache.org/validation.html
> [17:58]  <ulhasb> jstrachan: thanks for the quick responses
> [17:59]  <cibsen> jstrachan we should maybe have a predicate for schema 
> validation
> [17:59]  <cibsen> then you can route it a bit more nice without try .. catch
> [18:00]  * fbolton has quit ("Leaving.")
> [18:03]  * gertv has quit (Client closed connection)
> [18:05]  <jstrachan> cibsen: yeah
> [18:05]  <jstrachan> cibsen: maybe a kinda predicate language using the other 
> validators? filter().validate(theValidationEndpointUri).to("blah")

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to