Search in sources :

Example 41 with Log

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

the class DefaultChannelTest method packageManagerIsBroken.

@Test
public void packageManagerIsBroken() throws Persistence.PersistenceException, DeviceInfoHelper.DeviceInfoException {
    /* Setup mocking to make device properties generation fail. */
    when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenThrow(new DeviceInfoHelper.DeviceInfoException("mock", new PackageManager.NameNotFoundException()));
    Persistence persistence = mock(Persistence.class);
    @SuppressWarnings("ConstantConditions") DefaultChannel channel = new DefaultChannel(mock(Context.class), null, persistence, mock(IngestionHttp.class));
    channel.addGroup(TEST_GROUP, 50, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null);
    Channel.Listener listener = mock(Channel.Listener.class);
    channel.addListener(listener);
    /* Enqueue a log: listener is called before but then attaching device properties fails before saving the log. */
    Log log = mock(Log.class);
    channel.enqueue(log, TEST_GROUP);
    verify(listener).onEnqueuingLog(log, TEST_GROUP);
    verify(persistence, never()).putLog(TEST_GROUP, log);
}
Also used : Context(android.content.Context) Persistence(com.microsoft.azure.mobile.persistence.Persistence) IngestionHttp(com.microsoft.azure.mobile.ingestion.IngestionHttp) MobileCenterLog(com.microsoft.azure.mobile.utils.MobileCenterLog) Log(com.microsoft.azure.mobile.ingestion.models.Log) DeviceInfoHelper(com.microsoft.azure.mobile.utils.DeviceInfoHelper) Test(org.junit.Test)

Example 42 with Log

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

the class DefaultChannelTest method shutdown.

@Test
public void shutdown() throws Exception {
    Persistence mockPersistence = mock(Persistence.class);
    IngestionHttp mockIngestion = mock(IngestionHttp.class);
    Channel.GroupListener mockListener = mock(Channel.GroupListener.class);
    DatabasePersistenceAsync mockPersistenceAsync = spy(new DatabasePersistenceAsync(mockPersistence));
    whenNew(DatabasePersistenceAsync.class).withArguments(mockPersistence).thenReturn(mockPersistenceAsync);
    when(mockPersistence.getLogs(any(String.class), anyInt(), Matchers.<List<Log>>any())).then(getGetLogsAnswer(1));
    DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), mockPersistence, mockIngestion);
    channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, mockListener);
    /* Enqueuing 1 event. */
    channel.enqueue(mock(Log.class), TEST_GROUP);
    verify(mockListener).onBeforeSending(notNull(Log.class));
    channel.shutdown();
    verify(mockListener, never()).onFailure(any(Log.class), any(Exception.class));
    verify(mockPersistence).clearPendingLogState();
    verify(mockPersistenceAsync).waitForCurrentTasksToComplete(DefaultChannel.SHUTDOWN_TIMEOUT);
}
Also used : Persistence(com.microsoft.azure.mobile.persistence.Persistence) Context(android.content.Context) IngestionHttp(com.microsoft.azure.mobile.ingestion.IngestionHttp) MobileCenterLog(com.microsoft.azure.mobile.utils.MobileCenterLog) Log(com.microsoft.azure.mobile.ingestion.models.Log) Matchers.anyString(org.mockito.Matchers.anyString) DatabasePersistenceAsync(com.microsoft.azure.mobile.persistence.DatabasePersistenceAsync) SocketException(java.net.SocketException) IOException(java.io.IOException) HttpException(com.microsoft.azure.mobile.http.HttpException) CancellationException(com.microsoft.azure.mobile.CancellationException) Test(org.junit.Test)

Example 43 with Log

use of com.microsoft.azure.mobile.ingestion.models.Log 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 : Log(com.microsoft.azure.mobile.ingestion.models.Log) AbstractLog(com.microsoft.azure.mobile.ingestion.models.AbstractLog) AbstractLog(com.microsoft.azure.mobile.ingestion.models.AbstractLog) LogContainer(com.microsoft.azure.mobile.ingestion.models.LogContainer) Test(org.junit.Test)

Example 44 with Log

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

the class DatabasePersistenceAsyncTest method getLogs.

@Test
public void getLogs() {
    int limit = 35;
    List<Log> outLogs = new ArrayList<>();
    String batchId = UUID.randomUUID().toString();
    when(mPersistence.getLogs(GROUP, limit, outLogs)).thenReturn(batchId);
    mDatabase.getLogs(GROUP, limit, outLogs, mCallback);
    verify(mPersistence).getLogs(GROUP, limit, outLogs);
    verify(mCallback).onSuccess(batchId);
}
Also used : MobileCenterLog(com.microsoft.azure.mobile.utils.MobileCenterLog) Log(com.microsoft.azure.mobile.ingestion.models.Log) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 45 with Log

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

the class LogSerializerAndroidTest method customPropertiesLog.

@Test
public void customPropertiesLog() throws JSONException {
    CustomPropertiesLog log = new CustomPropertiesLog();
    Map<String, Object> properties = new HashMap<>();
    properties.put("t1", "test");
    properties.put("t2", new Date(0));
    properties.put("t3", 0);
    properties.put("t4", false);
    properties.put("t5", null);
    log.setProperties(properties);
    UUID sid = UUIDUtils.randomUUID();
    log.setSid(sid);
    /* Verify serialize and deserialize. */
    LogSerializer serializer = new DefaultLogSerializer();
    serializer.addLogFactory(CustomPropertiesLog.TYPE, new CustomPropertiesLogFactory());
    String payload = serializer.serializeLog(log);
    Log actualContainer = serializer.deserializeLog(payload);
    Assert.assertEquals(log, actualContainer);
}
Also used : HashMap(java.util.HashMap) Log(com.microsoft.azure.mobile.ingestion.models.Log) CustomPropertiesLog(com.microsoft.azure.mobile.ingestion.models.CustomPropertiesLog) StartServiceLog(com.microsoft.azure.mobile.ingestion.models.StartServiceLog) UUID(java.util.UUID) Date(java.util.Date) CustomPropertiesLog(com.microsoft.azure.mobile.ingestion.models.CustomPropertiesLog) Test(org.junit.Test)

Aggregations

Log (com.microsoft.azure.mobile.ingestion.models.Log)59 Test (org.junit.Test)44 MobileCenterLog (com.microsoft.azure.mobile.utils.MobileCenterLog)37 ArrayList (java.util.ArrayList)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 Context (android.content.Context)18 UUID (java.util.UUID)18 EventLog (com.microsoft.azure.mobile.analytics.ingestion.models.EventLog)13 LogSerializer (com.microsoft.azure.mobile.ingestion.models.json.LogSerializer)13 StartSessionLog (com.microsoft.azure.mobile.analytics.ingestion.models.StartSessionLog)12 LogContainer (com.microsoft.azure.mobile.ingestion.models.LogContainer)12 DefaultLogSerializer (com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer)11 Persistence (com.microsoft.azure.mobile.persistence.Persistence)11 Matchers.anyString (org.mockito.Matchers.anyString)10 IOException (java.io.IOException)9 Channel (com.microsoft.azure.mobile.channel.Channel)8 IngestionHttp (com.microsoft.azure.mobile.ingestion.IngestionHttp)8 StartServiceLog (com.microsoft.azure.mobile.ingestion.models.StartServiceLog)8 JSONException (org.json.JSONException)8 MediumTest (android.support.test.filters.MediumTest)7