use of com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty 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());
}
use of com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty in project mobile-center-sdk-android by Microsoft.
the class CommonSchemaDataUtilsAndroidTest method overrideMetadataCleanup.
@Test
public void overrideMetadataCleanup() throws JSONException {
MockCommonSchemaLog log = new MockCommonSchemaLog();
List<TypedProperty> properties = new ArrayList<>();
LongTypedProperty a = new LongTypedProperty();
a.setName("a.b.c");
a.setValue(1);
properties.add(a);
StringTypedProperty b = new StringTypedProperty();
b.setName("a.b");
b.setValue("2");
properties.add(b);
DoubleTypedProperty c = new DoubleTypedProperty();
c.setName("a.c");
c.setValue(3.14);
properties.add(c);
CommonSchemaDataUtils.addCommonSchemaData(properties, log);
/* Check data. */
JSONObject aData = new JSONObject();
aData.put("b", "2");
aData.put("c", 3.14);
JSONObject expectedData = new JSONObject();
expectedData.put("a", aData);
assertEquals(expectedData.toString(), log.getData().getProperties().toString());
/* Check metadata contains only a.c. */
JSONObject aFields = new JSONObject();
aFields.put("c", DATA_TYPE_DOUBLE);
JSONObject aMetadata = new JSONObject();
aMetadata.put(METADATA_FIELDS, aFields);
JSONObject rootFields = new JSONObject();
rootFields.put("a", aMetadata);
JSONObject expectedMetadata = new JSONObject();
expectedMetadata.put(METADATA_FIELDS, rootFields);
assertEquals(expectedMetadata.toString(), log.getExt().getMetadata().getMetadata().toString());
}
use of com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty 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, double value) {
if (isValidKey(key)) {
if (Double.isInfinite(value) || Double.isNaN(value)) {
AppCenterLog.error(LOG_TAG, "Double property value cannot be NaN or infinite.");
} else {
DoubleTypedProperty property = new DoubleTypedProperty();
property.setName(key);
property.setValue(value);
mProperties.put(key, property);
}
}
return this;
}
use of com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty 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));
}
use of com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty in project mobile-center-sdk-android by Microsoft.
the class EventPropertiesTest method setDouble.
@Test
public void setDouble() {
String key = "test";
EventProperties properties = new EventProperties();
assertEquals(0, properties.getProperties().size());
/* NaN value. */
double nanValue = Double.NaN;
properties = new EventProperties();
properties.set(key, nanValue);
assertEquals(0, properties.getProperties().size());
verifyStatic(times(1));
AppCenterLog.error(eq(Analytics.LOG_TAG), anyString());
/* Positive infinity value. */
double positiveInfinityValue = Double.POSITIVE_INFINITY;
properties = new EventProperties();
properties.set(key, positiveInfinityValue);
assertEquals(0, properties.getProperties().size());
verifyStatic(times(2));
AppCenterLog.error(eq(Analytics.LOG_TAG), anyString());
/* Negative infinity value. */
double negativeInfinityValue = Double.NEGATIVE_INFINITY;
properties = new EventProperties();
properties.set(key, negativeInfinityValue);
assertEquals(0, properties.getProperties().size());
verifyStatic(times(3));
AppCenterLog.error(eq(Analytics.LOG_TAG), anyString());
/* Normal value. */
double normalValue = 0.0;
properties.set(key, normalValue);
assertEquals(1, properties.getProperties().size());
DoubleTypedProperty expected = new DoubleTypedProperty();
expected.setName(key);
expected.setValue(normalValue);
verifyStatic(times(3));
AppCenterLog.error(eq(Analytics.LOG_TAG), anyString());
}
Aggregations