|
36 | 36 | * Tests for {@link WarPackagingWebStarterBuildCustomizer}. |
37 | 37 | * |
38 | 38 | * @author Stephane Nicoll |
| 39 | + * @author Moritz Halbritter |
39 | 40 | */ |
40 | 41 | class WarPackagingWebStarterBuildCustomizerTests { |
41 | 42 |
|
| 43 | + private static final String PLATFORM_VERSION = "1.0.0"; |
| 44 | + |
42 | 45 | private ProjectDescription projectDescription; |
43 | 46 |
|
44 | 47 | @BeforeEach |
45 | 48 | void setUp() { |
46 | 49 | MutableProjectDescription description = new MutableProjectDescription(); |
47 | | - description.setPlatformVersion(Version.parse("1.0.0")); |
| 50 | + description.setPlatformVersion(Version.parse(PLATFORM_VERSION)); |
48 | 51 | this.projectDescription = description; |
49 | 52 | } |
50 | 53 |
|
@@ -86,6 +89,30 @@ void addWebStarterDoesNotReplaceWebFacetDependency() { |
86 | 89 | assertThat(build.dependencies().ids()).containsOnly("test", "tomcat"); |
87 | 90 | } |
88 | 91 |
|
| 92 | + @Test |
| 93 | + void shouldUseResolvedDependencies() { |
| 94 | + Dependency web = Dependency.withId("web", "com.example", "web", null, Dependency.SCOPE_COMPILE); |
| 95 | + Dependency.Mapping webMapping = new Dependency.Mapping(); |
| 96 | + webMapping.setCompatibilityRange(PLATFORM_VERSION); |
| 97 | + webMapping.setArtifactId("mapped-web"); |
| 98 | + web.getMappings().add(webMapping); |
| 99 | + Dependency tomcat = Dependency.withId("tomcat", "com.example", "tomcat", null, Dependency.SCOPE_COMPILE); |
| 100 | + Dependency.Mapping tomcatMapping = new Dependency.Mapping(); |
| 101 | + tomcatMapping.setCompatibilityRange(PLATFORM_VERSION); |
| 102 | + tomcatMapping.setArtifactId("mapped-tomcat"); |
| 103 | + tomcat.getMappings().add(tomcatMapping); |
| 104 | + InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() |
| 105 | + .addDependencyGroup("web", web, tomcat) |
| 106 | + .build(); |
| 107 | + Build build = createBuild(metadata); |
| 108 | + new WarPackagingWebStarterBuildCustomizer(metadata, this.projectDescription).customize(build); |
| 109 | + assertThat(build.dependencies().ids()).containsOnly("web", "tomcat"); |
| 110 | + io.spring.initializr.generator.buildsystem.Dependency webDependency = build.dependencies().get("web"); |
| 111 | + assertThat(webDependency.getArtifactId()).isEqualTo("mapped-web"); |
| 112 | + io.spring.initializr.generator.buildsystem.Dependency tomcatDependency = build.dependencies().get("tomcat"); |
| 113 | + assertThat(tomcatDependency.getArtifactId()).isEqualTo("mapped-tomcat"); |
| 114 | + } |
| 115 | + |
89 | 116 | private Build createBuild(InitializrMetadata metadata) { |
90 | 117 | return new MavenBuild(new MetadataBuildItemResolver(metadata, Version.parse("2.0.0.RELEASE"))); |
91 | 118 | } |
|
0 commit comments