1 package org.apache.maven.plugin.deploy;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25 import org.apache.maven.model.Model;
26 import org.apache.maven.model.Parent;
27 import org.apache.maven.plugin.MojoExecutionException;
28
29 import java.io.File;
30
31
32
33
34
35 public class DeployFileMojoUnitTest
36 extends TestCase
37 {
38 public static void main( String[] args )
39 {
40 junit.textui.TestRunner.run( suite() );
41 }
42
43 public static Test suite()
44 {
45 TestSuite suite = new TestSuite( DeployFileMojoUnitTest.class );
46
47 return suite;
48 }
49
50 MockDeployFileMojo mojo;
51 Parent parent;
52
53 public void setUp()
54 {
55 Model pomModel = new Model();
56 pomModel.setPackaging( null );
57
58 parent = new Parent();
59 parent.setGroupId( "parentGroup" );
60 parent.setArtifactId( "parentArtifact" );
61 parent.setVersion( "parentVersion" );
62
63 mojo = new MockDeployFileMojo( pomModel );
64 }
65
66 public void tearDown()
67 {
68 mojo = null;
69 }
70
71 class MockDeployFileMojo extends DeployFileMojo {
72 private Model model;
73
74 public MockDeployFileMojo(Model model) {
75 this.model = model;
76 }
77
78 public void setModel(Model model) {
79 this.model = model;
80 }
81
82 protected Model readModel(File pomFile) throws MojoExecutionException {
83 return model;
84 }
85 }
86
87 public void testProcessPomFromPomFileWithParent1() throws MojoExecutionException
88 {
89 mojo.setPomFile( new File( "foo.bar" ) );
90
91 setMojoModel( mojo.model, null, null, null, null, parent );
92
93 try {
94 mojo.initProperties();
95 } catch (MojoExecutionException expected) {
96 assertTrue( true );
97 }
98
99 checkMojoProperties("parentGroup", null, "parentVersion", null);
100 }
101
102 public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException
103 {
104 mojo.setPomFile( new File( "foo.bar" ) );
105 setMojoModel( mojo.model, null, "artifact", null, null, parent );
106
107 try {
108 mojo.initProperties();
109 } catch (MojoExecutionException expected) {
110 assertTrue( true );
111 }
112
113 checkMojoProperties("parentGroup", "artifact", "parentVersion", null );
114
115 }
116
117 public void testProcessPomFromPomFileWithParent3() throws MojoExecutionException
118 {
119 mojo.setPomFile( new File( "foo.bar" ) );
120 setMojoModel( mojo.model, null, "artifact", "version", null, parent );
121
122 try {
123 mojo.initProperties();
124 } catch (MojoExecutionException expected) {
125 assertTrue( true );
126 }
127
128 checkMojoProperties( "parentGroup", "artifact", "version", null );
129 }
130
131 public void testProcessPomFromPomFileWithParent4() throws MojoExecutionException
132 {
133 mojo.setPomFile( new File( "foo.bar" ) );
134 setMojoModel( mojo.model, null, "artifact", "version", "packaging", parent );
135
136 mojo.initProperties();
137
138 checkMojoProperties("parentGroup", "artifact", "version", "packaging");
139 }
140
141 public void testProcessPomFromPomFileWithParent5() throws MojoExecutionException
142 {
143 mojo.setPomFile( new File( "foo.bar" ) );
144 setMojoModel( mojo.model, "group", "artifact", "version", "packaging", parent );
145
146 mojo.initProperties();
147
148 checkMojoProperties("group", "artifact", "version", "packaging");
149 }
150
151 public void testProcessPomFromPomFileWithParent6() throws MojoExecutionException
152 {
153 mojo.setPomFile( new File( "foo.bar" ) );
154 setMojoModel( mojo.model, "group", "artifact", "version", "packaging", null );
155
156 mojo.initProperties();
157
158 checkMojoProperties("group", "artifact", "version", "packaging");
159
160 }
161
162 public void testProcessPomFromPomFileWithOverrides() throws MojoExecutionException
163 {
164 mojo.setPomFile( new File( "foo.bar" ) );
165 setMojoModel( mojo.model, "group", "artifact", "version", "packaging", null );
166
167 mojo.setGroupId( "groupO" );
168 mojo.setArtifactId( "artifactO" );
169 mojo.setVersion( "versionO" );
170 mojo.setPackaging( "packagingO" );
171
172 mojo.initProperties();
173
174 checkMojoProperties("groupO", "artifactO", "versionO", "packagingO");
175 }
176
177 private void checkMojoProperties(final String expectedGroup, final String expectedArtifact, final String expectedVersion, final String expectedPackaging) {
178 assertEquals( expectedGroup, mojo.getGroupId() );
179 assertEquals( expectedArtifact, mojo.getArtifactId() );
180 assertEquals( expectedVersion, mojo.getVersion() );
181 assertEquals( expectedPackaging, mojo.getPackaging() );
182 }
183
184 private void setMojoModel(Model model, String group, String artifact, String version, String packaging, Parent parent ) {
185 model.setGroupId( group );
186 model.setArtifactId( artifact );
187 model.setVersion( version );
188 model.setPackaging( packaging );
189 model.setParent( parent );
190 }
191
192 }