View Javadoc

1   /*
2    * $Id: ValidatorBuilderTestCase.java 22772 2011-08-27 15:20:15Z 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 static org.junit.Assert.assertEquals;
14  
15  import org.mule.construct.Validator;
16  import org.mule.exception.DefaultMessagingExceptionStrategy;
17  import org.mule.routing.filters.PayloadTypeFilter;
18  import org.mule.tck.junit4.AbstractMuleContextTestCase;
19  
20  import org.junit.Test;
21  
22  public class ValidatorBuilderTestCase extends AbstractMuleContextTestCase
23  {
24      @Test
25      public void testConfigurationWithoutErrorExpression() throws Exception
26      {
27          final Validator validator = new ValidatorBuilder().name("test-validator-no-error")
28              .inboundAddress("test://foo.in")
29              .validationFilter(new PayloadTypeFilter(Integer.class))
30              .ackExpression("#[string:GOOD:#[message:payload]]")
31              .nackExpression("#[string:BAD:#[message:payload]]")
32              .outboundAddress("test://foo.out")
33              .exceptionStrategy(new DefaultMessagingExceptionStrategy(muleContext))
34              .build(muleContext);
35  
36          assertEquals("test-validator-no-error", validator.getName());
37      }
38  
39      @Test
40      public void testFullConfiguration() throws Exception
41      {
42          final Validator validator = new ValidatorBuilder().name("test-validator-full")
43              .inboundAddress("test://foo.in")
44              .validationFilter(new PayloadTypeFilter(Integer.class))
45              .ackExpression("#[string:GOOD:#[message:payload]]")
46              .nackExpression("#[string:BAD:#[message:payload]]")
47              .errorExpression("#[string:ERROR:#[message:payload]]")
48              .outboundAddress("test://foo.out")
49              .exceptionStrategy(new DefaultMessagingExceptionStrategy(muleContext))
50              .build(muleContext);
51  
52          assertEquals("test-validator-full", validator.getName());
53      }
54  }