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

OZG-1513 OZG-2594 remove postfach code from command controller

parent bdfe357f
No related branches found
No related tags found
No related merge requests found
......@@ -16,10 +16,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import de.itvsh.goofy.postfach.PostfachMail;
import de.itvsh.goofy.postfach.PostfachMailController;
import de.itvsh.goofy.vorgang.VorgangController;
import de.itvsh.goofy.vorgang.VorgangWithEingang;
import lombok.Getter;
@RestController
......@@ -72,10 +68,6 @@ public class CommandController {
@Autowired
private CommandService service;
@Autowired
private VorgangController vorgangController;
@Autowired
private PostfachMailController postfachController;
@PostMapping
public ResponseEntity<Void> createCommand(@PathVariable String vorgangId, @PathVariable String relationId,
......@@ -83,10 +75,6 @@ public class CommandController {
command = command.toBuilder().vorgangId(vorgangId).relationId(relationId).build();
var created = createCommand(command, relationVersion);
if (isSendPostfachMailOrder(command)) {
sendPostfachMail(created.getId(), buildPostfachMail(command));
}
return ResponseEntity.created(linkTo(CommandController.class).slash(created.getId()).toUri()).build();
}
......@@ -101,28 +89,5 @@ public class CommandController {
public Command createCommandWithoutValidation(CreateCommand command, String itemName) {
return service.createCommandWithoutValidation(command, itemName);
}
private boolean isSendPostfachMailOrder(CreateCommand command) {
return command.getOrder() == CommandOrder.SEND_POSTFACH_MAIL || command.getOrder() == CommandOrder.SEND_POSTFACH_NACHRICHT;
}
void sendPostfachMail(String commandId, PostfachMail postfachMail) {
postfachController.sendPostfachMail(commandId, postfachMail);
}
private PostfachMail buildPostfachMail(CreateCommand command) {
return ((PostfachMail) command.getBody()).toBuilder()
.vorgangId(command.getVorgangId())
.postfachId(getPostfachId(command.getVorgangId()))
.build();
}
private String getPostfachId(String vorgangId) {
return getVorgang(vorgangId).getEingang().getAntragsteller().getPostfachId();
}
private VorgangWithEingang getVorgang(String vorgangId) {
return vorgangController.getVorgang(vorgangId);
}
}
}
\ No newline at end of file
......@@ -25,12 +25,8 @@ import static org.assertj.core.api.Assertions.*;
import de.itvsh.goofy.common.command.CommandController.CommandByRelationController;
import de.itvsh.goofy.common.errorhandling.ExceptionController;
import de.itvsh.goofy.postfach.PostfachMail;
import de.itvsh.goofy.postfach.PostfachMailController;
import de.itvsh.goofy.postfach.PostfachMailTestFactory;
import de.itvsh.goofy.vorgang.VorgangController;
import de.itvsh.goofy.vorgang.VorgangHeaderTestFactory;
import de.itvsh.goofy.vorgang.VorgangWithEingangTestFactory;
import de.itvsh.kop.common.test.TestUtils;
class CommandControllerTest {
......@@ -126,10 +122,6 @@ class CommandControllerTest {
private CommandService service;
@Mock
private CommandModelAssembler modelAssembler;
@Mock
private VorgangController vorgangController;
@Mock
private PostfachMailController postfachController;
private MockMvc mockMvc;
......@@ -172,50 +164,6 @@ class CommandControllerTest {
.andExpect(header().stringValues("location", "http://localhost" + COMMANDS_PATH + "/" + CommandTestFactory.ID));
}
@Nested
@DisplayName("CreateCommand with postfach mail")
class WithPostfachMail {
@BeforeEach
void mockVorgangController() {
when(vorgangController.getVorgang(anyString())).thenReturn(VorgangWithEingangTestFactory.create());
}
@Test
void shouldHavePostfachMail() throws Exception {
doRequest(PostfachMailTestFactory.buildSendPostfachMailContent());
verify(service).createCommand(createCommandCaptor.capture(), anyLong());
assertThat(createCommandCaptor.getValue()).extracting(CreateCommand::getBody).usingRecursiveComparison()
.ignoringFields("id", "vorgangId", "postfachId", "createdAt", "createdBy", "direction", "sentAt", "sentSuccessful",
"messageCode",
"attachments") // TODO remove this when sending attachments
.isEqualTo(PostfachMailTestFactory.create());
}
@Test
void shouldCallVorgangController() throws Exception {
doRequest(PostfachMailTestFactory.buildSendPostfachMailContent());
verify(vorgangController).getVorgang(VorgangHeaderTestFactory.ID);
}
@Test
void shouldCallPostfachController() throws Exception {
doRequest(PostfachMailTestFactory.buildSendPostfachMailContent());
verify(postfachController).sendPostfachMail(anyString(), any(PostfachMail.class));
}
@Test
void shouldCallPostfachControllerOnNewOrder() throws Exception {
doRequest(PostfachMailTestFactory.buildSendPostfachMailContent(PostfachMailTestFactory.create(),
CommandOrder.SEND_POSTFACH_NACHRICHT));
verify(postfachController).sendPostfachMail(anyString(), any(PostfachMail.class));
}
}
private ResultActions doRequest() throws Exception {
return doRequest(
TestUtils.loadTextFile("jsonTemplates/command/createVorgangCommand.json.tmpl", CommandOrder.VORGANG_ANNEHMEN.name()));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment