Search in sources :

Example 6 with DefaultLogSerializer

use of com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer in project mobile-center-sdk-android by Microsoft.

the class ErrorModelTest method managedErrorLog.

@Test
public void managedErrorLog() throws JSONException {
    LogSerializer serializer = new DefaultLogSerializer();
    serializer.addLogFactory(ManagedErrorLog.TYPE, ManagedErrorLogFactory.getInstance());
    ManagedErrorLog errorLog1 = new ManagedErrorLog();
    ManagedErrorLog errorLog2 = new ManagedErrorLog();
    compareSelfNullClass(errorLog1);
    checkEquals(errorLog1, errorLog2);
    {
        errorLog1.setId(UUID.randomUUID());
        checkNotEquals(errorLog1, errorLog2);
        checkSerialization(errorLog1, serializer);
        errorLog2.setId(UUID.randomUUID());
        checkNotEquals(errorLog1, errorLog2);
        errorLog2.setId(errorLog1.getId());
        checkEquals(errorLog1, errorLog2);
    }
    {
        errorLog1.setProcessId(1);
        checkNotEquals(errorLog1, errorLog2);
        checkSerialization(errorLog1, serializer);
        errorLog2.setProcessId(2);
        checkNotEquals(errorLog1, errorLog2);
        errorLog2.setProcessId(errorLog1.getProcessId());
        checkEquals(errorLog1, errorLog2);
    }
    {
        errorLog1.setProcessName("1");
        checkNotEquals(errorLog1, errorLog2);
        checkSerialization(errorLog1, serializer);
        errorLog2.setProcessName("2");
        checkNotEquals(errorLog1, errorLog2);
        errorLog2.setProcessName(errorLog1.getProcessName());
        checkEquals(errorLog1, errorLog2);
    }
    {
        errorLog1.setParentProcessId(1);
        checkNotEquals(errorLog1, errorLog2);
        checkSerialization(errorLog1, serializer);
        errorLog2.setParentProcessId(2);
        checkNotEquals(errorLog1, errorLog2);
        errorLog2.setParentProcessId(errorLog1.getParentProcessId());
        checkEquals(errorLog1, errorLog2);
    }
    {
        errorLog1.setParentProcessName("1");
        checkNotEquals(errorLog1, errorLog2);
        checkSerialization(errorLog1, serializer);
        errorLog2.setParentProcessName("2");
        checkNotEquals(errorLog1, errorLog2);
        errorLog2.setParentProcessName(errorLog1.getParentProcessName());
        checkEquals(errorLog1, errorLog2);
    }
    {
        errorLog1.setErrorThreadId(1L);
        checkNotEquals(errorLog1, errorLog2);
        checkSerialization(errorLog1, serializer);
        errorLog2.setErrorThreadId(2L);
        checkNotEquals(errorLog1, errorLog2);
        errorLog2.setErrorThreadId(errorLog1.getErrorThreadId());
        checkEquals(errorLog1, errorLog2);
    }
    {
        errorLog1.setErrorThreadName("1");
        checkNotEquals(errorLog1, errorLog2);
        checkSerialization(errorLog1, serializer);
        errorLog2.setErrorThreadName("2");
        checkNotEquals(errorLog1, errorLog2);
        errorLog2.setErrorThreadName(errorLog1.getErrorThreadName());
        checkEquals(errorLog1, errorLog2);
    }
    {
        errorLog1.setFatal(true);
        checkNotEquals(errorLog1, errorLog2);
        checkSerialization(errorLog1, serializer);
        errorLog2.setFatal(false);
        checkNotEquals(errorLog1, errorLog2);
        errorLog2.setFatal(errorLog1.getFatal());
        checkEquals(errorLog1, errorLog2);
    }
    {
        errorLog1.setAppLaunchTOffset(1L);
        checkNotEquals(errorLog1, errorLog2);
        checkSerialization(errorLog1, serializer);
        errorLog2.setAppLaunchTOffset(2L);
        checkNotEquals(errorLog1, errorLog2);
        errorLog2.setAppLaunchTOffset(errorLog1.getAppLaunchTOffset());
        checkEquals(errorLog1, errorLog2);
    }
    {
        errorLog1.setArchitecture("1");
        checkNotEquals(errorLog1, errorLog2);
        checkSerialization(errorLog1, serializer);
        errorLog2.setArchitecture("2");
        checkNotEquals(errorLog1, errorLog2);
        errorLog2.setArchitecture(errorLog1.getArchitecture());
        checkEquals(errorLog1, errorLog2);
    }
    {
        Exception exception1 = new Exception();
        Exception exception2 = new Exception();
        compareSelfNullClass(exception1);
        checkEquals(exception1, exception2);
        {
            exception1.setType("1");
            checkNotEquals(exception1, exception2);
            checkExceptions(serializer, errorLog1, errorLog2, exception1, exception2);
            exception2.setType("2");
            checkNotEquals(exception1, exception2);
            exception2.setType(exception1.getType());
            checkEquals(exception1, exception2);
        }
        {
            exception1.setMessage("1");
            checkNotEquals(exception1, exception2);
            checkExceptions(serializer, errorLog1, errorLog2, exception1, exception2);
            exception2.setMessage("2");
            checkNotEquals(exception1, exception2);
            exception2.setMessage(exception1.getMessage());
            checkEquals(exception1, exception2);
        }
        {
            exception1.setStackTrace("1");
            checkNotEquals(exception1, exception2);
            checkExceptions(serializer, errorLog1, errorLog2, exception1, exception2);
            exception2.setStackTrace("2");
            checkNotEquals(exception1, exception2);
            exception2.setStackTrace(exception1.getStackTrace());
            checkEquals(exception1, exception2);
        }
        {
            errorLog1.setException(exception1);
            errorLog2.setException(exception2);
            StackFrame frame1 = new StackFrame();
            StackFrame frame2 = new StackFrame();
            compareSelfNullClass(frame1);
            checkEquals(frame1, frame2);
            {
                frame1.setClassName("1");
                checkNotEquals(frame1, frame2);
                checkFrames(serializer, errorLog1, errorLog2, exception1, exception2, frame1, frame2);
                frame2.setClassName("2");
                checkNotEquals(frame1, frame2);
                frame2.setClassName(frame1.getClassName());
                checkEquals(frame1, frame2);
            }
            {
                frame1.setMethodName("1");
                checkNotEquals(frame1, frame2);
                checkFrames(serializer, errorLog1, errorLog2, exception1, exception2, frame1, frame2);
                frame2.setMethodName("2");
                checkNotEquals(frame1, frame2);
                frame2.setMethodName(frame1.getMethodName());
                checkEquals(frame1, frame2);
            }
            {
                frame1.setLineNumber(1);
                checkNotEquals(frame1, frame2);
                checkFrames(serializer, errorLog1, errorLog2, exception1, exception2, frame1, frame2);
                frame2.setLineNumber(2);
                checkNotEquals(frame1, frame2);
                frame2.setLineNumber(frame1.getLineNumber());
                checkEquals(frame1, frame2);
            }
            {
                frame1.setFileName("1");
                checkNotEquals(frame1, frame2);
                checkFrames(serializer, errorLog1, errorLog2, exception1, exception2, frame1, frame2);
                frame2.setFileName("2");
                checkNotEquals(frame1, frame2);
                frame2.setFileName(frame1.getFileName());
                checkEquals(frame1, frame2);
            }
        }
        {
            exception1.setWrapperSdkName("1");
            checkNotEquals(exception1, exception2);
            checkExceptions(serializer, errorLog1, errorLog2, exception1, exception2);
            exception2.setWrapperSdkName("2");
            checkNotEquals(exception1, exception2);
            exception2.setWrapperSdkName(exception1.getWrapperSdkName());
            checkEquals(exception1, exception2);
        }
    }
    {
        Thread thread1 = new Thread();
        Thread thread2 = new Thread();
        compareSelfNullClass(thread1);
        checkEquals(thread1, thread2);
        {
            thread1.setId(1L);
            checkNotEquals(thread1, thread2);
            checkThreads(serializer, errorLog1, errorLog2, thread1, thread2);
            thread2.setId(2L);
            checkNotEquals(thread1, thread2);
            thread2.setId(thread1.getId());
            checkEquals(thread1, thread2);
        }
        {
            thread1.setName("1");
            checkNotEquals(thread1, thread2);
            checkThreads(serializer, errorLog1, errorLog2, thread1, thread2);
            thread2.setName("2");
            checkNotEquals(thread1, thread2);
            thread2.setName(thread1.getName());
            checkEquals(thread1, thread2);
        }
        {
            errorLog1.setThreads(singletonList(thread1));
            errorLog2.setThreads(singletonList(thread2));
            StackFrame frame1 = new StackFrame();
            StackFrame frame2 = new StackFrame();
            compareSelfNullClass(frame1);
            checkEquals(frame1, frame2);
            {
                frame1.setClassName("1");
                checkNotEquals(frame1, frame2);
                checkFrames(serializer, errorLog1, errorLog2, thread1, thread2, frame1, frame2);
                frame2.setClassName("2");
                checkNotEquals(frame1, frame2);
                frame2.setClassName(frame1.getClassName());
                checkEquals(frame1, frame2);
            }
            {
                frame1.setMethodName("1");
                checkNotEquals(frame1, frame2);
                checkFrames(serializer, errorLog1, errorLog2, thread1, thread2, frame1, frame2);
                frame2.setMethodName("2");
                checkNotEquals(frame1, frame2);
                frame2.setMethodName(frame1.getMethodName());
                checkEquals(frame1, frame2);
            }
            {
                frame1.setLineNumber(1);
                checkNotEquals(frame1, frame2);
                checkFrames(serializer, errorLog1, errorLog2, thread1, thread2, frame1, frame2);
                frame2.setLineNumber(2);
                checkNotEquals(frame1, frame2);
                frame2.setLineNumber(frame1.getLineNumber());
                checkEquals(frame1, frame2);
            }
            {
                frame1.setFileName("1");
                checkNotEquals(frame1, frame2);
                checkFrames(serializer, errorLog1, errorLog2, thread1, thread2, frame1, frame2);
                frame2.setFileName("2");
                checkNotEquals(frame1, frame2);
                frame2.setFileName(frame1.getFileName());
                checkEquals(frame1, frame2);
            }
        }
    }
    checkSerialization(errorLog1, serializer);
}
Also used : DefaultLogSerializer(com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer) LogSerializer(com.microsoft.azure.mobile.ingestion.models.json.LogSerializer) DefaultLogSerializer(com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer) JSONException(org.json.JSONException) Test(org.junit.Test)

