Search in sources :

Example 6 with Channel

use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.

the class CrashesAndroidTest method startFresh.

private void startFresh(CrashesListener listener) throws Exception {
    /* Configure new instance. */
    AppCenterPrivateHelper.unsetInstance();
    Crashes.unsetInstance();
    AppCenter.setLogLevel(android.util.Log.VERBOSE);
    AppCenter.configure(sApplication, "a");
    /* Clean logs. */
    AppCenter.setEnabled(false);
    AppCenter.setEnabled(true).get();
    /* Replace channel. */
    Method method = AppCenter.class.getDeclaredMethod("getInstance");
    method.setAccessible(true);
    AppCenter appCenter = (AppCenter) method.invoke(null);
    method = AppCenter.class.getDeclaredMethod("setChannel", Channel.class);
    method.setAccessible(true);
    method.invoke(appCenter, mChannel);
    /* Set listener. */
    Crashes.setListener(listener);
    /* Start crashes. */
    AppCenter.start(Crashes.class);
    /* Wait for start. */
    assertTrue(Crashes.isEnabled().get());
}
Also used : AppCenter(com.microsoft.appcenter.AppCenter) Channel(com.microsoft.appcenter.channel.Channel) Method(java.lang.reflect.Method)

Example 7 with Channel

use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.

the class WrapperSdkExceptionManagerAndroidTest method startFresh.

private void startFresh() throws java.lang.Exception {
    /* Configure new instance. */
    AppCenterPrivateHelper.unsetInstance();
    Crashes.unsetInstance();
    AppCenter.setLogLevel(android.util.Log.VERBOSE);
    AppCenter.configure(sApplication, "a");
    /* Replace channel. */
    Method method = AppCenter.class.getDeclaredMethod("getInstance");
    method.setAccessible(true);
    AppCenter appCenter = (AppCenter) method.invoke(null);
    method = AppCenter.class.getDeclaredMethod("setChannel", Channel.class);
    method.setAccessible(true);
    method.invoke(appCenter, mock(Channel.class));
    /* Start crashes. */
    AppCenter.start(Crashes.class);
    /* Wait for start. */
    Assert.assertTrue(Crashes.isEnabled().get());
}
Also used : AppCenter(com.microsoft.appcenter.AppCenter) Channel(com.microsoft.appcenter.channel.Channel) Method(java.lang.reflect.Method)

Example 8 with Channel

use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.

the class CrashesTest method queuePendingCrashesShouldProcess.

@Test
public void queuePendingCrashesShouldProcess() throws IOException, ClassNotFoundException, JSONException {
    /* Setup mock. */
    Context mockContext = mock(Context.class);
    Channel mockChannel = mock(Channel.class);
    ErrorReport report = new ErrorReport();
    mockStatic(ErrorLogHelper.class);
    when(ErrorLogHelper.getStoredErrorLogFiles()).thenReturn(new File[] { mock(File.class) });
    when(ErrorLogHelper.getNewMinidumpFiles()).thenReturn(new File[0]);
    when(ErrorLogHelper.getStoredThrowableFile(any(UUID.class))).thenReturn(mock(File.class));
    when(ErrorLogHelper.getErrorReportFromErrorLog(any(ManagedErrorLog.class), any(Throwable.class))).thenReturn(report);
    when(StorageHelper.InternalStorage.read(any(File.class))).thenReturn("");
    when(StorageHelper.InternalStorage.readObject(any(File.class))).thenReturn(new RuntimeException());
    CrashesListener mockListener = mock(CrashesListener.class);
    when(mockListener.shouldProcess(report)).thenReturn(true);
    when(mockListener.shouldAwaitUserConfirmation()).thenReturn(false);
    ErrorAttachmentLog mockAttachment = mock(ErrorAttachmentLog.class);
    when(mockAttachment.getId()).thenReturn(UUID.randomUUID());
    when(mockAttachment.getErrorId()).thenReturn(UUID.randomUUID());
    when(mockAttachment.getContentType()).thenReturn("");
    when(mockAttachment.getFileName()).thenReturn("");
    when(mockAttachment.getData()).thenReturn(new byte[0]);
    when(mockAttachment.isValid()).thenReturn(true);
    ErrorAttachmentLog mockEmptyAttachment = mock(ErrorAttachmentLog.class);
    final int skipAttachmentLogsCount = 2;
    List<ErrorAttachmentLog> errorAttachmentLogList = Arrays.asList(mockAttachment, mockAttachment, mockEmptyAttachment, null);
    when(mockListener.getErrorAttachments(report)).thenReturn(errorAttachmentLogList);
    LogSerializer logSerializer = mock(LogSerializer.class);
    when(logSerializer.deserializeLog(anyString())).thenReturn(mErrorLog);
    Crashes crashes = Crashes.getInstance();
    crashes.setLogSerializer(logSerializer);
    crashes.setInstanceListener(mockListener);
    crashes.onStarting(mAppCenterHandler);
    crashes.onStarted(mockContext, "", mockChannel);
    /* Test. */
    verify(mockListener).shouldProcess(report);
    verify(mockListener).shouldAwaitUserConfirmation();
    verify(mockListener).getErrorAttachments(report);
    verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {

        @Override
        public boolean matches(Object log) {
            return log.equals(mErrorLog);
        }
    }), eq(crashes.getGroupName()));
    verify(mockChannel, times(errorAttachmentLogList.size() - skipAttachmentLogsCount)).enqueue(mockAttachment, crashes.getGroupName());
}
Also used : Context(android.content.Context) SessionContext(com.microsoft.appcenter.SessionContext) Channel(com.microsoft.appcenter.channel.Channel) LogSerializer(com.microsoft.appcenter.ingestion.models.json.LogSerializer) ErrorReport(com.microsoft.appcenter.crashes.model.ErrorReport) ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) ArgumentMatcher(org.mockito.ArgumentMatcher) ErrorAttachmentLog(com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog) UUID(java.util.UUID) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with Channel

