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 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
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 public void testSecondGroupEmpty() throws Exception
62 {
63 String[][] groups = new String[][]{
64 new String[] { "a1" },
65 new String[] {}
66 };
67
68 assertOk(groups, "");
69
70 assertOk(groups, "x");
71
72 assertOk(groups, "a1");
73
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
85 assertBad(groups, "a1", "do not satisfy");
86
87 assertOk(groups, "b1");
88
89 assertOk(groups, "b2");
90
91 assertOk(groups, "a1 b1 x");
92 assertOk(groups, "a1 b2 x");
93
94 assertOk(groups, "a1 b1");
95
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 }