1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.launcher;
12
13 import org.mule.module.launcher.descriptor.ApplicationDescriptor;
14 import org.mule.module.launcher.descriptor.DescriptorParser;
15 import org.mule.module.launcher.descriptor.Preferred;
16 import org.mule.tck.AbstractMuleTestCase;
17
18 import java.io.File;
19 import java.io.IOException;
20
21 import org.apache.commons.collections.MultiMap;
22 import org.apache.commons.collections.map.MultiValueMap;
23
24 public class DescriptorParserTestCase extends AbstractMuleTestCase
25 {
26
27 public void testOverridePreferred() throws Exception
28 {
29 DefaultAppBloodhound bh = new DefaultAppBloodhound();
30 MultiMap overrides = new MultiValueMap();
31 overrides.put("properties", new TestDescriptorParserDefault());
32
33
34 bh.mergeParserOverrides(overrides);
35 assertEquals(1, bh.parserRegistry.size());
36 DescriptorParser result = bh.parserRegistry.get("properties");
37 assertNotNull(result);
38 assertTrue("@Preferred implementation ignored", result instanceof TestDescriptorParserDefault);
39 }
40
41 public void testBothPreferredWithWeight() throws Exception
42 {
43 DefaultAppBloodhound bh = new DefaultAppBloodhound();
44 MultiMap overrides = new MultiValueMap();
45 overrides.put("properties", new TestDescriptorParserDefault());
46 overrides.put("properties", new TestDescriptorParserPreferred());
47
48
49 bh.mergeParserOverrides(overrides);
50 assertEquals(1, bh.parserRegistry.size());
51 DescriptorParser result = bh.parserRegistry.get("properties");
52 assertNotNull(result);
53 assertTrue("@Preferred implementation ignored", result instanceof TestDescriptorParserPreferred);
54 }
55
56 public void testOverrideWithoutPreferred() throws Exception
57 {
58 DefaultAppBloodhound bh = new DefaultAppBloodhound();
59 MultiMap overrides = new MultiValueMap();
60 overrides.put("properties", new TestDescriptorParserNoAnnotation());
61
62
63 bh.mergeParserOverrides(overrides);
64 assertEquals(1, bh.parserRegistry.size());
65 DescriptorParser result = bh.parserRegistry.get("properties");
66 assertNotNull(result);
67 assertTrue("@Preferred implementation ignored", result instanceof TestDescriptorParserNoAnnotation);
68 }
69
70 public void testMixedOverrides() throws Exception
71 {
72 DefaultAppBloodhound bh = new DefaultAppBloodhound();
73 MultiMap overrides = new MultiValueMap();
74 overrides.put("properties", new TestDescriptorParserNoAnnotation());
75 overrides.put("properties", new TestDescriptorParserDefault());
76
77
78 bh.mergeParserOverrides(overrides);
79 assertEquals(1, bh.parserRegistry.size());
80 DescriptorParser result = bh.parserRegistry.get("properties");
81 assertNotNull(result);
82 assertTrue("@Preferred implementation ignored", result instanceof TestDescriptorParserDefault);
83 }
84
85
86
87
88
89 @Preferred()
90 class TestDescriptorParserDefault implements DescriptorParser
91 {
92
93 public ApplicationDescriptor parse(File descriptor) throws IOException
94 {
95 return null;
96 }
97
98 public String getSupportedFormat()
99 {
100 return "properties";
101 }
102 }
103
104
105
106
107 @Preferred(weight = 10)
108 class TestDescriptorParserPreferred implements DescriptorParser
109 {
110
111 public ApplicationDescriptor parse(File descriptor) throws IOException
112 {
113 return null;
114 }
115
116 public String getSupportedFormat()
117 {
118 return "properties";
119 }
120
121 }
122
123
124 class TestDescriptorParserNoAnnotation implements DescriptorParser
125 {
126
127 public ApplicationDescriptor parse(File descriptor) throws IOException
128 {
129 return null;
130 }
131
132 public String getSupportedFormat()
133 {
134 return "properties";
135 }
136
137 }
138
139 }