View Javadoc

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