-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: detach entities when converting to dto
- Loading branch information
Showing
9 changed files
with
178 additions
and
17 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
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
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
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
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
61 changes: 61 additions & 0 deletions
61
...ng-boot/src/test/java/org/citrusframework/simulator/service/MessageHeaderServiceTest.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,61 @@ | ||
package org.citrusframework.simulator.service; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import org.citrusframework.simulator.model.Message; | ||
import org.citrusframework.simulator.model.MessageHeader; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoInteractions; | ||
|
||
@ExtendWith({MockitoExtension.class}) | ||
class MessageHeaderServiceTest { | ||
|
||
@Mock | ||
private EntityManager entityManagerMock; | ||
|
||
@Nested | ||
class RestrictToDtoProperties { | ||
|
||
@Test | ||
void shouldFilterMessageDetails() { | ||
var message = mock(Message.class); | ||
doReturn(1234L).when(message).getMessageId(); | ||
doReturn("citrus-message-id").when(message).getCitrusMessageId(); | ||
|
||
var messageHeader = new MessageHeader(); | ||
messageHeader.setMessage(message); | ||
|
||
var restrictedMessageHeader = MessageHeaderService.restrictToDtoProperties(messageHeader, entityManagerMock); | ||
|
||
var restrictedMessage = restrictedMessageHeader.getMessage(); | ||
assertEquals(message.getMessageId(), restrictedMessage.getMessageId()); | ||
assertEquals(message.getCitrusMessageId(), restrictedMessage.getCitrusMessageId()); | ||
|
||
verify(message, never()).getHeaders(); | ||
verify(message, never()).getScenarioExecution(); | ||
|
||
verify(entityManagerMock).detach(messageHeader); | ||
} | ||
|
||
@Test | ||
void shouldHandleNullMessage() { | ||
var messageHeader = new MessageHeader(); | ||
|
||
var restrictedMessageHeader = MessageHeaderService.restrictToDtoProperties(messageHeader, entityManagerMock); | ||
|
||
assertNull(restrictedMessageHeader.getMessage()); | ||
|
||
verifyNoInteractions(entityManagerMock); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...g-boot/src/test/java/org/citrusframework/simulator/service/ScenarioActionServiceTest.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,62 @@ | ||
package org.citrusframework.simulator.service; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import org.citrusframework.simulator.model.ScenarioAction; | ||
import org.citrusframework.simulator.model.ScenarioExecution; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoInteractions; | ||
|
||
@ExtendWith({MockitoExtension.class}) | ||
class ScenarioActionServiceTest { | ||
|
||
@Mock | ||
private EntityManager entityManagerMock; | ||
|
||
@Nested | ||
class RestrictToDtoProperties { | ||
|
||
@Test | ||
void shouldFilterMessageDetails() { | ||
var scenarioExecution = mock(ScenarioExecution.class); | ||
doReturn(1234L).when(scenarioExecution).getExecutionId(); | ||
doReturn("scenario-name").when(scenarioExecution).getScenarioName(); | ||
|
||
var scenarioAction = new ScenarioAction(); | ||
scenarioAction.setScenarioExecution(scenarioExecution); | ||
|
||
var restrictedScenarioAction = ScenarioActionService.restrictToDtoProperties(scenarioAction, entityManagerMock); | ||
|
||
var restrictedScenarioExecution = restrictedScenarioAction.getScenarioExecution(); | ||
assertEquals(scenarioExecution.getExecutionId(), restrictedScenarioExecution.getExecutionId()); | ||
assertEquals(scenarioExecution.getScenarioName(), restrictedScenarioExecution.getScenarioName()); | ||
|
||
verify(scenarioExecution, never()).getScenarioParameters(); | ||
verify(scenarioExecution, never()).getScenarioActions(); | ||
verify(scenarioExecution, never()).getScenarioMessages(); | ||
|
||
verify(entityManagerMock).detach(scenarioAction); | ||
} | ||
|
||
@Test | ||
void shouldHandleNullMessage() { | ||
var scenarioAction = new ScenarioAction(); | ||
|
||
var restrictedScenarioAction = ScenarioActionService.restrictToDtoProperties(scenarioAction, entityManagerMock); | ||
|
||
assertNull(restrictedScenarioAction.getScenarioExecution()); | ||
|
||
verifyNoInteractions(entityManagerMock); | ||
} | ||
} | ||
} |
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
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