1
2
3
4
5
6
7
8
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
43 assertOk(groups, "x");
44
45 assertOk(groups, "a1");
46
47 assertOk(groups, "b1");
48 assertOk(groups, "b2");
49
50 assertOk(groups, "a1 x");
51
52 assertOk(groups, "x b1");
53 assertOk(groups, "x b2");
54
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
75 assertOk(groups, "x");
76
77 assertOk(groups, "a1");
78
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
91 assertBad(groups, "a1", "do not satisfy");
92
93 assertOk(groups, "b1");
94
95 assertOk(groups, "b2");
96
97 assertOk(groups, "a1 b1 x");
98 assertOk(groups, "a1 b2 x");
99
100 assertOk(groups, "a1 b1");
101
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 }