Skip to content

Commit 536eaa9

Browse files
Merge pull request #55 from michal-luczak/fix
Fix
2 parents d3f0f0c + 42502b6 commit 536eaa9

File tree

21 files changed

+131
-131
lines changed

21 files changed

+131
-131
lines changed

.github/workflows/build.yml

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,62 @@ on:
1010

1111
jobs:
1212
build:
13-
runs-on: ubuntu-20.04 # Określenie obrazu systemu
13+
runs-on: ubuntu-20.04
1414
steps:
1515
- name: Checkout repository
1616
uses: actions/checkout@v2
1717

18+
- name: Set up JDK 21
19+
uses: actions/setup-java@v3
20+
with:
21+
distribution: 'temurin'
22+
java-version: '21'
23+
24+
- name: Cache Maven packages
25+
uses: actions/cache@v3
26+
with:
27+
path: ~/.m2/repository
28+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
29+
restore-keys: |
30+
${{ runner.os }}-maven-
31+
1832
- name: Install Project dependencies using Maven
1933
run: mvn install -DskipTests
2034

21-
- name: Persist workspace
22-
run: |
23-
mkdir -p $GITHUB_WORKSPACE/build
24-
cp -r . $GITHUB_WORKSPACE/build
35+
- name: Upload build artifacts
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: build-artifacts
39+
path: .
2540

2641
test:
2742
runs-on: ubuntu-20.04
28-
needs: build # Zapewnienie, że testy uruchomią się po zakończeniu "build"
43+
needs: build
2944
steps:
3045
- name: Checkout repository
3146
uses: actions/checkout@v2
3247

