View Javadoc

1   /*
2    * $Id: ValidatorBuilderTestCase.java 20320 2010-11-24 15:03:31Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.construct.builder;
12  
13  import org.mule.construct.Validator;
14  import org.mule.exception.DefaultServiceExceptionStrategy;
15  import org.mule.routing.filters.PayloadTypeFilter;
16  import org.mule.tck.AbstractMuleTestCase;
17  
18  public class ValidatorBuilderTestCase extends AbstractMuleTestCase
19  {
20      public void testConfigurationWithoutErrorExpression() throws Exception
21      {
22          final Validator validator = new ValidatorBuilder().name("test-validator-no-error")
23              .inboundAddress("test://foo.in")
24              .validationFilter(new PayloadTypeFilter(Integer.class))
25              .ackExpression("#[string:GOOD:#[message:payload]]")
26              .nackExpression("#[string:BAD:#[message:payload]]")
27              .outboundAddress("test://foo.out")
28              .exceptionStrategy(new DefaultServiceExceptionStrategy(muleContext))
29              .build(muleContext);
30  
31          assertEquals("test-validator-no-error", validator.getName());
32      }
33  
34      public void testFullConfiguration() throws Exception
35      {
36          final Validator validator = new ValidatorBuilder().name("test-validator-full")
37              .inboundAddress("test://foo.in")
38              .validationFilter(new PayloadTypeFilter(Integer.class))
39              .ackExpression("#[string:GOOD:#[message:payload]]")
40              .nackExpression("#[string:BAD:#[message:payload]]")
41              .errorExpression("#[string:ERROR:#[message:payload]]")
42              .outboundAddress("test://foo.out")
43              .exceptionStrategy(new DefaultServiceExceptionStrategy(muleContext))
44              .build(muleContext);
45  
46          assertEquals("test-validator-full", validator.getName());
47      }
48  }