Example 7 with DefaultLogSerializer

use of com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer in project mobile-center-sdk-android by Microsoft.

the class ErrorModelTest method errorAttachmentLog.

@Test
public void errorAttachmentLog() throws JSONException {
    LogSerializer serializer = new DefaultLogSerializer();
    serializer.addLogFactory(ErrorAttachmentLog.TYPE, ErrorAttachmentLogFactory.getInstance());
    ErrorAttachmentLog attachmentLog1 = new ErrorAttachmentLog();
    ErrorAttachmentLog attachmentLog2 = new ErrorAttachmentLog();
    compareSelfNullClass(attachmentLog1);
    checkEquals(attachmentLog1, attachmentLog2);
    checkEquals(attachmentLog1.getType(), ErrorAttachmentLog.TYPE);
    {
        attachmentLog1.setId(UUID.randomUUID());
        checkNotEquals(attachmentLog1, attachmentLog2);
        attachmentLog2.setId(UUID.randomUUID());
        checkNotEquals(attachmentLog1, attachmentLog2);
        attachmentLog2.setId(attachmentLog1.getId());
        checkEquals(attachmentLog1, attachmentLog2);
    }
    {
        attachmentLog1.setErrorId(UUID.randomUUID());
        checkNotEquals(attachmentLog1, attachmentLog2);
        attachmentLog2.setErrorId(UUID.randomUUID());
        checkNotEquals(attachmentLog1, attachmentLog2);
        attachmentLog2.setErrorId(attachmentLog1.getErrorId());
        checkEquals(attachmentLog1, attachmentLog2);
    }
    {
        attachmentLog1.setContentType("1");
        checkNotEquals(attachmentLog1, attachmentLog2);
        attachmentLog2.setContentType("2");
        checkNotEquals(attachmentLog1, attachmentLog2);
        attachmentLog2.setContentType(attachmentLog1.getContentType());
        checkEquals(attachmentLog1, attachmentLog2);
    }
    {
        attachmentLog1.setFileName("1");
        checkNotEquals(attachmentLog1, attachmentLog2);
        attachmentLog2.setFileName("2");
        checkNotEquals(attachmentLog1, attachmentLog2);
        attachmentLog2.setFileName(attachmentLog1.getFileName());
        checkEquals(attachmentLog1, attachmentLog2);
    }
    {
        attachmentLog1.setData("1".getBytes(CHARSET));
        checkNotEquals(attachmentLog1, attachmentLog2);
        attachmentLog2.setData("2".getBytes(CHARSET));
        checkNotEquals(attachmentLog1, attachmentLog2);
        attachmentLog2.setData(attachmentLog1.getData());
        checkEquals(attachmentLog1, attachmentLog2);
    }
    {
        attachmentLog1.setSid(UUID.randomUUID());
        checkNotEquals(attachmentLog1, attachmentLog2);
        attachmentLog2.setSid(UUID.randomUUID());
        checkNotEquals(attachmentLog1, attachmentLog2);
        attachmentLog2.setSid(attachmentLog1.getSid());
        checkEquals(attachmentLog1, attachmentLog2);
    }
    {
        /* Check serialization without filename. */
        attachmentLog2.setFileName(null);
    }
    {
        checkSerialization(attachmentLog1, serializer);
        checkSerialization(attachmentLog2, serializer);
    }
}
Also used : DefaultLogSerializer(com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer) LogSerializer(com.microsoft.azure.mobile.ingestion.models.json.LogSerializer) DefaultLogSerializer(com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer) Test(org.junit.Test)

