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);
}
}
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());
}
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;
}
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());
}
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());
}
Aggregations