use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.
the class SmsMessageSenderTest method testSendMessageBatchFailed.
@Test
void testSendMessageBatchFailed() {
when(gatewayAdministrationService.getDefaultGateway()).thenReturn(smsGatewayConfig);
mockGateway();
responseForFailedBatch();
OutboundMessageBatch batch = new OutboundMessageBatch(outboundMessages, DeliveryChannel.SMS);
ArgumentCaptor<OutboundMessageBatch> argumentCaptor = ArgumentCaptor.forClass(OutboundMessageBatch.class);
OutboundMessageResponseSummary summary = smsMessageSender.sendMessageBatch(batch);
assertNotNull(summary);
assertEquals(OutboundMessageBatchStatus.FAILED, summary.getBatchStatus());
verify(bulkSmsGateway, times(1)).sendBatch(argumentCaptor.capture(), any());
assertEquals(batch, argumentCaptor.getValue());
assertEquals(4, argumentCaptor.getValue().size());
assertEquals(3, summary.getSent());
assertEquals(4, summary.getTotal());
assertEquals(1, summary.getFailed());
assertEquals(0, summary.getPending());
}
use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.
the class SmsMessageSenderTest method testSendMessageBatchCompleted.
@Test
void testSendMessageBatchCompleted() {
mockGateway();
when(gatewayAdministrationService.getDefaultGateway()).thenReturn(smsGatewayConfig);
responseForCompletedBatch();
OutboundMessageBatch batch = new OutboundMessageBatch(outboundMessages, DeliveryChannel.SMS);
ArgumentCaptor<OutboundMessageBatch> argumentCaptor = ArgumentCaptor.forClass(OutboundMessageBatch.class);
OutboundMessageResponseSummary summary = smsMessageSender.sendMessageBatch(batch);
assertNotNull(summary);
assertEquals(OutboundMessageBatchStatus.COMPLETED, summary.getBatchStatus());
verify(bulkSmsGateway, times(1)).sendBatch(argumentCaptor.capture(), any());
assertEquals(batch, argumentCaptor.getValue());
assertEquals(4, argumentCaptor.getValue().size());
assertEquals(4, summary.getSent());
assertEquals(4, summary.getTotal());
assertEquals(0, summary.getFailed());
assertEquals(0, summary.getPending());
}
use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.
the class SmsMessageSenderTest method testSendMessageBatchWithMaxRecipients.
@Test
void testSendMessageBatchWithMaxRecipients() {
// stub for GateAdministrationService
when(gatewayAdministrationService.getDefaultGateway()).thenReturn(smsGatewayConfig);
mockGateway();
summaryResponses.clear();
when(bulkSmsGateway.sendBatch(any(), isA(BulkSmsGatewayConfig.class))).then(invocation -> {
OutboundMessageBatch batch = (OutboundMessageBatch) invocation.getArguments()[0];
summaryResponses.addAll(batch.getMessages().stream().map(message -> new OutboundMessageResponse("success", GatewayResponse.RESULT_CODE_0, true)).collect(Collectors.toList()));
return summaryResponses;
});
createOutBoundMessagesWithMaxRecipients();
ArgumentCaptor<OutboundMessageBatch> argumentCaptor = ArgumentCaptor.forClass(OutboundMessageBatch.class);
OutboundMessageBatch batch = new OutboundMessageBatch(outboundMessages, DeliveryChannel.SMS);
OutboundMessageResponseSummary summary = smsMessageSender.sendMessageBatch(batch);
assertNotNull(summary);
assertEquals(OutboundMessageBatchStatus.COMPLETED, summary.getBatchStatus());
verify(bulkSmsGateway, times(1)).sendBatch(argumentCaptor.capture(), any());
assertEquals(batch, argumentCaptor.getValue());
assertEquals(6, argumentCaptor.getValue().size());
assertEquals(6, summary.getSent());
assertEquals(6, summary.getTotal());
assertEquals(0, summary.getFailed());
assertEquals(0, summary.getPending());
}
use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.
the class FakeMessageSender method sendMessageBatch.
@Override
public OutboundMessageResponseSummary sendMessageBatch(OutboundMessageBatch batch) {
for (OutboundMessage msg : batch.getMessages()) {
sendMessage(msg.getSubject(), msg.getText(), msg.getRecipients());
}
OutboundMessageResponseSummary summary = new OutboundMessageResponseSummary();
int n = batch.getMessages().size();
summary.setSent(n);
summary.setTotal(n);
summary.setBatchStatus(OutboundMessageBatchStatus.COMPLETED);
summary.setChannel(batch.getDeliveryChannel());
return summary;
}
Aggregations