use of com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty in project mobile-center-sdk-android by Microsoft.
the class AnalyticsValidatorForEventLogTest method shouldFilterTooLongPropertyKeysOfAnyType.
@Test
public void shouldFilterTooLongPropertyKeysOfAnyType() {
/* Set event name. */
String validEventName = "eventName";
mEventLog.setName(validEventName);
/* Use a long key for every property type. */
String longKey = generateString(MAX_PROPERTY_ITEM_LENGTH + 1, '*');
StringTypedProperty originalStringProperty = new StringTypedProperty();
originalStringProperty.setName(longKey);
originalStringProperty.setValue("does not matter");
BooleanTypedProperty originalBoolProperty = new BooleanTypedProperty();
originalBoolProperty.setName(longKey);
originalBoolProperty.setValue(true);
DoubleTypedProperty originalDoubleProperty = new DoubleTypedProperty();
originalDoubleProperty.setName(longKey);
originalDoubleProperty.setValue(3.14);
LongTypedProperty originalLongProperty = new LongTypedProperty();
originalLongProperty.setName(longKey);
originalLongProperty.setValue(-123);
DateTimeTypedProperty originalDateProperty = new DateTimeTypedProperty();
originalDateProperty.setName(longKey);
originalDateProperty.setValue(new Date());
/* Submit property list to validation, should pass with truncate. */
List<TypedProperty> typedProperties = new ArrayList<>();
typedProperties.add(originalStringProperty);
typedProperties.add(originalBoolProperty);
typedProperties.add(originalDoubleProperty);
typedProperties.add(originalLongProperty);
typedProperties.add(originalDateProperty);
mEventLog.setTypedProperties(typedProperties);
assertFalse(mAnalyticsValidator.shouldFilter(mEventLog));
/* Check name and number of property not modified. */
assertEquals(validEventName, mEventLog.getName());
assertEquals(5, mEventLog.getTypedProperties().size());
/* Verify all property names truncated. */
for (TypedProperty property : mEventLog.getTypedProperties()) {
assertEquals(MAX_PROPERTY_ITEM_LENGTH, property.getName().length());
}
/* Check all property changes were made by copy. */
assertSame(longKey, originalStringProperty.getName());
assertSame(longKey, originalBoolProperty.getName());
assertSame(longKey, originalDoubleProperty.getName());
assertSame(longKey, originalLongProperty.getName());
assertSame(longKey, originalDateProperty.getName());
}
use of com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty in project mobile-center-sdk-android by Microsoft.
the class AnalyticsSerializerTest method someBatch.
@Test
public void someBatch() throws JSONException {
LogContainer expectedContainer = new LogContainer();
Device device = new Device();
device.setSdkName("appcenter.android");
device.setSdkVersion("1.2.3");
device.setModel("S5");
device.setOemName("HTC");
device.setOsName("Android");
device.setOsVersion("4.0.3");
device.setOsBuild("LMY47X");
device.setOsApiLevel(15);
device.setLocale("en_US");
device.setTimeZoneOffset(120);
device.setScreenSize("800x600");
device.setAppVersion("3.2.1");
device.setAppBuild("42");
List<Log> logs = new ArrayList<>();
{
StartSessionLog startSessionLog = new StartSessionLog();
startSessionLog.setTimestamp(new Date());
logs.add(startSessionLog);
}
expectedContainer.setLogs(logs);
{
PageLog pageLog = new PageLog();
pageLog.setTimestamp(new Date());
pageLog.setName("home");
logs.add(pageLog);
}
{
PageLog pageLog = new PageLog();
pageLog.setTimestamp(new Date());
pageLog.setName("settings");
pageLog.setProperties(new HashMap<String, String>() {
{
put("from", "home_menu");
put("orientation", "portrait");
}
});
logs.add(pageLog);
}
{
EventLog eventLog = new EventLog();
eventLog.setTimestamp(new Date());
eventLog.setId(UUID.randomUUID());
eventLog.setName("subscribe");
logs.add(eventLog);
}
{
EventLog eventLog = new EventLog();
eventLog.setTimestamp(new Date());
eventLog.setId(UUID.randomUUID());
eventLog.setName("click");
eventLog.setProperties(new HashMap<String, String>() {
{
put("x", "1");
put("y", "2");
}
});
logs.add(eventLog);
}
{
List<TypedProperty> properties = new ArrayList<>();
BooleanTypedProperty bp = new BooleanTypedProperty();
bp.setName("n1");
bp.setValue(true);
properties.add(bp);
DateTimeTypedProperty dtp = new DateTimeTypedProperty();
dtp.setName("n2");
dtp.setValue(new Date());
properties.add(dtp);
DoubleTypedProperty dp = new DoubleTypedProperty();
dp.setName("n3");
dp.setValue(10);
properties.add(dp);
LongTypedProperty lp = new LongTypedProperty();
lp.setName("n4");
lp.setValue(10000000000L);
properties.add(lp);
StringTypedProperty sp = new StringTypedProperty();
sp.setName("n5");
sp.setValue("value");
properties.add(sp);
EventLog eventLog = new EventLog();
eventLog.setTimestamp(new Date());
eventLog.setId(UUID.randomUUID());
eventLog.setName("event");
eventLog.setTypedProperties(properties);
logs.add(eventLog);
}
UUID sid = UUID.randomUUID();
for (Log log : logs) {
log.setSid(sid);
log.setDevice(device);
}
LogSerializer serializer = new DefaultLogSerializer();
serializer.addLogFactory(StartSessionLog.TYPE, new StartSessionLogFactory());
serializer.addLogFactory(PageLog.TYPE, new PageLogFactory());
serializer.addLogFactory(EventLog.TYPE, new EventLogFactory());
String payload = serializer.serializeContainer(expectedContainer);
android.util.Log.v(TAG, payload);
LogContainer actualContainer = serializer.deserializeContainer(payload, null);
Assert.assertEquals(expectedContainer, actualContainer);
}
use of com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty in project mobile-center-sdk-android by Microsoft.
the class EventProperties method set.
/**
* Set the specified property value with the specified key.
* If the properties previously contained a property for the key, the old
* value is replaced.
*
* @param key key with which the specified value is to be set.
* @param value value to be set with the specified key.
* @return this instance.
*/
public EventProperties set(String key, boolean value) {
if (isValidKey(key)) {
BooleanTypedProperty property = new BooleanTypedProperty();
property.setName(key);
property.setValue(value);
mProperties.put(key, property);
}
return this;
}
use of com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty in project mobile-center-sdk-android by Microsoft.
the class AnalyticsValidator method copyProperty.
private static TypedProperty copyProperty(TypedProperty property, String newKey) {
String type = property.getType();
TypedProperty copy;
if (BooleanTypedProperty.TYPE.equals(type)) {
BooleanTypedProperty typedCopy = new BooleanTypedProperty();
typedCopy.setValue(((BooleanTypedProperty) property).getValue());
copy = typedCopy;
} else if (DateTimeTypedProperty.TYPE.equals(type)) {
DateTimeTypedProperty typedCopy = new DateTimeTypedProperty();
typedCopy.setValue(((DateTimeTypedProperty) property).getValue());
copy = typedCopy;
} else if (DoubleTypedProperty.TYPE.equals(type)) {
DoubleTypedProperty typedCopy = new DoubleTypedProperty();
typedCopy.setValue(((DoubleTypedProperty) property).getValue());
copy = typedCopy;
} else if (LongTypedProperty.TYPE.equals(type)) {
LongTypedProperty typedCopy = new LongTypedProperty();
typedCopy.setValue(((LongTypedProperty) property).getValue());
copy = typedCopy;
} else {
/* SDK invariant: unknown property type is not possible with public APIs. */
StringTypedProperty typedCopy = new StringTypedProperty();
typedCopy.setValue(((StringTypedProperty) property).getValue());
copy = typedCopy;
}
copy.setName(newKey);
return copy;
}
use of com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty in project mobile-center-sdk-android by Microsoft.
the class CommonSchemaDataUtilsAndroidTest method nestingWithTypes.
@Test
public void nestingWithTypes() throws JSONException {
MockCommonSchemaLog log = new MockCommonSchemaLog();
List<TypedProperty> properties = new ArrayList<>();
properties.add(typedProperty("baseType", "Some.Type"));
LongTypedProperty a = new LongTypedProperty();
a.setName("p.a");
a.setValue(1);
properties.add(a);
DoubleTypedProperty b = new DoubleTypedProperty();
b.setName("p.b");
b.setValue(2.0);
properties.add(b);
BooleanTypedProperty c = new BooleanTypedProperty();
c.setName("p.c");
c.setValue(true);
properties.add(c);
LongTypedProperty baseDataD = new LongTypedProperty();
baseDataD.setName("baseData.d");
baseDataD.setValue(4);
properties.add(baseDataD);
properties.add(typedProperty("baseData.e", "5"));
CommonSchemaDataUtils.addCommonSchemaData(properties, log);
/* Check data. */
JSONObject p = new JSONObject();
p.put("a", 1);
p.put("b", 2.0);
p.put("c", true);
JSONObject baseData = new JSONObject();
baseData.put("d", 4);
baseData.put("e", "5");
JSONObject expectedData = new JSONObject();
expectedData.put("baseType", "Some.Type");
expectedData.put("p", p);
expectedData.put("baseData", baseData);
assertEquals(expectedData.toString(), log.getData().getProperties().toString());
/* Check metadata, boolean is a default type. */
JSONObject metadataPChildren = new JSONObject();
metadataPChildren.put("a", DATA_TYPE_INT64);
metadataPChildren.put("b", DATA_TYPE_DOUBLE);
JSONObject metadataPFields = new JSONObject();
metadataPFields.put(METADATA_FIELDS, metadataPChildren);
JSONObject metadataBaseDataChildren = new JSONObject();
metadataBaseDataChildren.put("d", DATA_TYPE_INT64);
JSONObject metadataBaseDataFields = new JSONObject();
metadataBaseDataFields.put(METADATA_FIELDS, metadataBaseDataChildren);
JSONObject metadataFields = new JSONObject();
metadataFields.put("p", metadataPFields);
metadataFields.put("baseData", metadataBaseDataFields);
JSONObject expectedMetadata = new JSONObject();
expectedMetadata.put(METADATA_FIELDS, metadataFields);
assertEquals(expectedMetadata.toString(), log.getExt().getMetadata().getMetadata().toString());
}
Aggregations