Search in sources :

Example 6 with DateTimeTypedProperty

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

the class CommonSchemaDataUtilsAndroidTest method dateTimeTypedProperty.

@Test
public void dateTimeTypedProperty() throws JSONException {
    MockCommonSchemaLog log = new MockCommonSchemaLog();
    List<TypedProperty> properties = new ArrayList<>();
    DateTimeTypedProperty property = new DateTimeTypedProperty();
    property.setName("a");
    property.setValue(new Date(100));
    properties.add(property);
    CommonSchemaDataUtils.addCommonSchemaData(properties, log);
    /* Check data. */
    assertEquals(1, log.getData().getProperties().length());
    assertEquals(new Date(100), JSONDateUtils.toDate(log.getData().getProperties().getString("a")));
    /* Check metadata. */
    JSONObject expectedMetadata = new JSONObject();
    JSONObject a = new JSONObject();
    a.put("a", DATA_TYPE_DATETIME);
    expectedMetadata.put(METADATA_FIELDS, a);
    assertNotNull(log.getExt());
    assertNotNull(log.getExt().getMetadata());
    assertEquals(expectedMetadata.toString(), log.getExt().getMetadata().getMetadata().toString());
}
Also used : DateTimeTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) Date(java.util.Date) 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 7 with DateTimeTypedProperty

use of com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty 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 8 with DateTimeTypedProperty

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

the class PropertyConfiguratorTest method typedProperty.

@SuppressWarnings("SameParameterValue")
private static DateTimeTypedProperty typedProperty(String name, Date value) {
    DateTimeTypedProperty typedProperty = new DateTimeTypedProperty();
    typedProperty.setName(name);
    typedProperty.setValue(value);
    return typedProperty;
}
Also used : DateTimeTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty)

Example 9 with DateTimeTypedProperty

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

the class CommonSchemaDataUtils method validateProperty.

/**
 * Validate typed property.
 *
 * @param property typed property.
 * @return property value.
 * @throws IllegalArgumentException if the property is invalid.
 * @throws JSONException            if JSON date formatting fails (never happens).
 */
private static Object validateProperty(TypedProperty property) throws IllegalArgumentException, JSONException {
    /* Validate key not null. */
    String key = property.getName();
    if (key == null) {
        throw new IllegalArgumentException("Property key cannot be null.");
    }
    /* Validate baseType. */
    if (key.equals(BASE_TYPE) && !(property instanceof StringTypedProperty)) {
        throw new IllegalArgumentException("baseType must be a string.");
    }
    if (key.startsWith(BASE_TYPE + ".")) {
        throw new IllegalArgumentException("baseType must be a string.");
    }
    /* Validate baseData is an object, meaning it has at least 1 dot. */
    if (key.equals(BASE_DATA)) {
        throw new IllegalArgumentException("baseData must be an object.");
    }
    /* Get value from property. */
    Object value;
    if (property instanceof StringTypedProperty) {
        StringTypedProperty stringTypedProperty = (StringTypedProperty) property;
        value = stringTypedProperty.getValue();
    } else if (property instanceof LongTypedProperty) {
        LongTypedProperty longTypedProperty = (LongTypedProperty) property;
        value = longTypedProperty.getValue();
    } else if (property instanceof DoubleTypedProperty) {
        DoubleTypedProperty doubleTypedProperty = (DoubleTypedProperty) property;
        value = doubleTypedProperty.getValue();
    } else if (property instanceof DateTimeTypedProperty) {
        value = JSONDateUtils.toString(((DateTimeTypedProperty) property).getValue());
    } else if (property instanceof BooleanTypedProperty) {
        BooleanTypedProperty booleanTypedProperty = (BooleanTypedProperty) property;
        value = booleanTypedProperty.getValue();
    } else {
        throw new IllegalArgumentException("Unsupported property type: " + property.getType());
    }
    /* Validate value not null. */
    if (value == null) {
        throw new IllegalArgumentException("Value of property with key '" + key + "' cannot be null.");
    }
    return value;
}
Also used : DoubleTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty) DateTimeTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty) LongTypedProperty(com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty) BooleanTypedProperty(com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty) JSONObject(org.json.JSONObject) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty)

Aggregations

DateTimeTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty)9 BooleanTypedProperty (com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty)6 DoubleTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty)6 LongTypedProperty (com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty)6 StringTypedProperty (com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty)6 Date (java.util.Date)5 Test (org.junit.Test)5 TypedProperty (com.microsoft.appcenter.ingestion.models.properties.TypedProperty)3 ArrayList (java.util.ArrayList)3 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)2 JSONObject (org.json.JSONObject)2 Context (android.content.Context)1 PageLog (com.microsoft.appcenter.analytics.ingestion.models.PageLog)1 StartSessionLog (com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog)1 EventLogFactory (com.microsoft.appcenter.analytics.ingestion.models.json.EventLogFactory)1 PageLogFactory (com.microsoft.appcenter.analytics.ingestion.models.json.PageLogFactory)1 StartSessionLogFactory (com.microsoft.appcenter.analytics.ingestion.models.json.StartSessionLogFactory)1 CommonSchemaEventLog (com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog)1 Channel (com.microsoft.appcenter.channel.Channel)1 Device (com.microsoft.appcenter.ingestion.models.Device)1