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.config.spring.parsers.processors;
8   
9   import org.mule.config.spring.parsers.PreProcessor;
10  
11  import org.junit.Test;
12  
13  public class CheckExclusiveAttributesTestCase extends AbstractPreProcessorTestCase
14  {
15      @Test
16      public void testDisjointSingleAttributeGroups() throws Exception
17      {
18          String[][] groups = new String[][] {
19              new String[] { "a" }, 
20              new String[] { "b" }
21          };
22       
23          assertOk(groups, "a");
24          assertOk(groups, "b");
25          assertOk(groups, "x");
26      }
27      
28      @Test
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      @Test
62      public void testSecondGroupEmpty() throws Exception
63      {
64          String[][] groups = new String[][]{
65              new String[] { "a1" },
66              new String[] {}
67          };
68          
69          assertOk(groups, "");
70          // optional attribute
71          assertOk(groups, "x");
72          // only attribute from first group
73          assertOk(groups, "a1");
74          // attribute from first group plus optional attribute
75          assertOk(groups, "a1 x");
76      }
77      
78      @Test
79      public void testGroupsWithOverlappingAttributes() throws Exception
80      {
81          String[][] groups = new String[][] {
82              new String[] { "a1", "b1" },
83              new String[] { "a1", "b2" }
84          };
85          
86          // attribute from first group (can be in either group)
87          assertBad(groups, "a1", "do not satisfy");
88          // attribute from first group
89          assertOk(groups, "b1");
90          // attribute from second group
91          assertOk(groups, "b2");
92          // optional attribute
93          assertOk(groups, "a1 b1 x");
94          assertOk(groups, "a1 b2 x");
95          // complete first group
96          assertOk(groups, "a1 b1");
97          // complete second group
98          assertOk(groups, "a1 b2");
99      }
100     
101     @Test
102     public void testRealWorld() throws Exception
103     {
104         String[][] groups = new String[][] {
105             new String[] { "type", "recipient" },
106             new String[] { "type", "from" }
107         };
108         
109         assertOk(groups, "id name recipient subject type");
110     }
111     
112     @Override
113     protected PreProcessor createCheck(String[][] constraint)
114     {
115         return new CheckExclusiveAttributes(constraint);
116     }
117 }