Search in sources :

Example 16 with TypedProperty

use of com.microsoft.appcenter.ingestion.models.properties.TypedProperty 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());
}
Also used : DoubleTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty) LongTypedProperty(com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) 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 TypedProperty

use of com.microsoft.appcenter.ingestion.models.properties.TypedProperty in project mobile-center-sdk-android by Microsoft.

the class CommonSchemaDataUtilsAndroidTest method dateTimeTypedProperty.

@Test
public void dateTimeTypedProperty() throws JSONException {
    MockCommonSchemaLog log = new MockCommonSchemaLog();
    List<TypedProperty> properties = new ArrayList<>();
    DateTimeTypedProperty property = new DateTimeTypedProperty();
    property.setName("a");
    property.setValue(new Date(100));
    properties.add(property);
    CommonSchemaDataUtils.addCommonSchemaData(properties, log);
    /* Check data. */
    assertEquals(1, log.getData().getProperties().length());
    assertEquals(new Date(100), JSONDateUtils.toDate(log.getData().getProperties().getString("a")));
    /* Check metadata. */
    JSONObject expectedMetadata = new JSONObject();
    JSONObject a = new JSONObject();
    a.put("a", DATA_TYPE_DATETIME);
    expectedMetadata.put(METADATA_FIELDS, a);
    assertNotNull(log.getExt());
    assertNotNull(log.getExt().getMetadata());
    assertEquals(expectedMetadata.toString(), log.getExt().getMetadata().getMetadata().toString());
}
Also used : DateTimeTypedProperty(com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) Date(java.util.Date) 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 TypedProperty

use of com.microsoft.appcenter.ingestion.models.properties.TypedProperty in project mobile-center-sdk-android by Microsoft.

the class CommonSchemaDataUtilsAndroidTest method invalidBaseTypeRemovesBaseData.

@Test
public void invalidBaseTypeRemovesBaseData() {
    MockCommonSchemaLog log = new MockCommonSchemaLog();
    log.setExt(new Extensions());
    List<TypedProperty> properties = new ArrayList<>();
    LongTypedProperty a = new LongTypedProperty();
    a.setName("baseType");
    a.setValue(3);
    properties.add(a);
    properties.add(typedProperty("baseData.something", "value"));
    CommonSchemaDataUtils.addCommonSchemaData(properties, log);
    /* Check everything removed. */
    assertEquals(0, log.getData().getProperties().length());
    assertNull(log.getExt().getMetadata());
}
Also used : LongTypedProperty(com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty) ArrayList(java.util.ArrayList) 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 TypedProperty

use of com.microsoft.appcenter.ingestion.models.properties.TypedProperty in project mobile-center-sdk-android by Microsoft.

the class CommonSchemaDataUtilsAndroidTest method longTypedPropertyReuseExtensions.

@Test
public void longTypedPropertyReuseExtensions() throws JSONException {
    MockCommonSchemaLog log = new MockCommonSchemaLog();
    Extensions ext = new Extensions();
    log.setExt(ext);
    List<TypedProperty> properties = new ArrayList<>();
    LongTypedProperty property = new LongTypedProperty();
    property.setName("a");
    property.setValue(10000000000L);
    properties.add(property);
    CommonSchemaDataUtils.addCommonSchemaData(properties, log);
    assertEquals(1, log.getData().getProperties().length());
    assertEquals(10000000000L, log.getData().getProperties().getLong("a"));
    /* Check metadata. */
    JSONObject expectedMetadata = new JSONObject();
    JSONObject a = new JSONObject();
    a.put("a", DATA_TYPE_INT64);
    expectedMetadata.put(METADATA_FIELDS, a);
    assertSame(ext, log.getExt());
    assertNotNull(log.getExt().getMetadata());
    assertEquals(expectedMetadata.toString(), log.getExt().getMetadata().getMetadata().toString());
}
Also used : LongTypedProperty(com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) 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 20 with TypedProperty

use of com.microsoft.appcenter.ingestion.models.properties.TypedProperty 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());
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) StringTypedProperty(com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty) TypedProperty(com.microsoft.appcenter.ingestion.models.properties.TypedProperty) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

TypedProperty (com.microsoft.appcenter.ingestion.models.properties.TypedProperty)37 StringTypedProperty (com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty)35 BooleanTypedProperty (com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty)31 DateTimeTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty)31 DoubleTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty)31 LongTypedProperty (com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty)31 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)31 JSONObject (org.json.JSONObject)14 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 CommonSchemaEventLog (com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog)6 TestUtils.generateString (com.microsoft.appcenter.test.TestUtils.generateString)5 Date (java.util.Date)4 HashMap (java.util.HashMap)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Map (java.util.Map)2 JSONException (org.json.JSONException)2 Context (android.content.Context)1 EventProperties (com.microsoft.appcenter.analytics.EventProperties)1