|
| 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.Recording; |
| 9 | +import org.restcomm.sdk.domain.RecordingPage; |
| 10 | + |
| 11 | +import java.io.File; |
| 12 | +import java.io.IOException; |
| 13 | +import java.nio.file.Files; |
| 14 | +import java.util.Collections; |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +import static com.github.tomakehurst.wiremock.client.WireMock.*; |
| 18 | +import static org.junit.Assert.assertEquals; |
| 19 | +import static org.junit.Assert.assertNotNull; |
| 20 | + |
| 21 | +/** |
| 22 | + * @author Henrique Rosa ([email protected]) created on 22/05/2018 |
| 23 | + */ |
| 24 | +public class RecordingsEndpointTest { |
| 25 | + |
| 26 | + @Rule |
| 27 | + public WireMockRule wireMock = new WireMockRule(); |
| 28 | + |
| 29 | + @Test |
| 30 | + public void testGetRecordingPage() throws IOException { |
| 31 | + // given |
| 32 | + final String username = "username"; |
| 33 | + final String password = "password"; |
| 34 | + final String baseUrl = "http://localhost:" + wireMock.port(); |
| 35 | + final RestcommClient client = new RestcommClient(RestcommClientConfiguration.builder().accountSid(username).accountToken(password).baseUrl(baseUrl).build()); |
| 36 | + final RestEndpoints<RecordingPage> endpoint = client.getRecordingsEndpoint(); |
| 37 | + |
| 38 | + final File file = new File("src/test/resources/responses/recordings-response.json"); |
| 39 | + final String response = new String(Files.readAllBytes(file.toPath())); |
| 40 | + |
| 41 | + stubFor(get(urlPathEqualTo("/restcomm/2012-04-24/Accounts/" + username + "/Recordings.json")) |
| 42 | + .withBasicAuth(username, password) |
| 43 | + .willReturn(okJson(response))); |
| 44 | + |
| 45 | + // when |
| 46 | + final RecordingPage resultPage = endpoint.findOne(Collections.emptyMap()); |
| 47 | + |
| 48 | + // then |
| 49 | + assertNotNull(resultPage); |
| 50 | + assertEquals(0, resultPage.getPage()); |
| 51 | + assertEquals(397, resultPage.getNumPages()); |
| 52 | + assertEquals(50, resultPage.getPageSize()); |
| 53 | + assertEquals(19858, resultPage.getTotal()); |
| 54 | + assertEquals(0, resultPage.getStart()); |
| 55 | + assertEquals(49, resultPage.getEnd()); |
| 56 | + assertEquals("/restcomm/2012-04-24/Accounts/AC12345/Recordings", resultPage.getUri()); |
| 57 | + assertEquals("/restcomm/2012-04-24/Accounts/AC12345/Recordings?Page\u003d0\u0026PageSize\u003d50", resultPage.getFirstPageUri()); |
| 58 | + assertEquals("null", resultPage.getPreviousPageUri()); |
| 59 | + assertEquals("/restcomm/2012-04-24/Accounts/AC12345/Recordings?Page\u003d1\u0026PageSize\u003d50\u0026AfterSid\u003dRE22222", resultPage.getNextPageUri()); |
| 60 | + assertEquals("/restcomm/2012-04-24/Accounts/AC12345/Recordings?Page\u003d397\u0026PageSize\u003d50", resultPage.getLastPageUri()); |
| 61 | + final List<Recording> recordings = resultPage.getRecordings(); |
| 62 | + assertNotNull(recordings); |
| 63 | + assertEquals(2, recordings.size()); |
| 64 | + assertEquals("RE11111", recordings.get(0).getSid()); |
| 65 | + assertEquals("Fri, 25 Sep 2015 15:59:56 +0000", recordings.get(0).getDateCreated()); |
| 66 | + assertEquals("Fri, 25 Sep 2015 15:59:56 +0000", recordings.get(0).getDateUpdated()); |
| 67 | + assertEquals("AC12345", recordings.get(0).getAccountSid()); |
| 68 | + assertEquals("CA11111", recordings.get(0).getCallSid()); |
| 69 | + assertEquals(9.72275, recordings.get(0).getDuration(), 0); |
| 70 | + assertEquals("2012-04-24", recordings.get(0).getApiVersion()); |
| 71 | + assertEquals("/2012-04-24/Accounts/AC12345/Recordings/RE11111.json", recordings.get(0).getUri()); |
| 72 | + assertEquals("https://some.domain.com/restcomm/2012-04-24/Accounts/AC12345/Recordings/RE11111.wav", recordings.get(0).getFileUri()); |
| 73 | + } |
| 74 | + |
| 75 | +} |
0 commit comments