Search in sources :

Example 6 with BooleanTypedProperty

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

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

the class PropertyConfiguratorTest method typedProperty.

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

Example 8 with BooleanTypedProperty

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

the class AnalyticsValidatorForEventLogTest method shouldNotFilterNonStringTypedProperty.

/**
 * This test case only makes up missing branch in validateProperties when TypedProperty isn't StringTypedProperty.
 */
@Test
public void shouldNotFilterNonStringTypedProperty() {
    String validEventName = "eventName";
    mEventLog.setName(validEventName);
    BooleanTypedProperty property = new BooleanTypedProperty();
    property.setName("name");
    property.setValue(true);
    mEventLog.setTypedProperties(Collections.<TypedProperty>singletonList(property));
    assertFalse(mAnalyticsValidator.shouldFilter(mEventLog));
    assertEquals(validEventName, mEventLog.getName());
    assertEquals(1, mEventLog.getTypedProperties().size());
    BooleanTypedProperty booleanProperty = (BooleanTypedProperty) mEventLog.getTypedProperties().iterator().next();
    assertEquals("name", booleanProperty.getName());
    assertTrue(booleanProperty.getValue());
}
Also used : BooleanTypedProperty(com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty) TestUtils.generateString(com.microsoft.appcenter.test.TestUtils.generateString) Test(org.junit.Test)

Example 9 with BooleanTypedProperty

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

the class EventPropertiesTest method setBoolean.

@Test
public void setBoolean() {
    String key = "test";
    EventProperties properties = new EventProperties();
    assertEquals(0, properties.getProperties().size());
    /* Normal value. */
    properties.set(key, false);
    assertEquals(1, properties.getProperties().size());
    BooleanTypedProperty expected = new BooleanTypedProperty();
    expected.setName(key);
    expected.setValue(false);
    verifyStatic(never());
    AppCenterLog.error(eq(Analytics.LOG_TAG), anyString());
}
Also used : BooleanTypedProperty(com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with BooleanTypedProperty

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

BooleanTypedProperty (com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty)11 DateTimeTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty)7 DoubleTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty)7 LongTypedProperty (com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty)7 StringTypedProperty (com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty)7 Test (org.junit.Test)7 TypedProperty (com.microsoft.appcenter.ingestion.models.properties.TypedProperty)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)2 TestUtils.generateString (com.microsoft.appcenter.test.TestUtils.generateString)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