forked from RedHatInsights/notifications-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RHCLOUD-29035 Stop calling BOP with an empty recipients list (RedHatI…
- Loading branch information
Showing
3 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ail/src/test/java/com/redhat/cloud/notifications/connector/email/EmptyRecipientsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.redhat.cloud.notifications.connector.email; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import jakarta.inject.Inject; | ||
import org.apache.camel.Exchange; | ||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.builder.AdviceWithRouteBuilder; | ||
import org.apache.camel.component.mock.MockEndpoint; | ||
import org.apache.camel.quarkus.test.CamelQuarkusTestSupport; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.HashSet; | ||
|
||
import static com.redhat.cloud.notifications.connector.ConnectorToEngineRouteBuilder.SUCCESS; | ||
import static com.redhat.cloud.notifications.connector.email.constants.ExchangeProperty.FILTERED_USERS; | ||
import static com.redhat.cloud.notifications.connector.email.constants.Routes.SEND_EMAIL_BOP; | ||
import static com.redhat.cloud.notifications.connector.email.constants.Routes.SEND_EMAIL_BOP_CHOICE; | ||
import static com.redhat.cloud.notifications.connector.email.constants.Routes.SEND_EMAIL_BOP_SINGLE_PER_USER; | ||
import static org.apache.camel.builder.AdviceWith.adviceWith; | ||
|
||
@QuarkusTest | ||
public class EmptyRecipientsTest extends CamelQuarkusTestSupport { | ||
|
||
@Inject | ||
ProducerTemplate producerTemplate; | ||
|
||
@Override | ||
public boolean isUseRouteBuilder() { | ||
return false; | ||
} | ||
|
||
@Test | ||
void test() throws Exception { | ||
|
||
Exchange exchange = createExchangeWithBody(""); | ||
exchange.setProperty(FILTERED_USERS, new HashSet<>()); | ||
|
||
adviceWith(SEND_EMAIL_BOP_CHOICE, context(), new AdviceWithRouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
mockEndpointsAndSkip( | ||
"direct:" + SEND_EMAIL_BOP_SINGLE_PER_USER, | ||
"direct:" + SEND_EMAIL_BOP, | ||
"direct:" + SUCCESS | ||
); | ||
} | ||
}); | ||
|
||
MockEndpoint sendEmailBopSinglePerUserEndpoint = getMockEndpoint("mock:direct:" + SEND_EMAIL_BOP_SINGLE_PER_USER); | ||
sendEmailBopSinglePerUserEndpoint.expectedMessageCount(0); | ||
|
||
MockEndpoint sendEmailBopEndpoint = getMockEndpoint("mock:direct:" + SEND_EMAIL_BOP); | ||
sendEmailBopEndpoint.expectedMessageCount(0); | ||
|
||
MockEndpoint successEndpoint = getMockEndpoint("mock:direct:" + SUCCESS); | ||
successEndpoint.expectedMessageCount(1); | ||
|
||
producerTemplate.send("direct:" + SEND_EMAIL_BOP_CHOICE, exchange); | ||
|
||
sendEmailBopSinglePerUserEndpoint.assertIsSatisfied(); | ||
sendEmailBopEndpoint.assertIsSatisfied(); | ||
successEndpoint.assertIsSatisfied(); | ||
} | ||
} |