Skip to content

Commit

Permalink
feature: tests for the email proecessor (RedHatInsights#2165)
Browse files Browse the repository at this point in the history
The goal is to have the email processor fully tested.

RHCLOUD-28334
  • Loading branch information
MikelAlejoBR authored Sep 22, 2023
1 parent e65f278 commit 0f997e9
Show file tree
Hide file tree
Showing 3 changed files with 444 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ protected Set<RecipientSettings> extractRecipientSettings(final Event event, fin
).collect(Collectors.toSet());
}

protected Set<com.redhat.cloud.notifications.processors.email.connector.dto.RecipientSettings> extractAndTransformRecipientSettings(final Event event, final List<Endpoint> endpoints) {
/**
* Extracts the recipient settings from the event and the endpoints and
* transforms them to a DTO in order to send them to the email connector.
* @param event the event to extract the recipient settings from.
* @param endpoints the endpoints to extract the recipient settings from.
* @return a set of recipient settings DTOs.
*/
public Set<com.redhat.cloud.notifications.processors.email.connector.dto.RecipientSettings> extractAndTransformRecipientSettings(final Event event, final List<Endpoint> endpoints) {
final Set<RecipientSettings> recipientSettings = this.extractRecipientSettings(event, endpoints);

return recipientSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import java.util.Objects;
import java.util.Set;
import java.util.UUID;

Expand All @@ -18,6 +19,13 @@ public class RecipientSettings {
private final UUID groupUUID;
private final Set<String> users;

public RecipientSettings(final boolean adminsOnly, final boolean ignoreUserPreferences, final UUID groupUUID, final Set<String> users) {
this.adminsOnly = adminsOnly;
this.ignoreUserPreferences = ignoreUserPreferences;
this.groupUUID = groupUUID;
this.users = users;
}

public RecipientSettings(final com.redhat.cloud.notifications.recipients.RecipientSettings recipientSettings) {
this.adminsOnly = recipientSettings.isOnlyAdmins();
this.ignoreUserPreferences = recipientSettings.isIgnoreUserPreferences();
Expand All @@ -40,4 +48,32 @@ public UUID getGroupUUID() {
public Set<String> getUsers() {
return this.users;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}

if (o == null || this.getClass() != o.getClass()) {
return false;
}

final RecipientSettings that = (RecipientSettings) o;

return this.adminsOnly == that.adminsOnly
&& this.ignoreUserPreferences == that.ignoreUserPreferences
&& Objects.equals(this.groupUUID, that.groupUUID)
&& Objects.equals(this.users, that.users);
}

@Override
public int hashCode() {
return Objects.hash(
this.adminsOnly ? 1 : 0,
this.ignoreUserPreferences ? 1 : 0,
this.groupUUID != null ? this.groupUUID.hashCode() : 0,
this.users != null ? this.users.hashCode() : 0
);
}
}
Loading

0 comments on commit 0f997e9

Please sign in to comment.