From 5a364046023345c559bad443491052b41d95f10f Mon Sep 17 00:00:00 2001 From: Nathan Creger Date: Wed, 22 May 2024 11:19:58 -0400 Subject: [PATCH 1/9] update to use java 21 --- .travis.yml | 2 +- Dockerfile | 4 +-- build.gradle | 28 +++++++++---------- gradle/wrapper/gradle-wrapper.properties | 4 +-- .../kpmp/stateManager/StateController.java | 2 +- .../CustomStateRepositoryTest.java | 15 +++++----- .../stateManager/NotificationHandlerTest.java | 15 +++++----- .../stateManager/StateChangeEventTest.java | 12 ++++---- .../stateManager/StateControllerTest.java | 16 +++++------ .../kpmp/stateManager/StateDisplayTest.java | 15 +++++----- .../kpmp/stateManager/StateServiceTest.java | 15 +++++----- .../java/org/kpmp/stateManager/StateTest.java | 14 ++++++---- 12 files changed, 74 insertions(+), 68 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6de807c..701f21d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ dist: trusty language: java jdk: - - oraclejdk8 + - oraclejdk21 install: true diff --git a/Dockerfile b/Dockerfile index 171e8ae..dc6f652 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -FROM alpine +FROM alpine:3.19.1 RUN apk update && \ apk upgrade -RUN apk add openjdk8 +RUN apk add openjdk21 VOLUME /tmp ARG DEPENDENCY=target/dependency diff --git a/build.gradle b/build.gradle index fb3756d..5603d10 100644 --- a/build.gradle +++ b/build.gradle @@ -3,16 +3,17 @@ buildscript { mavenCentral() } dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.4") + classpath("org.springframework.boot:spring-boot-gradle-plugin:3.2.2") } - } plugins { - id 'com.palantir.docker' version '0.22.1' + id 'com.palantir.docker' version '0.35.0' + id 'org.springframework.boot' version '3.2.2' } - -group = 'kingstonduo' + +group='kingstonduo' +version='2.2' apply plugin: 'java' @@ -22,17 +23,14 @@ apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' apply plugin: 'com.palantir.docker' -jar { - baseName='state-manager-service' - version= '2.2' -} + repositories { mavenCentral() } -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' @@ -40,9 +38,11 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-test' implementation 'org.springframework.data:spring-data-mongodb' implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' + testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.mockito:mockito-core' - testImplementation 'junit:junit:4.12' + testImplementation('org.mockito:mockito-junit-jupiter:3.12.4') + testImplementation 'org.springframework:spring-test:5.2.25.RELEASE' } springBoot { @@ -71,7 +71,7 @@ def getCurrentGitBranch() { } catch (e) { } if (gitBranch == "develop" || gitBranch == "master"){ - return jar.version + return project.version }else{ return gitBranch } @@ -79,7 +79,7 @@ def getCurrentGitBranch() { } docker { - name "kingstonduo/${jar.baseName}:" + getCurrentGitBranch() + name "kingstonduo/state-manager-service:" + getCurrentGitBranch() copySpec.from(tasks.unpack.outputs).into("dependency") buildArgs(['DEPENDENCY': "dependency"]) } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 669386b..2bbac7d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/src/main/java/org/kpmp/stateManager/StateController.java b/src/main/java/org/kpmp/stateManager/StateController.java index 5b5bd39..dc18ba0 100644 --- a/src/main/java/org/kpmp/stateManager/StateController.java +++ b/src/main/java/org/kpmp/stateManager/StateController.java @@ -5,7 +5,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/test/java/org/kpmp/stateManager/CustomStateRepositoryTest.java b/src/test/java/org/kpmp/stateManager/CustomStateRepositoryTest.java index 25bc8a3..84c2979 100644 --- a/src/test/java/org/kpmp/stateManager/CustomStateRepositoryTest.java +++ b/src/test/java/org/kpmp/stateManager/CustomStateRepositoryTest.java @@ -1,6 +1,6 @@ package org.kpmp.stateManager; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -10,9 +10,9 @@ import java.util.List; import org.bson.Document; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.data.mongodb.core.MongoTemplate; @@ -29,14 +29,15 @@ public class CustomStateRepositoryTest { private MongoTemplate mongoTemplate; private CustomStateRepository customRepo; - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); customRepo = new CustomStateRepository(stateRepository, mongoTemplate); } - @After + @AfterEach public void tearDown() throws Exception { + MockitoAnnotations.openMocks(this).close(); customRepo = null; } diff --git a/src/test/java/org/kpmp/stateManager/NotificationHandlerTest.java b/src/test/java/org/kpmp/stateManager/NotificationHandlerTest.java index 63ad2ba..85fe550 100644 --- a/src/test/java/org/kpmp/stateManager/NotificationHandlerTest.java +++ b/src/test/java/org/kpmp/stateManager/NotificationHandlerTest.java @@ -1,13 +1,13 @@ package org.kpmp.stateManager; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -20,16 +20,17 @@ public class NotificationHandlerTest { private RestTemplate restTemplate; private NotificationHandler handler; - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); handler = new NotificationHandler(restTemplate); ReflectionTestUtils.setField(handler, "notificationServiceHost", "host"); ReflectionTestUtils.setField(handler, "notificationEndpoint", "/endpoint"); } - @After + @AfterEach public void tearDown() throws Exception { + MockitoAnnotations.openMocks(this).close(); handler = null; } diff --git a/src/test/java/org/kpmp/stateManager/StateChangeEventTest.java b/src/test/java/org/kpmp/stateManager/StateChangeEventTest.java index 16b4c16..69bab4a 100644 --- a/src/test/java/org/kpmp/stateManager/StateChangeEventTest.java +++ b/src/test/java/org/kpmp/stateManager/StateChangeEventTest.java @@ -1,21 +1,21 @@ package org.kpmp.stateManager; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class StateChangeEventTest { private StateChangeEvent event; - @Before + @BeforeEach public void setUp() throws Exception { event = new StateChangeEvent("origin", "packageId", "state", "codicil"); } - @After + @AfterEach public void tearDown() throws Exception { event = null; } diff --git a/src/test/java/org/kpmp/stateManager/StateControllerTest.java b/src/test/java/org/kpmp/stateManager/StateControllerTest.java index f4f7f5e..624581f 100644 --- a/src/test/java/org/kpmp/stateManager/StateControllerTest.java +++ b/src/test/java/org/kpmp/stateManager/StateControllerTest.java @@ -1,6 +1,6 @@ package org.kpmp.stateManager; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -8,11 +8,11 @@ import java.util.Arrays; import java.util.List; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -22,13 +22,13 @@ public class StateControllerTest { private StateService stateService; private StateController controller; - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this).close(); controller = new StateController(stateService); } - @After + @AfterEach public void tearDown() throws Exception { controller = null; } diff --git a/src/test/java/org/kpmp/stateManager/StateDisplayTest.java b/src/test/java/org/kpmp/stateManager/StateDisplayTest.java index 9e487cd..88fedd9 100644 --- a/src/test/java/org/kpmp/stateManager/StateDisplayTest.java +++ b/src/test/java/org/kpmp/stateManager/StateDisplayTest.java @@ -1,26 +1,27 @@ package org.kpmp.stateManager; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import org.bson.Document; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.MockitoAnnotations; public class StateDisplayTest { private StateDisplay stateDisplay; - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); stateDisplay = new StateDisplay(); } - @After + @AfterEach public void tearDown() throws Exception { + MockitoAnnotations.openMocks(this).close(); stateDisplay = null; } diff --git a/src/test/java/org/kpmp/stateManager/StateServiceTest.java b/src/test/java/org/kpmp/stateManager/StateServiceTest.java index 0925eac..ce3b906 100644 --- a/src/test/java/org/kpmp/stateManager/StateServiceTest.java +++ b/src/test/java/org/kpmp/stateManager/StateServiceTest.java @@ -1,6 +1,6 @@ package org.kpmp.stateManager; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -11,9 +11,9 @@ import java.util.List; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.test.util.ReflectionTestUtils; @@ -28,16 +28,17 @@ public class StateServiceTest { @Mock private StateDisplayRepository stateDisplayRepo; - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); service = new StateService(stateRepository, notificationHandler, stateDisplayRepo); ReflectionTestUtils.setField(service, "uploadFailedState", "UPLOAD_FAILED"); ReflectionTestUtils.setField(service, "uploadSucceededState", "UPLOAD_SUCCEEDED"); } - @After + @AfterEach public void tearDown() throws Exception { + MockitoAnnotations.openMocks(this).close(); service = null; } diff --git a/src/test/java/org/kpmp/stateManager/StateTest.java b/src/test/java/org/kpmp/stateManager/StateTest.java index 1cb7eee..64b2cab 100644 --- a/src/test/java/org/kpmp/stateManager/StateTest.java +++ b/src/test/java/org/kpmp/stateManager/StateTest.java @@ -1,23 +1,25 @@ package org.kpmp.stateManager; -import static org.junit.Assert.assertEquals; + +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Date; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + public class StateTest { private State state; - @Before + @BeforeEach public void setUp() throws Exception { state = new State(); } - @After + @AfterEach public void tearDown() throws Exception { state = null; } From 0946d2515796d2b8f1faafb0465415256b0d1560 Mon Sep 17 00:00:00 2001 From: Nathan Creger Date: Wed, 22 May 2024 13:57:04 -0400 Subject: [PATCH 2/9] minor tweaks to resolve warnings --- .../kpmp/stateManager/DluPackageInventoryService.java | 4 ++-- .../java/org/kpmp/stateManager/StateController.java | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/kpmp/stateManager/DluPackageInventoryService.java b/src/main/java/org/kpmp/stateManager/DluPackageInventoryService.java index 300df2c..1307b09 100644 --- a/src/main/java/org/kpmp/stateManager/DluPackageInventoryService.java +++ b/src/main/java/org/kpmp/stateManager/DluPackageInventoryService.java @@ -16,7 +16,7 @@ public class DluPackageInventoryService { private String dataManagerHost; @Value("${data-manager.service.endpoint}") private String dataManagerEndpoint; - private RestTemplate restTemplate; + private final RestTemplate restTemplate; private static final Log log = LogFactory.getLog(DluPackageInventoryService.class); @@ -26,7 +26,7 @@ public DluPackageInventoryService(RestTemplate restTemplate) { } public String setPackageInError(String packageId) { - HashMap payload = new HashMap<>(); + HashMap payload = new HashMap<>(); payload.put("dlu_error", true); String retPackageId = null; String url = dataManagerHost + dataManagerEndpoint + "/package/" + packageId; diff --git a/src/main/java/org/kpmp/stateManager/StateController.java b/src/main/java/org/kpmp/stateManager/StateController.java index dc18ba0..d3779b8 100644 --- a/src/main/java/org/kpmp/stateManager/StateController.java +++ b/src/main/java/org/kpmp/stateManager/StateController.java @@ -5,8 +5,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; -import jakarta.servlet.http.HttpServletRequest; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -19,10 +17,12 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.context.request.async.DeferredResult; +import jakarta.servlet.http.HttpServletRequest; + @Controller public class StateController { - private StateService stateService; + private final StateService stateService; private static final Log log = LogFactory.getLog(StateController.class); @Value("${package.state.longpoll.timeout}") @@ -60,10 +60,11 @@ public StateController(StateService stateService) { return stateService.getAllStateDisplays(); } + @RequestMapping(value = "/v1/state/events/{afterTime}", method = RequestMethod.GET) public @ResponseBody DeferredResult> getStateEvents(@PathVariable("afterTime") String afterTime, HttpServletRequest request) { - Date stateChangeDate = new Date(new Long(afterTime)); + Date stateChangeDate = new Date(Long.parseLong(afterTime)); log.info("URI: " + request.getRequestURI() + " | MSG: Long poll for events after " + stateChangeDate); @@ -73,7 +74,7 @@ public StateController(StateService stateService) { try { List result = stateService.findPackagesChangedAfterStateChangeDate(stateChangeDate); - while (result.size() == 0) { + while (result.isEmpty()) { TimeUnit.SECONDS.sleep(2); result = stateService.findPackagesChangedAfterStateChangeDate(stateChangeDate); } From 70900bb3d81469d8a6ae85f6285efa0ddc80391f Mon Sep 17 00:00:00 2001 From: Nathan Creger Date: Wed, 22 May 2024 13:57:35 -0400 Subject: [PATCH 3/9] use '21' instaed of JavaVersion.VERSION_21 --- build.gradle | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 5603d10..1f5e601 100644 --- a/build.gradle +++ b/build.gradle @@ -8,6 +8,7 @@ buildscript { } plugins { + id 'java' id 'com.palantir.docker' version '0.35.0' id 'org.springframework.boot' version '3.2.2' } @@ -29,8 +30,8 @@ repositories { mavenCentral() } -sourceCompatibility = JavaVersion.VERSION_21 -targetCompatibility = JavaVersion.VERSION_21 +sourceCompatibility = '21' +targetCompatibility = '21' dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' From ebfcbc8da90c5fe4dbf222b573671684a3792348 Mon Sep 17 00:00:00 2001 From: Nathan Creger Date: Wed, 22 May 2024 14:01:55 -0400 Subject: [PATCH 4/9] hide annoying .vscode dirs --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fac18c3..9ae554c 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ build/ .idea *.iml bin/ +.vscode \ No newline at end of file From 700eeb1297b654ba83e049e258019ab2f75e52f0 Mon Sep 17 00:00:00 2001 From: Nathan Creger Date: Wed, 22 May 2024 14:10:20 -0400 Subject: [PATCH 5/9] add final --- src/main/java/org/kpmp/stateManager/NotificationHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/kpmp/stateManager/NotificationHandler.java b/src/main/java/org/kpmp/stateManager/NotificationHandler.java index f4779a7..848354f 100644 --- a/src/main/java/org/kpmp/stateManager/NotificationHandler.java +++ b/src/main/java/org/kpmp/stateManager/NotificationHandler.java @@ -11,7 +11,7 @@ class NotificationHandler { private String notificationServiceHost; @Value("${notification.endpoint}") private String notificationEndpoint; - private RestTemplate restTemplate; + private final RestTemplate restTemplate; public NotificationHandler(RestTemplate restTemplate) { this.restTemplate = restTemplate; From 09887581aa43c71f98993f846d86aa5016ba663b Mon Sep 17 00:00:00 2001 From: Nathan Creger Date: Wed, 22 May 2024 14:29:17 -0400 Subject: [PATCH 6/9] upgrade spring boot to v 3.2.5 --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 1f5e601..e4e5257 100644 --- a/build.gradle +++ b/build.gradle @@ -3,14 +3,14 @@ buildscript { mavenCentral() } dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:3.2.2") + classpath("org.springframework.boot:spring-boot-gradle-plugin:3.2.5") } } plugins { id 'java' id 'com.palantir.docker' version '0.35.0' - id 'org.springframework.boot' version '3.2.2' + id 'org.springframework.boot' version '3.2.5' } group='kingstonduo' @@ -35,7 +35,7 @@ targetCompatibility = '21' dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.apache.commons:commons-compress:1.21' + implementation 'org.apache.commons:commons-compress:1.26.0' implementation 'org.springframework.boot:spring-boot-starter-test' implementation 'org.springframework.data:spring-data-mongodb' implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' From a47118f5fe663d1e5e4fe872da6ab114f48edc00 Mon Sep 17 00:00:00 2001 From: Nathan Creger Date: Thu, 23 May 2024 09:06:48 -0400 Subject: [PATCH 7/9] update build action --- .github/workflows/build-gradle-project.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-gradle-project.yml b/.github/workflows/build-gradle-project.yml index bf1a69e..e08d90c 100644 --- a/.github/workflows/build-gradle-project.yml +++ b/.github/workflows/build-gradle-project.yml @@ -21,12 +21,12 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-java@v3 with: - java-version: '8' + java-version: '21' distribution: 'temurin' - name: Setup Gradle uses: gradle/gradle-build-action@v2 with: - gradle-version: 7.4 + gradle-version: 8.5 - name: Login to Docker Hub uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a From 217ed44019ba29e8b5e6015c0a088f53fd03d9e0 Mon Sep 17 00:00:00 2001 From: rlreamy <34109594+rlreamy@users.noreply.github.com> Date: Tue, 11 Jun 2024 11:23:03 -0400 Subject: [PATCH 8/9] Update build.gradle --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index e4e5257..ff6086d 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ plugins { } group='kingstonduo' -version='2.2' +version='4.1' apply plugin: 'java' From d06eb1e8c56e4e566a28b9e94d8639b62778fe29 Mon Sep 17 00:00:00 2001 From: rlreamy <34109594+rlreamy@users.noreply.github.com> Date: Tue, 11 Jun 2024 11:24:00 -0400 Subject: [PATCH 9/9] Update build-gradle-project.yml --- .github/workflows/build-gradle-project.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-gradle-project.yml b/.github/workflows/build-gradle-project.yml index e08d90c..7b654d3 100644 --- a/.github/workflows/build-gradle-project.yml +++ b/.github/workflows/build-gradle-project.yml @@ -6,7 +6,7 @@ on: jobs: build-gradle-project: env: - IMAGE_TAG: 2.2 + IMAGE_TAG: 4.1 runs-on: ubuntu-latest steps: - name: Get branch names