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

package com.twilio.rest.messaging.v1.service;

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 UsAppToPersonTest {
    @Mocked
    private TwilioRestClient twilioRestClient;

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

    @Test
    public void testCreateRequest() {
        new NonStrictExpectations() {{
            Request request = new Request(HttpMethod.POST,
                                          Domains.MESSAGING.toString(),
                                          "/v1/Services/MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Compliance/Usa2p");
            request.addPostParam("BrandRegistrationSid", serialize("BNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));
            request.addPostParam("Description", serialize("description"));
            request.addPostParam("MessageSamples", serialize(Promoter.listOfOne("message_samples")));
            request.addPostParam("UsAppToPersonUsecase", serialize("us_app_to_person_usecase"));
            request.addPostParam("HasEmbeddedLinks", serialize(true));
            request.addPostParam("HasEmbeddedPhone", serialize(true));
            twilioRestClient.request(request);
            times = 1;
            result = new Response("", 500);
            twilioRestClient.getAccountSid();
            result = "AC123";
        }};

        try {
            UsAppToPerson.creator("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "BNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "description", Promoter.listOfOne("message_samples"), "us_app_to_person_usecase", true, true).create();
            fail("Expected TwilioException to be thrown for 500");
        } catch (TwilioException e) {}
    }

    @Test
    public void testCreateResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"sid\": \"QE2c6890da8086d771620e9b13fadeba0b\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"brand_registration_sid\": \"BNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"messaging_service_sid\": \"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"description\": \"Send marketing messages about sales to opted in customers.\",\"message_samples\": [\"EXPRESS: Denim Days Event is ON\",\"LAST CHANCE: Book your next flight for just 1 (ONE) EUR\"],\"us_app_to_person_usecase\": \"MARKETING\",\"has_embedded_links\": true,\"has_embedded_phone\": false,\"campaign_status\": \"PENDING\",\"campaign_id\": \"CXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"is_externally_registered\": false,\"rate_limits\": {\"att\": {\"mps\": 600,\"msg_class\": \"A\"},\"tmobile\": {\"brand_tier\": \"TOP\"}},\"date_created\": \"2021-02-18T14:48:52Z\",\"date_updated\": \"2021-02-18T14:48:52Z\",\"url\": \"https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Compliance/Usa2p/QE2c6890da8086d771620e9b13fadeba0b\",\"mock\": false}", TwilioRestClient.HTTP_STATUS_CODE_CREATED);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        UsAppToPerson.creator("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "BNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "description", Promoter.listOfOne("message_samples"), "us_app_to_person_usecase", true, true).create();
    }

    @Test
    public void testDeleteRequest() {
        new NonStrictExpectations() {{
            Request request = new Request(HttpMethod.DELETE,
                                          Domains.MESSAGING.toString(),
                                          "/v1/Services/MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Compliance/Usa2p/QEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

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

        try {
            UsAppToPerson.deleter("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "QEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").delete();
            fail("Expected TwilioException to be thrown for 500");
        } catch (TwilioException e) {}
    }

    @Test
    public void testDeleteResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("null", TwilioRestClient.HTTP_STATUS_CODE_NO_CONTENT);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        UsAppToPerson.deleter("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "QEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").delete();
    }

    @Test
    public void testReadRequest() {
        new NonStrictExpectations() {{
            Request request = new Request(HttpMethod.GET,
                                          Domains.MESSAGING.toString(),
                                          "/v1/Services/MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Compliance/Usa2p");

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

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

    @Test
    public void testReadFullResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"compliance\": [{\"sid\": \"QE2c6890da8086d771620e9b13fadeba0b\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"brand_registration_sid\": \"BNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"messaging_service_sid\": \"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"description\": \"Send marketing messages about sales to opted in customers.\",\"message_samples\": [\"EXPRESS: Denim Days Event is ON\",\"LAST CHANCE: Book your next flight for just 1 (ONE) EUR\"],\"us_app_to_person_usecase\": \"MARKETING\",\"has_embedded_links\": true,\"has_embedded_phone\": false,\"campaign_status\": \"PENDING\",\"campaign_id\": \"CXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"is_externally_registered\": false,\"rate_limits\": {\"att\": {\"mps\": 600,\"msg_class\": \"A\"},\"tmobile\": {\"brand_tier\": \"TOP\"}},\"date_created\": \"2021-02-18T14:48:52Z\",\"date_updated\": \"2021-02-18T14:48:52Z\",\"url\": \"https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Compliance/Usa2p/QE2c6890da8086d771620e9b13fadeba0b\",\"mock\": false}],\"meta\": {\"page\": 0,\"page_size\": 50,\"first_page_url\": \"https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Compliance/Usa2p?PageSize=50&Page=0\",\"previous_page_url\": null,\"next_page_url\": null,\"url\": \"https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Compliance/Usa2p?PageSize=50&Page=0\",\"key\": \"compliance\"}}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsAppToPerson.reader("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").read());
    }

    @Test
    public void testFetchRequest() {
        new NonStrictExpectations() {{
            Request request = new Request(HttpMethod.GET,
                                          Domains.MESSAGING.toString(),
                                          "/v1/Services/MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Compliance/Usa2p/QEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

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

        try {
            UsAppToPerson.fetcher("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "QEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").fetch();
            fail("Expected TwilioException to be thrown for 500");
        } catch (TwilioException e) {}
    }

    @Test
    public void testFetchResponse() {
        new NonStrictExpectations() {{
            twilioRestClient.request((Request) any);
            result = new Response("{\"sid\": \"QE2c6890da8086d771620e9b13fadeba0b\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"brand_registration_sid\": \"BNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"messaging_service_sid\": \"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"description\": \"Send marketing messages about sales to opted in customers.\",\"message_samples\": [\"EXPRESS: Denim Days Event is ON\",\"LAST CHANCE: Book your next flight for just 1 (ONE) EUR\"],\"us_app_to_person_usecase\": \"MARKETING\",\"has_embedded_links\": true,\"has_embedded_phone\": false,\"campaign_status\": \"PENDING\",\"campaign_id\": \"CXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"is_externally_registered\": false,\"rate_limits\": {\"att\": {\"mps\": 600,\"msg_class\": \"A\"},\"tmobile\": {\"brand_tier\": \"TOP\"}},\"date_created\": \"2021-02-18T14:48:52Z\",\"date_updated\": \"2021-02-18T14:48:52Z\",\"url\": \"https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Compliance/Usa2p/QE2c6890da8086d771620e9b13fadeba0b\",\"mock\": false}", TwilioRestClient.HTTP_STATUS_CODE_OK);
            twilioRestClient.getObjectMapper();
            result = new ObjectMapper();
        }};

        assertNotNull(UsAppToPerson.fetcher("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "QEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").fetch());
    }
}