|
| 1 | +/* |
| 2 | + * Copyright 2021 - 2022 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.sbm.boot.upgrade_27_30.checks; |
| 18 | + |
| 19 | +import org.assertj.core.api.Assertions; |
| 20 | +import org.intellij.lang.annotations.Language; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | +import org.openrewrite.maven.tree.Scope; |
| 23 | +import org.springframework.sbm.build.api.ApplicationModule; |
| 24 | +import org.springframework.sbm.engine.context.ProjectContext; |
| 25 | +import org.springframework.sbm.project.resource.TestProjectContext; |
| 26 | + |
| 27 | +import java.util.Set; |
| 28 | + |
| 29 | +import static org.assertj.core.api.Assertions.assertThat; |
| 30 | + |
| 31 | +public class JerseyTemporarilyRemovedFinderTest { |
| 32 | + |
| 33 | + @Test |
| 34 | + void finderShouldFindAnyJerseyDependency() { |
| 35 | + String dependencyCoordinates = "org.glassfish.jersey.connectors:jersey-jdk-connector:2.35"; |
| 36 | + ProjectContext context = TestProjectContext.buildProjectContext() |
| 37 | + .withBuildFileHavingDependencies(dependencyCoordinates) |
| 38 | + .build(); |
| 39 | + |
| 40 | + JerseyTemporarilyRemovedFinder sut = new JerseyTemporarilyRemovedFinder(); |
| 41 | + Set<ApplicationModule> matches = sut.findMatches(context); |
| 42 | + assertThat(matches).isNotEmpty(); |
| 43 | + assertThat(matches).hasSize(1); |
| 44 | + assertThat(matches.iterator().next().getBuildFile().getDeclaredDependencies(Scope.Compile).get(0).getCoordinates()).isEqualTo(dependencyCoordinates); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void finderShouldFindOnlyJerseyDependency() { |
| 49 | + |
| 50 | + @Language("xml") |
| 51 | + String parentPomXml = |
| 52 | + """ |
| 53 | + <?xml version="1.0" encoding="UTF-8"?> |
| 54 | + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 55 | + <modelVersion>4.0.0</modelVersion> |
| 56 | + <groupId>com.example</groupId> |
| 57 | + <artifactId>parent</artifactId> |
| 58 | + <version>0.1.0-SNAPSHOT</version> |
| 59 | + <packaging>pom</packaging> |
| 60 | + <modules> |
| 61 | + <module>module1</module> |
| 62 | + <module>module2</module> |
| 63 | + </modules> |
| 64 | + </project> |
| 65 | + """; |
| 66 | + |
| 67 | + |
| 68 | + @Language("xml") |
| 69 | + String module1PomXml = |
| 70 | + """ |
| 71 | + <?xml version="1.0" encoding="UTF-8"?> |
| 72 | + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 73 | + <modelVersion>4.0.0</modelVersion> |
| 74 | + <parent> |
| 75 | + <groupId>com.example</groupId> |
| 76 | + <artifactId>parent</artifactId> |
| 77 | + <version>0.1.0-SNAPSHOT</version> |
| 78 | + </parent> |
| 79 | + <artifactId>module1</artifactId> |
| 80 | + <packaging>jar</packaging> |
| 81 | + <dependencies> |
| 82 | + <dependency> |
| 83 | + <groupId>org.glassfish</groupId> |
| 84 | + <artifactId>javax.el</artifactId> |
| 85 | + <version>3.0.0</version> |
| 86 | + </dependency> |
| 87 | + </dependencies> |
| 88 | + </project> |
| 89 | + """; |
| 90 | + |
| 91 | + @Language("xml") |
| 92 | + String module2PomXml = |
| 93 | + """ |
| 94 | + <?xml version="1.0" encoding="UTF-8"?> |
| 95 | + <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 96 | + <modelVersion>4.0.0</modelVersion> |
| 97 | + <parent> |
| 98 | + <groupId>com.example</groupId> |
| 99 | + <version>0.1.0-SNAPSHOT</version> |
| 100 | + <artifactId>parent</artifactId> |
| 101 | + </parent> |
| 102 | + <artifactId>module2</artifactId> |
| 103 | + <packaging>jar</packaging> |
| 104 | + <dependencies> |
| 105 | + <dependency> |
| 106 | + <groupId>org.glassfish.jersey.connectors</groupId> |
| 107 | + <artifactId>jersey-jdk-connector</artifactId> |
| 108 | + <version>2.35</version> |
| 109 | + </dependency> |
| 110 | + |
| 111 | + </dependencies> |
| 112 | + </project> |
| 113 | + """; |
| 114 | + |
| 115 | + String jerseyDependencyCoordinates = "org.glassfish.jersey.connectors:jersey-jdk-connector:2.35"; |
| 116 | + ProjectContext context = TestProjectContext.buildProjectContext() |
| 117 | + .withMavenBuildFileSource("", parentPomXml) |
| 118 | + .withMavenBuildFileSource("module1", module1PomXml) |
| 119 | + .withMavenBuildFileSource("module2", module2PomXml) |
| 120 | + .build(); |
| 121 | + |
| 122 | + JerseyTemporarilyRemovedFinder sut = new JerseyTemporarilyRemovedFinder(); |
| 123 | + Set<ApplicationModule> matches = sut.findMatches(context); |
| 124 | + assertThat(context.getApplicationModules().list()).hasSize(3); |
| 125 | + assertThat(matches).isNotEmpty(); |
| 126 | + assertThat(matches).hasSize(1); |
| 127 | + assertThat(matches.iterator().next().getBuildFile().getDeclaredDependencies(Scope.Compile).get(0).getCoordinates()).isEqualTo(jerseyDependencyCoordinates); |
| 128 | + } |
| 129 | + |
| 130 | +} |
0 commit comments