Skip to content
Snippets Groups Projects
Commit 826f1bcc authored by Jörg Bolay's avatar Jörg Bolay
Browse files

KOP-2964 umstellen von WebClient auf RestClient und entfernen von...

KOP-2964 umstellen von WebClient auf RestClient und entfernen von Bindestrichen aus Spring Properties
parent 2bfcedf0
Branches
Tags
1 merge request!10KOP-2964 umstellen von WebClient auf RestClient und entfernen von...
Pipeline #1587 failed
......@@ -16,6 +16,8 @@ import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import de.ozgcloud.nachrichten.postfach.osiv2.factory.JsonUtil;
import de.ozgcloud.nachrichten.postfach.osiv2.factory.V1ReplyMessageFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
......@@ -70,7 +72,57 @@ public class OsiPostfachRemoteServiceITCase {
private MockServerClient postfachFacadeMockClient;
@BeforeEach
@SneakyThrows
private void mockOperationsAndResponses(Map<String, String> operationsAndResponses) {
postfachFacadeMockClient.upsert(
openAPIExpectation()
.withSpecUrlOrPayload(Files.readString(Path.of("spec", "postfach-api-facade.yaml")))
.withOperationsAndResponses(Map.of(
"deleteMessage", "200"
))
.withSpecUrlOrPayload(getPostfachApiSpec())
.withOperationsAndResponses(operationsAndResponses)
);
assertDoesNotThrow(() -> osiPostfachRemoteService.deleteMessage("00000000-0000-0000-0000-000000000000"));
}
@SneakyThrows
private static String getPostfachApiSpec() {
return Files.readString(Path.of("spec", "postfach-api-facade.yaml"));
}
private void mockPostfachMessageAndResponse(final String... uuids) {
// Stub message listing response
mockJsonOperation("receiveMessages", new MessageExchangeReceiveMessagesResponse()
.messages(Arrays.stream(uuids)
.map(uuid -> new MessageExchangeReceiveMessage()
.guid(UUID.fromString(uuid)))
.toList()));
for (String uuid : uuids) {
// Stub individual response for message
mockJsonOperation("getMessage", V1ReplyMessageFactory.create()
.messageBox(UUID.fromString(uuid))
.responseTime(OffsetDateTime.now()));
}
}
private void mockJsonOperation(final String operationId, final Object body) {
postfachFacadeMockClient
.when(
new OpenAPIDefinition()
.withSpecUrlOrPayload(getPostfachApiSpec())
.withOperationId(operationId)
)
.respond(
response()
.withHeader("Content-type", "application/json")
.withBody(JsonUtil.toJson(body))
);
}
@BeforeEach
@SneakyThrows
public void setup() {
postfachFacadeMockClient = OSI_MOCK_SERVER_EXTENSION.getPostfachFacadeMockClient();
......@@ -80,15 +132,10 @@ public class OsiPostfachRemoteServiceITCase {
@DisplayName("should send dummy request with jwt")
@Test
@SneakyThrows
void shouldSendDummyRequestWithJwt() {
postfachFacadeMockClient.upsert(
openAPIExpectation()
.withSpecUrlOrPayload(Files.readString(Path.of("spec", "postfach-api-facade.yaml")))
.withOperationsAndResponses(Map.of(
"SendMessage", "200"
))
);
void shouldSendRequestWithJwt() {
mockOperationsAndResponses(Map.of(
"SendMessage", "200"
));
osiPostfachRemoteService.sendMessage(postfachNachricht);
......@@ -101,18 +148,12 @@ public class OsiPostfachRemoteServiceITCase {
assertThat(jwt.body().read("$.aud", String.class)).isEqualTo(RESOURCE_URN);
}
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());
@DisplayName("should receive one messages")
@Test
@SneakyThrows
void shouldReceiveMessages() {
var uuid = UUID.fromString("00000000-0000-0000-0000-000000000000");
createMessagesJson(uuid, null);
createOneReplyMessageJson(uuid);
mockPostfachMessageAndResponse("00000000-0000-0000-0000-000000000000");
var messageStream = osiPostfachRemoteService.getAllMessages();
......@@ -125,29 +166,11 @@ public class OsiPostfachRemoteServiceITCase {
@Test
@SneakyThrows
void shouldReceiveTwoMessages() {
var uuid1 = UUID.fromString("00000000-0000-0000-0000-000000000000");
var uuid2 = UUID.fromString("00000000-0000-0000-0000-000000000001");
createMessagesJson(uuid1, uuid2);
mockPostfachMessageAndResponse("00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000001");
createOneReplyMessageJson(uuid1);
createOneReplyMessageJson(uuid2);
var messageList = osiPostfachRemoteService.getAllMessages().toList();
var messageStream = osiPostfachRemoteService.getAllMessages();
var messageList = messageStream.toList();
assertThat(messageList).size().isEqualTo(2);
}
private void createMessagesJson(final UUID... uuids) throws IOException {
var messagesList = Arrays.stream(uuids).filter(Objects::nonNull).map(uuid -> new MessageExchangeReceiveMessage().guid(uuid)).toList();
var messages = new MessageExchangeReceiveMessagesResponse().messages(messagesList);
ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter();
String messagesJson = ow.writeValueAsString(messages);
createMessagesCall("receiveMessages", messagesJson);
assertThat(messageList).hasSize(2);
}
private void createMessagesCall(final String receiveMessages, final String messagesJson) throws IOException {
......@@ -160,16 +183,6 @@ public class OsiPostfachRemoteServiceITCase {
.respond(response().withHeader("Content-type", "application/json").withBody(messagesJson));
}
private void createOneReplyMessageJson(final UUID uuid) throws IOException {
ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter();
var replyMessage = new V1ReplyMessage()
.body("das ist ein toller Body").replyAction(V1ReplyBehavior.REPLYPOSSIBLE).messageBox(uuid).responseTime(OffsetDateTime.now());
String messageJson = ow.writeValueAsString(replyMessage);
createMessagesCall("getMessage", messageJson);
}
@DisplayName("should delete message")
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment