package com.africastalking.test.sms;

import com.africastalking.AfricasTalking;
import com.africastalking.SmsService;
import com.africastalking.Status;
import com.africastalking.TokenService;
import com.africastalking.sms.Message;
import com.africastalking.sms.Recipient;
import com.africastalking.sms.Subscription;
import com.africastalking.sms.SubscriptionResponse;
import com.africastalking.test.Fixtures;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.africastalking.token.CheckoutTokenResponse;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

public class SmsTest {

    @Before
    public void setup() {
        AfricasTalking.initialize(Fixtures.USERNAME, Fixtures.API_KEY);
    }

    @Test
    public void testSend() throws IOException {
        SmsService sms = AfricasTalking.getService(AfricasTalking.SERVICE_SMS);
        List<Recipient> resp = sms.send("testSend()", "AT2FA", new String[] {"+25411082302", "+254731034588"}, false);
        Assert.assertEquals(2, resp.size());
        Assert.assertEquals(Status.SUCCESS, resp.get(0).status);
    }

    @Test
    public void testSendPremium() throws IOException {

        SmsService sms = AfricasTalking.getService(AfricasTalking.SERVICE_SMS);
        List<Recipient> resp = sms.sendPremium("testSendPremium()", "8989", "KiKi", "Linky", 10, new String[] {"+254711082302", "+254731034588"});
        Assert.assertEquals(2, resp.size());
        Assert.assertEquals(Status.SUCCESS, resp.get(0).status);

    }

    @Test
    public void testFetchMessages() throws IOException {
        SmsService sms = AfricasTalking.getService(AfricasTalking.SERVICE_SMS);
        List<Message> resp = sms.fetchMessages("0");
        Assert.assertEquals(true, resp.size() >= 0);
    }

    @Test
    public void testFetchSubscriptions() throws IOException {
        SmsService sms = AfricasTalking.getService(AfricasTalking.SERVICE_SMS);
        List<Subscription> resp = sms.fetchSubscriptions("AT2FA", "KiKi", "0");
        Assert.assertEquals(true, resp.size() >= 0);
    }

    @Test
    public void testCreateSubscription() throws IOException {
        String phone = "+254731034" + ThreadLocalRandom.current().nextInt(100, 999);
        SmsService sms = AfricasTalking.getService(AfricasTalking.SERVICE_SMS);
        TokenService tokenService = AfricasTalking.getService(AfricasTalking.SERVICE_TOKEN);
        CheckoutTokenResponse checkoutToken = tokenService.createCheckoutToken(phone);
        
        SubscriptionResponse resp = sms.createSubscription("AT2FA", "KiKi", phone, checkoutToken.token);
        Assert.assertEquals("Waiting for user input", resp.description);
    }

}

@@ -73,16 +73,52 @@
 alking;%0A
+import com.africastalking.Callback;%0A
 import c
@@ -139,32 +139,32 @@
 ing.SmsService;%0A
-
 import com.afric
@@ -800,32 +800,1660 @@
 PI_KEY);%0A    %7D%0A%0A
+    @Test%0A    public void testSendHighMultipleVolume() throws IOException %7B%0A        SmsService sms = AfricasTalking.getService(AfricasTalking.SERVICE_SMS);%0A        int count = 100000;%0A        for (int i = 0; i %3C count; i++) %7B%0A            int offset = count + i;%0A            String%5B%5D numbers = new String%5B%5D %7B %22+254711%22 + offset %7D;%0A            sms.send(%22testSendHighMultipleVolume(%22 + numbers%5B0%5D + %22)%22, %22AT2FA%22, numbers, true, new Callback%3CList%3CRecipient%3E%3E() %7B%0A                @Override%0A                public void onSuccess(List%3CRecipient%3E response) %7B%0A                    Assert.assertNotNull(response);%0A                %7D%0A%0A                @Override%0A                public void onFailure(Throwable throwable) %7B%0A                    Assert.fail(throwable.getMessage());%0A                %7D%0A            %7D);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void testSendHighSingleVolume() throws IOException %7B%0A        SmsService sms = AfricasTalking.getService(AfricasTalking.SERVICE_SMS);%0A%0A        int count = 100000;%0A        String%5B%5D numbers = new String%5Bcount%5D;%0A        for (int i = 0; i %3C count; i++) %7B%0A            int offset = count + i;%0A            numbers%5Bi%5D = %22+254711%22 + offset;%0A        %7D%0A        sms.send(%22testSendHighSingleVolume()%22, %22AT2FA%22, numbers, true, new Callback%3CList%3CRecipient%3E%3E() %7B%0A                @Override%0A                public void onSuccess(List%3CRecipient%3E response) %7B%0A                    Assert.assertNotNull(response);%0A                %7D%0A%0A                @Override%0A                public void onFailure(Throwable throwable) %7B%0A                    Assert.fail(throwable.getMessage());%0A                %7D%0A        %7D);%0A    %7D%0A%0A
     @Test%0A    pu
@@ -2566,32 +2566,32 @@
 g.SERVICE_SMS);%0A
-
         List%3CRec
@@ -2656,16 +2656,17 @@
 %5D %7B%22+254
+7
 11082302

Test sending 100k messages