/**
 * This code was generated by
 * \ / _    _  _|   _  _
 *  | (_)\/(_)(_|\/| |(/_  v1.0.0
 *       /       /
 */

package com.twilio.rest.supersim.v1;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.twilio.Twilio;
import com.twilio.converter.DateConverter;
import com.twilio.converter.Promoter;
import com.twilio.exception.TwilioException;
import com.twilio.http.HttpMethod;
import com.twilio.http.Request;
import com.twilio.http.Response;
import com.twilio.http.TwilioRestClient;
import com.twilio.rest.Domains;
import mockit.Mocked;
import mockit.NonStrictExpectations;
import org.junit.Before;
import org.junit.Test;

import java.net.URI;

import static com.twilio.TwilioTest.serialize;
import static org.junit.Assert.*;

public class UsageRecordTest {
    @Mocked
    private TwilioRestClient twilioRestClient;

    @Before
    public void setUp() throws Exception {
        Twilio.init("AC123", "AUTH TOKEN");
    }

    @Test
    public void testReadRequest() {
        new NonStrictExpectations() {{
            Request request = new Request(HttpMethod.GET,
                                          Domains.SUPERSIM.toString(),
                                          "/v1/UsageRecords");

            twilioRestClient.request(request);
            times = 1;
            result = new Response("", 500);
            twilioRestClient.getAccountSid();
            result = "AC123";
        }};

        try {
            UsageRecord.reader().read();
            fail("Expected TwilioException to be thrown for 500");
        } catch (TwilioException e) {}
    }

