-
Notifications
You must be signed in to change notification settings - Fork 162
/
ProjectPluginTest.java
233 lines (192 loc) · 7.94 KB
/
ProjectPluginTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
package org.jboss.forge.shell.test.plugins.builtin;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.maven.MavenCoreFacet;
import org.jboss.forge.maven.facets.MavenDependencyFacet;
import org.jboss.forge.project.Project;
import org.jboss.forge.project.dependencies.Dependency;
import org.jboss.forge.project.dependencies.DependencyBuilder;
import org.jboss.forge.project.dependencies.ScopeType;
import org.jboss.forge.test.AbstractShellTest;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @author <a href="mailto:macdude357@gmail.com">Tim Pedone</a>
*/
@RunWith(Arquillian.class)
public class ProjectPluginTest extends AbstractShellTest
{
@Test
public void testAddDependencyFromManagedParent() throws IOException
{
initializeJavaProject();
// commons-httpclient v 3.1 is in the depManagement section of the weld-api-bom
MavenCoreFacet mvnFacet = getProject().getFacet(MavenCoreFacet.class);
Parent parent = new Parent();
parent.setArtifactId("weld-api-bom");
parent.setGroupId("org.jboss.weld");
parent.setVersion("1.1.Final");
Model pom = mvnFacet.getPOM();
pom.setParent(parent);
mvnFacet.setPOM(pom);
DependencyBuilder dep = DependencyBuilder.create();
dep.setArtifactId("commons-httpclient");
dep.setGroupId("commons-httpclient");
dep.setVersion("3.1");
dep.setScopeType(ScopeType.COMPILE);
dep.setPackagingType("jar");
MavenDependencyFacet facet = getProject().getFacet(MavenDependencyFacet.class);
assertNull(facet.getDependency(dep));
queueInputLines("Y");
getShell().execute("project add-dependency commons-httpclient:commons-httpclient");
Dependency newDep = facet.getDependency(dep);
assertEquals(newDep.toCoordinates(), dep.toCoordinates());
}
/**
* Tests that if a dependency is managed by a parent and a different version is managed in the pom itself, then the
* local version will be used
*
* @throws IOException
*/
@Test
public void testAddDependencyFromLocalAndManagedParent() throws IOException
{
initializeJavaProject();
getShell().execute("project add-managed-dependency commons-httpclient:commons-httpclient:3.0");
// commons-httpclient v 3.1 is in the depManagement section of the weld-api-bom
MavenCoreFacet mvnFacet = getProject().getFacet(MavenCoreFacet.class);
Parent parent = new Parent();
parent.setArtifactId("weld-api-bom");
parent.setGroupId("org.jboss.weld");
parent.setVersion("1.1.Final");
Model pom = mvnFacet.getPOM();
pom.setParent(parent);
mvnFacet.setPOM(pom);
DependencyBuilder dep = DependencyBuilder.create();
dep.setArtifactId("commons-httpclient");
dep.setGroupId("commons-httpclient");
dep.setVersion("3.0");
dep.setScopeType(ScopeType.COMPILE);
dep.setPackagingType("jar");
MavenDependencyFacet facet = getProject().getFacet(MavenDependencyFacet.class);
assertNull(facet.getDependency(dep));
queueInputLines("Y");
getShell().execute("project add-dependency commons-httpclient:commons-httpclient");
Dependency newDep = facet.getDependency(dep);
assertEquals(newDep.toCoordinates(), dep.toCoordinates());
}
/**
* Tests that a dependency managed by an imported pom will be used.
*
* @throws IOException
*/
@Test
public void testAddDependencyFromManagedImport() throws IOException
{
initializeJavaProject();
// commons-httpclient v 3.1 is in the depManagement section of the weld-api-bom
getShell().execute("project add-managed-dependency org.jboss.weld:weld-api-bom:1.1.Final:import:pom");
MavenCoreFacet mvnFacet = getProject().getFacet(MavenCoreFacet.class);
Model pom = mvnFacet.getPOM();
mvnFacet.setPOM(pom);
DependencyBuilder dep = DependencyBuilder.create();
dep.setArtifactId("commons-httpclient");
dep.setGroupId("commons-httpclient");
dep.setVersion("3.1");
dep.setScopeType(ScopeType.COMPILE);
dep.setPackagingType("jar");
MavenDependencyFacet facet = getProject().getFacet(MavenDependencyFacet.class);
assertNull(facet.getDependency(dep));
queueInputLines("Y");
getShell().execute("project add-dependency commons-httpclient:commons-httpclient");
Dependency newDep = facet.getDependency(dep);
assertEquals(newDep.toCoordinates(), dep.toCoordinates());
}
/**
* Tests that a dependency that is managed in the local pom will be used.
*
* @throws IOException
*/
@Test
public void testAddDependencyFromManaged() throws IOException
{
Project project = initializeJavaProject();
getShell().execute("project add-managed-dependency com.ocpsoft:prettyfaces-jsf2:3.2.0");
MavenDependencyFacet facet = project.getFacet(MavenDependencyFacet.class);
DependencyBuilder dep = DependencyBuilder.create();
dep.setArtifactId("prettyfaces-jsf2");
dep.setGroupId("com.ocpsoft");
dep.setVersion("3.2.0");
dep.setScopeType("compile");
dep.setPackagingType("jar");
assertNull(facet.getDependency(dep));
queueInputLines("Y");
getShell().execute("project add-dependency com.ocpsoft:prettyfaces-jsf2");
Dependency newDep = facet.getDependency(dep);
assertEquals(newDep.toCoordinates(), dep.toCoordinates());
}
/**
* Tests overriding managed dependency with a different version.
*
* @throws IOException
*/
@Test
public void testAddDependencyOverrideManaged() throws IOException
{
queueInputLines("", "n");
Project project = initializeJavaProject();
getShell().execute("project add-managed-dependency com.ocpsoft:prettyfaces-jsf2:3.2.0");
MavenDependencyFacet facet = project.getFacet(MavenDependencyFacet.class);
DependencyBuilder dep = DependencyBuilder.create();
dep.setArtifactId("prettyfaces-jsf2");
dep.setGroupId("com.ocpsoft");
dep.setVersion("3.0.1");
dep.setScopeType("compile");
dep.setPackagingType("jar");
assertNull(facet.getDependency(dep));
getShell().execute("project add-dependency com.ocpsoft:prettyfaces-jsf2:3.0.1");
Dependency newDep = facet.getDependency(dep);
dep.setVersion("3.0.1");
assertEquals(newDep.toCoordinates(), dep.toCoordinates());
}
/**
* Tests overriding managed dependency with a different version.
*
* @throws IOException
*/
@Test
public void testAddDependencyOverrideManagedRange() throws IOException
{
queueInputLines("", "n", "2");
Project project = initializeJavaProject();
getShell().execute("project add-managed-dependency com.ocpsoft:prettyfaces-jsf2:3.2.0");
MavenDependencyFacet facet = project.getFacet(MavenDependencyFacet.class);
DependencyBuilder dep = DependencyBuilder.create();
dep.setArtifactId("prettyfaces-jsf2");
dep.setGroupId("com.ocpsoft");
dep.setVersion("3.0.1");
dep.setScopeType("compile");
dep.setPackagingType("jar");
assertNull(facet.getDependency(dep));
getShell().execute("project add-dependency com.ocpsoft:prettyfaces-jsf2");
Dependency newDep = facet.getDependency(dep);
dep.setVersion("3.0.1");
assertEquals(newDep.toCoordinates(), dep.toCoordinates());
}
@Test
public void testRemoveFacet() throws Exception
{
Project project = initializeJavaProject();
assertFalse(project.hasFacet(MockFacet.class));
getShell().execute("project install-facet mockfacet");
assertTrue(project.hasFacet(MockFacet.class));
getShell().execute("project remove-facet mockfacet");
assertFalse(project.hasFacet(MockFacet.class));
}
}