Search in sources :

Example 11 with OutboundMessageResponseSummary

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());
}
Also used : OutboundMessageBatch(org.hisp.dhis.outboundmessage.OutboundMessageBatch) OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) Test(org.junit.jupiter.api.Test)

Example 12 with OutboundMessageResponseSummary

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());
}
Also used : OutboundMessageBatch(org.hisp.dhis.outboundmessage.OutboundMessageBatch) OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) Test(org.junit.jupiter.api.Test)

Example 13 with OutboundMessageResponseSummary

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());
}
Also used : OutboundMessageBatch(org.hisp.dhis.outboundmessage.OutboundMessageBatch) OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse) Test(org.junit.jupiter.api.Test)

Example 14 with OutboundMessageResponseSummary

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;
}
Also used : OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) OutboundMessage(org.hisp.dhis.outboundmessage.OutboundMessage)

Aggregations

OutboundMessageResponseSummary (org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary)14 OutboundMessageBatch (org.hisp.dhis.outboundmessage.OutboundMessageBatch)6 Test (org.junit.jupiter.api.Test)6 OutboundMessageResponse (org.hisp.dhis.outboundmessage.OutboundMessageResponse)4 GatewayResponse (org.hisp.dhis.sms.outbound.GatewayResponse)2 Date (java.util.Date)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)1 NotificationMessage (org.hisp.dhis.notification.NotificationMessage)1 BatchResponseStatus (org.hisp.dhis.outboundmessage.BatchResponseStatus)1 OutboundMessage (org.hisp.dhis.outboundmessage.OutboundMessage)1 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)1 BulkSmsGatewayConfig (org.hisp.dhis.sms.config.BulkSmsGatewayConfig)1 Transactional (org.springframework.transaction.annotation.Transactional)1