Example 8 with DefaultLogSerializer

use of com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer in project mobile-center-sdk-android by Microsoft.

the class PushSerializerTest method serialize.

@Test
public void serialize() throws JSONException {
    LogContainer expectedContainer = new LogContainer();
    List<Log> logs = new ArrayList<>();
    {
        PushInstallationLog log = new PushInstallationLog();
        log.setPushToken("TEST");
        logs.add(log);
    }
    expectedContainer.setLogs(logs);
    UUID sid = UUIDUtils.randomUUID();
    for (Log log : logs) {
        log.setSid(sid);
    }
    LogSerializer serializer = new DefaultLogSerializer();
    serializer.addLogFactory(PushInstallationLog.TYPE, new PushInstallationLogFactory());
    String payload = serializer.serializeContainer(expectedContainer);
    LogContainer actualContainer = serializer.deserializeContainer(payload);
    Assert.assertEquals(expectedContainer, actualContainer);
}
Also used : PushInstallationLog(com.microsoft.azure.mobile.push.ingestion.models.PushInstallationLog) Log(com.microsoft.azure.mobile.ingestion.models.Log) PushInstallationLog(com.microsoft.azure.mobile.push.ingestion.models.PushInstallationLog) ArrayList(java.util.ArrayList) LogContainer(com.microsoft.azure.mobile.ingestion.models.LogContainer) DefaultLogSerializer(com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer) LogSerializer(com.microsoft.azure.mobile.ingestion.models.json.LogSerializer) UUID(java.util.UUID) PushInstallationLogFactory(com.microsoft.azure.mobile.push.ingestion.models.json.PushInstallationLogFactory) DefaultLogSerializer(com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer) Test(org.junit.Test)

