Skip to content
Merged

Fix #55

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<description>application</description>

<properties>
<java.version>17</java.version>
<java.version>21</java.version>
<offer-rest-fetcher.version>1.0</offer-rest-fetcher.version>
<offerDAO-mongodb.version>1.0</offerDAO-mongodb.version>
<userDAO-jpa.version>1.0</userDAO-jpa.version>
Expand Down
23 changes: 11 additions & 12 deletions domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@
<artifactId>domain</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.12.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<directory>../target/domain-target-jar</directory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<testSourceDirectory>src/test/java</testSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
4 changes: 2 additions & 2 deletions infrastructure/AOP/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<artifactId>AOP</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
4 changes: 2 additions & 2 deletions infrastructure/adapters/offer-rest-controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<artifactId>offer-rest-controller</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
4 changes: 2 additions & 2 deletions infrastructure/adapters/offer-rest-fetcher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<artifactId>offer-rest-fetcher</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<wiremock-jre8-standalone.version>2.35.2</wiremock-jre8-standalone.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {

Expand All @@ -33,52 +33,58 @@ 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<HttpStatus> 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<HttpStatus> enumSet = EnumSet.of(HttpStatus.UNAUTHORIZED);

// WHEN && THEN
enumSet.forEach(status -> testTemplate(status, "", HttpStatus.UNAUTHORIZED));
private EnumSet<HttpStatus> createEnumSet(Predicate<HttpStatus> predicate) {
EnumSet<HttpStatus> 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);
assertThat(exception.getStatusCode())
.isEqualTo(responseStatus);
}

private EnumSet<HttpStatus> createEnumSet(Predicate<HttpStatus> predicate) {
EnumSet<HttpStatus> enumSet = EnumSet.allOf(HttpStatus.class);
return EnumSet.copyOf(
enumSet.stream()
.filter(predicate)
.collect(Collectors.toSet())
);
@Test
void should_handle_404_http_code() {
// GIVEN
EnumSet<HttpStatus> enumSet = EnumSet.of(HttpStatus.NOT_FOUND);

// WHEN && THEN
enumSet.forEach(status -> testTemplate("", HttpStatus.NOT_FOUND));
}

@Test
void should_handle_401_http_code() {
// GIVEN
EnumSet<HttpStatus> enumSet = EnumSet.of(HttpStatus.UNAUTHORIZED);

// WHEN && THEN
enumSet.forEach(status -> testTemplate("", HttpStatus.UNAUTHORIZED));
}
}
4 changes: 2 additions & 2 deletions infrastructure/adapters/offerDAO-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<artifactId>offerDAO-mongodb</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

@DataMongoTest
@ContextConfiguration(classes = OfferRepositoryTestConfig.class)
@Disabled
class OfferRepositoryTest {

@Autowired
Expand All @@ -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()
Expand All @@ -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";
Expand All @@ -61,7 +61,7 @@ void should_throw_an_exception_because_of_duplication() {
.companyName("testCompanyName")
.jobName("testJobName")
.salary("testSalary")
.uniqueID(null)
.uniqueID("uniqueID")
.build();

// WHEN
Expand All @@ -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<OfferDocument> document = offerRepository.findByUrl(url);

// THEN
assertAll(() -> {
assertThat(document).isPresent();
assertThat(document.get())
.usingRecursiveComparison()
.ignoringFields("uniqueID")
.isEqualTo(offerDocument);
});
}

@Test
void should_not_find_offer() {
// GIVEN
Expand Down
4 changes: 2 additions & 2 deletions infrastructure/adapters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
</modules>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<domain.version>1.0</domain.version>
</properties>
Expand Down
4 changes: 2 additions & 2 deletions infrastructure/adapters/user-rest-controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<artifactId>user-rest-controller</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
4 changes: 2 additions & 2 deletions infrastructure/adapters/userDAO-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<artifactId>userDAO-jpa</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
Loading
Loading