1
2
3
4
5
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
39 assertOk(groups, "x");
40
41 assertOk(groups, "a1");
42
43 assertOk(groups, "b1");
44 assertOk(groups, "b2");
45
46 assertOk(groups, "a1 x");
47
48 assertOk(groups, "x b1");
49 assertOk(groups, "x b2");
50
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
71 assertOk(groups, "x");
72
73 assertOk(groups, "a1");
74
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
87 assertBad(groups, "a1", "do not satisfy");
88
89 assertOk(groups, "b1");
90
91 assertOk(groups, "b2");
92
93 assertOk(groups, "a1 b1 x");
94 assertOk(groups, "a1 b2 x");
95
96 assertOk(groups, "a1 b1");
97
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 }