forked from Onlineberatung/onlineBeratung-userService
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Onlineberatung/develop
Merge deletion workflow fix
- Loading branch information
Showing
4 changed files
with
165 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
.../java/de/caritas/cob/userservice/api/workflow/delete/service/WorkflowErrorLogService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package de.caritas.cob.userservice.api.workflow.delete.service; | ||
|
||
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty; | ||
|
||
import de.caritas.cob.userservice.api.workflow.delete.model.DeletionWorkflowError; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** Service class to log all deletion workflow errors. */ | ||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class WorkflowErrorLogService { | ||
|
||
public void logWorkflowErrors(List<DeletionWorkflowError> workflowErrors) { | ||
if (isNotEmpty(workflowErrors)) { | ||
workflowErrors.forEach( | ||
workflowError -> | ||
log.warn( | ||
"Errors during deletion workflow:" | ||
+ " SourceType = {}; " | ||
+ "TargetType = {}; " | ||
+ "Identifier = {}; " | ||
+ "Reason = {}; " | ||
+ "Timestamp = {}.", | ||
workflowError.getDeletionSourceType(), | ||
workflowError.getDeletionTargetType(), | ||
workflowError.getIdentifier(), | ||
workflowError.getReason(), | ||
workflowError.getTimestamp())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...a/de/caritas/cob/userservice/api/workflow/delete/service/WorkflowErrorLogServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package de.caritas.cob.userservice.api.workflow.delete.service; | ||
|
||
import static de.caritas.cob.userservice.api.helper.CustomLocalDateTime.nowInUtc; | ||
import static de.caritas.cob.userservice.api.workflow.delete.model.DeletionSourceType.ASKER; | ||
import static de.caritas.cob.userservice.api.workflow.delete.model.DeletionTargetType.ROCKET_CHAT; | ||
import static java.util.Collections.emptyList; | ||
|
||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.read.ListAppender; | ||
import de.caritas.cob.userservice.api.workflow.delete.model.DeletionWorkflowError; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class WorkflowErrorLogServiceTest { | ||
|
||
@InjectMocks private WorkflowErrorLogService workflowErrorLogService; | ||
|
||
private ListAppender<ILoggingEvent> listAppender; | ||
|
||
@Before | ||
public void setUp() { | ||
Logger logger = (Logger) LoggerFactory.getLogger(WorkflowErrorLogService.class); | ||
listAppender = new ListAppender<>(); | ||
listAppender.start(); | ||
logger.addAppender(listAppender); | ||
} | ||
|
||
@Test | ||
public void logWorkflowErrors_Should_logNoErrors_When_workflowErrorsAreNull() { | ||
|
||
// when | ||
this.workflowErrorLogService.logWorkflowErrors(null); | ||
|
||
// then | ||
Assertions.assertThat(listAppender.list).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void logWorkflowErrors_Should_logNoErrors_When_workflowErrorsAreEmpty() { | ||
|
||
// when | ||
this.workflowErrorLogService.logWorkflowErrors(emptyList()); | ||
|
||
// then | ||
Assertions.assertThat(listAppender.list).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void logWorkflowErrors_Should_logErrors_When_workflowErrorsExists() { | ||
// given | ||
List<DeletionWorkflowError> workflowErrors = new ArrayList<>(); | ||
workflowErrors.add( | ||
DeletionWorkflowError.builder() | ||
.deletionSourceType(ASKER) | ||
.deletionTargetType(ROCKET_CHAT) | ||
.timestamp(nowInUtc()) | ||
.reason("reason") | ||
.identifier("id") | ||
.build()); | ||
|
||
// when | ||
this.workflowErrorLogService.logWorkflowErrors(workflowErrors); | ||
|
||
// then | ||
Assertions.assertThat(listAppender.list).hasSize(1); | ||
} | ||
} |