Search in sources :

Example 11 with StringTypedProperty

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

the class CommonSchemaDataUtilsAndroidTest method invalidBaseData.

@Test
public void invalidBaseData() {
    /* When using invalid base data. */
    MockCommonSchemaLog log = new MockCommonSchemaLog();
    log.setExt(new Extensions());
    List<TypedProperty> properties = new ArrayList<>();
    StringTypedProperty a = new StringTypedProperty();
    a.setName("baseData");
    a.setValue("myData");
    properties.add(a);
    CommonSchemaDataUtils.addCommonSchemaData(properties, log);
    /* Check data and metadata is missing type. */
    assertEquals(0, log.getData().getProperties().length());
    assertNull(log.getExt().getMetadata());
}
Also used : ArrayList(java.util.ArrayList) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) DoubleTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty) LongTypedProperty(com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty) BooleanTypedProperty(com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) TypedProperty(com.microsoft.appcenter.ingestion.models.properties.TypedProperty) DateTimeTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty) Test(org.junit.Test)

Example 12 with StringTypedProperty

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

the class CommonSchemaDataUtilsAndroidTest method overrideMetadataCleanup.

@Test
public void overrideMetadataCleanup() throws JSONException {
    MockCommonSchemaLog log = new MockCommonSchemaLog();
    List<TypedProperty> properties = new ArrayList<>();
    LongTypedProperty a = new LongTypedProperty();
    a.setName("a.b.c");
    a.setValue(1);
    properties.add(a);
    StringTypedProperty b = new StringTypedProperty();
    b.setName("a.b");
    b.setValue("2");
    properties.add(b);
    DoubleTypedProperty c = new DoubleTypedProperty();
    c.setName("a.c");
    c.setValue(3.14);
    properties.add(c);
    CommonSchemaDataUtils.addCommonSchemaData(properties, log);
    /* Check data. */
    JSONObject aData = new JSONObject();
    aData.put("b", "2");
    aData.put("c", 3.14);
    JSONObject expectedData = new JSONObject();
    expectedData.put("a", aData);
    assertEquals(expectedData.toString(), log.getData().getProperties().toString());
    /* Check metadata contains only a.c. */
    JSONObject aFields = new JSONObject();
    aFields.put("c", DATA_TYPE_DOUBLE);
    JSONObject aMetadata = new JSONObject();
    aMetadata.put(METADATA_FIELDS, aFields);
    JSONObject rootFields = new JSONObject();
    rootFields.put("a", aMetadata);
    JSONObject expectedMetadata = new JSONObject();
    expectedMetadata.put(METADATA_FIELDS, rootFields);
    assertEquals(expectedMetadata.toString(), log.getExt().getMetadata().getMetadata().toString());
}
Also used : DoubleTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty) LongTypedProperty(com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) DoubleTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty) LongTypedProperty(com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty) BooleanTypedProperty(com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) TypedProperty(com.microsoft.appcenter.ingestion.models.properties.TypedProperty) DateTimeTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty) Test(org.junit.Test)

Example 13 with StringTypedProperty

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

the class CommonSchemaDataUtilsTest method coverJSONException.

@Test
public void coverJSONException() throws Exception {
    /* Fake JSON exception to cover the checked exception that never happens. */
    JSONObject value = mock(JSONObject.class);
    whenNew(JSONObject.class).withNoArguments().thenReturn(value);
    when(value.put(anyString(), any())).thenThrow(new JSONException("mock"));
    CommonSchemaLog commonSchemaLog = new MockCommonSchemaLog();
    List<TypedProperty> properties = new ArrayList<>();
    StringTypedProperty stringTypedProperty = new StringTypedProperty();
    stringTypedProperty.setName("a");
    stringTypedProperty.setValue("b");
    properties.add(stringTypedProperty);
    CommonSchemaDataUtils.addCommonSchemaData(properties, commonSchemaLog);
    assertEquals(0, commonSchemaLog.getData().getProperties().length());
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) TypedProperty(com.microsoft.appcenter.ingestion.models.properties.TypedProperty) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with StringTypedProperty

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

the class AnalyticsTest method trackEventFromAppWithEventProperties.

