27
27
import java .io .StringReader ;
28
28
import java .util .HashMap ;
29
29
30
+ import org .codehaus .plexus .util .xml .pull .XmlPullParser ;
30
31
import org .codehaus .plexus .util .xml .pull .XmlPullParserException ;
31
32
import org .junit .Test ;
32
33
@@ -38,24 +39,34 @@ public void testShouldPerformAppendAtFirstSubElementLevel()
38
39
// create the dominant DOM
39
40
Xpp3Dom t1 = new Xpp3Dom ( "top" );
40
41
t1 .setAttribute ( Xpp3Dom .CHILDREN_COMBINATION_MODE_ATTRIBUTE , Xpp3Dom .CHILDREN_COMBINATION_APPEND );
42
+ t1 .setInputLocation ( "t1top" );
41
43
42
44
Xpp3Dom t1s1 = new Xpp3Dom ( "topsub1" );
43
45
t1s1 .setValue ( "t1s1Value" );
46
+ t1s1 .setInputLocation ( "t1s1" );
44
47
45
48
t1 .addChild ( t1s1 );
46
49
47
50
// create the recessive DOM
48
51
Xpp3Dom t2 = new Xpp3Dom ( "top" );
52
+ t2 .setInputLocation ( "t2top" );
49
53
50
54
Xpp3Dom t2s1 = new Xpp3Dom ( "topsub1" );
51
55
t2s1 .setValue ( "t2s1Value" );
56
+ t2s1 .setInputLocation ( "t2s1" );
52
57
53
58
t2 .addChild ( t2s1 );
54
59
55
60
// merge and check results.
56
61
Xpp3Dom result = Xpp3Dom .mergeXpp3Dom ( t1 , t2 );
57
62
58
63
assertEquals ( 2 , result .getChildren ( "topsub1" ).length );
64
+ assertEquals ( "t2s1Value" , result .getChildren ( "topsub1" )[0 ].getValue () );
65
+ assertEquals ( "t1s1Value" , result .getChildren ( "topsub1" )[1 ].getValue () );
66
+
67
+ assertEquals ( "t1top" , result .getInputLocation () );
68
+ assertEquals ( "t2s1" , result .getChildren ( "topsub1" )[0 ].getInputLocation () );
69
+ assertEquals ( "t1s1" , result .getChildren ( "topsub1" )[1 ].getInputLocation () );
59
70
}
60
71
61
72
@ Test
@@ -64,24 +75,32 @@ public void testShouldOverrideAppendAndDeepMerge()
64
75
// create the dominant DOM
65
76
Xpp3Dom t1 = new Xpp3Dom ( "top" );
66
77
t1 .setAttribute ( Xpp3Dom .CHILDREN_COMBINATION_MODE_ATTRIBUTE , Xpp3Dom .CHILDREN_COMBINATION_APPEND );
78
+ t1 .setInputLocation ( "t1top" );
67
79
68
80
Xpp3Dom t1s1 = new Xpp3Dom ( "topsub1" );
69
81
t1s1 .setValue ( "t1s1Value" );
82
+ t1s1 .setInputLocation ( "t1s1" );
70
83
71
84
t1 .addChild ( t1s1 );
72
85
73
86
// create the recessive DOM
74
87
Xpp3Dom t2 = new Xpp3Dom ( "top" );
88
+ t2 .setInputLocation ( "t2top" );
75
89
76
90
Xpp3Dom t2s1 = new Xpp3Dom ( "topsub1" );
77
91
t2s1 .setValue ( "t2s1Value" );
92
+ t2s1 .setInputLocation ( "t2s1" );
78
93
79
94
t2 .addChild ( t2s1 );
80
95
81
96
// merge and check results.
82
97
Xpp3Dom result = Xpp3Dom .mergeXpp3Dom ( t1 , t2 , Boolean .TRUE );
83
98
84
99
assertEquals ( 1 , result .getChildren ( "topsub1" ).length );
100
+ assertEquals ( "t1s1Value" , result .getChildren ( "topsub1" )[0 ].getValue () );
101
+
102
+ assertEquals ( "t1top" , result .getInputLocation () );
103
+ assertEquals ( "t1s1" , result .getChildren ( "topsub1" )[0 ].getInputLocation () );
85
104
}
86
105
87
106
@ Test
@@ -90,19 +109,22 @@ public void testShouldPerformSelfOverrideAtTopLevel()
90
109
// create the dominant DOM
91
110
Xpp3Dom t1 = new Xpp3Dom ( "top" );
92
111
t1 .setAttribute ( "attr" , "value" );
112
+ t1 .setInputLocation ( "t1top" );
93
113
94
114
t1 .setAttribute ( Xpp3Dom .SELF_COMBINATION_MODE_ATTRIBUTE , Xpp3Dom .SELF_COMBINATION_OVERRIDE );
95
115
96
116
// create the recessive DOM
97
117
Xpp3Dom t2 = new Xpp3Dom ( "top" );
98
118
t2 .setAttribute ( "attr2" , "value2" );
99
119
t2 .setValue ( "t2Value" );
120
+ t2 .setInputLocation ( "t2top" );
100
121
101
122
// merge and check results.
102
123
Xpp3Dom result = Xpp3Dom .mergeXpp3Dom ( t1 , t2 );
103
124
104
125
assertEquals ( 2 , result .getAttributeNames ().length );
105
126
assertNull ( result .getValue () );
127
+ assertEquals ( "t1top" , result .getInputLocation () );
106
128
}
107
129
108
130
@ Test
@@ -111,11 +133,13 @@ public void testShouldMergeValuesAtTopLevelByDefault()
111
133
// create the dominant DOM
112
134
Xpp3Dom t1 = new Xpp3Dom ( "top" );
113
135
t1 .setAttribute ( "attr" , "value" );
136
+ t1 .setInputLocation ( "t1top" );
114
137
115
138
// create the recessive DOM
116
139
Xpp3Dom t2 = new Xpp3Dom ( "top" );
117
140
t2 .setAttribute ( "attr2" , "value2" );
118
141
t2 .setValue ( "t2Value" );
142
+ t2 .setInputLocation ( "t2top" );
119
143
120
144
// merge and check results.
121
145
Xpp3Dom result = Xpp3Dom .mergeXpp3Dom ( t1 , t2 );
@@ -124,6 +148,7 @@ public void testShouldMergeValuesAtTopLevelByDefault()
124
148
assertEquals ( 2 , result .getAttributeNames ().length );
125
149
126
150
assertEquals ( result .getValue (), t2 .getValue () );
151
+ assertEquals ( "t2top" , result .getInputLocation () );
127
152
}
128
153
129
154
@ Test
@@ -213,10 +238,12 @@ public void testShouldOverwritePluginConfigurationSubItemsByDefault()
213
238
throws XmlPullParserException , IOException
214
239
{
215
240
String parentConfigStr = "<configuration><items><item>one</item><item>two</item></items></configuration>" ;
216
- Xpp3Dom parentConfig = Xpp3DomBuilder .build ( new StringReader ( parentConfigStr ) );
241
+ Xpp3Dom parentConfig =
242
+ Xpp3DomBuilder .build ( new StringReader ( parentConfigStr ), new FixedInputLocationBuilder ( "parent" ) );
217
243
218
244
String childConfigStr = "<configuration><items><item>three</item></items></configuration>" ;
219
- Xpp3Dom childConfig = Xpp3DomBuilder .build ( new StringReader ( childConfigStr ) );
245
+ Xpp3Dom childConfig =
246
+ Xpp3DomBuilder .build ( new StringReader ( childConfigStr ), new FixedInputLocationBuilder ( "child" ) );
220
247
221
248
Xpp3Dom result = Xpp3Dom .mergeXpp3Dom ( childConfig , parentConfig );
222
249
Xpp3Dom items = result .getChild ( "items" );
@@ -225,18 +252,21 @@ public void testShouldOverwritePluginConfigurationSubItemsByDefault()
225
252
226
253
Xpp3Dom item = items .getChild ( 0 );
227
254
assertEquals ( "three" , item .getValue () );
255
+ assertEquals ( "child" , item .getInputLocation () );
228
256
}
229
257
230
258
@ Test
231
259
public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet ()
232
260
throws XmlPullParserException , IOException
233
261
{
234
262
String parentConfigStr = "<configuration><items><item>one</item><item>two</item></items></configuration>" ;
235
- Xpp3Dom parentConfig = Xpp3DomBuilder .build ( new StringReader ( parentConfigStr ) );
263
+ Xpp3Dom parentConfig =
264
+ Xpp3DomBuilder .build ( new StringReader ( parentConfigStr ), new FixedInputLocationBuilder ( "parent" ) );
236
265
237
266
String childConfigStr =
238
267
"<configuration><items combine.children=\" append\" ><item>three</item></items></configuration>" ;
239
- Xpp3Dom childConfig = Xpp3DomBuilder .build ( new StringReader ( childConfigStr ) );
268
+ Xpp3Dom childConfig =
269
+ Xpp3DomBuilder .build ( new StringReader ( childConfigStr ), new FixedInputLocationBuilder ( "child" ) );
240
270
241
271
Xpp3Dom result = Xpp3Dom .mergeXpp3Dom ( childConfig , parentConfig );
242
272
Xpp3Dom items = result .getChild ( "items" );
@@ -246,8 +276,11 @@ public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet()
246
276
Xpp3Dom [] item = items .getChildren ();
247
277
248
278
assertEquals ( "one" , item [0 ].getValue () );
279
+ assertEquals ( "parent" , item [0 ].getInputLocation () );
249
280
assertEquals ( "two" , item [1 ].getValue () );
281
+ assertEquals ( "parent" , item [1 ].getInputLocation () );
250
282
assertEquals ( "three" , item [2 ].getValue () );
283
+ assertEquals ( "child" , item [2 ].getInputLocation () );
251
284
}
252
285
253
286
@ Test
@@ -295,4 +328,20 @@ public void testDupeChildren()
295
328
assertNotNull ( dom );
296
329
assertEquals ( "y" , dom .getChild ( "foo" ).getValue () );
297
330
}
331
+
332
+ private static class FixedInputLocationBuilder
333
+ implements Xpp3DomBuilder .InputLocationBuilder
334
+ {
335
+ private final Object location ;
336
+
337
+ public FixedInputLocationBuilder ( Object location )
338
+ {
339
+ this .location = location ;
340
+ }
341
+
342
+ public Object toInputLocation ( XmlPullParser parser )
343
+ {
344
+ return location ;
345
+ }
346
+ }
298
347
}
0 commit comments