Example 9 with DefaultLogSerializer

use of com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer in project mobile-center-sdk-android by Microsoft.

the class AnalyticsSerializerTest method someBatch.

@Test
public void someBatch() throws JSONException {
    LogContainer expectedContainer = new LogContainer();
    Device device = new Device();
    device.setSdkName("mobilecenter.android");
    device.setSdkVersion("1.2.3");
    device.setModel("S5");
    device.setOemName("HTC");
    device.setOsName("Android");
    device.setOsVersion("4.0.3");
    device.setOsBuild("LMY47X");
    device.setOsApiLevel(15);
    device.setLocale("en_US");
    device.setTimeZoneOffset(120);
    device.setScreenSize("800x600");
    device.setAppVersion("3.2.1");
    device.setAppBuild("42");
    List<Log> logs = new ArrayList<>();
    {
        logs.add(new StartSessionLog());
    }
    expectedContainer.setLogs(logs);
    {
        PageLog pageLog = new PageLog();
        pageLog.setName("home");
        logs.add(pageLog);
    }
    {
        PageLog pageLog = new PageLog();
        pageLog.setName("settings");
        pageLog.setProperties(new HashMap<String, String>() {

            {
                put("from", "home_menu");
                put("orientation", "portrait");
            }
        });
        logs.add(pageLog);
    }
    {
        EventLog eventLog = new EventLog();
        eventLog.setId(UUIDUtils.randomUUID());
        eventLog.setName("subscribe");
        logs.add(eventLog);
    }
    {
        EventLog eventLog = new EventLog();
        eventLog.setId(UUIDUtils.randomUUID());
        eventLog.setName("click");
        eventLog.setProperties(new HashMap<String, String>() {

            {
                put("x", "1");
                put("y", "2");
            }
        });
        logs.add(eventLog);
    }
    UUID sid = UUIDUtils.randomUUID();
    for (Log log : logs) {
        log.setSid(sid);
        log.setDevice(device);
    }
    LogSerializer serializer = new DefaultLogSerializer();
    serializer.addLogFactory(StartSessionLog.TYPE, new StartSessionLogFactory());
    serializer.addLogFactory(PageLog.TYPE, new PageLogFactory());
    serializer.addLogFactory(EventLog.TYPE, new EventLogFactory());
    String payload = serializer.serializeContainer(expectedContainer);
    android.util.Log.v(TAG, payload);
    LogContainer actualContainer = serializer.deserializeContainer(payload);
    Assert.assertEquals(expectedContainer, actualContainer);
}
Also used : PageLog(com.microsoft.azure.mobile.analytics.ingestion.models.PageLog) StartSessionLog(com.microsoft.azure.mobile.analytics.ingestion.models.StartSessionLog) Log(com.microsoft.azure.mobile.ingestion.models.Log) EventLog(com.microsoft.azure.mobile.analytics.ingestion.models.EventLog) HashMap(java.util.HashMap) Device(com.microsoft.azure.mobile.ingestion.models.Device) PageLog(com.microsoft.azure.mobile.analytics.ingestion.models.PageLog) EventLog(com.microsoft.azure.mobile.analytics.ingestion.models.EventLog) ArrayList(java.util.ArrayList) PageLogFactory(com.microsoft.azure.mobile.analytics.ingestion.models.json.PageLogFactory) DefaultLogSerializer(com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer) LogSerializer(com.microsoft.azure.mobile.ingestion.models.json.LogSerializer) StartSessionLogFactory(com.microsoft.azure.mobile.analytics.ingestion.models.json.StartSessionLogFactory) StartSessionLog(com.microsoft.azure.mobile.analytics.ingestion.models.StartSessionLog) LogContainer(com.microsoft.azure.mobile.ingestion.models.LogContainer) UUID(java.util.UUID) EventLogFactory(com.microsoft.azure.mobile.analytics.ingestion.models.json.EventLogFactory) DefaultLogSerializer(com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer) Test(org.junit.Test)

