use of com.microsoft.appcenter.crashes.ingestion.models.HandledErrorLog in project AppCenter-SDK-Android by Microsoft.
the class CrashesTest method trackException.
@Test
public void trackException() {
/* Track exception test. */
Crashes crashes = Crashes.getInstance();
Channel mockChannel = mock(Channel.class);
crashes.onStarting(mAppCenterHandler);
crashes.onStarted(mock(Context.class), "", mockChannel);
Crashes.trackException(EXCEPTION);
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof HandledErrorLog && EXCEPTION.getMessage().equals(((HandledErrorLog) item).getException().getMessage());
}
}), eq(crashes.getGroupName()));
reset(mockChannel);
Crashes.trackException(EXCEPTION, new HashMap<String, String>() {
{
put(null, null);
put("", null);
put(generateString(ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH + 1, '*'), null);
put("1", null);
}
});
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof HandledErrorLog && EXCEPTION.getMessage().equals(((HandledErrorLog) item).getException().getMessage()) && ((HandledErrorLog) item).getProperties().size() == 0;
}
}), eq(crashes.getGroupName()));
reset(mockChannel);
Crashes.trackException(EXCEPTION, new HashMap<String, String>() {
{
for (int i = 0; i < 10; i++) {
put("valid" + i, "valid");
}
}
});
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof HandledErrorLog && EXCEPTION.getMessage().equals(((HandledErrorLog) item).getException().getMessage()) && ((HandledErrorLog) item).getProperties().size() == 5;
}
}), eq(crashes.getGroupName()));
reset(mockChannel);
final String longerMapItem = generateString(ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH + 1, '*');
Crashes.trackException(EXCEPTION, new HashMap<String, String>() {
{
put(longerMapItem, longerMapItem);
}
});
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof HandledErrorLog) {
HandledErrorLog errorLog = (HandledErrorLog) item;
if (EXCEPTION.getMessage().equals((errorLog.getException().getMessage()))) {
if (errorLog.getProperties().size() == 1) {
Map.Entry<String, String> entry = errorLog.getProperties().entrySet().iterator().next();
String truncatedMapItem = generateString(ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH, '*');
return entry.getKey().length() == ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH && entry.getValue().length() == ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH;
}
}
}
return false;
}
}), eq(crashes.getGroupName()));
HandledErrorLog mockLog = mock(HandledErrorLog.class);
CrashesListener mockListener = mock(CrashesListener.class);
crashes.setInstanceListener(mockListener);
/* Crashes callback test for trackException. */
crashes.getChannelListener().onBeforeSending(mockLog);
verify(mockListener, never()).onBeforeSending(any(ErrorReport.class));
crashes.getChannelListener().onSuccess(mockLog);
verify(mockListener, never()).onSendingSucceeded(any(ErrorReport.class));
crashes.getChannelListener().onFailure(mockLog, EXCEPTION);
verify(mockListener, never()).onSendingFailed(any(ErrorReport.class), eq(EXCEPTION));
ErrorAttachmentLog attachmentLog = mock(ErrorAttachmentLog.class);
crashes.getChannelListener().onBeforeSending(attachmentLog);
verify(mockListener, never()).onBeforeSending(any(ErrorReport.class));
crashes.getChannelListener().onSuccess(attachmentLog);
verify(mockListener, never()).onSendingSucceeded(any(ErrorReport.class));
crashes.getChannelListener().onFailure(attachmentLog, EXCEPTION);
verify(mockListener, never()).onSendingFailed(any(ErrorReport.class), eq(EXCEPTION));
}
use of com.microsoft.appcenter.crashes.ingestion.models.HandledErrorLog in project AppCenter-SDK-Android by Microsoft.
the class CrashesTest method trackExceptionForWrapperSdk.
@Test
public void trackExceptionForWrapperSdk() {
StackFrame frame = new StackFrame();
frame.setClassName("1");
frame.setFileName("2");
frame.setLineNumber(3);
frame.setMethodName("4");
final com.microsoft.appcenter.crashes.ingestion.models.Exception exception = new com.microsoft.appcenter.crashes.ingestion.models.Exception();
exception.setType("5");
exception.setMessage("6");
exception.setFrames(singletonList(frame));
Crashes crashes = Crashes.getInstance();
Channel mockChannel = mock(Channel.class);
WrapperSdkExceptionManager.trackException(exception);
verify(mockChannel, never()).enqueue(any(Log.class), eq(crashes.getGroupName()));
crashes.onStarting(mAppCenterHandler);
crashes.onStarted(mock(Context.class), "", mockChannel);
WrapperSdkExceptionManager.trackException(exception);
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof HandledErrorLog && exception.equals(((HandledErrorLog) item).getException());
}
}), eq(crashes.getGroupName()));
reset(mockChannel);
WrapperSdkExceptionManager.trackException(exception, new HashMap<String, String>() {
{
put(null, null);
put("", null);
put(generateString(ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH + 1, '*'), null);
put("1", null);
}
});
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof HandledErrorLog && exception.equals(((HandledErrorLog) item).getException()) && ((HandledErrorLog) item).getProperties().size() == 0;
}
}), eq(crashes.getGroupName()));
reset(mockChannel);
WrapperSdkExceptionManager.trackException(exception, new HashMap<String, String>() {
{
for (int i = 0; i < 10; i++) {
put("valid" + i, "valid");
}
}
});
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof HandledErrorLog && exception.equals(((HandledErrorLog) item).getException()) && ((HandledErrorLog) item).getProperties().size() == 5;
}
}), eq(crashes.getGroupName()));
reset(mockChannel);
final String longerMapItem = generateString(ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH + 1, '*');
WrapperSdkExceptionManager.trackException(exception, new HashMap<String, String>() {
{
put(longerMapItem, longerMapItem);
}
});
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof HandledErrorLog) {
HandledErrorLog errorLog = (HandledErrorLog) item;
if (exception.equals((errorLog.getException()))) {
if (errorLog.getProperties().size() == 1) {
Map.Entry<String, String> entry = errorLog.getProperties().entrySet().iterator().next();
String truncatedMapItem = generateString(ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH, '*');
return entry.getKey().length() == ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH && entry.getValue().length() == ErrorLogHelper.MAX_PROPERTY_ITEM_LENGTH;
}
}
}
return false;
}
}), eq(crashes.getGroupName()));
}
use of com.microsoft.appcenter.crashes.ingestion.models.HandledErrorLog in project mobile-center-sdk-android by Microsoft.
the class HandledErrorTest method trackErrorWithOneAttachment.
@Test
public void trackErrorWithOneAttachment() {
/* If we start crashes. */
startCrashes();
/* When we track error with an attachment. */
ErrorAttachmentLog textAttachment = ErrorAttachmentLog.attachmentWithText("text", null);
Crashes.trackError(EXCEPTION, null, Collections.singleton(textAttachment));
/* Then we send the handled error. */
ArgumentCaptor<Log> log = ArgumentCaptor.forClass(Log.class);
verify(mChannel, times(2)).enqueue(log.capture(), eq(mCrashes.getGroupName()), eq(DEFAULTS));
assertNotNull(log.getAllValues());
assertEquals(2, log.getAllValues().size());
assertTrue(log.getAllValues().get(0) instanceof HandledErrorLog);
HandledErrorLog handledErrorLog = (HandledErrorLog) log.getAllValues().get(0);
assertEquals(EXCEPTION.getMessage(), handledErrorLog.getException().getMessage());
/* Then the attachment. */
assertSame(textAttachment, log.getAllValues().get(1));
}
use of com.microsoft.appcenter.crashes.ingestion.models.HandledErrorLog in project mobile-center-sdk-android by Microsoft.
the class HandledErrorTest method trackExceptionWithEverythingFromWrapper.
@Test
public void trackExceptionWithEverythingFromWrapper() {
/* If we start crashes. */
startCrashes();
/* And set a userId. */
UserIdContext.getInstance().setUserId("omega");
/* When we track error. */
ErrorAttachmentLog textAttachment = ErrorAttachmentLog.attachmentWithText("text", null);
ErrorAttachmentLog binaryAttachment = ErrorAttachmentLog.attachmentWithBinary("hello".getBytes(), "hello.so", "application/octet-stream");
HashMap<String, String> properties = new HashMap<String, String>() {
{
put("a", "b");
}
};
Exception modelException = new Exception();
String errorId = WrapperSdkExceptionManager.trackException(modelException, properties, Arrays.asList(textAttachment, binaryAttachment));
assertNotNull(errorId);
/* Then we send the handled error. */
ArgumentCaptor<Log> logs = ArgumentCaptor.forClass(Log.class);
verify(mChannel, times(3)).enqueue(logs.capture(), eq(mCrashes.getGroupName()), eq(DEFAULTS));
assertNotNull(logs.getAllValues());
assertEquals(3, logs.getAllValues().size());
assertTrue(logs.getAllValues().get(0) instanceof HandledErrorLog);
HandledErrorLog handledErrorLog = (HandledErrorLog) logs.getAllValues().get(0);
assertEquals(modelException, handledErrorLog.getException());
assertEquals(properties, handledErrorLog.getProperties());
assertEquals(errorId, String.valueOf(handledErrorLog.getId()));
/* Then the attachments. */
assertSame(textAttachment, logs.getAllValues().get(1));
assertSame(binaryAttachment, logs.getAllValues().get(2));
/* We send userId only in the error log. */
assertEquals("omega", handledErrorLog.getUserId());
assertNull(logs.getAllValues().get(1).getUserId());
assertNull(logs.getAllValues().get(2).getUserId());
}
use of com.microsoft.appcenter.crashes.ingestion.models.HandledErrorLog in project mobile-center-sdk-android by Microsoft.
the class HandledErrorTest method trackExceptionWithOneAttachmentFromWrapper.
@Test
public void trackExceptionWithOneAttachmentFromWrapper() {
/* If we start crashes. */
startCrashes();
/* When we track error with an attachment. */
ErrorAttachmentLog textAttachment = ErrorAttachmentLog.attachmentWithText("text", null);
Exception exception = new Exception();
String errorId = WrapperSdkExceptionManager.trackException(exception, null, Collections.singleton(textAttachment));
assertNotNull(errorId);
/* Then we send the handled error. */
ArgumentCaptor<Log> log = ArgumentCaptor.forClass(Log.class);
verify(mChannel, times(2)).enqueue(log.capture(), eq(mCrashes.getGroupName()), eq(DEFAULTS));
assertNotNull(log.getAllValues());
assertEquals(2, log.getAllValues().size());
assertTrue(log.getAllValues().get(0) instanceof HandledErrorLog);
HandledErrorLog handledErrorLog = (HandledErrorLog) log.getAllValues().get(0);
assertEquals(exception, handledErrorLog.getException());
assertEquals(errorId, String.valueOf(handledErrorLog.getId()));
/* Then the attachment. */
assertSame(textAttachment, log.getAllValues().get(1));
}
Aggregations