Search in sources :

Example 1 with CustomPropertiesLog

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

the class LogSerializerAndroidTest method serializeWithoutProperties.

@Test(expected = JSONException.class)
public void serializeWithoutProperties() throws JSONException {
    LogSerializer serializer = new DefaultLogSerializer();
    CustomPropertiesLog invalidTypeLog = new CustomPropertiesLog();
    invalidTypeLog.setTimestamp(new Date());
    serializer.serializeLog(invalidTypeLog);
}
Also used : Date(java.util.Date) CustomPropertiesLog(com.microsoft.appcenter.ingestion.models.CustomPropertiesLog) Test(org.junit.Test)

Example 2 with CustomPropertiesLog

use of com.microsoft.appcenter.ingestion.models.CustomPropertiesLog 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);
    log.setTimestamp(new Date());
    /* 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) StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) CustomPropertiesLog(com.microsoft.appcenter.ingestion.models.CustomPropertiesLog) Log(com.microsoft.appcenter.ingestion.models.Log) UUID(java.util.UUID) Date(java.util.Date) CustomPropertiesLog(com.microsoft.appcenter.ingestion.models.CustomPropertiesLog) Test(org.junit.Test)

Example 3 with CustomPropertiesLog

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

the class AppCenter method queueCustomProperties.

/**
 * Send custom properties.
 * Unit test requires top level methods when PowerMock.whenNew.
 *
 * @param properties properties to send.
 */
@WorkerThread
private void queueCustomProperties(@NonNull Map<String, Object> properties) {
    CustomPropertiesLog customPropertiesLog = new CustomPropertiesLog();
    customPropertiesLog.setProperties(properties);
    mChannel.enqueue(customPropertiesLog, CORE_GROUP);
}
Also used : CustomPropertiesLog(com.microsoft.appcenter.ingestion.models.CustomPropertiesLog) WorkerThread(android.support.annotation.WorkerThread)

Example 4 with CustomPropertiesLog

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

the class AppCenterTest method setCustomPropertiesTest.

@Test
public void setCustomPropertiesTest() throws Exception {
    /* Configure mocking. */
    CustomPropertiesLog log = mock(CustomPropertiesLog.class);
    whenNew(CustomPropertiesLog.class).withAnyArguments().thenReturn(log);
    /* Call before start is forbidden. */
    AppCenter.setCustomProperties(new CustomProperties().clear("test"));
    verify(mChannel, never()).enqueue(eq(log), eq(CORE_GROUP));
    verifyStatic(times(1));
    AppCenterLog.error(eq(LOG_TAG), anyString());
    /* Start. */
    AppCenter.start(mApplication, DUMMY_APP_SECRET, DummyService.class);
    /* Set null. */
    AppCenter.setCustomProperties(null);
    verify(mChannel, never()).enqueue(eq(log), eq(CORE_GROUP));
    verifyStatic(times(2));
    AppCenterLog.error(eq(LOG_TAG), anyString());
    /* Set empty. */
    CustomProperties empty = new CustomProperties();
    AppCenter.setCustomProperties(empty);
    verify(mChannel, never()).enqueue(eq(log), eq(CORE_GROUP));
    verifyStatic(times(3));
    AppCenterLog.error(eq(LOG_TAG), anyString());
    /* Set normal. */
    CustomProperties properties = new CustomProperties();
    properties.set("test", "test");
    AppCenter.setCustomProperties(properties);
    verify(log).setProperties(eq(properties.getProperties()));
    verify(mChannel).enqueue(eq(log), eq(CORE_GROUP));
    /* Call after disabled triggers an error. */
    AppCenter.setEnabled(false);
    AppCenter.setCustomProperties(properties);
    verifyStatic(times(4));
    AppCenterLog.error(eq(LOG_TAG), anyString());
    /* No more log enqueued. */
    verify(mChannel).enqueue(eq(log), eq(CORE_GROUP));
}
Also used : CustomPropertiesLog(com.microsoft.appcenter.ingestion.models.CustomPropertiesLog) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with CustomPropertiesLog

use of com.microsoft.appcenter.ingestion.models.CustomPropertiesLog in project AppCenter-SDK-Android by Microsoft.

the class AppCenter method queueCustomProperties.

/**
 * Send custom properties.
 * Unit test requires top level methods when PowerMock.whenNew.
 *
 * @param properties properties to send.
 */
@WorkerThread
private void queueCustomProperties(@NonNull Map<String, Object> properties) {
    CustomPropertiesLog customPropertiesLog = new CustomPropertiesLog();
    customPropertiesLog.setProperties(properties);
    mChannel.enqueue(customPropertiesLog, CORE_GROUP);
}
Also used : CustomPropertiesLog(com.microsoft.appcenter.ingestion.models.CustomPropertiesLog) WorkerThread(android.support.annotation.WorkerThread)

Aggregations

CustomPropertiesLog (com.microsoft.appcenter.ingestion.models.CustomPropertiesLog)10 Test (org.junit.Test)8 Date (java.util.Date)6 HashMap (java.util.HashMap)4 WorkerThread (android.support.annotation.WorkerThread)2 Log (com.microsoft.appcenter.ingestion.models.Log)2 StartServiceLog (com.microsoft.appcenter.ingestion.models.StartServiceLog)2 UUID (java.util.UUID)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2