Search in sources :

Example 16 with StringTypedProperty

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());
}
Also used : ArrayList(java.util.ArrayList) TestUtils.generateString(com.microsoft.appcenter.test.TestUtils.generateString) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) DoubleTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty) LongTypedProperty(com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty) BooleanTypedProperty(com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) TypedProperty(com.microsoft.appcenter.ingestion.models.properties.TypedProperty) DateTimeTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty) Test(org.junit.Test)

Example 17 with StringTypedProperty

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());
}
Also used : ArrayList(java.util.ArrayList) TestUtils.generateString(com.microsoft.appcenter.test.TestUtils.generateString) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) DoubleTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty) LongTypedProperty(com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty) BooleanTypedProperty(com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) TypedProperty(com.microsoft.appcenter.ingestion.models.properties.TypedProperty) DateTimeTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty) Test(org.junit.Test)

Example 18 with StringTypedProperty

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());
}
Also used : ArrayList(java.util.ArrayList) TestUtils.generateString(com.microsoft.appcenter.test.TestUtils.generateString) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) DoubleTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty) LongTypedProperty(com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty) BooleanTypedProperty(com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) TypedProperty(com.microsoft.appcenter.ingestion.models.properties.TypedProperty) DateTimeTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty) Test(org.junit.Test)

Example 19 with StringTypedProperty

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));
}
Also used : HashMap(java.util.HashMap) EventLog(com.microsoft.appcenter.analytics.ingestion.models.EventLog) CommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog) ArrayList(java.util.ArrayList) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) CommonSchemaEventLogFactory(com.microsoft.appcenter.analytics.ingestion.models.one.json.CommonSchemaEventLogFactory) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) TypedProperty(com.microsoft.appcenter.ingestion.models.properties.TypedProperty) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 20 with StringTypedProperty

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());
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

StringTypedProperty (com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty)25 TypedProperty (com.microsoft.appcenter.ingestion.models.properties.TypedProperty)17 Test (org.junit.Test)17 BooleanTypedProperty (com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty)16 DateTimeTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty)16 DoubleTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty)16 LongTypedProperty (com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty)16 ArrayList (java.util.ArrayList)16 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)5 TestUtils.generateString (com.microsoft.appcenter.test.TestUtils.generateString)5 JSONObject (org.json.JSONObject)5 Context (android.content.Context)3 CommonSchemaEventLog (com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog)3 Channel (com.microsoft.appcenter.channel.Channel)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Matchers.anyString (org.mockito.Matchers.anyString)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 UserIdContext (com.microsoft.appcenter.utils.context.UserIdContext)2 PageLog (com.microsoft.appcenter.analytics.ingestion.models.PageLog)1