use of com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty in project mobile-center-sdk-android by Microsoft.
the class CommonSchemaDataUtilsAndroidTest method invalidBaseData.
@Test
public void invalidBaseData() {
/* When using invalid base data. */
MockCommonSchemaLog log = new MockCommonSchemaLog();
log.setExt(new Extensions());
List<TypedProperty> properties = new ArrayList<>();
StringTypedProperty a = new StringTypedProperty();
a.setName("baseData");
a.setValue("myData");
properties.add(a);
CommonSchemaDataUtils.addCommonSchemaData(properties, log);
/* Check data and metadata is missing type. */
assertEquals(0, log.getData().getProperties().length());
assertNull(log.getExt().getMetadata());
}
use of com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty 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.StringTypedProperty in project mobile-center-sdk-android by Microsoft.
the class CommonSchemaDataUtilsTest method coverJSONException.
@Test
public void coverJSONException() throws Exception {
/* Fake JSON exception to cover the checked exception that never happens. */
JSONObject value = mock(JSONObject.class);
whenNew(JSONObject.class).withNoArguments().thenReturn(value);
when(value.put(anyString(), any())).thenThrow(new JSONException("mock"));
CommonSchemaLog commonSchemaLog = new MockCommonSchemaLog();
List<TypedProperty> properties = new ArrayList<>();
StringTypedProperty stringTypedProperty = new StringTypedProperty();
stringTypedProperty.setName("a");
stringTypedProperty.setValue("b");
properties.add(stringTypedProperty);
CommonSchemaDataUtils.addCommonSchemaData(properties, commonSchemaLog);
assertEquals(0, commonSchemaLog.getData().getProperties().length());
}
use of com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty 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.StringTypedProperty 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;
}
Aggregations