|
| 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 | +package org.springframework.sbm; |
| 17 | + |
| 18 | +import org.jetbrains.annotations.NotNull; |
| 19 | +import org.junit.jupiter.api.Tag; |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | +import org.openrewrite.maven.MavenParser; |
| 22 | +import org.openrewrite.xml.tree.Xml; |
| 23 | + |
| 24 | +import java.nio.file.Path; |
| 25 | + |
| 26 | +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; |
| 27 | + |
| 28 | +public class BootUpgrade_27_30_IntegrationTest extends IntegrationTestBaseClass { |
| 29 | + |
| 30 | + @Override |
| 31 | + protected String getTestSubDir() { |
| 32 | + return "boot-migration-27-30"; |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + @Tag("integration") |
| 37 | + void migrateSimpleApplication() { |
| 38 | + intializeTestProject(); |
| 39 | + |
| 40 | + scanProject(); |
| 41 | + |
| 42 | + applyRecipe("boot-2.7-3.0-dependency-version-update"); |
| 43 | + |
| 44 | + verifyParentPomVersion(); |
| 45 | + verifyMicrometerPackageUpdate(); |
| 46 | + verifyYamlConfigurationUpdate(); |
| 47 | + verifyPropertyConfigurationUpdate(); |
| 48 | + verifyConstructorBindingRemoval(); |
| 49 | + verifyCrudRepoAddition(); |
| 50 | + } |
| 51 | + |
| 52 | + private void verifyCrudRepoAddition() { |
| 53 | + |
| 54 | + String studentRepo = loadJavaFile("org.springboot.example.upgrade", "StudentRepo"); |
| 55 | + |
| 56 | + assertThat(studentRepo).isEqualTo(""" |
| 57 | + package org.springboot.example.upgrade; |
| 58 | + |
| 59 | + import org.springframework.data.repository.CrudRepository; |
| 60 | + import org.springframework.data.repository.PagingAndSortingRepository; |
| 61 | + |
| 62 | + public interface StudentRepo extends PagingAndSortingRepository<Student<?>, Long>, CrudRepository<Student<?>, Long> { |
| 63 | + } |
| 64 | + """); |
| 65 | + } |
| 66 | + |
| 67 | + private void verifyConstructorBindingRemoval() { |
| 68 | + String constructorBindingConfigClass = loadJavaFile("org.springboot.example.upgrade", "ConstructorBindingConfig"); |
| 69 | + assertThat(constructorBindingConfigClass).isEqualTo("package org.springboot.example.upgrade;\n" + |
| 70 | + "\n" + |
| 71 | + "import org.springframework.boot.context.properties.ConfigurationProperties;\n" + |
| 72 | + "\n" + |
| 73 | + "@ConfigurationProperties(prefix = \"mail\")\n" + |
| 74 | + "public class ConstructorBindingConfig {\n" + |
| 75 | + " private String hostName;\n" + |
| 76 | + "\n" + |
| 77 | + " public ConstructorBindingConfig(String hostName) {\n" + |
| 78 | + " this.hostName = hostName;\n" + |
| 79 | + " }\n" + |
| 80 | + "}" + |
| 81 | + "\n"); |
| 82 | + } |
| 83 | + |
| 84 | + private void verifyMicrometerPackageUpdate() { |
| 85 | + String micrometerClass = loadFile(Path.of("src/main/java/org/springboot/example/upgrade/MicrometerConfig.java")); |
| 86 | + assertThat(micrometerClass).isEqualTo( |
| 87 | + "package org.springboot.example.upgrade;\n" + |
| 88 | + "\n" + |
| 89 | + "import io.micrometer.binder.MeterBinder;\n" + |
| 90 | + "\n" + |
| 91 | + "public class MicroMeterConfig {\n" + |
| 92 | + "\n" + |
| 93 | + " private MeterBinder k;\n" + |
| 94 | + "}\n"); |
| 95 | + } |
| 96 | + |
| 97 | + private void verifyYamlConfigurationUpdate() { |
| 98 | + String micrometerClass = loadFile(Path.of("src/main/resources/application.yaml")); |
| 99 | + assertThat(micrometerClass).isEqualTo( |
| 100 | + "spring:\n" + |
| 101 | + " elasticsearch:\n" + |
| 102 | + " connection-timeout: '1'\n" + |
| 103 | + " password: testpassword\n" + |
| 104 | + " socket-timeout: '2'\n" + |
| 105 | + " restclient.sniffer.delay-after-failure: '3'\n" + |
| 106 | + " restclient.sniffer.interval: '4'\n" + |
| 107 | + " username: username\n" + |
| 108 | + " security:\n" + |
| 109 | + " saml2:\n" + |
| 110 | + " relyingparty:\n" + |
| 111 | + " registration:\n" + |
| 112 | + " idpone:\n" + |
| 113 | + " assertingparty:\n" + |
| 114 | + " verification:\n" + |
| 115 | + " credentials:\n" + |
| 116 | + " certificate-location: classpath:saml/idpone.crt\n" + |
| 117 | + " entity-id: https://idpone.com\n" + |
| 118 | + " sso-url: https://idpone.com\n" + |
| 119 | + " elasticsearch.connection-timeout: '1000'\n" + |
| 120 | + " elasticsearch.webclient.max-in-memory-size: '122'\n" + |
| 121 | + " elasticsearch.password: abc\n" + |
| 122 | + " elasticsearch.socket-timeout: '100'\n" + |
| 123 | + " elasticsearch.username: testUser\n" + |
| 124 | + " sql.init.data-locations: testdata\n" + |
| 125 | + " sql.init.password: password\n" + |
| 126 | + " sql.init.username: username-data\n" + |
| 127 | + " sql.init.mode: mode1\n" + |
| 128 | + " sql.init.platform: pls\n" + |
| 129 | + " sql.init.schema-locations: table1\n" + |
| 130 | + " sql.init.password: password2\n" + |
| 131 | + " sql.init.username: username-schema\n" + |
| 132 | + " sql.init.separator: k\n" + |
| 133 | + " sql.init.encoding: UTF-8\n" + |
| 134 | + "server.reactive.session.cookie.same-site: 'true'" + |
| 135 | + "\n"); |
| 136 | + } |
| 137 | + |
| 138 | + |
| 139 | + private void verifyPropertyConfigurationUpdate() { |
| 140 | + |
| 141 | + String applicationProperties = loadFile(Path.of("src/main/resources/application.properties")); |
| 142 | + assertThat(applicationProperties).isEqualTo( |
| 143 | + "spring.elasticsearch.connection-timeout=1000\n" + |
| 144 | + "spring.elasticsearch.webclient.max-in-memory-size=122\n" + |
| 145 | + "spring.elasticsearch.password=abc\n" + |
| 146 | + "spring.elasticsearch.socket-timeout=100\n" + |
| 147 | + "spring.elasticsearch.username=testUser\n" + |
| 148 | + "\n" + |
| 149 | + "spring.sql.init.data-locations=testdata\n" + |
| 150 | + "spring.sql.init.password=password\n" + |
| 151 | + "spring.sql.init.username=username\n" + |
| 152 | + "spring.sql.init.mode=mode1\n" + |
| 153 | + "spring.sql.init.platform=pls\n" + |
| 154 | + "spring.sql.init.schema-locations=table1\n" + |
| 155 | + "spring.sql.init.password=password2\n" + |
| 156 | + "spring.sql.init.username=username2\n" + |
| 157 | + "spring.sql.init.separator=k\n" + |
| 158 | + "spring.sql.init.encoding=UTF-8\n" + |
| 159 | + "\n" + |
| 160 | + "spring.elasticsearch.connection-timeout=1\n" + |
| 161 | + "spring.elasticsearch.password=testpassword\n" + |
| 162 | + "spring.elasticsearch.socket-timeout=2\n" + |
| 163 | + "spring.elasticsearch.restclient.sniffer.delay-after-failure=3\n" + |
| 164 | + "spring.elasticsearch.restclient.sniffer.interval=4\n" + |
| 165 | + "spring.elasticsearch.username=username\n" + |
| 166 | + "\n" + |
| 167 | + "spring.security.saml2.relyingparty.registration.idpone.assertingparty.entity-id=https://idpone.com\n" + |
| 168 | + "spring.security.saml2.relyingparty.registration.idpone.assertingparty.sso-url=https://idpone.com\n" + |
| 169 | + "spring.security.saml2.relyingparty.registration.idpone.assertingparty.verification.credentials.certificate-location=classpath:saml/idpone.crt\n" + |
| 170 | + "\n" + |
| 171 | + "server.reactive.session.cookie.same-site=true\n"); |
| 172 | + } |
| 173 | + |
| 174 | + private void verifyParentPomVersion() { |
| 175 | + String pomContent = loadFile(Path.of("pom.xml")); |
| 176 | + |
| 177 | + Xml.Document mavenAsXMLDocument = parsePom(pomContent); |
| 178 | + |
| 179 | + Xml.Tag parentTag =mavenAsXMLDocument |
| 180 | + .getRoot() |
| 181 | + .getChildren("parent").get(0); |
| 182 | + |
| 183 | + String version = parentTag.getChildValue("version").get(); |
| 184 | + |
| 185 | + String groupId = parentTag.getChildValue("groupId").get(); |
| 186 | + String artifactId = parentTag.getChildValue("artifactId").get(); |
| 187 | + |
| 188 | + assertThat(version).isEqualTo("3.0.0-M3"); |
| 189 | + assertThat(groupId).isEqualTo("org.springframework.boot"); |
| 190 | + assertThat(artifactId).isEqualTo("spring-boot-starter-parent"); |
| 191 | + } |
| 192 | + |
| 193 | + @NotNull |
| 194 | + private Xml.Document parsePom(String pomContent) { |
| 195 | + MavenParser mavenParser = new MavenParser.Builder().build(); |
| 196 | + return mavenParser.parse(pomContent).get(0); |
| 197 | + } |
| 198 | +} |
0 commit comments