33-
- name: Restore workspace
34-
run: |
35-
cp -r $GITHUB_WORKSPACE/build/* .
48+
- name: Set up JDK 21
49+
uses: actions/setup-java@v3
50+
with:
51+
distribution: 'temurin'
52+
java-version: '21'
3653

37-
- name: Set up Docker for testing
38-
uses: docker/setup-buildx-action@v2 # Konfiguracja do używania dockera
54+
- name: Cache Maven packages
55+
uses: actions/cache@v3
56+
with:
57+
path: ~/.m2/repository
58+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
59+
restore-keys: |
60+
${{ runner.os }}-maven-
61+
62+
- name: Download build artifacts
63+
uses: actions/download-artifact@v4
3964
with:
40-
version: 20.10.14
65+
name: build-artifacts
66+
67+
- name: Set up Docker for testing
68+
uses: docker/setup-buildx-action@v2
4169

4270
- name: Run Tests
4371
run: mvn test

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM eclipse-temurin:17-jre-alpine
1+
FROM eclipse-temurin:21-jre-alpine
22

33
COPY ./target/application-0.0.1-SNAPSHOT.jar ./application-0.0.1-SNAPSHOT.jar
44

application/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<description>application</description>
1414

1515
<properties>
16-
<java.version>17</java.version>
16+
<java.version>21</java.version>
1717
<offer-rest-fetcher.version>1.0</offer-rest-fetcher.version>
1818
<offerDAO-mongodb.version>1.0</offerDAO-mongodb.version>
1919
<userDAO-jpa.version>1.0</userDAO-jpa.version>

domain/pom.xml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@
1111
<artifactId>domain</artifactId>
1212

1313
<properties>
14-
<maven.compiler.source>17</maven.compiler.source>
15-
<maven.compiler.target>17</maven.compiler.target>
14+
<maven.compiler.source>21</maven.compiler.source>
15+
<maven.compiler.target>21</maven.compiler.target>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717
</properties>
1818

19+
<dependencies>
20+
<dependency>
21+
<groupId>org.junit.jupiter</groupId>
22+
<artifactId>junit-jupiter</artifactId>
23+
<version>5.12.1</version>
24+
<scope>test</scope>
25+
</dependency>
26+
</dependencies>
27+
1928
<build>
2029
<directory>../target/domain-target-jar</directory>
21-
<plugins>
22-
<plugin>
23-
<groupId>org.apache.maven.plugins</groupId>
24-
<artifactId>maven-surefire-plugin</artifactId>
25-
<version>3.2.5</version>
26-
<configuration>
27-
<testSourceDirectory>src/test/java</testSourceDirectory>
28-
</configuration>
29-
</plugin>
30-
</plugins>
3130
</build>
3231
</project>

infrastructure/AOP/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<artifactId>AOP</artifactId>
1313

1414
<properties>
15-
<maven.compiler.source>17</maven.compiler.source>
16-
<maven.compiler.target>17</maven.compiler.target>
15+
<maven.compiler.source>21</maven.compiler.source>
16+
<maven.compiler.target>21</maven.compiler.target>
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1818
</properties>
1919

infrastructure/adapters/offer-rest-controller/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<artifactId>offer-rest-controller</artifactId>
1212

1313
<properties>
14-
<maven.compiler.source>17</maven.compiler.source>
15-
<maven.compiler.target>17</maven.compiler.target>
14+
<maven.compiler.source>21</maven.compiler.source>
15+
<maven.compiler.target>21</maven.compiler.target>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717
</properties>
1818

infrastructure/adapters/offer-rest-fetcher/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<artifactId>offer-rest-fetcher</artifactId>
1212

1313
<properties>
14-
<maven.compiler.source>17</maven.compiler.source>
15-
<maven.compiler.target>17</maven.compiler.target>
14+
<maven.compiler.source>21</maven.compiler.source>
15+
<maven.compiler.target>21</maven.compiler.target>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717
<wiremock-jre8-standalone.version>2.35.2</wiremock-jre8-standalone.version>
1818
</properties>

infrastructure/adapters/offer-rest-fetcher/src/main/java/pl/luczak/michal/joboffersapp/resttemplate/RestTemplateResponseErrorHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package pl.luczak.michal.joboffersapp.resttemplate;
22

33
import lombok.extern.log4j.Log4j2;
4+
import org.springframework.http.HttpMethod;
45
import org.springframework.http.HttpStatus;
56
import org.springframework.http.HttpStatusCode;
67
import org.springframework.http.client.ClientHttpResponse;
7-
import org.springframework.lang.NonNullApi;
88
import org.springframework.web.client.DefaultResponseErrorHandler;
99
import org.springframework.web.server.ResponseStatusException;
10+
11+
import java.net.URI;
12+
1013
@Log4j2
1114
class RestTemplateResponseErrorHandler extends DefaultResponseErrorHandler {
1215

1316
@Override
14-
protected void handleError(ClientHttpResponse response, HttpStatusCode statusCode) {
17+
protected void handleError(ClientHttpResponse response, HttpStatusCode statusCode, URI url, HttpMethod method) {
1518
if (statusCode.is5xxServerError()) {
1619
log.error("Error 5xx while using using http client");
1720
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Error while using http client");

infrastructure/adapters/offer-rest-fetcher/src/test/java/pl/luczak/michal/joboffersapp/resttemplate/RestTemplateResponseErrorHandlerTest.java

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.junit.jupiter.api.Test;
55
import org.mockito.Mockito;
66
import org.springframework.http.HttpStatus;
7-
import org.springframework.http.HttpStatusCode;
87
import org.springframework.http.client.ClientHttpResponse;
98
import org.springframework.web.server.ResponseStatusException;
109

@@ -13,7 +12,8 @@
1312
import java.util.stream.Collectors;
1413

1514
import static org.assertj.core.api.Assertions.assertThat;
16-
import static org.junit.jupiter.api.Assertions.*;
15+
import static org.junit.jupiter.api.Assertions.assertThrows;
16+
import static org.mockito.Mockito.when;
1717

1818
class RestTemplateResponseErrorHandlerTest {
1919

@@ -33,52 +33,58 @@ void should_handle_5xx_http_code() {
3333
// WHEN && THEN
3434
enumSet.forEach(status ->
3535
testTemplate(
36-
status,
37-
expectedMessage,
38-
HttpStatus.INTERNAL_SERVER_ERROR
36+
expectedMessage,
37+
HttpStatus.INTERNAL_SERVER_ERROR
3938
)
4039
);
4140
}
4241

43-
@Test
44-
void should_handle_404_http_code() {
45-
// GIVEN
46-
EnumSet<HttpStatus> enumSet = EnumSet.of(HttpStatus.NOT_FOUND);
47-
48-
// WHEN && THEN
49-
enumSet.forEach(status -> testTemplate(status, "", HttpStatus.NOT_FOUND));
50-
}
51-
52-
@Test
53-
void should_handle_401_http_code() {
54-
// GIVEN
55-
EnumSet<HttpStatus> enumSet = EnumSet.of(HttpStatus.UNAUTHORIZED);
56-
57-
// WHEN && THEN
58-
enumSet.forEach(status -> testTemplate(status, "", HttpStatus.UNAUTHORIZED));
42+
private EnumSet<HttpStatus> createEnumSet(Predicate<HttpStatus> predicate) {
43+
EnumSet<HttpStatus> enumSet = EnumSet.allOf(HttpStatus.class);
44+
return EnumSet.copyOf(
45+
enumSet.stream()
46+
.filter(predicate)
47+
.collect(Collectors.toSet())
48+
);
5949
}
6050

61-
private void testTemplate(HttpStatus status, String message, HttpStatus responseStatus) {
51+
private void testTemplate(String message, HttpStatus responseStatus) {
6252
// GIVEN
6353
ClientHttpResponse response = Mockito.mock(ClientHttpResponse.class);
6454

65-
// WHEN && THEN
55+
// WHEN
56+
try {
57+
when(response.getStatusCode()).thenReturn(responseStatus);
58+
} catch (Exception e) {
59+
throw new RuntimeException(e);
60+
}
61+
62+
// THEN
6663
ResponseStatusException exception = assertThrows(
6764
ResponseStatusException.class,
68-
() -> restTemplateResponseErrorHandler.handleError(response, status)
65+
() -> restTemplateResponseErrorHandler.handleError(response)
6966
);
7067
assertThat(exception.getMessage())
7168
.contains(message);
7269
assertThat(exception.getStatusCode())
7370
.isEqualTo(responseStatus);
7471
}
7572

76-
private EnumSet<HttpStatus> createEnumSet(Predicate<HttpStatus> predicate) {
77-
EnumSet<HttpStatus> enumSet = EnumSet.allOf(HttpStatus.class);
78-
return EnumSet.copyOf(
79-
enumSet.stream()
80-
.filter(predicate)
81-
.collect(Collectors.toSet())
82-
);
73+
@Test
74+
void should_handle_404_http_code() {
75+
// GIVEN
76+
EnumSet<HttpStatus> enumSet = EnumSet.of(HttpStatus.NOT_FOUND);
77+
78+
// WHEN && THEN
79+
enumSet.forEach(status -> testTemplate("", HttpStatus.NOT_FOUND));
80+
}
81+
82+
@Test
83+
void should_handle_401_http_code() {
84+
// GIVEN
85+
EnumSet<HttpStatus> enumSet = EnumSet.of(HttpStatus.UNAUTHORIZED);
86+
87+
// WHEN && THEN
88+
enumSet.forEach(status -> testTemplate("", HttpStatus.UNAUTHORIZED));
8389
}
8490
}

infrastructure/adapters/offerDAO-mongodb/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<artifactId>offerDAO-mongodb</artifactId>
1010

1111
<properties>
12-
<maven.compiler.source>17</maven.compiler.source>
13-
<maven.compiler.target>17</maven.compiler.target>
12+
<maven.compiler.source>21</maven.compiler.source>
13+
<maven.compiler.target>21</maven.compiler.target>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
</properties>
1616

0 commit comments

Comments
 (0)