Search in sources :

Example 6 with OutboundMessage

use of org.hisp.dhis.outboundmessage.OutboundMessage in project dhis2-core by dhis2.

the class BulkSmsGatewayTest method initTest.

@BeforeEach
public void initTest() {
    smsGatewayConfig = new BulkSmsGatewayConfig();
    smsGatewayConfig.setDefault(true);
    smsGatewayConfig.setUsername("username");
    smsGatewayConfig.setPassword("password");
    recipients.add(PHONE_NUMBER);
    outboundMessageList.add(new OutboundMessage(SUBJECT, MESSAGE, recipients));
    outboundMessageList.add(new OutboundMessage(SUBJECT, MESSAGE, recipients));
    outboundMessageList.add(new OutboundMessage(SUBJECT, MESSAGE, recipients));
    batch = new OutboundMessageBatch(outboundMessageList, DeliveryChannel.SMS);
    when(pbeStringEncryptor.decrypt(anyString())).thenReturn(smsGatewayConfig.getPassword());
}
Also used : OutboundMessageBatch(org.hisp.dhis.outboundmessage.OutboundMessageBatch) OutboundMessage(org.hisp.dhis.outboundmessage.OutboundMessage) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with OutboundMessage

use of org.hisp.dhis.outboundmessage.OutboundMessage in project dhis2-core by dhis2.

the class SMPPGatewayTest method testBulkMessage.

@Test
void testBulkMessage() {
    List<OutboundMessage> messages = new ArrayList<>();
    messages.add(new OutboundMessage(SUBJECT, TEXT, Sets.newHashSet(RECIPIENT)));
    messages.add(new OutboundMessage(SUBJECT, TEXT, Sets.newHashSet(RECIPIENT)));
    messages.add(new OutboundMessage(SUBJECT, TEXT, Sets.newHashSet(RECIPIENT)));
    messages.add(new OutboundMessage(SUBJECT, TEXT, Sets.newHashSet(RECIPIENT)));
    messages.add(new OutboundMessage(SUBJECT, TEXT, Sets.newHashSet(RECIPIENT)));
    messages.add(new OutboundMessage(SUBJECT, TEXT, Sets.newHashSet(RECIPIENT)));
    messages.add(new OutboundMessage(SUBJECT, TEXT, Sets.newHashSet(RECIPIENT)));
    messages.add(new OutboundMessage(SUBJECT, TEXT, Sets.newHashSet(RECIPIENT)));
    OutboundMessageBatch batch = new OutboundMessageBatch(messages, DeliveryChannel.SMS);
    List<OutboundMessageResponse> responses = gateway.sendBatch(batch, config);
    assertNotNull(responses);
    assertEquals(8, responses.size());
    responses.forEach(r -> assertTrue(r.isOk()));
}
Also used : OutboundMessageBatch(org.hisp.dhis.outboundmessage.OutboundMessageBatch) ArrayList(java.util.ArrayList) OutboundMessage(org.hisp.dhis.outboundmessage.OutboundMessage) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with OutboundMessage

use of org.hisp.dhis.outboundmessage.OutboundMessage 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)

Example 9 with OutboundMessage

use of org.hisp.dhis.outboundmessage.OutboundMessage in project dhis2-core by dhis2.

the class FakeMessageSender method sendMessage.

@Override
public OutboundMessageResponse sendMessage(String subject, String text, Set<String> recipients) {
    OutboundMessage message = new OutboundMessage(subject, text, recipients);
    for (String recipient : recipients) {
        sendMessagesByRecipient.computeIfAbsent(recipient, key -> new ArrayList<>()).add(message);
    }
    OutboundMessageResponse response = new OutboundMessageResponse();
    response.setOk(true);
    response.setAsync(false);
    response.setDescription(subject + ":" + text);
    response.setResponseObject(EmailResponse.SENT);
    return response;
}
Also used : Collections.unmodifiableList(java.util.Collections.unmodifiableList) OutboundMessageBatch(org.hisp.dhis.outboundmessage.OutboundMessageBatch) OutboundMessageBatchStatus(org.hisp.dhis.outboundmessage.OutboundMessageBatchStatus) ListenableFuture(org.springframework.util.concurrent.ListenableFuture) Collections.emptyList(java.util.Collections.emptyList) EmailResponse(org.hisp.dhis.email.EmailResponse) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Set(java.util.Set) HashMap(java.util.HashMap) OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) OutboundMessage(org.hisp.dhis.outboundmessage.OutboundMessage) ArrayList(java.util.ArrayList) List(java.util.List) Future(java.util.concurrent.Future) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) User(org.hisp.dhis.user.User) AsyncResult(org.springframework.scheduling.annotation.AsyncResult) Collectors.toSet(java.util.stream.Collectors.toSet) ArrayList(java.util.ArrayList) OutboundMessage(org.hisp.dhis.outboundmessage.OutboundMessage) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse)

Example 10 with OutboundMessage

use of org.hisp.dhis.outboundmessage.OutboundMessage in project dhis2-core by dhis2.

the class UserControllerTest method testResetToInvite.

@Test
void testResetToInvite() {
    assertStatus(HttpStatus.NO_CONTENT, POST("/users/" + peter.getUid() + "/reset"));
    OutboundMessage email = assertMessageSendTo("peter@pan.net");
    assertValidToken(extractTokenFromEmailText(email.getText()));
}
Also used : OutboundMessage(org.hisp.dhis.outboundmessage.OutboundMessage) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Aggregations

OutboundMessage (org.hisp.dhis.outboundmessage.OutboundMessage)10 OutboundMessageResponse (org.hisp.dhis.outboundmessage.OutboundMessageResponse)4 OutboundMessageBatch (org.hisp.dhis.outboundmessage.OutboundMessageBatch)3 ArrayList (java.util.ArrayList)2 OutboundMessageResponseSummary (org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary)2 BulkSmsGatewayConfig (org.hisp.dhis.sms.config.BulkSmsGatewayConfig)2 User (org.hisp.dhis.user.User)2 Test (org.junit.jupiter.api.Test)2 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singleton (java.util.Collections.singleton)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 Future (java.util.concurrent.Future)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 EmailResponse (org.hisp.dhis.email.EmailResponse)1