Example 10 with DefaultLogSerializer

use of com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer in project mobile-center-sdk-android by Microsoft.

the class DatabasePersistenceAndroidTest method putTooManyLogs.

@Test
public void putTooManyLogs() throws PersistenceException, IOException {
    /* Initialize database persistence. */
    DatabasePersistence persistence = new DatabasePersistence("test-persistence", "putTooManyLogs", 1, 2);
    /* Set a mock log serializer. */
    LogSerializer logSerializer = new DefaultLogSerializer();
    logSerializer.addLogFactory(MOCK_LOG_TYPE, new MockLogFactory());
    persistence.setLogSerializer(logSerializer);
    try {
        /* Generate too many logs and persist. */
        Log log1 = AndroidTestUtils.generateMockLog();
        Log log2 = AndroidTestUtils.generateMockLog();
        Log log3 = AndroidTestUtils.generateMockLog();
        Log log4 = AndroidTestUtils.generateMockLog();
        persistence.putLog("test-p1", log1);
        persistence.putLog("test-p1", log2);
        persistence.putLog("test-p1", log3);
        persistence.putLog("test-p1", log4);
        /* Get logs from persistence. */
        List<Log> outputLogs = new ArrayList<>();
        persistence.getLogs("test-p1", 4, outputLogs);
        assertEquals(2, outputLogs.size());
        assertEquals(log3, outputLogs.get(0));
        assertEquals(log4, outputLogs.get(1));
        assertEquals(2, persistence.countLogs("test-p1"));
    } finally {
        /* Close. */
        //noinspection ThrowFromFinallyBlock
        persistence.close();
    }
}
Also used : MockLogFactory(com.microsoft.azure.mobile.ingestion.models.json.MockLogFactory) Log(com.microsoft.azure.mobile.ingestion.models.Log) ArrayList(java.util.ArrayList) DefaultLogSerializer(com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer) LogSerializer(com.microsoft.azure.mobile.ingestion.models.json.LogSerializer) DefaultLogSerializer(com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Aggregations

DefaultLogSerializer (com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer)11 LogSerializer (com.microsoft.azure.mobile.ingestion.models.json.LogSerializer)10 Test (org.junit.Test)10 Log (com.microsoft.azure.mobile.ingestion.models.Log)8 ArrayList (java.util.ArrayList)8 MediumTest (android.support.test.filters.MediumTest)6 MockLogFactory (com.microsoft.azure.mobile.ingestion.models.json.MockLogFactory)5 SuppressLint (android.annotation.SuppressLint)3 LogContainer (com.microsoft.azure.mobile.ingestion.models.LogContainer)2 UUID (java.util.UUID)2 JSONException (org.json.JSONException)2 Mockito.anyString (org.mockito.Mockito.anyString)2 EventLog (com.microsoft.azure.mobile.analytics.ingestion.models.EventLog)1 PageLog (com.microsoft.azure.mobile.analytics.ingestion.models.PageLog)1 StartSessionLog (com.microsoft.azure.mobile.analytics.ingestion.models.StartSessionLog)1 EventLogFactory (com.microsoft.azure.mobile.analytics.ingestion.models.json.EventLogFactory)1 PageLogFactory (com.microsoft.azure.mobile.analytics.ingestion.models.json.PageLogFactory)1 StartSessionLogFactory (com.microsoft.azure.mobile.analytics.ingestion.models.json.StartSessionLogFactory)1 DefaultChannel (com.microsoft.azure.mobile.channel.DefaultChannel)1 Device (com.microsoft.azure.mobile.ingestion.models.Device)1