use of com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty 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.BooleanTypedProperty in project mobile-center-sdk-android by Microsoft.
the class PropertyConfiguratorTest method typedProperty.
@SuppressWarnings("SameParameterValue")
private static BooleanTypedProperty typedProperty(String name, boolean value) {
BooleanTypedProperty typedProperty = new BooleanTypedProperty();
typedProperty.setName(name);
typedProperty.setValue(value);
return typedProperty;
}
use of com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty in project mobile-center-sdk-android by Microsoft.
the class AnalyticsValidatorForEventLogTest method shouldNotFilterNonStringTypedProperty.
/**
* This test case only makes up missing branch in validateProperties when TypedProperty isn't StringTypedProperty.
*/
@Test
public void shouldNotFilterNonStringTypedProperty() {
String validEventName = "eventName";
mEventLog.setName(validEventName);
BooleanTypedProperty property = new BooleanTypedProperty();
property.setName("name");
property.setValue(true);
mEventLog.setTypedProperties(Collections.<TypedProperty>singletonList(property));
assertFalse(mAnalyticsValidator.shouldFilter(mEventLog));
assertEquals(validEventName, mEventLog.getName());
assertEquals(1, mEventLog.getTypedProperties().size());
BooleanTypedProperty booleanProperty = (BooleanTypedProperty) mEventLog.getTypedProperties().iterator().next();
assertEquals("name", booleanProperty.getName());
assertTrue(booleanProperty.getValue());
}
use of com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty in project mobile-center-sdk-android by Microsoft.
the class EventPropertiesTest method setBoolean.
@Test
public void setBoolean() {
String key = "test";
EventProperties properties = new EventProperties();
assertEquals(0, properties.getProperties().size());
/* Normal value. */
properties.set(key, false);
assertEquals(1, properties.getProperties().size());
BooleanTypedProperty expected = new BooleanTypedProperty();
expected.setName(key);
expected.setValue(false);
verifyStatic(never());
AppCenterLog.error(eq(Analytics.LOG_TAG), anyString());
}
use of com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty in project mobile-center-sdk-android by Microsoft.
the class CommonSchemaDataUtils method validateProperty.
/**
* Validate typed property.
*
* @param property typed property.
* @return property value.
* @throws IllegalArgumentException if the property is invalid.
* @throws JSONException if JSON date formatting fails (never happens).
*/
private static Object validateProperty(TypedProperty property) throws IllegalArgumentException, JSONException {
/* Validate key not null. */
String key = property.getName();
if (key == null) {
throw new IllegalArgumentException("Property key cannot be null.");
}
/* Validate baseType. */
if (key.equals(BASE_TYPE) && !(property instanceof StringTypedProperty)) {
throw new IllegalArgumentException("baseType must be a string.");
}
if (key.startsWith(BASE_TYPE + ".")) {
throw new IllegalArgumentException("baseType must be a string.");
}
/* Validate baseData is an object, meaning it has at least 1 dot. */
if (key.equals(BASE_DATA)) {
throw new IllegalArgumentException("baseData must be an object.");
}
/* Get value from property. */
Object value;
if (property instanceof StringTypedProperty) {
StringTypedProperty stringTypedProperty = (StringTypedProperty) property;
value = stringTypedProperty.getValue();
} else if (property instanceof LongTypedProperty) {
LongTypedProperty longTypedProperty = (LongTypedProperty) property;
value = longTypedProperty.getValue();
} else if (property instanceof DoubleTypedProperty) {
DoubleTypedProperty doubleTypedProperty = (DoubleTypedProperty) property;
value = doubleTypedProperty.getValue();
} else if (property instanceof DateTimeTypedProperty) {
value = JSONDateUtils.toString(((DateTimeTypedProperty) property).getValue());
} else if (property instanceof BooleanTypedProperty) {
BooleanTypedProperty booleanTypedProperty = (BooleanTypedProperty) property;
value = booleanTypedProperty.getValue();
} else {
throw new IllegalArgumentException("Unsupported property type: " + property.getType());
}
/* Validate value not null. */
if (value == null) {
throw new IllegalArgumentException("Value of property with key '" + key + "' cannot be null.");
}
return value;
}
Aggregations