use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.

the class CrashesTest method noQueueNullLog.

@Test
public void noQueueNullLog() throws JSONException {
    Context mockContext = mock(Context.class);
    Channel mockChannel = mock(Channel.class);
    mockStatic(ErrorLogHelper.class);
    when(ErrorLogHelper.getStoredErrorLogFiles()).thenReturn(new File[] { mock(File.class) });
    when(ErrorLogHelper.getNewMinidumpFiles()).thenReturn(new File[0]);
    Crashes crashes = Crashes.getInstance();
    LogSerializer logSerializer = mock(LogSerializer.class);
    when(logSerializer.deserializeLog(anyString())).thenReturn(null);
    crashes.setLogSerializer(logSerializer);
    crashes.onStarting(mAppCenterHandler);
    crashes.onStarted(mockContext, "", mockChannel);
    verify(mockChannel, never()).enqueue(any(Log.class), anyString());
}
Also used : Context(android.content.Context) SessionContext(com.microsoft.appcenter.SessionContext) HandledErrorLog(com.microsoft.appcenter.crashes.ingestion.models.HandledErrorLog) ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) Log(com.microsoft.appcenter.ingestion.models.Log) AppCenterLog(com.microsoft.appcenter.utils.AppCenterLog) ErrorAttachmentLog(com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog) Channel(com.microsoft.appcenter.channel.Channel) LogSerializer(com.microsoft.appcenter.ingestion.models.json.LogSerializer) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with Channel

use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.

the class CrashesTest method queuePendingCrashesShouldNotProcess.

@Test
public void queuePendingCrashesShouldNotProcess() throws IOException, ClassNotFoundException, JSONException {
    Context mockContext = mock(Context.class);
    Channel mockChannel = mock(Channel.class);
    ErrorReport report = new ErrorReport();
    mockStatic(ErrorLogHelper.class);
    when(ErrorLogHelper.getStoredErrorLogFiles()).thenReturn(new File[] { mock(File.class) });
    when(ErrorLogHelper.getNewMinidumpFiles()).thenReturn(new File[0]);
    when(ErrorLogHelper.getStoredThrowableFile(any(UUID.class))).thenReturn(mock(File.class));
    when(ErrorLogHelper.getErrorReportFromErrorLog(any(ManagedErrorLog.class), any(Throwable.class))).thenReturn(report);
    when(StorageHelper.InternalStorage.read(any(File.class))).thenReturn("");
    when(StorageHelper.InternalStorage.readObject(any(File.class))).thenReturn(new RuntimeException()).thenReturn(new byte[] {});
    CrashesListener mockListener = mock(CrashesListener.class);
    when(mockListener.shouldProcess(report)).thenReturn(false);
    Crashes crashes = Crashes.getInstance();
    LogSerializer logSerializer = mock(LogSerializer.class);
    when(logSerializer.deserializeLog(anyString())).thenReturn(mErrorLog);
    crashes.setLogSerializer(logSerializer);
    crashes.setInstanceListener(mockListener);
    crashes.onStarting(mAppCenterHandler);
    crashes.onStarted(mockContext, "", mockChannel);
    verify(mockListener).shouldProcess(report);
    verify(mockListener, never()).shouldAwaitUserConfirmation();
    verify(mockListener, never()).getErrorAttachments(report);
    verify(mockChannel, never()).enqueue(any(Log.class), eq(crashes.getGroupName()));
}
Also used : Context(android.content.Context) SessionContext(com.microsoft.appcenter.SessionContext) ErrorReport(com.microsoft.appcenter.crashes.model.ErrorReport) ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) HandledErrorLog(com.microsoft.appcenter.crashes.ingestion.models.HandledErrorLog) ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) Log(com.microsoft.appcenter.ingestion.models.Log) AppCenterLog(com.microsoft.appcenter.utils.AppCenterLog) ErrorAttachmentLog(com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog) Channel(com.microsoft.appcenter.channel.Channel) LogSerializer(com.microsoft.appcenter.ingestion.models.json.LogSerializer) UUID(java.util.UUID) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Channel (com.microsoft.appcenter.channel.Channel)35 Context (android.content.Context)33 Test (org.junit.Test)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 SessionContext (com.microsoft.appcenter.SessionContext)14 Log (com.microsoft.appcenter.ingestion.models.Log)14 AppCenterLog (com.microsoft.appcenter.utils.AppCenterLog)14 ManagedErrorLog (com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog)13 ErrorAttachmentLog (com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog)11 File (java.io.File)11 LogSerializer (com.microsoft.appcenter.ingestion.models.json.LogSerializer)10 HandledErrorLog (com.microsoft.appcenter.crashes.ingestion.models.HandledErrorLog)9 ArgumentMatcher (org.mockito.ArgumentMatcher)9 PageLog (com.microsoft.appcenter.analytics.ingestion.models.PageLog)8 Matchers.anyString (org.mockito.Matchers.anyString)8 StartSessionLog (com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog)7 ErrorReport (com.microsoft.appcenter.crashes.model.ErrorReport)7 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)6 HashMap (java.util.HashMap)6 UUID (java.util.UUID)6