|
| 1 | +package org.restcomm.sdk.endpoints; |
| 2 | + |
| 3 | +import com.github.tomakehurst.wiremock.junit.WireMockRule; |
| 4 | +import org.junit.Rule; |
| 5 | +import org.junit.Test; |
| 6 | +import org.restcomm.sdk.RestcommClient; |
| 7 | +import org.restcomm.sdk.RestcommClientConfiguration; |
| 8 | +import org.restcomm.sdk.domain.Call; |
| 9 | +import org.restcomm.sdk.domain.CallPage; |
| 10 | +import org.restcomm.sdk.domain.CallStatus; |
| 11 | + |
| 12 | +import java.io.File; |
| 13 | +import java.io.IOException; |
| 14 | +import java.nio.file.Files; |
| 15 | +import java.util.Collections; |
| 16 | +import java.util.List; |
| 17 | + |
| 18 | +import static com.github.tomakehurst.wiremock.client.WireMock.*; |
| 19 | +import static org.junit.Assert.assertEquals; |
| 20 | +import static org.junit.Assert.assertNotNull; |
| 21 | + |
| 22 | +/** |
| 23 | + * @author Henrique Rosa ([email protected]) created on 22/05/2018 |
| 24 | + */ |
| 25 | +public class CallsEndpointTest { |
| 26 | + |
| 27 | + @Rule |
| 28 | + public WireMockRule wireMock = new WireMockRule(); |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testGetCallPage() throws IOException { |
| 32 | + // given |
| 33 | + final String username = "username"; |
| 34 | + final String password = "password"; |
| 35 | + final String baseUrl = "http://localhost:" + wireMock.port(); |
| 36 | + final RestcommClient client = new RestcommClient(RestcommClientConfiguration.builder().accountSid(username).accountToken(password).baseUrl(baseUrl).build()); |
| 37 | + final RestEndpoints<CallPage> callsEndpoint = client.getCallsEndpoint(); |
| 38 | + |
| 39 | + final File file = new File("src/test/resources/responses/calls-response.json"); |
| 40 | + final String response = new String(Files.readAllBytes(file.toPath())); |
| 41 | + |
| 42 | + stubFor(get(urlPathEqualTo("/restcomm/2012-04-24/Accounts/" + username + "/Calls.json")) |
| 43 | + .withBasicAuth(username, password) |
| 44 | + .willReturn(okJson(response))); |
| 45 | + |
| 46 | + // when |
| 47 | + final CallPage callPage = callsEndpoint.get(Collections.emptyMap()); |
| 48 | + |
| 49 | + // then |
| 50 | + assertNotNull(callPage); |
| 51 | + assertEquals(0, callPage.getPage()); |
| 52 | + assertEquals(50, callPage.getPageSize()); |
| 53 | + assertEquals(1, callPage.getTotal()); |
| 54 | + assertEquals(0, callPage.getStart()); |
| 55 | + assertEquals(1, callPage.getEnd()); |
| 56 | + assertEquals("/2012-04-24/Accounts/ACa12345/Calls", callPage.getUri()); |
| 57 | + assertEquals("/2012-04-24/Accounts/ACa12345/Calls?Page\u003d0\u0026PageSize\u003d50", callPage.getFirstPageUri()); |
| 58 | + assertEquals("null", callPage.getPreviousPageUri()); |
| 59 | + assertEquals("null", callPage.getNextPageUri()); |
| 60 | + assertEquals("/2012-04-24/Accounts/ACa12345/Calls?Page\u003d0\u0026PageSize\u003d50", callPage.getLastPageUri()); |
| 61 | + final List<Call> calls = callPage.getCalls(); |
| 62 | + assertNotNull(calls); |
| 63 | + assertEquals(1, calls.size()); |
| 64 | + assertEquals("ID12345-CA12345", calls.get(0).getSid()); |
| 65 | + assertEquals("Fri, 18 May 2018 14:57:59 +0000", calls.get(0).getDateCreated()); |
| 66 | + assertEquals("Fri, 18 May 2018 14:58:59 +0000", calls.get(0).getDateUpdated()); |
| 67 | + assertEquals("ACa12345", calls.get(0).getAccountSid()); |
| 68 | + assertEquals("1708a040dd94e22b04b721b21d", calls.get(0).getTo()); |
| 69 | + assertEquals("fd5a300f60744d6eb013e06f64da2132", calls.get(0).getFrom()); |
| 70 | + assertEquals("ACa12345", calls.get(0).getPhoneNumberSid()); |
| 71 | + assertEquals(CallStatus.FAILED.description(), calls.get(0).getStatus()); |
| 72 | + assertEquals("2018-05-18T14:57:59.000Z", calls.get(0).getStartTime()); |
| 73 | + assertEquals("2018-05-18T14:58:59.000Z", calls.get(0).getEndTime()); |
| 74 | + assertEquals(0, calls.get(0).getDuration()); |
| 75 | + assertEquals(0.0, calls.get(0).getPrice(), 0); |
| 76 | + assertEquals("2012-04-24", calls.get(0).getApiVersion()); |
| 77 | + assertEquals("Unknown", calls.get(0).getCallerName()); |
| 78 | + assertEquals("/2012-04-24/Accounts/ACa12345/Calls/ID12345-CA12345.json", calls.get(0).getUri()); |
| 79 | + } |
| 80 | + |
| 81 | +} |
0 commit comments