|
| 1 | +package com.messagebird; |
| 2 | + |
| 3 | +import com.messagebird.exceptions.GeneralException; |
| 4 | +import com.messagebird.exceptions.NotFoundException; |
| 5 | +import com.messagebird.exceptions.UnauthorizedException; |
| 6 | +import com.messagebird.objects.OutboundSmsPriceResponse; |
| 7 | +import com.messagebird.util.Resources; |
| 8 | +import org.junit.Test; |
| 9 | + |
| 10 | +import java.math.BigDecimal; |
| 11 | + |
| 12 | +import static org.junit.Assert.assertEquals; |
| 13 | +import static org.junit.Assert.assertNull; |
| 14 | + |
| 15 | +public class OutboundSmsPricesTest { |
| 16 | + |
| 17 | + @Test |
| 18 | + public void testGetOutboundSmsPrices() throws GeneralException, UnauthorizedException, NotFoundException { |
| 19 | + String responseFixture = Resources.readResourceText("/fixtures/outbound_sms_prices.json"); |
| 20 | + |
| 21 | + MessageBirdService messageBirdService = SpyService |
| 22 | + .expects("GET", "pricing/sms/outbound") |
| 23 | + .withRestAPIBaseURL() |
| 24 | + .andReturns(new APIResponse(responseFixture, 200)); |
| 25 | + MessageBirdClient messageBirdClient = new MessageBirdClient(messageBirdService); |
| 26 | + |
| 27 | + assertReceivedExpectedResponse(messageBirdClient.getOutboundSmsPrices()); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testGetOutboundSmsPricesSmppUsername() throws GeneralException, UnauthorizedException, NotFoundException { |
| 32 | + String responseFixture = Resources.readResourceText("/fixtures/outbound_sms_prices.json"); |
| 33 | + |
| 34 | + MessageBirdService messageBirdService = SpyService |
| 35 | + .expects("GET", "pricing/sms/outbound/smpp/test-smpp-user") |
| 36 | + .withRestAPIBaseURL() |
| 37 | + .andReturns(new APIResponse(responseFixture, 200)); |
| 38 | + MessageBirdClient messageBirdClient = new MessageBirdClient(messageBirdService); |
| 39 | + |
| 40 | + assertReceivedExpectedResponse(messageBirdClient.getOutboundSmsPrices("test-smpp-user")); |
| 41 | + } |
| 42 | + |
| 43 | + private static void assertReceivedExpectedResponse(OutboundSmsPriceResponse outboundSmsPriceResponse) { |
| 44 | + assertEquals(10, outboundSmsPriceResponse.getGateway()); |
| 45 | + assertEquals("EUR", outboundSmsPriceResponse.getCurrencyCode()); |
| 46 | + assertEquals(3, outboundSmsPriceResponse.getTotalCount()); |
| 47 | + |
| 48 | + assertEquals(3, outboundSmsPriceResponse.getPrices().size()); |
| 49 | + |
| 50 | + assertEquals(new BigDecimal("0.060000"), outboundSmsPriceResponse.getPrices().get(0).getPrice()); |
| 51 | + assertEquals("EUR", outboundSmsPriceResponse.getPrices().get(0).getCurrencyCode()); |
| 52 | + assertEquals("0", outboundSmsPriceResponse.getPrices().get(0).getMccmnc()); |
| 53 | + assertEquals("0", outboundSmsPriceResponse.getPrices().get(0).getMcc()); |
| 54 | + assertNull(outboundSmsPriceResponse.getPrices().get(0).getMnc()); |
| 55 | + assertEquals("Default Rate", outboundSmsPriceResponse.getPrices().get(0).getCountryName()); |
| 56 | + assertEquals("XX", outboundSmsPriceResponse.getPrices().get(0).getCountryIsoCode()); |
| 57 | + assertEquals("Default Rate", outboundSmsPriceResponse.getPrices().get(0).getOperatorName()); |
| 58 | + |
| 59 | + assertEquals(new BigDecimal("0.047000"), outboundSmsPriceResponse.getPrices().get(1).getPrice()); |
| 60 | + assertEquals("EUR", outboundSmsPriceResponse.getPrices().get(1).getCurrencyCode()); |
| 61 | + assertEquals("202", outboundSmsPriceResponse.getPrices().get(1).getMccmnc()); |
| 62 | + assertEquals("202", outboundSmsPriceResponse.getPrices().get(1).getMcc()); |
| 63 | + assertNull(outboundSmsPriceResponse.getPrices().get(1).getMnc()); |
| 64 | + assertEquals("Greece", outboundSmsPriceResponse.getPrices().get(1).getCountryName()); |
| 65 | + assertEquals("GR", outboundSmsPriceResponse.getPrices().get(1).getCountryIsoCode()); |
| 66 | + assertNull(outboundSmsPriceResponse.getPrices().get(1).getOperatorName()); |
| 67 | + |
| 68 | + assertEquals(new BigDecimal("0.045000"), outboundSmsPriceResponse.getPrices().get(2).getPrice()); |
| 69 | + assertEquals("EUR", outboundSmsPriceResponse.getPrices().get(2).getCurrencyCode()); |
| 70 | + assertEquals("20205", outboundSmsPriceResponse.getPrices().get(2).getMccmnc()); |
| 71 | + assertEquals("202", outboundSmsPriceResponse.getPrices().get(2).getMcc()); |
| 72 | + assertEquals("05", outboundSmsPriceResponse.getPrices().get(2).getMnc()); |
| 73 | + assertEquals("Greece", outboundSmsPriceResponse.getPrices().get(2).getCountryName()); |
| 74 | + assertEquals("GR", outboundSmsPriceResponse.getPrices().get(2).getCountryIsoCode()); |
| 75 | + assertEquals("Vodafone", outboundSmsPriceResponse.getPrices().get(2).getOperatorName()); |
| 76 | + } |
| 77 | +} |
0 commit comments