forked from shrinkwrap/shrinkwrap
/
DependenciesUnitTestCase.java
186 lines (151 loc) · 7.39 KB
/
DependenciesUnitTestCase.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
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.shrinkwrap.dependencies;
import java.io.File;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.dependencies.impl.MavenDependencies;
import org.jboss.shrinkwrap.dependencies.impl.MavenRepositorySettings;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Tests to ensure Dependencies resolves dependencies correctly
*
* @author <a href="kpiwko@redhat.com">Karel Piwko</a>
* @version $Revision: $
*/
public class DependenciesUnitTestCase
{
@BeforeClass
public static void setRemoteRepository() {
System.setProperty(MavenRepositorySettings.ALT_USER_SETTINGS_XML_LOCATION, "target/settings/profiles/settings.xml");
System.setProperty(MavenRepositorySettings.ALT_LOCAL_REPOSITORY_LOCATION, "target/the-other-repository");
}
// -------------------------------------------------------------------------------------||
// Tests ------------------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||
/**
* Tests that artifact is cannot be packaged, but is is resolved right.
* This test is not executed but shows that some jars cannot be packaged
*/
//@Test(expected = org.jboss.shrinkwrap.api.importer.ArchiveImportException.class)
//@Ignore
public void testSimpleResolutionWrongArtifact() throws DependencyException
{
String name = "simpleResolutionWrongArtifact";
WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war")
.addAsLibraries(Dependencies.artifact("org.apache.maven.plugins:maven-compiler-plugin:2.3.2").resolve());
// it will fail here
war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);
}
/**
* Tests a resolution of an artifact from central
* @throws DependencyException
*/
@Test
public void testSimpleResolution() throws DependencyException
{
String name = "simpleResolution";
WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war")
.addAsLibraries(Dependencies.artifact("org.jboss.shrinkwrap.test:test-deps-c:1.0.0")
.resolve());
DependencyTreeDescription desc = new DependencyTreeDescription(new File("src/test/resources/dependency-trees/test-deps-c.tree"));
desc.validateArchive(war).results();
war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);
}
/**
* Tests a resolution of an artifact from central with custom settings
* @throws DependencyException
*/
@Test
public void testSimpleResolutionWithCustomSettings() throws DependencyException
{
String name = "simpleResolutionWithCustomSettings";
WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war")
.addAsLibraries(Dependencies.use(MavenDependencies.class)
.configureFrom("target/settings/profiles/settings.xml")
.artifact("org.jboss.shrinkwrap.test:test-deps-c:1.0.0")
.resolve());
DependencyTreeDescription desc = new DependencyTreeDescription(new File("src/test/resources/dependency-trees/test-deps-c.tree"));
desc.validateArchive(war).results();
war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);
}
/**
* Tests passing invalid path to a settings XML
* @throws DependencyException
*/
@Test(expected = IllegalArgumentException.class)
public void testInvalidSettingsPath() throws DependencyException
{
// this should fail
ShrinkWrap.create(WebArchive.class, "testSimpleResolutionWithCustomSettings.war")
.addAsLibraries(Dependencies.use(MavenDependencies.class)
.configureFrom("src/test/invalid/custom-settings.xml")
.artifact("org.jboss.shrinkwrap.test:test-deps-c:1.0.0")
.resolve());
}
/**
* Tests a resolution of two artifacts from central
* @throws DependencyException
*/
@Test
public void testMultipleResolution() throws DependencyException
{
String name = "multipleResolution";
WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war")
.addAsLibraries(Dependencies.artifact("org.jboss.shrinkwrap.test:test-deps-c:1.0.0")
.artifact("org.jboss.shrinkwrap.test:test-deps-g:1.0.0")
.resolve());
DependencyTreeDescription desc = new DependencyTreeDescription(new File("src/test/resources/dependency-trees/test-deps-c+g.tree"));
desc.validateArchive(war).results();
war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);
}
/**
* Tests a resolution of two artifacts from central using single call
* @throws DependencyException
*/
@Test
public void testMultipleResolutionSingleCall() throws DependencyException
{
String name = "multipleResolutionSingleCall";
WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war")
.addAsLibraries(Dependencies.artifacts("org.jboss.shrinkwrap.test:test-deps-c:1.0.0",
"org.jboss.shrinkwrap.test:test-deps-g:1.0.0")
.resolve());
DependencyTreeDescription desc = new DependencyTreeDescription(new File("src/test/resources/dependency-trees/test-deps-c+g.tree"));
desc.validateArchive(war).results();
war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);
}
/**
* Tests direct usage of MavenDependencies implementation
* @throws DependencyException
*/
@Test
public void testCustomDependencies() throws DependencyException
{
String name = "customDependencies";
WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war")
.addAsLibraries(Dependencies.use(MavenDependencies.class)
.artifact("org.jboss.shrinkwrap.test:test-deps-c:1.0.0")
.artifact("org.jboss.shrinkwrap.test:test-deps-g:1.0.0")
.resolve());
DependencyTreeDescription desc = new DependencyTreeDescription(new File("src/test/resources/dependency-trees/test-deps-c+g.tree"));
desc.validateArchive(war).results();
war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);
}
}