@Test
public void trackEventFromAppWithEventProperties() {
    Analytics analytics = Analytics.getInstance();
    Channel channel = mock(Channel.class);
    ArgumentCaptor<EventLog> argumentCaptor = ArgumentCaptor.forClass(EventLog.class);
    analytics.onStarting(mAppCenterHandler);
    analytics.onStarted(mock(Context.class), channel, "", null, true);
    /* Prepare typed properties. */
    Date date = new Date();
    StringTypedProperty stringTypedProperty = new StringTypedProperty();
    stringTypedProperty.setName("n0");
    stringTypedProperty.setValue("value");
    DateTimeTypedProperty dateTimeTypedProperty = new DateTimeTypedProperty();
    dateTimeTypedProperty.setName("n1");
    dateTimeTypedProperty.setValue(date);
    LongTypedProperty longTypedProperty = new LongTypedProperty();
    longTypedProperty.setName("n2");
    longTypedProperty.setValue(0);
    DoubleTypedProperty doubleTypedProperty = new DoubleTypedProperty();
    doubleTypedProperty.setName("n3");
    doubleTypedProperty.setValue(0);
    BooleanTypedProperty booleanTypedProperty = new BooleanTypedProperty();
    booleanTypedProperty.setName("n4");
    booleanTypedProperty.setValue(true);
    /* Send event with non-empty EventProperties. */
    EventProperties eventProperties = new EventProperties();
    eventProperties.set("n0", "value");
    eventProperties.set("n1", date);
    eventProperties.set("n2", 0L);
    eventProperties.set("n3", 0d);
    eventProperties.set("n4", true);
    Analytics.trackEvent("eventName", eventProperties);
    verify(channel).enqueue(argumentCaptor.capture(), anyString(), eq(DEFAULTS));
    assertNotNull(argumentCaptor.getValue());
    assertEquals("eventName", argumentCaptor.getValue().getName());
    assertEquals(stringTypedProperty, argumentCaptor.getValue().getTypedProperties().get(0));
    assertEquals(dateTimeTypedProperty, argumentCaptor.getValue().getTypedProperties().get(1));
    assertEquals(longTypedProperty, argumentCaptor.getValue().getTypedProperties().get(2));
    assertEquals(doubleTypedProperty, argumentCaptor.getValue().getTypedProperties().get(3));
    assertEquals(booleanTypedProperty, argumentCaptor.getValue().getTypedProperties().get(4));
}
Also used : Context(android.content.Context) UserIdContext(com.microsoft.appcenter.utils.context.UserIdContext) DateTimeTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty) DoubleTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty) LongTypedProperty(com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty) BooleanTypedProperty(com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty) Channel(com.microsoft.appcenter.channel.Channel) EventLog(com.microsoft.appcenter.analytics.ingestion.models.EventLog) CommonSchemaEventLog(com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) Date(java.util.Date) Test(org.junit.Test)

Example 15 with StringTypedProperty

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

the class Analytics method convertProperties.

/**
 * Internal conversion for properties.
 *
 * @param properties input properties.
 * @return copy as a typed list.
 */
private static List<TypedProperty> convertProperties(Map<String, String> properties) {
    if (properties == null) {
        return null;
    }
    List<TypedProperty> typedProperties = new ArrayList<>(properties.size());
    for (Map.Entry<String, String> property : properties.entrySet()) {
        StringTypedProperty typedProperty = new StringTypedProperty();
        typedProperty.setName(property.getKey());
        typedProperty.setValue(property.getValue());
        typedProperties.add(typedProperty);
    }
    return typedProperties;
}
Also used : ArrayList(java.util.ArrayList) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) HashMap(java.util.HashMap) Map(java.util.Map) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) TypedProperty(com.microsoft.appcenter.ingestion.models.properties.TypedProperty)

Aggregations

StringTypedProperty (com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty)25 TypedProperty (com.microsoft.appcenter.ingestion.models.properties.TypedProperty)17 Test (org.junit.Test)17 BooleanTypedProperty (com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty)16 DateTimeTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty)16 DoubleTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty)16 LongTypedProperty (com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty)16 ArrayList (java.util.ArrayList)16 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)5 TestUtils.generateString (com.microsoft.appcenter.test.TestUtils.generateString)5 JSONObject (org.json.JSONObject)5 Context (android.content.Context)3 CommonSchemaEventLog (com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog)3 Channel (com.microsoft.appcenter.channel.Channel)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Matchers.anyString (org.mockito.Matchers.anyString)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 UserIdContext (com.microsoft.appcenter.utils.context.UserIdContext)2 PageLog (com.microsoft.appcenter.analytics.ingestion.models.PageLog)1