View Javadoc

1   /*
2    * $Id: CheckExclusiveAttributesTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.config.spring.parsers.processors;
12  
13  import org.mule.config.spring.parsers.PreProcessor;
14  
15  public class CheckExclusiveAttributesTestCase extends AbstractPreProcessorTestCase
16  {
17      public void testDisjointSingleAttributeGroups() throws Exception
18      {
19          String[][] groups = new String[][] {
20              new String[] { "a" }, 
21              new String[] { "b" }
22          };
23       
24          assertOk(groups, "a");
25          assertOk(groups, "b");
26          assertOk(groups, "x");
27      }
28      
29      public void testDisjointMultipleAttributes() throws Exception
30      {
31          String[][] groups = new String[][] {
32              new String[] { "a1" }, 
33              new String[] { "b1", "b2" }
34          };
35          String text = "do not match the exclusive groups";
36          
37          assertOk(groups, "");
38          // optional attribute
39          assertOk(groups, "x");
40          // all attributes from first group
41          assertOk(groups, "a1");
42          // attribute from second group        
43          assertOk(groups, "b1");
44          assertOk(groups, "b2");
45          // attribute from first group and optional attribute
46          assertOk(groups, "a1 x");
47          // attribute from second group and optional attribute
48          assertOk(groups, "x b1");
49          assertOk(groups, "x b2");
50          // all attributes from second group
51          assertOk(groups, "b1 b2");
52          
53          assertBad(groups, "a1 b1", text);
54          assertBad(groups, "b1 a1", text);
55          assertBad(groups, "a1 b2", text);
56          assertBad(groups, "b2 a1", text);
57          assertBad(groups, "a1 b1 b2", text);
58          assertBad(groups, "a1 b2 x", text);
59      }
60  
61      public void testSecondGroupEmpty() throws Exception
62      {
63          String[][] groups = new String[][]{
64              new String[] { "a1" },
65              new String[] {}
66          };
67          
68          assertOk(groups, "");
69          // optional attribute
70          assertOk(groups, "x");
71          // only attribute from first group
72          assertOk(groups, "a1");
73          // attribute from first group plus optional attribute
74          assertOk(groups, "a1 x");
75      }
76      
77      public void testGroupsWithOverlappingAttributes() throws Exception
78      {
79          String[][] groups = new String[][] {
80              new String[] { "a1", "b1" },
81              new String[] { "a1", "b2" }
82          };
83          
84          // attribute from first group (can be in either group)
85          assertBad(groups, "a1", "do not satisfy");
86          // attribute from first group
87          assertOk(groups, "b1");
88          // attribute from second group
89          assertOk(groups, "b2");
90          // optional attribute
91          assertOk(groups, "a1 b1 x");
92          assertOk(groups, "a1 b2 x");
93          // complete first group
94          assertOk(groups, "a1 b1");
95          // complete second group
96          assertOk(groups, "a1 b2");
97      }
98      
99      public void testRealWorld() throws Exception
100     {
101         String[][] groups = new String[][] {
102             new String[] { "type", "recipient" },
103             new String[] { "type", "from" }
104         };
105         
106         assertOk(groups, "id name recipient subject type");
107     }
108     
109     @Override
110     protected PreProcessor createCheck(String[][] constraint)
111     {
112         return new CheckExclusiveAttributes(constraint);
113     }
114 }