KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > project > ModelUtilsTest


1 package org.apache.maven.project;
2
3 import junit.framework.TestCase;
4
5 import org.apache.maven.model.Plugin;
6 import org.apache.maven.model.PluginContainer;
7 import org.apache.maven.model.PluginExecution;
8 import org.apache.maven.model.Dependency;
9
10 import java.util.Collections JavaDoc;
11
12 /*
13  * Copyright 2001-2005 The Apache Software Foundation.
14  *
15  * Licensed under the Apache License, Version 2.0 (the "License");
16  * you may not use this file except in compliance with the License.
17  * You may obtain a copy of the License at
18  *
19  * http://www.apache.org/licenses/LICENSE-2.0
20  *
21  * Unless required by applicable law or agreed to in writing, software
22  * distributed under the License is distributed on an "AS IS" BASIS,
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24  * See the License for the specific language governing permissions and
25  * limitations under the License.
26  */

27
28 public class ModelUtilsTest
29     extends TestCase
30 {
31     public void testShouldInheritOnePluginWithExecution()
32     {
33         Plugin parent = new Plugin();
34         parent.setArtifactId( "testArtifact" );
35         parent.setGroupId( "testGroup" );
36         parent.setVersion( "1.0" );
37
38         PluginExecution parentExecution = new PluginExecution();
39         parentExecution.setId( "testExecution" );
40
41         parent.addExecution( parentExecution );
42
43         Plugin child = new Plugin();
44         child.setArtifactId( "testArtifact" );
45         child.setGroupId( "testGroup" );
46         child.setVersion( "1.0" );
47
48         ModelUtils.mergePluginDefinitions( child, parent, false );
49
50         assertEquals( 1, child.getExecutions().size() );
51     }
52
53     public void testShouldMergeInheritedPluginHavingExecutionWithLocalPlugin()
54     {
55         Plugin parent = new Plugin();
56         parent.setArtifactId( "testArtifact" );
57         parent.setGroupId( "testGroup" );
58         parent.setVersion( "1.0" );
59
60         PluginExecution parentExecution = new PluginExecution();
61         parentExecution.setId( "testExecution" );
62
63         parent.addExecution( parentExecution );
64
65         Plugin child = new Plugin();
66         child.setArtifactId( "testArtifact" );
67         child.setGroupId( "testGroup" );
68         child.setVersion( "1.0" );
69
70         PluginExecution childExecution = new PluginExecution();
71         childExecution.setId( "testExecution2" );
72
73         child.addExecution( childExecution );
74
75         ModelUtils.mergePluginDefinitions( child, parent, false );
76
77         assertEquals( 2, child.getExecutions().size() );
78     }
79
80     public void testShouldNOTMergeInheritedPluginHavingInheritEqualFalse()
81     {
82         Plugin parent = new Plugin();
83         parent.setArtifactId( "testArtifact" );
84         parent.setGroupId( "testGroup" );
85         parent.setVersion( "1.0" );
86         parent.setInherited( "false" );
87
88         PluginExecution parentExecution = new PluginExecution();
89         parentExecution.setId( "testExecution" );
90
91         parent.addExecution( parentExecution );
92
93         Plugin child = new Plugin();
94         child.setArtifactId( "testArtifact" );
95         child.setGroupId( "testGroup" );
96         child.setVersion( "1.0" );
97
98         ModelUtils.mergePluginDefinitions( child, parent, true );
99
100         assertEquals( 0, child.getExecutions().size() );
101     }
102
103     /**
104      * Verifies MNG-1499: The order of the merged list should be the plugins specified by the parent followed by the
105      * child list.
106      */

107     public void testShouldKeepOriginalPluginOrdering()
108     {
109         Plugin parentPlugin1 = new Plugin();
110         parentPlugin1.setArtifactId( "testArtifact" );
111         parentPlugin1.setGroupId( "zzz" ); // This will put this plugin last in the sorted map
112
parentPlugin1.setVersion( "1.0" );
113
114         PluginExecution parentExecution1 = new PluginExecution();
115         parentExecution1.setId( "testExecution" );
116
117         parentPlugin1.addExecution( parentExecution1 );
118
119         Plugin parentPlugin2 = new Plugin();
120         parentPlugin2.setArtifactId( "testArtifact" );
121         parentPlugin2.setGroupId( "yyy" );
122         parentPlugin2.setVersion( "1.0" );
123
124         PluginExecution parentExecution2 = new PluginExecution();
125         parentExecution2.setId( "testExecution" );
126
127         parentPlugin2.addExecution( parentExecution2 );
128
129         PluginContainer parentContainer = new PluginContainer();
130         parentContainer.addPlugin(parentPlugin1);
131         parentContainer.addPlugin(parentPlugin2);
132
133
134         Plugin childPlugin1 = new Plugin();
135         childPlugin1.setArtifactId( "testArtifact" );
136         childPlugin1.setGroupId( "bbb" );
137         childPlugin1.setVersion( "1.0" );
138
139         PluginExecution childExecution1 = new PluginExecution();
140         childExecution1.setId( "testExecution" );
141
142         childPlugin1.addExecution( childExecution1 );
143
144         Plugin childPlugin2 = new Plugin();
145         childPlugin2.setArtifactId( "testArtifact" );
146         childPlugin2.setGroupId( "aaa" );
147         childPlugin2.setVersion( "1.0" );
148
149         PluginExecution childExecution2 = new PluginExecution();
150         childExecution2.setId( "testExecution" );
151
152         childPlugin2.addExecution( childExecution2 );
153
154         PluginContainer childContainer = new PluginContainer();
155         childContainer.addPlugin(childPlugin1);
156         childContainer.addPlugin(childPlugin2);
157
158
159         ModelUtils.mergePluginLists(childContainer, parentContainer, true);
160
161         assertEquals( 4, childContainer.getPlugins().size() );
162         assertSame(parentPlugin1, childContainer.getPlugins().get(0));
163         assertSame(parentPlugin2, childContainer.getPlugins().get(1));
164         assertSame(childPlugin1, childContainer.getPlugins().get(2));
165         assertSame(childPlugin2, childContainer.getPlugins().get(3));
166     }
167
168     /**
169      * Verifies MNG-1499: The ordering of plugin executions should also be in the specified order.
170      */

171     public void testShouldKeepOriginalPluginExecutionOrdering()
172     {
173         Plugin parent = new Plugin();
174         parent.setArtifactId( "testArtifact" );
175         parent.setGroupId( "testGroup" );
176         parent.setVersion( "1.0" );
177
178         PluginExecution parentExecution1 = new PluginExecution();
179         parentExecution1.setId( "zzz" ); // Will show up last in the sorted map
180
PluginExecution parentExecution2 = new PluginExecution();
181         parentExecution2.setId( "yyy" ); // Will show up last in the sorted map
182

183         parent.addExecution( parentExecution1 );
184         parent.addExecution( parentExecution2 );
185
186         // this block verifies MNG-1703
187
Dependency dep = new Dependency();
188         dep.setGroupId( "depGroupId" );
189         dep.setArtifactId( "depArtifactId" );
190         dep.setVersion( "depVersion" );
191         parent.setDependencies( Collections.singletonList( dep ) );
192
193         Plugin child = new Plugin();
194         child.setArtifactId( "testArtifact" );
195         child.setGroupId( "testGroup" );
196         child.setVersion( "1.0" );
197
198         PluginExecution childExecution1 = new PluginExecution();
199         childExecution1.setId( "bbb" );
200         PluginExecution childExecution2 = new PluginExecution();
201         childExecution2.setId( "aaa" );
202
203         child.addExecution( childExecution1 );
204         child.addExecution( childExecution2 );
205
206         ModelUtils.mergePluginDefinitions( child, parent, false );
207
208         assertEquals( 4, child.getExecutions().size() );
209         assertSame(parentExecution1, child.getExecutions().get(0));
210         assertSame(parentExecution2, child.getExecutions().get(1));
211         assertSame(childExecution1, child.getExecutions().get(2));
212         assertSame(childExecution2, child.getExecutions().get(3));
213
214         // this block prevents MNG-1703
215
assertEquals( 1, child.getDependencies().size() );
216         Dependency dep2 = (Dependency) child.getDependencies().get( 0 );
217         assertEquals( dep.getManagementKey(), dep2.getManagementKey() );
218     }
219 }
220
Popular Tags