Skip to content

Commit

Permalink
remove obsolete hashcode and equals implementation from inTransit record
Browse files Browse the repository at this point in the history
  • Loading branch information
ekl176 committed Jan 24, 2025
1 parent 5e3c78e commit db8e6b0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
package de.bund.digitalservice.a2j.repository.egvp;

public record MessageInTransit(String userId, String customId, String bundIdMailbox) {

public int hashCode() {

return customId.hashCode();
}

public boolean equals(Object obj) {
if (obj == null) {
return false;
}

if (obj.getClass() != this.getClass()) {
return false;
}

return customId.equals(((MessageInTransit) obj).customId)
&& userId.equals(((MessageInTransit) obj).userId);
}
}
public record MessageInTransit(String userId, String customId, String bundIdMailbox) {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ public EgvpClient(RestTemplate client) {
this.client = client;
}

/**
* Get Version of connected egvp enterprise instance. Mostly used for testing purposes to check if
* a connection can be established
*
* @return current Version of connected egvp instance
* @throws EgvpClientException
*/
public GetVersionResponse getVersion() throws EgvpClientException {
return invoke(() -> this.client.getForEntity("/getVersion", GetVersionResponse.class))
.getBody();
}

public SendMessageResponse sendMessage(SendMessageRequest request) throws EgvpClientException {
return invoke(
() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.bund.digitalservice.a2j.service.egvp.client.EgvpClient;
import de.bund.digitalservice.a2j.service.egvp.client.EgvpClientException;
import de.bund.digitalservice.a2j.service.egvp.client.MessageDeliveryStatusResponse;
import de.bund.digitalservice.a2j.service.egvp.client.SendMessageRequest;
import de.bund.digitalservice.a2j.service.egvp.client.SendMessageResponse;
import de.bund.digitalservice.a2j.service.egvp.client.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -39,6 +35,23 @@ void setup() {
this.mockServer = MockRestServiceServer.createServer(restTemplate);
}

@Test
void getVersion() throws EgvpClientException {
mockServer
.expect(requestTo("http://localhost:8088/getVersion"))
.andRespond(
withSuccess(
"""
{
"version":"5.2.1"
}
""",
MediaType.APPLICATION_JSON));
GetVersionResponse expectedResponse = new GetVersionResponse("5.2.1");

assertEquals(expectedResponse, client.getVersion());
}

@Test
void checkMessageStatus() throws EgvpClientException {
mockServer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.bund.digitalservice.a2j.repository.egvp;

import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ExtendWith(SpringExtension.class)
public class MessageInTransitInMemoryRepositoryTest {

MessagesInTransitInMemoryRepository repo;

@BeforeEach
void setup() {
repo = new MessagesInTransitInMemoryRepository();
}

@Test
void deleteASpecificMessage() {
MessageInTransit messageToBeDeleted = new MessageInTransit("userId", "customId2", "mailboxId");

List.of(
new MessageInTransit("userId", "customId", "mailboxId"),
new MessageInTransit("userId", "customId3", "mailboxId"))
.forEach(m -> repo.add(m));

repo.removeAll(Set.of(messageToBeDeleted));

Assertions.assertFalse(repo.getAll().stream().anyMatch(m -> m.customId().equals("customId2")));
Assertions.assertEquals(2, repo.getAll().size());
}
}

0 comments on commit db8e6b0

Please sign in to comment.