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