2727import java .io .StringReader ;
2828import java .util .HashMap ;
2929
30+ import org .codehaus .plexus .util .xml .pull .XmlPullParser ;
3031import org .codehaus .plexus .util .xml .pull .XmlPullParserException ;
3132import org .junit .Test ;
3233
@@ -38,24 +39,34 @@ public void testShouldPerformAppendAtFirstSubElementLevel()
3839 // create the dominant DOM
3940 Xpp3Dom t1 = new Xpp3Dom ( "top" );
4041 t1 .setAttribute ( Xpp3Dom .CHILDREN_COMBINATION_MODE_ATTRIBUTE , Xpp3Dom .CHILDREN_COMBINATION_APPEND );
42+ t1 .setInputLocation ( "t1top" );
4143
4244 Xpp3Dom t1s1 = new Xpp3Dom ( "topsub1" );
4345 t1s1 .setValue ( "t1s1Value" );
46+ t1s1 .setInputLocation ( "t1s1" );
4447
4548 t1 .addChild ( t1s1 );
4649
4750 // create the recessive DOM
4851 Xpp3Dom t2 = new Xpp3Dom ( "top" );
52+ t2 .setInputLocation ( "t2top" );
4953
5054 Xpp3Dom t2s1 = new Xpp3Dom ( "topsub1" );
5155 t2s1 .setValue ( "t2s1Value" );
56+ t2s1 .setInputLocation ( "t2s1" );
5257
5358 t2 .addChild ( t2s1 );
5459
5560 // merge and check results.
5661 Xpp3Dom result = Xpp3Dom .mergeXpp3Dom ( t1 , t2 );
5762
5863 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 () );
5970 }
6071
6172 @ Test
@@ -64,24 +75,32 @@ public void testShouldOverrideAppendAndDeepMerge()
6475 // create the dominant DOM
6576 Xpp3Dom t1 = new Xpp3Dom ( "top" );
6677 t1 .setAttribute ( Xpp3Dom .CHILDREN_COMBINATION_MODE_ATTRIBUTE , Xpp3Dom .CHILDREN_COMBINATION_APPEND );
78+ t1 .setInputLocation ( "t1top" );
6779
6880 Xpp3Dom t1s1 = new Xpp3Dom ( "topsub1" );
6981 t1s1 .setValue ( "t1s1Value" );
82+ t1s1 .setInputLocation ( "t1s1" );
7083
7184 t1 .addChild ( t1s1 );
7285
7386 // create the recessive DOM
7487 Xpp3Dom t2 = new Xpp3Dom ( "top" );
88+ t2 .setInputLocation ( "t2top" );
7589
7690 Xpp3Dom t2s1 = new Xpp3Dom ( "topsub1" );
7791 t2s1 .setValue ( "t2s1Value" );
92+ t2s1 .setInputLocation ( "t2s1" );
7893
7994 t2 .addChild ( t2s1 );
8095
8196 // merge and check results.
8297 Xpp3Dom result = Xpp3Dom .mergeXpp3Dom ( t1 , t2 , Boolean .TRUE );
8398
8499 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 () );
85104 }
86105
87106 @ Test
@@ -90,19 +109,22 @@ public void testShouldPerformSelfOverrideAtTopLevel()
90109 // create the dominant DOM
91110 Xpp3Dom t1 = new Xpp3Dom ( "top" );
92111 t1 .setAttribute ( "attr" , "value" );
112+ t1 .setInputLocation ( "t1top" );
93113
94114 t1 .setAttribute ( Xpp3Dom .SELF_COMBINATION_MODE_ATTRIBUTE , Xpp3Dom .SELF_COMBINATION_OVERRIDE );
95115
96116 // create the recessive DOM
97117 Xpp3Dom t2 = new Xpp3Dom ( "top" );
98118 t2 .setAttribute ( "attr2" , "value2" );
99119 t2 .setValue ( "t2Value" );
120+ t2 .setInputLocation ( "t2top" );
100121
101122 // merge and check results.
102123 Xpp3Dom result = Xpp3Dom .mergeXpp3Dom ( t1 , t2 );
103124
104125 assertEquals ( 2 , result .getAttributeNames ().length );
105126 assertNull ( result .getValue () );
127+ assertEquals ( "t1top" , result .getInputLocation () );
106128 }
107129
108130 @ Test
@@ -111,11 +133,13 @@ public void testShouldMergeValuesAtTopLevelByDefault()
111133 // create the dominant DOM
112134 Xpp3Dom t1 = new Xpp3Dom ( "top" );
113135 t1 .setAttribute ( "attr" , "value" );
136+ t1 .setInputLocation ( "t1top" );
114137
115138 // create the recessive DOM
116139 Xpp3Dom t2 = new Xpp3Dom ( "top" );
117140 t2 .setAttribute ( "attr2" , "value2" );
118141 t2 .setValue ( "t2Value" );
142+ t2 .setInputLocation ( "t2top" );
119143
120144 // merge and check results.
121145 Xpp3Dom result = Xpp3Dom .mergeXpp3Dom ( t1 , t2 );
@@ -124,6 +148,7 @@ public void testShouldMergeValuesAtTopLevelByDefault()
124148 assertEquals ( 2 , result .getAttributeNames ().length );
125149
126150 assertEquals ( result .getValue (), t2 .getValue () );
151+ assertEquals ( "t2top" , result .getInputLocation () );
127152 }
128153
129154 @ Test
@@ -213,10 +238,12 @@ public void testShouldOverwritePluginConfigurationSubItemsByDefault()
213238 throws XmlPullParserException , IOException
214239 {
215240 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" ) );
217243
218244 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" ) );
220247
221248 Xpp3Dom result = Xpp3Dom .mergeXpp3Dom ( childConfig , parentConfig );
222249 Xpp3Dom items = result .getChild ( "items" );
@@ -225,18 +252,21 @@ public void testShouldOverwritePluginConfigurationSubItemsByDefault()
225252
226253 Xpp3Dom item = items .getChild ( 0 );
227254 assertEquals ( "three" , item .getValue () );
255+ assertEquals ( "child" , item .getInputLocation () );
228256 }
229257
230258 @ Test
231259 public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet ()
232260 throws XmlPullParserException , IOException
233261 {
234262 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" ) );
236265
237266 String childConfigStr =
238267 "<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" ) );
240270
241271 Xpp3Dom result = Xpp3Dom .mergeXpp3Dom ( childConfig , parentConfig );
242272 Xpp3Dom items = result .getChild ( "items" );
@@ -246,8 +276,11 @@ public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet()
246276 Xpp3Dom [] item = items .getChildren ();
247277
248278 assertEquals ( "one" , item [0 ].getValue () );
279+ assertEquals ( "parent" , item [0 ].getInputLocation () );
249280 assertEquals ( "two" , item [1 ].getValue () );
281+ assertEquals ( "parent" , item [1 ].getInputLocation () );
250282 assertEquals ( "three" , item [2 ].getValue () );
283+ assertEquals ( "child" , item [2 ].getInputLocation () );
251284 }
252285
253286 @ Test
@@ -295,4 +328,20 @@ public void testDupeChildren()
295328 assertNotNull ( dom );
296329 assertEquals ( "y" , dom .getChild ( "foo" ).getValue () );
297330 }
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+ }
298347}
0 commit comments