use of com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty 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.StringTypedProperty 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());
}
use of com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty in project mobile-center-sdk-android by Microsoft.
the class AnalyticsValidatorForEventLogTest method shouldFilterTooManyProperties.
@Test
public void shouldFilterTooManyProperties() {
final String validEventName = "eventName";
mEventLog.setName(validEventName);
final String validPropertyItem = "valid";
List<TypedProperty> properties = new ArrayList<>();
for (int i = 0; i < 30; i++) {
StringTypedProperty property = new StringTypedProperty();
property.setName(validPropertyItem + i);
property.setValue(validPropertyItem);
properties.add(property);
}
mEventLog.setTypedProperties(properties);
assertFalse(mAnalyticsValidator.shouldFilter(mEventLog));
assertEquals(validEventName, mEventLog.getName());
assertEquals(MAX_PROPERTY_COUNT, mEventLog.getTypedProperties().size());
}
use of com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty in project mobile-center-sdk-android by Microsoft.
the class EventLogFactoryTest method convertEventWithoutProperties.
@Test
@PrepareForTest({ PartAUtils.class, CommonSchemaDataUtils.class })
public void convertEventWithoutProperties() {
/* Mock utilities. */
mockStatic(PartAUtils.class);
mockStatic(CommonSchemaDataUtils.class);
/* Create event log. */
EventLog log = new EventLog();
log.setName("test");
/* Old properties are ignored. */
Map<String, String> oldProperties = new HashMap<>();
oldProperties.put("ignored", "ignored");
log.setProperties(oldProperties);
/* Set typed properties. */
List<TypedProperty> properties = new ArrayList<>();
StringTypedProperty stringTypedProperty = new StringTypedProperty();
stringTypedProperty.setName("a");
stringTypedProperty.setValue("b");
properties.add(stringTypedProperty);
log.setTypedProperties(properties);
/* With 2 targets. */
log.addTransmissionTarget("t1");
log.addTransmissionTarget("t2");
/* And with a tag. */
Object tag = new Object();
log.setTag(tag);
/* When we convert logs. */
Collection<CommonSchemaLog> convertedLogs = new EventLogFactory().toCommonSchemaLogs(log);
/* Check number of logs: 1 per target. */
assertNotNull(convertedLogs);
assertEquals(2, convertedLogs.size());
/* For each target. */
for (CommonSchemaLog commonSchemaLog : convertedLogs) {
/* Check name was added. */
verifyStatic();
PartAUtils.setName(same(commonSchemaLog), eq("test"));
/* Check tag was added. */
assertSame(tag, commonSchemaLog.getTag());
}
/* Check Part A was added with target tokens. */
verifyStatic();
PartAUtils.addPartAFromLog(eq(log), notNull(CommonSchemaLog.class), eq("t1"));
verifyStatic();
PartAUtils.addPartAFromLog(eq(log), notNull(CommonSchemaLog.class), eq("t2"));
/* Check data was added with typed properties (and thus not old ones). */
verifyStatic(times(2));
CommonSchemaDataUtils.addCommonSchemaData(eq(properties), notNull(CommonSchemaLog.class));
}
use of com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty in project mobile-center-sdk-android by Microsoft.
the class EventPropertiesTest method setString.
@Test
public void setString() {
String key = "test";
EventProperties properties = new EventProperties();
assertEquals(0, properties.getProperties().size());
/* Null value. */
properties.set(key, (String) null);
assertEquals(0, properties.getProperties().size());
verifyStatic(times(1));
AppCenterLog.error(eq(Analytics.LOG_TAG), anyString());
/* Normal value. */
String normalValue = "test";
properties.set(key, normalValue);
assertEquals(1, properties.getProperties().size());
StringTypedProperty expected = new StringTypedProperty();
expected.setName(key);
expected.setValue(normalValue);
assertEquals(expected, properties.getProperties().get(key));
verifyStatic(times(1));
AppCenterLog.error(eq(Analytics.LOG_TAG), anyString());
}
Aggregations