Search in sources :

Example 6 with LongTypedProperty

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

the class CommonSchemaDataUtilsAndroidTest method noMetadataCleanupOnNestingString.

@Test
public void noMetadataCleanupOnNestingString() throws JSONException {
    MockCommonSchemaLog log = new MockCommonSchemaLog();
    log.setExt(new Extensions());
    List<TypedProperty> properties = new ArrayList<>();
    LongTypedProperty a = new LongTypedProperty();
    a.setName("a.b");
    a.setValue(1);
    properties.add(a);
    StringTypedProperty b = new StringTypedProperty();
    b.setName("b.c");
    b.setValue("2");
    properties.add(b);
    CommonSchemaDataUtils.addCommonSchemaData(properties, log);
    /* Check data. */
    JSONObject aData = new JSONObject();
    aData.put("b", 1);
    JSONObject bData = new JSONObject();
    bData.put("c", "2");
    JSONObject expectedData = new JSONObject();
    expectedData.put("a", aData);
    expectedData.put("b", bData);
    assertEquals(expectedData.toString(), log.getData().getProperties().toString());
    /* Check metadata. a.b only. */
    JSONObject aFields = new JSONObject();
    aFields.put("b", DATA_TYPE_INT64);
    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 : 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 7 with LongTypedProperty

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

use of com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty 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 9 with LongTypedProperty

use of com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty 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 10 with LongTypedProperty

use of com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty 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)

Aggregations

LongTypedProperty (com.microsoft.appcenter.ingestion.models.properties.LongTypedProperty)17 BooleanTypedProperty (com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty)14 DateTimeTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DateTimeTypedProperty)14 DoubleTypedProperty (com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty)14 StringTypedProperty (com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty)14 Test (org.junit.Test)13 TypedProperty (com.microsoft.appcenter.ingestion.models.properties.TypedProperty)11 ArrayList (java.util.ArrayList)11 JSONObject (org.json.JSONObject)8 Date (java.util.Date)3 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)2 Context (android.content.Context)1 PageLog (com.microsoft.appcenter.analytics.ingestion.models.PageLog)1 StartSessionLog (com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog)1 EventLogFactory (com.microsoft.appcenter.analytics.ingestion.models.json.EventLogFactory)1 PageLogFactory (com.microsoft.appcenter.analytics.ingestion.models.json.PageLogFactory)1 StartSessionLogFactory (com.microsoft.appcenter.analytics.ingestion.models.json.StartSessionLogFactory)1 CommonSchemaEventLog (com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog)1 Channel (com.microsoft.appcenter.channel.Channel)1 Device (com.microsoft.appcenter.ingestion.models.Device)1