diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 49c7962..d1cf988 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,34 +10,62 @@ on: jobs: build: - runs-on: ubuntu-20.04 # Określenie obrazu systemu + runs-on: ubuntu-20.04 steps: - name: Checkout repository uses: actions/checkout@v2 + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '21' + + - name: Cache Maven packages + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Install Project dependencies using Maven run: mvn install -DskipTests - - name: Persist workspace - run: | - mkdir -p $GITHUB_WORKSPACE/build - cp -r . $GITHUB_WORKSPACE/build + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: . test: runs-on: ubuntu-20.04 - needs: build # Zapewnienie, że testy uruchomią się po zakończeniu "build" + needs: build steps: - name: Checkout repository uses: actions/checkout@v2 - - name: Restore workspace - run: | - cp -r $GITHUB_WORKSPACE/build/* . + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '21' - - name: Set up Docker for testing - uses: docker/setup-buildx-action@v2 # Konfiguracja do używania dockera + - name: Cache Maven packages + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Download build artifacts + uses: actions/download-artifact@v4 with: - version: 20.10.14 + name: build-artifacts + + - name: Set up Docker for testing + uses: docker/setup-buildx-action@v2 - name: Run Tests run: mvn test diff --git a/Dockerfile b/Dockerfile index b19c9d6..98a8713 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM eclipse-temurin:17-jre-alpine +FROM eclipse-temurin:21-jre-alpine COPY ./target/application-0.0.1-SNAPSHOT.jar ./application-0.0.1-SNAPSHOT.jar diff --git a/application/pom.xml b/application/pom.xml index e502c94..a323457 100644 --- a/application/pom.xml +++ b/application/pom.xml @@ -13,7 +13,7 @@ application - 17 + 21 1.0 1.0 1.0 diff --git a/domain/pom.xml b/domain/pom.xml index 14ac201..5ef452f 100644 --- a/domain/pom.xml +++ b/domain/pom.xml @@ -11,22 +11,21 @@ domain - 17 - 17 + 21 + 21 UTF-8 + + + org.junit.jupiter + junit-jupiter + 5.12.1 + test + + + ../target/domain-target-jar - - - org.apache.maven.plugins - maven-surefire-plugin - 3.2.5 - - src/test/java - - - \ No newline at end of file diff --git a/infrastructure/AOP/pom.xml b/infrastructure/AOP/pom.xml index 72f9c18..43045a2 100644 --- a/infrastructure/AOP/pom.xml +++ b/infrastructure/AOP/pom.xml @@ -12,8 +12,8 @@ AOP - 17 - 17 + 21 + 21 UTF-8 diff --git a/infrastructure/adapters/offer-rest-controller/pom.xml b/infrastructure/adapters/offer-rest-controller/pom.xml index 3708be9..dd9f1f3 100644 --- a/infrastructure/adapters/offer-rest-controller/pom.xml +++ b/infrastructure/adapters/offer-rest-controller/pom.xml @@ -11,8 +11,8 @@ offer-rest-controller - 17 - 17 + 21 + 21 UTF-8 diff --git a/infrastructure/adapters/offer-rest-fetcher/pom.xml b/infrastructure/adapters/offer-rest-fetcher/pom.xml index 69b737c..7217614 100644 --- a/infrastructure/adapters/offer-rest-fetcher/pom.xml +++ b/infrastructure/adapters/offer-rest-fetcher/pom.xml @@ -11,8 +11,8 @@ offer-rest-fetcher - 17 - 17 + 21 + 21 UTF-8 2.35.2 diff --git a/infrastructure/adapters/offer-rest-fetcher/src/main/java/pl/luczak/michal/joboffersapp/resttemplate/RestTemplateResponseErrorHandler.java b/infrastructure/adapters/offer-rest-fetcher/src/main/java/pl/luczak/michal/joboffersapp/resttemplate/RestTemplateResponseErrorHandler.java index 4482551..c36a7db 100644 --- a/infrastructure/adapters/offer-rest-fetcher/src/main/java/pl/luczak/michal/joboffersapp/resttemplate/RestTemplateResponseErrorHandler.java +++ b/infrastructure/adapters/offer-rest-fetcher/src/main/java/pl/luczak/michal/joboffersapp/resttemplate/RestTemplateResponseErrorHandler.java @@ -1,17 +1,20 @@ package pl.luczak.michal.joboffersapp.resttemplate; import lombok.extern.log4j.Log4j2; +import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.client.ClientHttpResponse; -import org.springframework.lang.NonNullApi; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.server.ResponseStatusException; + +import java.net.URI; + @Log4j2 class RestTemplateResponseErrorHandler extends DefaultResponseErrorHandler { @Override - protected void handleError(ClientHttpResponse response, HttpStatusCode statusCode) { + protected void handleError(ClientHttpResponse response, HttpStatusCode statusCode, URI url, HttpMethod method) { if (statusCode.is5xxServerError()) { log.error("Error 5xx while using using http client"); throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Error while using http client"); diff --git a/infrastructure/adapters/offer-rest-fetcher/src/test/java/pl/luczak/michal/joboffersapp/resttemplate/RestTemplateResponseErrorHandlerTest.java b/infrastructure/adapters/offer-rest-fetcher/src/test/java/pl/luczak/michal/joboffersapp/resttemplate/RestTemplateResponseErrorHandlerTest.java index 8bcf07f..cc2bc5d 100644 --- a/infrastructure/adapters/offer-rest-fetcher/src/test/java/pl/luczak/michal/joboffersapp/resttemplate/RestTemplateResponseErrorHandlerTest.java +++ b/infrastructure/adapters/offer-rest-fetcher/src/test/java/pl/luczak/michal/joboffersapp/resttemplate/RestTemplateResponseErrorHandlerTest.java @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.http.HttpStatus; -import org.springframework.http.HttpStatusCode; import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.server.ResponseStatusException; @@ -13,7 +12,8 @@ import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.when; class RestTemplateResponseErrorHandlerTest { @@ -33,39 +33,36 @@ void should_handle_5xx_http_code() { // WHEN && THEN enumSet.forEach(status -> testTemplate( - status, - expectedMessage, - HttpStatus.INTERNAL_SERVER_ERROR + expectedMessage, + HttpStatus.INTERNAL_SERVER_ERROR ) ); } - @Test - void should_handle_404_http_code() { - // GIVEN - EnumSet enumSet = EnumSet.of(HttpStatus.NOT_FOUND); - - // WHEN && THEN - enumSet.forEach(status -> testTemplate(status, "", HttpStatus.NOT_FOUND)); - } - - @Test - void should_handle_401_http_code() { - // GIVEN - EnumSet enumSet = EnumSet.of(HttpStatus.UNAUTHORIZED); - - // WHEN && THEN - enumSet.forEach(status -> testTemplate(status, "", HttpStatus.UNAUTHORIZED)); + private EnumSet createEnumSet(Predicate predicate) { + EnumSet enumSet = EnumSet.allOf(HttpStatus.class); + return EnumSet.copyOf( + enumSet.stream() + .filter(predicate) + .collect(Collectors.toSet()) + ); } - private void testTemplate(HttpStatus status, String message, HttpStatus responseStatus) { + private void testTemplate(String message, HttpStatus responseStatus) { // GIVEN ClientHttpResponse response = Mockito.mock(ClientHttpResponse.class); - // WHEN && THEN + // WHEN + try { + when(response.getStatusCode()).thenReturn(responseStatus); + } catch (Exception e) { + throw new RuntimeException(e); + } + + // THEN ResponseStatusException exception = assertThrows( ResponseStatusException.class, - () -> restTemplateResponseErrorHandler.handleError(response, status) + () -> restTemplateResponseErrorHandler.handleError(response) ); assertThat(exception.getMessage()) .contains(message); @@ -73,12 +70,21 @@ private void testTemplate(HttpStatus status, String message, HttpStatus response .isEqualTo(responseStatus); } - private EnumSet createEnumSet(Predicate predicate) { - EnumSet enumSet = EnumSet.allOf(HttpStatus.class); - return EnumSet.copyOf( - enumSet.stream() - .filter(predicate) - .collect(Collectors.toSet()) - ); + @Test + void should_handle_404_http_code() { + // GIVEN + EnumSet enumSet = EnumSet.of(HttpStatus.NOT_FOUND); + + // WHEN && THEN + enumSet.forEach(status -> testTemplate("", HttpStatus.NOT_FOUND)); + } + + @Test + void should_handle_401_http_code() { + // GIVEN + EnumSet enumSet = EnumSet.of(HttpStatus.UNAUTHORIZED); + + // WHEN && THEN + enumSet.forEach(status -> testTemplate("", HttpStatus.UNAUTHORIZED)); } } \ No newline at end of file diff --git a/infrastructure/adapters/offerDAO-mongodb/pom.xml b/infrastructure/adapters/offerDAO-mongodb/pom.xml index ae4e50e..97294c8 100644 --- a/infrastructure/adapters/offerDAO-mongodb/pom.xml +++ b/infrastructure/adapters/offerDAO-mongodb/pom.xml @@ -9,8 +9,8 @@ offerDAO-mongodb - 17 - 17 + 21 + 21 UTF-8 diff --git a/infrastructure/adapters/offerDAO-mongodb/src/test/java/pl/luczak/michal/joboffersapp/offer/OfferRepositoryTest.java b/infrastructure/adapters/offerDAO-mongodb/src/test/java/pl/luczak/michal/joboffersapp/offer/OfferRepositoryTest.java index a94e1dc..18bde98 100644 --- a/infrastructure/adapters/offerDAO-mongodb/src/test/java/pl/luczak/michal/joboffersapp/offer/OfferRepositoryTest.java +++ b/infrastructure/adapters/offerDAO-mongodb/src/test/java/pl/luczak/michal/joboffersapp/offer/OfferRepositoryTest.java @@ -16,7 +16,6 @@ @DataMongoTest @ContextConfiguration(classes = OfferRepositoryTestConfig.class) -@Disabled class OfferRepositoryTest { @Autowired @@ -28,7 +27,7 @@ void tearDown() { } @Test - void should_successfully_save_offer() { + void should_successfully_save_and_find_by_id_offer() { // GIVEN String url = "testUrl"; OfferDocument offerDocument = OfferDocument.builder() @@ -53,6 +52,7 @@ void should_successfully_save_offer() { } @Test + @Disabled("Problems with mongo testing lib") void should_throw_an_exception_because_of_duplication() { // GIVEN String url = "testUrl"; @@ -61,7 +61,7 @@ void should_throw_an_exception_because_of_duplication() { .companyName("testCompanyName") .jobName("testJobName") .salary("testSalary") - .uniqueID(null) + .uniqueID("uniqueID") .build(); // WHEN @@ -75,32 +75,6 @@ void should_throw_an_exception_because_of_duplication() { ); } - @Test - void should_successfully_find_offer_by_url() { - // GIVEN - String url = "testUrl"; - OfferDocument offerDocument = OfferDocument.builder() - .url(url) - .companyName("testCompanyName") - .jobName("testJobName") - .salary("testSalary") - .uniqueID(null) - .build(); - - // WHEN - offerRepository.save(offerDocument); - Optional document = offerRepository.findByUrl(url); - - // THEN - assertAll(() -> { - assertThat(document).isPresent(); - assertThat(document.get()) - .usingRecursiveComparison() - .ignoringFields("uniqueID") - .isEqualTo(offerDocument); - }); - } - @Test void should_not_find_offer() { // GIVEN diff --git a/infrastructure/adapters/pom.xml b/infrastructure/adapters/pom.xml index 1a811a6..5d625ad 100644 --- a/infrastructure/adapters/pom.xml +++ b/infrastructure/adapters/pom.xml @@ -20,8 +20,8 @@ - 17 - 17 + 21 + 21 UTF-8 1.0 diff --git a/infrastructure/adapters/user-rest-controller/pom.xml b/infrastructure/adapters/user-rest-controller/pom.xml index 0bd1516..a55f013 100644 --- a/infrastructure/adapters/user-rest-controller/pom.xml +++ b/infrastructure/adapters/user-rest-controller/pom.xml @@ -12,8 +12,8 @@ user-rest-controller - 17 - 17 + 21 + 21 UTF-8 diff --git a/infrastructure/adapters/userDAO-jpa/pom.xml b/infrastructure/adapters/userDAO-jpa/pom.xml index 3645849..203fbaa 100644 --- a/infrastructure/adapters/userDAO-jpa/pom.xml +++ b/infrastructure/adapters/userDAO-jpa/pom.xml @@ -11,8 +11,8 @@ userDAO-jpa - 17 - 17 + 21 + 21 UTF-8 diff --git a/infrastructure/adapters/userDAO-jpa/src/main/java/pl/luczak/michal/joboffersapp/user/UserEntity.java b/infrastructure/adapters/userDAO-jpa/src/main/java/pl/luczak/michal/joboffersapp/user/UserEntity.java index fe220a9..d3282af 100644 --- a/infrastructure/adapters/userDAO-jpa/src/main/java/pl/luczak/michal/joboffersapp/user/UserEntity.java +++ b/infrastructure/adapters/userDAO-jpa/src/main/java/pl/luczak/michal/joboffersapp/user/UserEntity.java @@ -24,4 +24,9 @@ class UserEntity { @Column(nullable = false) private String password; + + UserEntity(String username, String password) { + this.username = username; + this.password = password; + } } diff --git a/infrastructure/adapters/userDAO-jpa/src/test/java/pl/luczak/michal/joboffersapp/user/UserRepositoryTest.java b/infrastructure/adapters/userDAO-jpa/src/test/java/pl/luczak/michal/joboffersapp/user/UserRepositoryTest.java index b0e77f5..c9ae5cc 100644 --- a/infrastructure/adapters/userDAO-jpa/src/test/java/pl/luczak/michal/joboffersapp/user/UserRepositoryTest.java +++ b/infrastructure/adapters/userDAO-jpa/src/test/java/pl/luczak/michal/joboffersapp/user/UserRepositoryTest.java @@ -21,15 +21,14 @@ class UserRepositoryTest { @Test void should_successfully_save_user_and_then_find_user_by_username() { // GIVEN - UserEntity userEntity = new UserEntity(1L, "testUsername", "testPassword"); + UserEntity userEntity = new UserEntity("testUsername", "testPassword"); // WHEN userRepository.save(userEntity); Optional optionalUserEntity = userRepository.findByUsername(userEntity.getUsername()); // THEN - assertThat(optionalUserEntity).isPresent(); - assertThat(optionalUserEntity.get()).isEqualTo(userEntity); + assertThat(optionalUserEntity).isPresent().contains(userEntity); } @Test diff --git a/infrastructure/pom.xml b/infrastructure/pom.xml index 09e3064..9aa0d75 100644 --- a/infrastructure/pom.xml +++ b/infrastructure/pom.xml @@ -18,8 +18,8 @@ - 17 - 17 + 21 + 21 UTF-8 \ No newline at end of file diff --git a/infrastructure/security/authentication/pom.xml b/infrastructure/security/authentication/pom.xml index 4b9b53c..2197465 100644 --- a/infrastructure/security/authentication/pom.xml +++ b/infrastructure/security/authentication/pom.xml @@ -12,8 +12,8 @@ authentication - 17 - 17 + 21 + 21 UTF-8 diff --git a/infrastructure/security/pom.xml b/infrastructure/security/pom.xml index f8209bb..2b91a39 100644 --- a/infrastructure/security/pom.xml +++ b/infrastructure/security/pom.xml @@ -15,8 +15,8 @@ security - 17 - 17 + 21 + 21 UTF-8 1.0 diff --git a/integration/pom.xml b/integration/pom.xml index fbcb96a..b6fc1a1 100644 --- a/integration/pom.xml +++ b/integration/pom.xml @@ -12,8 +12,8 @@ integration - 17 - 17 + 21 + 21 UTF-8 1.20.6 2.35.2 diff --git a/pom.xml b/pom.xml index 326c218..185934b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.springframework.boot spring-boot-starter-parent - 3.0.5 + 3.4.4 pl.luczak.michal.joboffersapp @@ -23,8 +23,8 @@ - 17 - 17 + 21 + 21 UTF-8 2.18.3 3.4.4 @@ -33,8 +33,6 @@ 4.3.1 1.18.30 3.23.1 - 5.9.2 - 5.9.2 @@ -127,18 +125,6 @@ ${lombok.version} - - org.junit.jupiter - junit-jupiter-api - ${junit-jupiter-api.version} - test - - - org.junit.jupiter - junit-jupiter-engine - ${junit-jupiter-engine.version} - test - org.assertj assertj-core @@ -152,7 +138,7 @@ org.jacoco jacoco-maven-plugin - 0.8.8 + 0.8.13