Skip to content
Snippets Groups Projects
Commit e32f5b9b authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2566 OZG-2686 adjust "editKommentar"

parent 91c27b15
Branches
Tags
No related merge requests found
Showing
with 208 additions and 111 deletions
...@@ -35,6 +35,21 @@ public class VorgangAttachedItemService { ...@@ -35,6 +35,21 @@ public class VorgangAttachedItemService {
return commandService.createCommand(buildCreateCommand(vorgangId, vorgangAttachedItem)); return commandService.createCommand(buildCreateCommand(vorgangId, vorgangAttachedItem));
} }
CreateCommand buildCreateCommand(String vorgangId, CommandBody body) {
return CreateCommand.builder()
.vorgangId(vorgangId)
.relationId(vorgangId)
.order(CommandOrder.CREATE_ATTACHED_ITEM)
.body(body)
.build();
}
public Command editKommentar(Kommentar kommentar, String kommentarId, long kommentarVersion) {
var vorgangAttachedItem = buildVorgangAttachedItem(kommentar, kommentar.getVorgangId(), KOMMENTAR_ITEM_NAME);
return commandService.createCommand(buildUpdateCommand(kommentar.getVorgangId(), kommentarId, vorgangAttachedItem), kommentarVersion);
}
VorgangAttachedItem buildVorgangAttachedItem(CommandBody body, String vorgangId, String itemName) { VorgangAttachedItem buildVorgangAttachedItem(CommandBody body, String vorgangId, String itemName) {
return VorgangAttachedItem.builder() return VorgangAttachedItem.builder()
.vorgangId(vorgangId) .vorgangId(vorgangId)
...@@ -43,12 +58,12 @@ public class VorgangAttachedItemService { ...@@ -43,12 +58,12 @@ public class VorgangAttachedItemService {
.build(); .build();
} }
CreateCommand buildCreateCommand(String vorgangId, CommandBody commandBody) { CreateCommand buildUpdateCommand(String vorgangId, String kommentarId, CommandBody body) {
return CreateCommand.builder() return CreateCommand.builder()
.vorgangId(vorgangId) .vorgangId(vorgangId)
.relationId(vorgangId) .relationId(kommentarId)
.order(CommandOrder.CREATE_ATTACHED_ITEM) .order(CommandOrder.UPDATE_ATTACHED_ITEM)
.body(commandBody) .body(body)
.build(); .build();
} }
} }
\ No newline at end of file
...@@ -87,7 +87,7 @@ public class CommandController { ...@@ -87,7 +87,7 @@ public class CommandController {
command = prepareCommandForPostfachNachricht(command, vorgangId); command = prepareCommandForPostfachNachricht(command, vorgangId);
} }
var created = createCommand(command, relationVersion); var created = service.createCommandWithValidation(command, relationVersion);
return ResponseEntity.created(linkTo(CommandController.class).slash(created.getId()).toUri()).build(); return ResponseEntity.created(linkTo(CommandController.class).slash(created.getId()).toUri()).build();
} }
...@@ -118,10 +118,6 @@ public class CommandController { ...@@ -118,10 +118,6 @@ public class CommandController {
return vorgangController.getVorgang(vorgangId); return vorgangController.getVorgang(vorgangId);
} }
public Command createCommand(CreateCommand command, long relationVersion) {
return service.createCommand(command, relationVersion);
}
// Anlegen eines Commands fuer eine neue PostfachNachricht(resend) // Anlegen eines Commands fuer eine neue PostfachNachricht(resend)
public Command createCommandWithoutRelation(CreateCommand command) { public Command createCommandWithoutRelation(CreateCommand command) {
return service.createCommandWithoutRelation(command); return service.createCommandWithoutRelation(command);
......
...@@ -26,8 +26,14 @@ public class CommandService { ...@@ -26,8 +26,14 @@ public class CommandService {
return remoteService.createCommand(command); return remoteService.createCommand(command);
} }
////////// public Command createCommand(CreateCommand command, long relationVersion) {
public Command createCommand(@Valid CreateCommand command, long relationVersion) { command = command.toBuilder().relationVersion(relationVersion).build();
return remoteService.createCommand(command);
}
////////
public Command createCommandWithValidation(@Valid CreateCommand command, long relationVersion) {
command = command.toBuilder().relationVersion(relationVersion).build(); command = command.toBuilder().relationVersion(relationVersion).build();
return remoteService.createCommand(command); return remoteService.createCommand(command);
......
...@@ -12,9 +12,6 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -12,9 +12,6 @@ import org.springframework.web.bind.annotation.RestController;
import de.itvsh.goofy.common.command.Command; import de.itvsh.goofy.common.command.Command;
import de.itvsh.goofy.common.command.CommandController; import de.itvsh.goofy.common.command.CommandController;
import de.itvsh.goofy.common.command.CommandController.CommandByRelationController;
import de.itvsh.goofy.common.command.CommandOrder;
import de.itvsh.goofy.common.command.CreateCommand;
@RestController @RestController
@RequestMapping(KommentarCommandController.KOMMENTAR_COMMANDS) @RequestMapping(KommentarCommandController.KOMMENTAR_COMMANDS)
...@@ -25,34 +22,18 @@ public class KommentarCommandController { ...@@ -25,34 +22,18 @@ public class KommentarCommandController {
@Autowired @Autowired
private KommentarService service; private KommentarService service;
@Autowired
private CommandByRelationController commandByRelationController;
@PostMapping @PostMapping
public ResponseEntity<Void> editKommentar(@RequestBody KommentarCommand kommentarCommand, @PathVariable String kommentarId, public ResponseEntity<Void> editKommentar(@RequestBody KommentarCommand kommentarCommand, @PathVariable String kommentarId,
@PathVariable long kommentarVersion) { @PathVariable long kommentarVersion) {
var command = commandByRelationController.createCommand(buildCommand(service.getById(kommentarId), kommentarCommand), var createdCommand = service.editKommentar(kommentarCommand, kommentarId, kommentarVersion);
KommentarRemoteService.ITEM_NAME, kommentarVersion);
return buildResponseLink(command); return buildResponseLink(createdCommand);
} }
private ResponseEntity<Void> buildResponseLink(Command createdKommentarCommand) { private ResponseEntity<Void> buildResponseLink(Command createdKommentarCommand) {
return ResponseEntity.created(linkTo(CommandController.class).slash(createdKommentarCommand.getId()).toUri()).build(); return ResponseEntity.created(linkTo(CommandController.class).slash(createdKommentarCommand.getId()).toUri()).build();
} }
CreateCommand buildCommand(Kommentar kommentar, KommentarCommand command) {
var commandBuilder = CreateCommand.builder()
.order(CommandOrder.UPDATE_ATTACHED_ITEM)
.relationId(kommentar.getId())
.vorgangId(kommentar.getVorgangId());
return commandBuilder.body(updateKommentarByCommand(kommentar, command)).build();
}
private Kommentar updateKommentarByCommand(Kommentar kommentar, KommentarCommand command) {
return kommentar.toBuilder().text(command.getKommentar().getText()).build();
}
@RestController @RestController
@RequestMapping(KommentarCommandByVorgangController.KOMMENTAR_COMMANDS_BY_VORGANG) @RequestMapping(KommentarCommandByVorgangController.KOMMENTAR_COMMANDS_BY_VORGANG)
public static class KommentarCommandByVorgangController { public static class KommentarCommandByVorgangController {
......
...@@ -35,6 +35,13 @@ class KommentarService { ...@@ -35,6 +35,13 @@ class KommentarService {
.build(); .build();
} }
public Command editKommentar(@Valid KommentarCommand kommentarCommand, String kommentarId, long kommentarVersion) {
var loadedKommentar = getById(kommentarId);
var preparedKommentar = loadedKommentar.toBuilder().text(kommentarCommand.getKommentar().getText()).build();
return vorgangAttachedItemService.editKommentar(preparedKommentar, kommentarId, kommentarVersion);
}
public Stream<Kommentar> findByVorgangId(String vorgangId) { public Stream<Kommentar> findByVorgangId(String vorgangId) {
return remoteService.findByVorgangId(vorgangId); return remoteService.findByVorgangId(vorgangId);
} }
......
...@@ -39,10 +39,6 @@ class VorgangAttachedItemServiceTest { ...@@ -39,10 +39,6 @@ class VorgangAttachedItemServiceTest {
@Nested @Nested
class TestCreateNewWiedervorlage { class TestCreateNewWiedervorlage {
@DisplayName("should call")
@Nested
class TestCalls {
private Wiedervorlage wiedervorlage = WiedervorlageTestFactory.create(); private Wiedervorlage wiedervorlage = WiedervorlageTestFactory.create();
@BeforeEach @BeforeEach
...@@ -51,28 +47,36 @@ class VorgangAttachedItemServiceTest { ...@@ -51,28 +47,36 @@ class VorgangAttachedItemServiceTest {
doReturn(CommandTestFactory.createCreateCommand()).when(service).buildCreateCommand(any(), any()); doReturn(CommandTestFactory.createCreateCommand()).when(service).buildCreateCommand(any(), any());
} }
@DisplayName("command service") @Test
void shouldBuildVorgangAttachedItem() {
callCreateNewWiedervorlage();
verify(service).buildVorgangAttachedItem(wiedervorlage, VorgangHeaderTestFactory.ID, VorgangAttachedItemService.WIEDERVORLAGE_ITEM_NAME);
}
@Test
void shouldBuildCreateCommand() {
callCreateNewWiedervorlage();
verify(service).buildCreateCommand(eq(VorgangHeaderTestFactory.ID), any(VorgangAttachedItem.class));
}
@Test @Test
void shouldCallCommandService() { void shouldCallCommandService() {
callCreateNewWiedervorlage(); callCreateNewWiedervorlage();
verify(commandService).createCommand(any()); verify(commandService).createCommand(any(CreateCommand.class));
} }
private Command callCreateNewWiedervorlage() { private Command callCreateNewWiedervorlage() {
return service.createNewWiedervorlage(wiedervorlage, VorgangHeaderTestFactory.ID); return service.createNewWiedervorlage(wiedervorlage, VorgangHeaderTestFactory.ID);
} }
} }
}
@DisplayName("Create new kommentar") @DisplayName("Create new kommentar")
@Nested @Nested
class TestCreateNewKommentar { class TestCreateNewKommentar {
@DisplayName("should call")
@Nested
class TestCalls {
private Kommentar kommentar = KommentarTestFactory.create(); private Kommentar kommentar = KommentarTestFactory.create();
@BeforeEach @BeforeEach
...@@ -81,18 +85,68 @@ class VorgangAttachedItemServiceTest { ...@@ -81,18 +85,68 @@ class VorgangAttachedItemServiceTest {
doReturn(CommandTestFactory.createCreateCommand()).when(service).buildCreateCommand(any(), any()); doReturn(CommandTestFactory.createCreateCommand()).when(service).buildCreateCommand(any(), any());
} }
@DisplayName("command service") @Test
void shouldBuildVorgangAttachedItem() {
callCreateNewKommentar();
verify(service).buildVorgangAttachedItem(kommentar, VorgangHeaderTestFactory.ID, VorgangAttachedItemService.KOMMENTAR_ITEM_NAME);
}
@Test
void shouldBuildCreateCommand() {
callCreateNewKommentar();
verify(service).buildCreateCommand(eq(VorgangHeaderTestFactory.ID), any(VorgangAttachedItem.class));
}
@Test @Test
void shouldCallCommandService() { void shouldCallCommandService() {
callCreateNewKommentar(); callCreateNewKommentar();
verify(commandService).createCommand(any()); verify(commandService).createCommand(any(CreateCommand.class));
} }
private Command callCreateNewKommentar() { private Command callCreateNewKommentar() {
return service.createNewKommentar(kommentar, VorgangHeaderTestFactory.ID); return service.createNewKommentar(kommentar, VorgangHeaderTestFactory.ID);
} }
} }
@Nested
class TestEditKommentar {
private Kommentar kommentar = KommentarTestFactory.create();
@BeforeEach
void mockService() {
doReturn(VorgangAttachedItemTestFactory.create()).when(service).buildVorgangAttachedItem(any(), any(), any());
doReturn(CommandTestFactory.createCreateCommand()).when(service).buildUpdateCommand(any(), any(), any());
}
@Test
void shouldBuildVorgangAttachedItem() {
callEditKommentar();
verify(service).buildVorgangAttachedItem(kommentar, VorgangHeaderTestFactory.ID, VorgangAttachedItemService.KOMMENTAR_ITEM_NAME);
}
@Test
void shouldBuildCreateCommand() {
callEditKommentar();
verify(service).buildUpdateCommand(eq(VorgangHeaderTestFactory.ID), eq(KommentarTestFactory.ID), any(VorgangAttachedItem.class));
}
@Test
void shouldCallCommandService() {
callEditKommentar();
verify(commandService).createCommand(any(CreateCommand.class), eq(KommentarTestFactory.VERSION));
}
private Command callEditKommentar() {
return service.editKommentar(kommentar, KommentarTestFactory.ID, KommentarTestFactory.VERSION);
}
} }
@DisplayName("build createCommand") @DisplayName("build createCommand")
......
...@@ -146,7 +146,7 @@ class CommandControllerTest { ...@@ -146,7 +146,7 @@ class CommandControllerTest {
@BeforeEach @BeforeEach
void initTest() { void initTest() {
when(service.createCommand(any(CreateCommand.class), anyLong())).thenReturn(CommandTestFactory.create()); when(service.createCommandWithValidation(any(CreateCommand.class), anyLong())).thenReturn(CommandTestFactory.create());
} }
@DisplayName("should return CREATED") @DisplayName("should return CREATED")
...@@ -160,7 +160,7 @@ class CommandControllerTest { ...@@ -160,7 +160,7 @@ class CommandControllerTest {
void callService() throws Exception { void callService() throws Exception {
doRequest(); doRequest();
verify(service).createCommand(createCommandCaptor.capture(), eq(CommandTestFactory.RELATION_VERSION)); verify(service).createCommandWithValidation(createCommandCaptor.capture(), eq(CommandTestFactory.RELATION_VERSION));
assertThat(createCommandCaptor.getValue().getOrder()).isEqualTo(CommandTestFactory.ORDER); assertThat(createCommandCaptor.getValue().getOrder()).isEqualTo(CommandTestFactory.ORDER);
assertThat(createCommandCaptor.getValue().getVorgangId()).isEqualTo(CommandTestFactory.VORGANG_ID); assertThat(createCommandCaptor.getValue().getVorgangId()).isEqualTo(CommandTestFactory.VORGANG_ID);
assertThat(createCommandCaptor.getValue().getRelationId()).isEqualTo(CommandTestFactory.RELATION_ID); assertThat(createCommandCaptor.getValue().getRelationId()).isEqualTo(CommandTestFactory.RELATION_ID);
......
...@@ -59,7 +59,7 @@ class CommandServiceTest { ...@@ -59,7 +59,7 @@ class CommandServiceTest {
} }
@Test @Test
void shouldHaveSetRelationId() { void shouldHaveSetRelationVersion() {
service.createCommand(command, CommandTestFactory.RELATION_VERSION); service.createCommand(command, CommandTestFactory.RELATION_VERSION);
verify(remoteService).createCommand(createCommandCaptor.capture()); verify(remoteService).createCommand(createCommandCaptor.capture());
...@@ -67,6 +67,25 @@ class CommandServiceTest { ...@@ -67,6 +67,25 @@ class CommandServiceTest {
} }
} }
@Nested
class TestWithValidation {
@Test
void shouldCallRemoteService() {
service.createCommandWithValidation(command, CommandTestFactory.RELATION_VERSION);
verify(remoteService).createCommand(any(CreateCommand.class));
}
@Test
void shouldHaveSetRelationVersion() {
service.createCommandWithValidation(command, CommandTestFactory.RELATION_VERSION);
verify(remoteService).createCommand(createCommandCaptor.capture());
assertThat(createCommandCaptor.getValue().getRelationVersion()).isEqualTo(CommandTestFactory.RELATION_VERSION);
}
}
@Nested @Nested
class TestWithoutRelationVersion { class TestWithoutRelationVersion {
...@@ -78,7 +97,7 @@ class CommandServiceTest { ...@@ -78,7 +97,7 @@ class CommandServiceTest {
} }
@Test @Test
void shouldHaveSetRelationId() { void shouldHaveSetRelationVersion() {
service.createCommandWithoutRelation(command); service.createCommandWithoutRelation(command);
verify(remoteService).createCommand(createCommandCaptor.capture()); verify(remoteService).createCommand(createCommandCaptor.capture());
...@@ -104,7 +123,7 @@ class CommandServiceTest { ...@@ -104,7 +123,7 @@ class CommandServiceTest {
} }
@Test @Test
void shouldHaveSetRelationId() { void shouldHaveSetRelationVersion() {
service.createCommand(command, ITEM_NAME, CommandTestFactory.RELATION_VERSION); service.createCommand(command, ITEM_NAME, CommandTestFactory.RELATION_VERSION);
verify(remoteService).createCommand(createCommandCaptor.capture(), eq(ITEM_NAME)); verify(remoteService).createCommand(createCommandCaptor.capture(), eq(ITEM_NAME));
...@@ -123,7 +142,7 @@ class CommandServiceTest { ...@@ -123,7 +142,7 @@ class CommandServiceTest {
} }
@Test @Test
void shouldHaveSetRelationId() { void shouldHaveSetRelationVersion() {
service.createCommandWithoutValidation(command, ITEM_NAME, CommandTestFactory.RELATION_VERSION); service.createCommandWithoutValidation(command, ITEM_NAME, CommandTestFactory.RELATION_VERSION);
verify(remoteService).createCommand(createCommandCaptor.capture(), eq(ITEM_NAME)); verify(remoteService).createCommand(createCommandCaptor.capture(), eq(ITEM_NAME));
......
...@@ -19,10 +19,6 @@ import org.springframework.test.web.servlet.MockMvc; ...@@ -19,10 +19,6 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import static org.assertj.core.api.Assertions.*;
import de.itvsh.goofy.common.command.CommandController.CommandByRelationController;
import de.itvsh.goofy.common.command.CommandOrder;
import de.itvsh.goofy.common.command.CommandTestFactory; import de.itvsh.goofy.common.command.CommandTestFactory;
import de.itvsh.goofy.common.command.CreateCommand; import de.itvsh.goofy.common.command.CreateCommand;
import de.itvsh.goofy.kommentar.KommentarCommandController.KommentarCommandByVorgangController; import de.itvsh.goofy.kommentar.KommentarCommandController.KommentarCommandByVorgangController;
...@@ -76,14 +72,12 @@ class KommentarCommandControllerTest { ...@@ -76,14 +72,12 @@ class KommentarCommandControllerTest {
@Nested @Nested
class TestCreateEditKommentarCommand { class TestCreateEditKommentarCommand {
final String REPONSE_HEADER = "http://localhost/api/commands/" + KommentarCommandTestFactory.ID; private final static String REPONSE_HEADER = "http://localhost/api/commands/" + KommentarCommandTestFactory.ID;
@Spy @Spy
@InjectMocks @InjectMocks
private KommentarCommandController controller; private KommentarCommandController controller;
@Mock @Mock
private CommandByRelationController commandByRelationController;
@Mock
private KommentarService service; private KommentarService service;
private MockMvc mockMvc; private MockMvc mockMvc;
...@@ -91,41 +85,20 @@ class KommentarCommandControllerTest { ...@@ -91,41 +85,20 @@ class KommentarCommandControllerTest {
@BeforeEach @BeforeEach
void init() { void init() {
mockMvc = MockMvcBuilders.standaloneSetup(controller).build(); mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
when(commandByRelationController.createCommand(any(), anyString(), anyLong())).thenReturn(CommandTestFactory.create());
when(service.getById(any())).thenReturn(KommentarTestFactory.createBuilder().vorgangId(VorgangHeaderTestFactory.ID).build());
}
@Test when(service.editKommentar(any(), any(), anyLong())).thenReturn(CommandTestFactory.create());
void shouldReturnCreated() throws Exception {
doRequest().andExpect(status().isCreated());
} }
@Test @Test
void shouldCallService() throws Exception { void shouldCallService() throws Exception {
doRequest(); doRequest();
verify(service).getById(any()); verify(service).editKommentar(any(KommentarCommand.class), eq(KommentarTestFactory.ID), eq(KommentarTestFactory.VERSION));
}
@Test
void shouldBuildCommand() throws Exception {
doRequest();
verify(controller).buildCommand(any(Kommentar.class), any(KommentarCommand.class));
} }
@Test @Test
void shouldGiveCommandToService() throws Exception { void shouldReturnCreated() throws Exception {
doRequest(); doRequest().andExpect(status().isCreated());
verify(commandByRelationController).createCommand(commandCaptor.capture(), anyString(), anyLong());
var command = commandCaptor.getValue();
assertThat(command).usingRecursiveComparison()
.ignoringFields("body", "status", "relationVersion")// TODO relationVersion beachten OZG-2684
.isEqualTo(CommandTestFactory.createCreateCommandBuilder().order(CommandOrder.UPDATE_ATTACHED_ITEM)
.relationId(KommentarTestFactory.ID)
.build());
} }
@Test @Test
......
...@@ -46,14 +46,14 @@ class KommentarCommandITCase { ...@@ -46,14 +46,14 @@ class KommentarCommandITCase {
@BeforeEach @BeforeEach
void initTest() { void initTest() {
when(remoteService.getById(any())).thenReturn(KommentarTestFactory.create()); when(remoteService.getById(any())).thenReturn(KommentarTestFactory.create());
when(commandRemoteService.createCommand(any(), anyString())).thenReturn(CommandTestFactory.create()); when(commandRemoteService.createCommand(any())).thenReturn(CommandTestFactory.create());
} }
@Test @Test
void shouldCreateCommand() throws Exception { void shouldCreateCommand() throws Exception {
doRequestByKommentarId(createValidRequestContent()).andExpect(status().isCreated()); doRequestByKommentarId(createValidRequestContent()).andExpect(status().isCreated());
verify(commandRemoteService).createCommand(any(), eq(KommentarRemoteService.ITEM_NAME)); verify(commandRemoteService).createCommand(any());
} }
@WithMockUser @WithMockUser
...@@ -61,6 +61,8 @@ class KommentarCommandITCase { ...@@ -61,6 +61,8 @@ class KommentarCommandITCase {
@Nested @Nested
class TestValidation { class TestValidation {
private static final String FIELD_PREFIX = "kommentarCommand.kommentar";
@DisplayName("for null Text") @DisplayName("for null Text")
@Test @Test
void createCommandWithInvalidText() throws Exception { void createCommandWithInvalidText() throws Exception {
...@@ -68,7 +70,7 @@ class KommentarCommandITCase { ...@@ -68,7 +70,7 @@ class KommentarCommandITCase {
doRequestByKommentarId(content).andExpect(status().isUnprocessableEntity()) doRequestByKommentarId(content).andExpect(status().isUnprocessableEntity())
.andExpect(jsonPath("$.issues.length()").value(1)) .andExpect(jsonPath("$.issues.length()").value(1))
.andExpect(jsonPath("$.issues.[0].field").value("command.body.text")) .andExpect(jsonPath("$.issues.[0].field").value(FIELD_PREFIX + ".text"))
.andExpect(jsonPath("$.issues.[0].messageCode").value(ValidationMessageCodes.FIELD_IS_EMPTY)); .andExpect(jsonPath("$.issues.[0].messageCode").value(ValidationMessageCodes.FIELD_IS_EMPTY));
} }
...@@ -78,7 +80,7 @@ class KommentarCommandITCase { ...@@ -78,7 +80,7 @@ class KommentarCommandITCase {
String content = buildContentWithText(StringUtils.EMPTY); String content = buildContentWithText(StringUtils.EMPTY);
doRequestByKommentarId(content).andExpect(status().isUnprocessableEntity()) doRequestByKommentarId(content).andExpect(status().isUnprocessableEntity())
.andExpect(jsonPath("$.issues.[0].field").value("command.body.text")); .andExpect(jsonPath("$.issues.[0].field").value(FIELD_PREFIX + ".text"));
} }
......
...@@ -10,6 +10,8 @@ import org.junit.jupiter.api.BeforeEach; ...@@ -10,6 +10,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
...@@ -99,6 +101,46 @@ class KommentarServiceTest { ...@@ -99,6 +101,46 @@ class KommentarServiceTest {
} }
} }
@DisplayName("Edit kommentar")
@Nested
class TestEditKommentar {
@Captor
private ArgumentCaptor<Kommentar> kommentarCaptor;
@BeforeEach
void mockKommentarService() {
when(remoteService.getById(anyString())).thenReturn(KommentarTestFactory.createBuilder().text("text needs to be override").build());
}
@Test
void shouldCallGetById() {
callEditKommentar();
verify(service).getById(KommentarTestFactory.ID);
}
@Test
void shouldReplaceText() {
callEditKommentar();
verify(vorgangAttachedItemService).editKommentar(kommentarCaptor.capture(), eq(KommentarTestFactory.ID),
eq(KommentarTestFactory.VERSION));
assertThat(kommentarCaptor.getValue().getText()).isEqualTo(KommentarTestFactory.TEXT);
}
@Test
void shouldCallVorgangAttachedItemService() {
callEditKommentar();
verify(vorgangAttachedItemService).editKommentar(any(Kommentar.class), eq(KommentarTestFactory.ID), eq(KommentarTestFactory.VERSION));
}
private Command callEditKommentar() {
return service.editKommentar(KommentarCommandTestFactory.create(), KommentarTestFactory.ID, KommentarTestFactory.VERSION);
}
}
@Nested @Nested
class TestGetById { class TestGetById {
......
...@@ -8,6 +8,7 @@ import com.thedeanda.lorem.Lorem; ...@@ -8,6 +8,7 @@ import com.thedeanda.lorem.Lorem;
import com.thedeanda.lorem.LoremIpsum; import com.thedeanda.lorem.LoremIpsum;
import de.itvsh.goofy.common.user.UserProfileTestFactory; import de.itvsh.goofy.common.user.UserProfileTestFactory;
import de.itvsh.goofy.vorgang.VorgangHeaderTestFactory;
public class KommentarTestFactory { public class KommentarTestFactory {
...@@ -29,6 +30,7 @@ public class KommentarTestFactory { ...@@ -29,6 +30,7 @@ public class KommentarTestFactory {
public static Kommentar.KommentarBuilder createBuilder() { public static Kommentar.KommentarBuilder createBuilder() {
return Kommentar.builder() return Kommentar.builder()
.id(ID) .id(ID)
.vorgangId(VorgangHeaderTestFactory.ID)
.version(VERSION) .version(VERSION)
.text(TEXT) .text(TEXT)
.createdBy(CREATED_BY) .createdBy(CREATED_BY)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment