Search in sources :

Example 6 with LogContainer

use of com.microsoft.appcenter.ingestion.models.LogContainer in project mobile-center-sdk-android by Microsoft.

the class LogContainerTest method compareLogContainer.

@Test
public void compareLogContainer() {
    LogContainer container1 = new LogContainer();
    LogContainer container2 = new LogContainer();
    TestUtils.compareSelfNullClass(container1);
    TestUtils.checkEquals(container1, container2);
    Log log1 = new AbstractLog() {

        @Override
        public String getType() {
            return "null";
        }
    };
    log1.setSid(UUID.randomUUID());
    container1.setLogs(Collections.singletonList(log1));
    TestUtils.compareSelfNullClass(container1);
    TestUtils.checkNotEquals(container1, container2);
    container2.setLogs(Collections.singletonList(log1));
    TestUtils.compareSelfNullClass(container1);
    TestUtils.checkEquals(container1, container2);
    Log log2 = new AbstractLog() {

        @Override
        public String getType() {
            return null;
        }
    };
    log2.setSid(UUID.randomUUID());
    container2.setLogs(Collections.singletonList(log2));
    TestUtils.compareSelfNullClass(container1);
    TestUtils.checkNotEquals(container1, container2);
}
Also used : AbstractLog(com.microsoft.appcenter.ingestion.models.AbstractLog) Log(com.microsoft.appcenter.ingestion.models.Log) AbstractLog(com.microsoft.appcenter.ingestion.models.AbstractLog) LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) Test(org.junit.Test)

Example 7 with LogContainer

use of com.microsoft.appcenter.ingestion.models.LogContainer in project mobile-center-sdk-android by Microsoft.

the class DistributeSerializerTest method serialize.

@Test
public void serialize() throws JSONException {
    LogContainer expectedContainer = new LogContainer();
    List<Log> logs = new ArrayList<>();
    {
        DistributionStartSessionLog log = new DistributionStartSessionLog();
        log.setTimestamp(new Date());
        logs.add(log);
    }
    expectedContainer.setLogs(logs);
    UUID sid = UUIDUtils.randomUUID();
    for (Log log : logs) {
        log.setSid(sid);
    }
    /* Serialize and deserialize logs container. */
    LogSerializer serializer = new DefaultLogSerializer();
    serializer.addLogFactory(DistributionStartSessionLog.TYPE, new DistributionStartSessionLogFactory());
    String payload = serializer.serializeContainer(expectedContainer);
    LogContainer actualContainer = serializer.deserializeContainer(payload);
    /* Verify that logs container successfully deserialized. */
    Assert.assertEquals(expectedContainer, actualContainer);
}
Also used : DistributionStartSessionLogFactory(com.microsoft.appcenter.distribute.ingestion.models.json.DistributionStartSessionLogFactory) DistributionStartSessionLog(com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog) Log(com.microsoft.appcenter.ingestion.models.Log) DistributionStartSessionLog(com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog) ArrayList(java.util.ArrayList) LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) DefaultLogSerializer(com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer) LogSerializer(com.microsoft.appcenter.ingestion.models.json.LogSerializer) UUID(java.util.UUID) Date(java.util.Date) DefaultLogSerializer(com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer) Test(org.junit.Test)

Example 8 with LogContainer

use of com.microsoft.appcenter.ingestion.models.LogContainer in project mobile-center-sdk-android by Microsoft.

the class JSONUtilsAndroidTest method serializeContainerWithDefaultWriter.

@Test
public void serializeContainerWithDefaultWriter() throws JSONException {
    /* Create a mock log container. */
    LogContainer mockContainer = mock(LogContainer.class);
    /* Set log level to VERBOSE to instantiate JSONStringer for pretty JSON string. */
    AppCenterLog.setLogLevel(Log.VERBOSE);
    LogSerializer serializer = new DefaultLogSerializer();
    String json = serializer.serializeContainer(mockContainer);
    /* Remove new lines and spaces. */
    json = json.replace("\n", "").replace(" ", "");
    /* Set log level to ERROR to instantiate JSONStringer without indentations. */
    AppCenterLog.setLogLevel(Log.ERROR);
    /* Verify. */
    assertEquals(json, serializer.serializeContainer(mockContainer));
}
Also used : LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) Test(org.junit.Test)

Example 9 with LogContainer

use of com.microsoft.appcenter.ingestion.models.LogContainer in project mobile-center-sdk-android by Microsoft.

the class LogSerializerAndroidTest method emptyLogs.

@Test
public void emptyLogs() throws JSONException {
    LogContainer expectedContainer = new LogContainer();
    expectedContainer.setLogs(Collections.<Log>emptyList());
    LogSerializer serializer = new DefaultLogSerializer();
    String payload = serializer.serializeContainer(expectedContainer);
    android.util.Log.v(TAG, payload);
    LogContainer actualContainer = serializer.deserializeContainer(payload);
    Assert.assertEquals(expectedContainer, actualContainer);
}
Also used : LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) Test(org.junit.Test)

Example 10 with LogContainer

use of com.microsoft.appcenter.ingestion.models.LogContainer in project mobile-center-sdk-android by Microsoft.

the class LogSerializerAndroidTest method oneLog.

@Test
public void oneLog() throws JSONException {
    LogContainer expectedContainer = AndroidTestUtils.generateMockLogContainer();
    LogSerializer serializer = new DefaultLogSerializer();
    serializer.addLogFactory(MOCK_LOG_TYPE, new MockLogFactory());
    String payload = serializer.serializeContainer(expectedContainer);
    android.util.Log.v(TAG, payload);
    LogContainer actualContainer = serializer.deserializeContainer(payload);
    Assert.assertEquals(expectedContainer, actualContainer);
    Assert.assertEquals(expectedContainer.hashCode(), actualContainer.hashCode());
}
Also used : LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) Test(org.junit.Test)

Aggregations

LogContainer (com.microsoft.appcenter.ingestion.models.LogContainer)12 Test (org.junit.Test)9 Log (com.microsoft.appcenter.ingestion.models.Log)8 ArrayList (java.util.ArrayList)7 LogSerializer (com.microsoft.appcenter.ingestion.models.json.LogSerializer)5 UUID (java.util.UUID)5 ServiceCallback (com.microsoft.appcenter.http.ServiceCallback)3 DefaultLogSerializer (com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer)3 AppCenterLog (com.microsoft.appcenter.utils.AppCenterLog)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Context (android.content.Context)2 NonNull (android.support.annotation.NonNull)2 HttpClientNetworkStateHandler (com.microsoft.appcenter.http.HttpClientNetworkStateHandler)2 ServiceCall (com.microsoft.appcenter.http.ServiceCall)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 MainThread (android.support.annotation.MainThread)1