    @Test
    public void testReadAllResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"usage_records\": [{\"period\": {\"start_time\": \"2015-05-01T20:00:00Z\",\"end_time\": \"2015-06-01T20:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": null}],\"meta\": {\"first_page_url\": \"https://supersim.twilio.com/v1/UsageRecords?PageSize=50&Page=0\",\"key\": \"usage_records\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://supersim.twilio.com/v1/UsageRecords?PageSize=50&Page=0\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsageRecord.reader().read());
    }

    @Test
    public void testReadAllDayResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"usage_records\": [{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": null},{\"period\": {\"start_time\": \"2019-05-02T00:00:00Z\",\"end_time\": \"2019-05-03T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": null}],\"meta\": {\"first_page_url\": \"https://supersim.twilio.com/v1/UsageRecords?Granularity=day&PageSize=50&Page=0\",\"key\": \"usage_records\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://supersim.twilio.com/v1/UsageRecords?Granularity=day&PageSize=50&Page=0\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsageRecord.reader().read());
    }

    @Test
    public void testReadAllHourResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"usage_records\": [{\"period\": {\"start_time\": \"2019-05-01T01:00:00Z\",\"end_time\": \"2019-05-01T02:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": null},{\"period\": {\"start_time\": \"2019-05-01T00:00:00Z\",\"end_time\": \"2019-05-01T01:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": null}],\"meta\": {\"first_page_url\": \"https://supersim.twilio.com/v1/UsageRecords?Granularity=hour&PageSize=50&Page=0\",\"key\": \"usage_records\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://supersim.twilio.com/v1/UsageRecords?Granularity=hour&PageSize=50&Page=0\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsageRecord.reader().read());
    }

    @Test
    public void testReadDaySimFilterResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"usage_records\": [{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": \"HSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": null},{\"period\": {\"start_time\": \"2019-05-02T00:00:00Z\",\"end_time\": \"2019-05-03T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": \"HSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": null}],\"meta\": {\"first_page_url\": \"https://supersim.twilio.com/v1/UsageRecords?Sim=HSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&Granularity=day&PageSize=50&Page=0\",\"key\": \"usage_records\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://supersim.twilio.com/v1/UsageRecords?Sim=HSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&Granularity=day&PageSize=50&Page=0\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsageRecord.reader().read());
    }

    @Test
    public void testReadDayNetworkFilterResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"usage_records\": [{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": \"HWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"iso_country\": null},{\"period\": {\"start_time\": \"2019-05-02T00:00:00Z\",\"end_time\": \"2019-05-03T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": \"HWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"iso_country\": null}],\"meta\": {\"first_page_url\": \"https://supersim.twilio.com/v1/UsageRecords?Network=HWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&Granularity=day&PageSize=50&Page=0\",\"key\": \"usage_records\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://supersim.twilio.com/v1/UsageRecords?Network=HWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&Granularity=day&PageSize=50&Page=0\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsageRecord.reader().read());
    }

    @Test
    public void testReadDayCountryFilterResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"usage_records\": [{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": \"FR\"},{\"period\": {\"start_time\": \"2019-05-02T00:00:00Z\",\"end_time\": \"2019-05-03T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": \"FR\"}],\"meta\": {\"first_page_url\": \"https://supersim.twilio.com/v1/UsageRecords?IsoCountry=FR&Granularity=day&PageSize=50&Page=0\",\"key\": \"usage_records\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://supersim.twilio.com/v1/UsageRecords?IsoCountry=FR&Granularity=day&PageSize=50&Page=0\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsageRecord.reader().read());
    }

    @Test
    public void testReadDayFleetFilterResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"usage_records\": [{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": \"HFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"network_sid\": null,\"iso_country\": null},{\"period\": {\"start_time\": \"2019-05-02T00:00:00Z\",\"end_time\": \"2019-05-03T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": \"HFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"network_sid\": null,\"iso_country\": null}],\"meta\": {\"first_page_url\": \"https://supersim.twilio.com/v1/UsageRecords?Fleet=HFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&Granularity=day&PageSize=50&Page=0\",\"key\": \"usage_records\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://supersim.twilio.com/v1/UsageRecords?Fleet=HFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&Granularity=day&PageSize=50&Page=0\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsageRecord.reader().read());
    }

    @Test
    public void testReadDayGroupBySimResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"usage_records\": [{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": \"HSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": null},{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 500,\"data_download\": 1500,\"data_total\": 2000,\"sim_sid\": \"HSbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": null}],\"meta\": {\"first_page_url\": \"https://supersim.twilio.com/v1/UsageRecords?Group=sim&PageSize=50&Page=0\",\"key\": \"usage_records\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://supersim.twilio.com/v1/UsageRecords?Group=sim&PageSize=50&Page=0\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsageRecord.reader().read());
    }

    @Test
    public void testReadDayGroupByFleetResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"usage_records\": [{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": \"HFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"network_sid\": null,\"iso_country\": null},{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 500,\"data_download\": 1500,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": \"HFbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"network_sid\": null,\"iso_country\": null}],\"meta\": {\"first_page_url\": \"https://supersim.twilio.com/v1/UsageRecords?Group=fleet&PageSize=50&Page=0\",\"key\": \"usage_records\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://supersim.twilio.com/v1/UsageRecords?Group=fleet&PageSize=50&Page=0\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsageRecord.reader().read());
    }

    @Test
    public void testReadDayGroupByNetworkResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"usage_records\": [{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": \"HWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"iso_country\": null},{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 500,\"data_download\": 1500,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": \"HWbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"iso_country\": null}],\"meta\": {\"first_page_url\": \"https://supersim.twilio.com/v1/UsageRecords?Group=network&PageSize=50&Page=0\",\"key\": \"usage_records\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://supersim.twilio.com/v1/UsageRecords?Group=network&PageSize=50&Page=0\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsageRecord.reader().read());
    }

    @Test
    public void testReadDayGroupByIsoCountryResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"usage_records\": [{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": \"FR\"},{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 500,\"data_download\": 1500,\"data_total\": 2000,\"sim_sid\": null,\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": \"US\"}],\"meta\": {\"first_page_url\": \"https://supersim.twilio.com/v1/UsageRecords?Group=isoCountry&PageSize=50&Page=0\",\"key\": \"usage_records\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://supersim.twilio.com/v1/UsageRecords?Group=isoCountry&PageSize=50&Page=0\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsageRecord.reader().read());
    }

    @Test
    public void testReadDayGroupBySimAndFilterByCountryResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"usage_records\": [{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 1000,\"data_download\": 1000,\"data_total\": 2000,\"sim_sid\": \"HSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": \"FR\"},{\"period\": {\"start_time\": \"2019-05-03T00:00:00Z\",\"end_time\": \"2019-05-04T00:00:00Z\"},\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"data_upload\": 500,\"data_download\": 1500,\"data_total\": 2000,\"sim_sid\": \"HSbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"fleet_sid\": null,\"network_sid\": null,\"iso_country\": \"FR\"}],\"meta\": {\"first_page_url\": \"https://supersim.twilio.com/v1/UsageRecords?IsoCountry=FR&Group=sim&PageSize=50&Page=0\",\"key\": \"usage_records\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://supersim.twilio.com/v1/UsageRecords?IsoCountry=FR&Group=sim&PageSize=50&Page=0\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsageRecord.reader().read());
    }
}