Skip to content

Commit

Permalink
Merge pull request #25 from KPMP/KPMP-5646_upgrade-to-java21
Browse files Browse the repository at this point in the history
upgrade to java21
  • Loading branch information
rlreamy authored Dec 13, 2024
2 parents c55c78f + e7e5e44 commit cf38b7e
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-gradle-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.updateBuildConfiguration": "interactive"
}
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
FROM alpine
FROM alpine:3.20.0

RUN apk update && \
apk upgrade
RUN apk add openjdk8

RUN apk add --no-cache tzdata
RUN cp /usr/share/zoneinfo/America/Detroit /etc/localtime
RUN echo "America/Detroit" > /etc/timezone
RUN apk add openjdk21

VOLUME /tmp
ARG DEPENDENCY=target/dependency
Expand All @@ -15,4 +11,8 @@ COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app

ENTRYPOINT ["java","-cp","app:app/lib/*","org.kpmp.Application"]
RUN apk add --no-cache tzdata
ENV TZ=America/Detroit
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

ENTRYPOINT ["java", "-cp","app:app/lib/*","org.kpmp.Application"]
42 changes: 19 additions & 23 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
buildscript {
ext {
springBootVersion = '2.7.4'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:3.2.5")
}
}

plugins {
id 'com.palantir.docker' version '0.22.1'
id 'java'
id 'com.palantir.docker' version '0.35.0'
id 'org.springframework.boot' version '3.2.5'
}

group = 'kingstonduo'
Expand All @@ -21,30 +20,27 @@ apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'eclipse'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'
sourceCompatibility = '21'
targetCompatibility = '21'

repositories {
mavenCentral()
}

dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'com.auth0:java-jwt:3.18.3'
implementation 'com.auth0:java-jwt:4.4.0'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.jsoup:jsoup:1.15.3'
testImplementation 'junit:junit:4.12'
implementation 'org.jsoup:jsoup:1.18.3'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation('org.mockito:mockito-junit-jupiter:3.12.4')
}

version='2.2'

springBoot {
mainClass = "org.kpmp.Application"
}

jar {
baseName='user-auth'
version='2.2'
}

task unpack(type: Copy) {
dependsOn bootJar
from(zipTree(tasks.bootJar.outputs.files.singleFile))
Expand All @@ -67,15 +63,15 @@ def getCurrentGitBranch() {
} catch (e) {
}
if (gitBranch == "develop" || gitBranch == "master"){
return jar.version
return project.version
}else{
return gitBranch
}
}
}

docker {
name "kingstonduo/${jar.baseName}:" + getCurrentGitBranch()
name "kingstonduo/user-auth:" + getCurrentGitBranch()
copySpec.from(tasks.unpack.outputs).into("dependency")
buildArgs(['DEPENDENCY': "dependency"])
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/main/java/org/kpmp/auth/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class AuthController {
private static final String userNotFoundFmt = "Using default client. User with shib id {} not found";
private static final String userClientFoundFmt = "Using client ID {}. User with shib id {} found: {}";
private static final String userClientNotFoundFmt = "Using client ID {}. User with shib id {} not found";
private static final String portalError = "There was a problem connecting to the User Portal. ";
private static final String portalError = "There was a problem connecting to the User Portal.";

private UserPortalService userPortalService;

Expand Down
68 changes: 43 additions & 25 deletions src/test/java/org/kpmp/auth/AuthControllerTest.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
package org.kpmp.auth;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.http.HttpStatus;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.server.ResponseStatusException;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class AuthControllerTest {

@Mock
private UserPortalService userPortalService;
private AuthController authController;

@Rule
public final ExpectedException exception = ExpectedException.none();

@Before
@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
authController = new AuthController(userPortalService);
}

@After
@AfterEach
public void tearDown() throws Exception {
authController = null;
}
Expand All @@ -45,18 +43,30 @@ public void testGetUserAuth() throws Exception {

@Test
public void testGetUserAuthNotFound() {
when(userPortalService.getUserAuth("shibId")).thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
exception.expect(ResponseStatusException.class);
exception.expectMessage("User shibId not found");
authController.getUserInfo("shibId");
String shibId = "shibId";
when(userPortalService.getUserAuth(shibId)).thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));

ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> {
authController.getUserInfo(shibId);
});

assertEquals(HttpStatus.NOT_FOUND, exception.getStatusCode());
assertEquals("User " + shibId + " not found", exception.getReason());

verify(userPortalService).getUserAuth(shibId);
}

@Test
public void testUserPortalProblem() {
when(userPortalService.getUserAuth("shibId")).thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR));
exception.expect(ResponseStatusException.class);
exception.expectMessage("There was a problem connecting to the User Portal");
authController.getUserInfo("shibId");

ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> {
authController.getUserInfo("shibId");
});

assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, exception.getStatusCode());
assertEquals("There was a problem connecting to the User Portal.", exception.getReason());
verify(userPortalService).getUserAuth("shibId");
}

@Test
Expand All @@ -71,17 +81,25 @@ public void testGetUserAuthWithClient() throws Exception {
@Test
public void testGetUserAuthWithClientNotFound() {
when(userPortalService.getUserAuthWithClient("clientId", "shibId")).thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
exception.expect(ResponseStatusException.class);
exception.expectMessage("User not found");
authController.getUserInfoWithClient("clientId", "shibId");

ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> {
authController.getUserInfoWithClient("clientId", "shibId");
});
assertEquals(HttpStatus.NOT_FOUND, exception.getStatusCode());
assertEquals("User not found", exception.getReason());
verify(userPortalService).getUserAuthWithClient("clientId", "shibId");
}

@Test
public void testGetUserAuthWithClientPortalProblem() {
when(userPortalService.getUserAuthWithClient("clientId", "shibId")).thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR));
exception.expect(ResponseStatusException.class);
exception.expectMessage("There was a problem connecting to the User Portal");
authController.getUserInfoWithClient("clientId", "shibId");

ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> {
authController.getUserInfoWithClient("clientId", "shibId");
});
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, exception.getStatusCode());
assertEquals("There was a problem connecting to the User Portal.", exception.getReason());
verify(userPortalService).getUserAuthWithClient("clientId", "shibId");
}

}
15 changes: 8 additions & 7 deletions src/test/java/org/kpmp/auth/UserAuthTest.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package org.kpmp.auth;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class UserAuthTest {

private UserAuth testUserAuth;

@Before
@BeforeEach
public void setUp() throws Exception {
testUserAuth = new UserAuth();
}

@After
@AfterEach
public void tearDown() throws Exception {
testUserAuth = null;
}
Expand Down

0 comments on commit cf38b7e

Please sign in to comment.