Search in sources :

Example 21 with TypedProperty

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

the class EventPropertiesActivity method updatePropertyList.

@SuppressWarnings({ "unchecked", "ConstantConditions" })
private void updatePropertyList() {
    try {
        Field field = getSelectedTarget().getPropertyConfigurator().getClass().getDeclaredField("mEventProperties");
        field.setAccessible(true);
        EventProperties eventProperties;
        try {
            eventProperties = (EventProperties) field.get(getSelectedTarget().getPropertyConfigurator());
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        Method method = eventProperties.getClass().getDeclaredMethod("getProperties");
        method.setAccessible(true);
        Map<String, TypedProperty> properties = (Map<String, TypedProperty>) method.invoke(eventProperties);
        mPropertyListAdapter.mList.clear();
        for (Map.Entry<String, TypedProperty> entry : properties.entrySet()) {
            Object value = entry.getValue().getClass().getMethod("getValue").invoke(entry.getValue());
            mPropertyListAdapter.mList.add(new Pair<>(entry.getKey(), value));
        }
        mListView.setAdapter(mPropertyListAdapter);
        mPropertyListAdapter.notifyDataSetChanged();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : EventProperties(com.microsoft.appcenter.analytics.EventProperties) Method(java.lang.reflect.Method) Field(java.lang.reflect.Field) JSONObject(org.json.JSONObject) Map(java.util.Map) TypedProperty(com.microsoft.appcenter.ingestion.models.properties.TypedProperty)

Example 22 with TypedProperty

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

the class PropertyConfiguratorTest method setCommonEventProperties.

@Test
public void setCommonEventProperties() {
    /* Create transmission target and add property. */
    AnalyticsTransmissionTarget target = Analytics.getTransmissionTarget("test");
    target.getPropertyConfigurator().setEventProperty("key", "value");
    /* Track event without property. */
    target.trackEvent("eventName");
    /* Check event. */
    ArgumentCaptor<EventLog> eventLogArg = ArgumentCaptor.forClass(EventLog.class);
    verify(mChannel).enqueue(eventLogArg.capture(), anyString(), eq(DEFAULTS));
    EventLog log = eventLogArg.getValue();
    assertNotNull(log);
    assertEquals(Collections.singleton("test"), log.getTransmissionTargetTokens());
    assertEquals("eventName", log.getName());
    assertNull(log.getProperties());
    List<TypedProperty> typedProperties = new ArrayList<>();
    typedProperties.add(typedProperty("key", "value"));
    assertEquals(typedProperties, log.getTypedProperties());
}
Also used : EventLog(com.microsoft.appcenter.analytics.ingestion.models.EventLog) CommonSchemaEventLog(com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog) ArrayList(java.util.ArrayList) DateTimeTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty) DoubleTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty) BooleanTypedProperty(com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) LongTypedProperty(com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty) TypedProperty(com.microsoft.appcenter.ingestion.models.properties.TypedProperty) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 23 with TypedProperty

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

Example 24 with TypedProperty

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

the class AnalyticsValidatorForEventLogTest method shouldFilterInvalidPropertyKeys.

@Test
public void shouldFilterInvalidPropertyKeys() {
    final String validEventName = "eventName";
    mEventLog.setName(validEventName);
    List<TypedProperty> properties = new ArrayList<>();
    /* null, null property. */
    StringTypedProperty property = new StringTypedProperty();
    property.setName(null);
    property.setValue(null);
    properties.add(property);
    /* Empty string, null property. */
    property = new StringTypedProperty();
    property.setName("");
    property.setValue(null);
    properties.add(property);
    /* Long string, null property. */
    property = new StringTypedProperty();
    property.setName(generateString(MAX_PROPERTY_ITEM_LENGTH + 1, '*'));
    property.setValue(null);
    properties.add(property);
    /* Invalid string, null property. */
    property = new StringTypedProperty();
    property.setName("1");
    property.setValue(null);
    properties.add(property);
    /* Set typed properties. */
    mEventLog.setTypedProperties(properties);
    assertFalse(mAnalyticsValidator.shouldFilter(mEventLog));
    assertEquals(validEventName, mEventLog.getName());
    assertEquals(0, mEventLog.getTypedProperties().size());
}
Also used : ArrayList(java.util.ArrayList) TestUtils.generateString(com.microsoft.appcenter.test.TestUtils.generateString) 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 25 with TypedProperty

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

the class AnalyticsValidatorForEventLogTest method shouldFilterTooLongStringTypedPropertyStringValue.

@Test
public void shouldFilterTooLongStringTypedPropertyStringValue() {
    String validEventName = "eventName";
    mEventLog.setName(validEventName);
    String longerPropertyItem = generateString(MAX_PROPERTY_ITEM_LENGTH + 1, '*');
    StringTypedProperty originalProperty = new StringTypedProperty();
    originalProperty.setName("regularName");
    originalProperty.setValue(longerPropertyItem);
    List<TypedProperty> typedProperties = new ArrayList<>();
    typedProperties.add(originalProperty);
    mEventLog.setTypedProperties(typedProperties);
    assertFalse(mAnalyticsValidator.shouldFilter(mEventLog));
    assertEquals(validEventName, mEventLog.getName());
    assertEquals(1, mEventLog.getTypedProperties().size());
    StringTypedProperty stringProperty = (StringTypedProperty) mEventLog.getTypedProperties().iterator().next();
    assertEquals("regularName", stringProperty.getName());
    assertEquals(MAX_PROPERTY_ITEM_LENGTH, stringProperty.getValue().length());
    /* Verify original property value reference was not modified. */
    assertSame(longerPropertyItem, originalProperty.getValue());
}
Also used : ArrayList(java.util.ArrayList) TestUtils.generateString(com.microsoft.appcenter.test.TestUtils.generateString) 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)

Aggregations

TypedProperty (com.microsoft.appcenter.ingestion.models.properties.TypedProperty)37 StringTypedProperty (com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty)35 BooleanTypedProperty (com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty)31 DateTimeTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty)31 DoubleTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty)31 LongTypedProperty (com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty)31 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)31 JSONObject (org.json.JSONObject)14 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 CommonSchemaEventLog (com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog)6 TestUtils.generateString (com.microsoft.appcenter.test.TestUtils.generateString)5 Date (java.util.Date)4 HashMap (java.util.HashMap)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Map (java.util.Map)2 JSONException (org.json.JSONException)2 Context (android.content.Context)1 EventProperties (com.microsoft.appcenter.analytics.EventProperties)1