Skip to content

Commit facb0b8

Browse files
sanagaraj-pivotalBoykoAlex
authored andcommitted
Add JSON-B recipe to spring boot upgrade
1 parent 06aee50 commit facb0b8

File tree

30 files changed

+905
-687
lines changed

30 files changed

+905
-687
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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.apache.commons.io.FileUtils;
19+
import org.junit.jupiter.api.AfterEach;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.springframework.boot.test.context.SpringBootTest;
22+
import java.io.IOException;
23+
import java.nio.file.Path;
24+
25+
@SpringBootTest(properties = {
26+
"spring.shell.interactive.enabled=false",
27+
"spring.shell.script.enabled=false",
28+
"sbm.gitSupportEnabled=false"
29+
})
30+
public abstract class IntegrationTestBaseClass {
31+
32+
/**
33+
* Points to the source root directory where example projects are expected.
34+
*
35+
* See {@link #getTestSubDir()}.
36+
*/
37+
public static final String TESTCODE_DIR = "src/test/resources/testcode/";
38+
39+
/**
40+
* Points to the target root directory where example projects will be copied to.
41+
*
42+
* See {@link #getTestSubDir()}.
43+
*/
44+
public static final String INTEGRATION_TEST_DIR = "./target/sbm-integration-test/";
45+
46+
private Path testDir;
47+
48+
private String output;
49+
50+
51+
@BeforeEach
52+
public void beforeEach() throws IOException {
53+
testDir = Path.of(INTEGRATION_TEST_DIR).resolve(getTestSubDir());
54+
clearTestDir();
55+
testDir.resolve(this.getClass().getName());
56+
FileUtils.forceMkdir(testDir.toFile());
57+
testDir = testDir.toRealPath();
58+
}
59+
60+
/**
61+
* Copies example project used for integrationTest.
62+
*/
63+
protected void intializeTestProject() {
64+
try {
65+
Path s = Path.of(TESTCODE_DIR).resolve(getTestSubDir());
66+
FileUtils.copyDirectory(s.toFile(), getTestDir().toFile());
67+
} catch (IOException e) {
68+
throw new RuntimeException(e);
69+
}
70+
}
71+
72+
73+
protected abstract String getTestSubDir();
74+
75+
protected Path getTestDir() {
76+
return testDir;
77+
}
78+
79+
80+
@AfterEach
81+
public void afterEach() throws IOException {
82+
clearTestDir();
83+
}
84+
85+
private void clearTestDir() throws IOException {
86+
if (getTestDir().toFile().exists()) {
87+
FileUtils.forceDelete(getTestDir().toFile());
88+
}
89+
}
90+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.springframework.sbm;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.DefaultApplicationArguments;
6+
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
public class ReportTestSingleModule extends IntegrationTestBaseClass {
10+
11+
@Autowired
12+
private SpringBootMigratorRunner springBootMigratorRunner;
13+
14+
@Autowired
15+
private ReportHolder reportHolder;
16+
17+
@Override
18+
protected String getTestSubDir() {
19+
return "boot-migration-27-30";
20+
}
21+
22+
23+
@Test
24+
public void generatesAllRelevantSection() {
25+
intializeTestProject();
26+
27+
springBootMigratorRunner.run(new DefaultApplicationArguments(getTestDir().toString()));
28+
29+
assertThat(reportHolder.getReport()).contains("Constructor Binding");
30+
assertThat(reportHolder.getReport()).contains("Johnzon Dependency Upgrade");
31+
}
32+
}

applications/spring-boot-upgrade/src/test/resources/test-code/bootify-jaxrs/pom.xml

Lines changed: 0 additions & 49 deletions
This file was deleted.

applications/spring-boot-upgrade/src/test/resources/test-code/bootify-jaxrs/src/main/java/com/example/jee/app/PersonController.java

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
**Features used in the current project**
2+
3+
* ehcache in pom is mentioned this helps validate our migration to spring 3 where ehcache classifier has to be used to resolve version.
4+
* Uses Constructor binding on classes which will be removed when migrating to Spring 3
5+
* Uses PagingAndSortingRepo interface where CrudRepo has been removed.
6+
* Uses properties that will be removed/moved on spring 3 migration
7+
* Uses micrometer packages which are moved to a new structure.
8+
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.7.1</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.example</groupId>
12+
<artifactId>boot-upgrade-27_30</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>boot-upgrade-27_30</name>
15+
<description>boot-upgrade-27_30</description>
16+
<properties>
17+
<java.version>17</java.version>
18+
<spring-cloud.version>2021.0.4</spring-cloud.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-web</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.ehcache</groupId>
28+
<artifactId>ehcache</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-data-jpa</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>com.h2database</groupId>
36+
<artifactId>h2</artifactId>
37+
<scope>runtime</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.github.tomakehurst</groupId>
41+
<artifactId>wiremock-jre8</artifactId>
42+
<version>2.26.3</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>io.projectreactor</groupId>
46+
<artifactId>reactor-core</artifactId>
47+
</dependency>
48+
<dependency>
49+
<groupId>io.reactivex.rxjava3</groupId>
50+
<artifactId>rxjava</artifactId>
51+
<version>3.1.5</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.apache.johnzon</groupId>
55+
<artifactId>johnzon-core</artifactId>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.springframework.boot</groupId>
59+
<artifactId>spring-boot-starter-test</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
</dependencies>
63+
<dependencyManagement>
64+
<dependencies>
65+
<dependency>
66+
<groupId>org.springframework.cloud</groupId>
67+
<artifactId>spring-cloud-dependencies</artifactId>
68+
<version>${spring-cloud.version}</version>
69+
<type>pom</type>
70+
<scope>import</scope>
71+
</dependency>
72+
</dependencies>
73+
</dependencyManagement>
74+
<repositories>
75+
<repository>
76+
<id>spring-snapshot</id>
77+
<url>https://repo.spring.io/snapshot</url>
78+
<releases>
79+
<enabled>false</enabled>
80+
</releases>
81+
</repository>
82+
<repository>
83+
<id>spring-milestone</id>
84+
<url>https://repo.spring.io/milestone</url>
85+
<snapshots>
86+
<enabled>false</enabled>
87+
</snapshots>
88+
</repository>
89+
<repository>
90+
<id>spring-release</id>
91+
<url>https://repo.spring.io/release</url>
92+
<snapshots>
93+
<enabled>false</enabled>
94+
</snapshots>
95+
</repository>
96+
</repositories>
97+
98+
<build>
99+
<plugins>
100+
<plugin>
101+
<groupId>org.springframework.boot</groupId>
102+
<artifactId>spring-boot-maven-plugin</artifactId>
103+
</plugin>
104+
</plugins>
105+
</build>
106+
107+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.hello;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
public class GreetingConfig {
8+
9+
@Bean
10+
public String hello() {
11+
return "こんにちは";
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.springboot.example.ehcache;
2+
3+
import org.ehcache.event.CacheEvent;
4+
import org.ehcache.event.CacheEventListener;
5+
6+
public class EventLogger implements CacheEventListener<Object, Object> {
7+
@Override
8+
public void onEvent(CacheEvent<?, ?> cacheEvent) {
9+
System.out.println("My ehcache event listener is called");
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.springboot.example.upgrade;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class BootUpgrade2730Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(BootUpgrade2730Application.class, args);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.springboot.example.upgrade;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
import org.springframework.boot.context.properties.ConstructorBinding;
5+
6+
@ConfigurationProperties(prefix = "mail")
7+
@ConstructorBinding
8+
public class ConstructorBindingConfig {
9+
private String hostName;
10+
11+
public ConstructorBindingConfig(String hostName) {
12+
this.hostName = hostName;
13+
}
14+
}

0 commit comments

Comments
 (0)