Search in sources :

Example 1 with ApiIOException

use of org.infobip.mobile.messaging.api.support.ApiIOException in project mobile-messaging-sdk-android by infobip.

the class MobileApiResourceProviderTest method shouldUseNewUrlForSecondRequest.

@Test
public void shouldUseNewUrlForSecondRequest() {
    // given
    debugServer.respondWith(NanoHTTPD.Response.Status.OK, null, new HashMap<String, String>() {

        {
            put(CustomApiHeaders.NEW_BASE_URL.getValue(), "http://customurl");
        }
    });
    MobileApiVersion givenMobileApiVersion = mobileApiResourceProvider.getMobileApiVersion(context);
    // when
    givenMobileApiVersion.getLatestRelease();
    try {
        givenMobileApiVersion.getLatestRelease();
        assertTrue(false);
    } catch (ApiIOException e) {
        assertTrue(e.getCause() instanceof UnknownHostException);
        assertTrue(e.getCause().getMessage().contains("customurl"));
    }
}
Also used : MobileApiVersion(org.infobip.mobile.messaging.api.version.MobileApiVersion) UnknownHostException(java.net.UnknownHostException) ApiIOException(org.infobip.mobile.messaging.api.support.ApiIOException) Test(org.junit.Test)

Example 2 with ApiIOException

use of org.infobip.mobile.messaging.api.support.ApiIOException in project mobile-messaging-sdk-android by infobip.

the class MAsyncTaskTest method shouldMapInvalidCustomValueToAppropriateException.

@Test
public void shouldMapInvalidCustomValueToAppropriateException() {
    // Given
    ApiIOException givenError = new ApiIOException(ApiErrorCode.INVALID_VALUE, "");
    Mockito.when(tester.run(any(Object[].class))).thenThrow(givenError);
    // When
    asyncTask.execute(executor);
    // Then
    Mockito.verify(tester, Mockito.after(100).times(1)).error(any(Object[].class), eqInvalidParamErrorWith(givenError));
    Mockito.verify(tester, Mockito.never()).after(Mockito.any());
}
Also used : ApiIOException(org.infobip.mobile.messaging.api.support.ApiIOException) Test(org.junit.Test)

Example 3 with ApiIOException

use of org.infobip.mobile.messaging.api.support.ApiIOException in project mobile-messaging-sdk-android by infobip.

the class MAsyncTaskTest method shouldMapInvalidEmailToAppropriateException.

@Test
public void shouldMapInvalidEmailToAppropriateException() {
    // Given
    ApiIOException givenError = new ApiIOException(ApiErrorCode.INVALID_EMAIL_FORMAT, "");
    Mockito.when(tester.run(any(Object[].class))).thenThrow(givenError);
    // When
    asyncTask.execute(executor);
    // Then
    Mockito.verify(tester, Mockito.after(100).times(1)).error(any(Object[].class), eqInvalidParamErrorWith(givenError));
    Mockito.verify(tester, Mockito.never()).after(Mockito.any());
}
Also used : ApiIOException(org.infobip.mobile.messaging.api.support.ApiIOException) Test(org.junit.Test)

Example 4 with ApiIOException

use of org.infobip.mobile.messaging.api.support.ApiIOException in project mobile-messaging-sdk-android by infobip.

the class MAsyncTaskTest method shouldMapErrorWithContentAndInvalidParameterToAppropriateException.

@Test
public void shouldMapErrorWithContentAndInvalidParameterToAppropriateException() {
    // Given
    String givenContent = "content";
    ApiIOException givenError = new ApiBackendExceptionWithContent(ApiErrorCode.INVALID_MSISDN_FORMAT, "", givenContent);
    Mockito.when(tester.run(any(Object[].class))).thenThrow(givenError);
    // When
    asyncTask.execute(executor);
    // Then
    Mockito.verify(tester, Mockito.after(100).times(1)).error(any(Object[].class), eqInvalidParamErrorWithContent(givenError, givenContent));
    Mockito.verify(tester, Mockito.never()).after(Mockito.any());
}
Also used : ApiBackendExceptionWithContent(org.infobip.mobile.messaging.api.support.ApiBackendExceptionWithContent) ApiIOException(org.infobip.mobile.messaging.api.support.ApiIOException) Test(org.junit.Test)

Example 5 with ApiIOException

use of org.infobip.mobile.messaging.api.support.ApiIOException in project mobile-messaging-sdk-android by infobip.

the class MAsyncTaskTest method shouldMapInvalidMsisdnToAppropriateException.

@Test
public void shouldMapInvalidMsisdnToAppropriateException() {
    // Given
    ApiIOException givenError = new ApiIOException(ApiErrorCode.INVALID_MSISDN_FORMAT, "");
    Mockito.when(tester.run(any(Object[].class))).thenThrow(givenError);
    // When
    asyncTask.execute(executor);
    // Then
    Mockito.verify(tester, Mockito.after(100).times(1)).error(any(Object[].class), eqInvalidParamErrorWith(givenError));
    Mockito.verify(tester, Mockito.never()).after(Mockito.any());
}
Also used : ApiIOException(org.infobip.mobile.messaging.api.support.ApiIOException) Test(org.junit.Test)

Aggregations

ApiIOException (org.infobip.mobile.messaging.api.support.ApiIOException)10 Test (org.junit.Test)8 ApiBackendExceptionWithContent (org.infobip.mobile.messaging.api.support.ApiBackendExceptionWithContent)3 BackendCommunicationException (org.infobip.mobile.messaging.mobile.common.exceptions.BackendCommunicationException)2 SuppressLint (android.annotation.SuppressLint)1 BufferedOutputStream (java.io.BufferedOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 Collection (java.util.Collection)1 Map (java.util.Map)1 MobileApiData (org.infobip.mobile.messaging.api.data.MobileApiData)1 SystemDataReport (org.infobip.mobile.messaging.api.data.SystemDataReport)1 UserDataReport (org.infobip.mobile.messaging.api.data.UserDataReport)1 EventReportBody (org.infobip.mobile.messaging.api.geo.EventReportBody)1 MobileApiMessages (org.infobip.mobile.messaging.api.messages.MobileApiMessages)1 SyncMessagesBody (org.infobip.mobile.messaging.api.messages.SyncMessagesBody)1