@Test public void checkPartAConversionDoesNotInstantiateExtensionObjectAgain() { Log log = mock(Log.class); when(log.getDevice()).thenReturn(getDevice(0)); MockCommonSchemaLog commonSchemaLog = new MockCommonSchemaLog(); Extensions extensions = new Extensions(); commonSchemaLog.setExt(extensions); PartAUtils.addPartAFromLog(log, commonSchemaLog, "T1UUID1-T2UUID2"); assertEquals(extensions, commonSchemaLog.getExt()); }
@Test public void noMetadataCleanupOnNestingString() throws JSONException { MockCommonSchemaLog log = new MockCommonSchemaLog(); log.setExt(new Extensions()); List<TypedProperty> properties = new ArrayList<>(); LongTypedProperty a = new LongTypedProperty();
@Test public void noNestingAccident() throws JSONException { MockCommonSchemaLog log = new MockCommonSchemaLog(); log.setExt(new Extensions()); List<TypedProperty> properties = new ArrayList<>(); LongTypedProperty a = new LongTypedProperty();
@Test public void invalidBaseDataRemovesBaseType() { MockCommonSchemaLog log = new MockCommonSchemaLog(); log.setExt(new Extensions()); List<TypedProperty> properties = new ArrayList<>(); properties.add(typedProperty("baseType", "Some.Type")); properties.add(typedProperty("baseData", "value")); CommonSchemaDataUtils.addCommonSchemaData(properties, log); /* Check everything removed. */ assertEquals(0, log.getData().getProperties().length()); assertNull(log.getExt().getMetadata()); }
@Test public void overrideMetadataToNull() throws JSONException { MockCommonSchemaLog log = new MockCommonSchemaLog(); log.setExt(new Extensions()); 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); CommonSchemaDataUtils.addCommonSchemaData(properties, log); /* Check data. */ JSONObject aData = new JSONObject(); aData.put("b", "2"); JSONObject expectedData = new JSONObject(); expectedData.put("a", aData); assertEquals(expectedData.toString(), log.getData().getProperties().toString()); /* Check metadata is null */ assertNull(log.getExt().getMetadata()); }
@Test public void baseTypeOverriddenToBeInvalid() { MockCommonSchemaLog log = new MockCommonSchemaLog(); log.setExt(new Extensions()); List<TypedProperty> properties = new ArrayList<>(); properties.add(typedProperty("baseType", "Some.Type")); properties.add(typedProperty("baseType.something", "test")); properties.add(typedProperty("baseData.something", "test")); CommonSchemaDataUtils.addCommonSchemaData(properties, log); /* Check only string base type was kept. */ assertEquals(2, log.getData().getProperties().length()); assertEquals("Some.Type", log.getData().getProperties().optString("baseType")); assertNull(log.getExt().getMetadata()); } }
@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()); }
@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()); }
@Test public void baseTypeMissing() { /* 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.test"); a.setValue("test"); properties.add(a); CommonSchemaDataUtils.addCommonSchemaData(properties, log); /* Check data and metadata is missing type. */ assertEquals(0, log.getData().getProperties().length()); assertNull(log.getExt().getMetadata()); }
@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()); }
@Test public void baseDataMissing() { /* When using invalid base data. */ MockCommonSchemaLog log = new MockCommonSchemaLog(); log.setExt(new Extensions()); List<TypedProperty> properties = new ArrayList<>(); StringTypedProperty a = new StringTypedProperty(); a.setName("baseType"); a.setValue("Some.Type"); properties.add(a); CommonSchemaDataUtils.addCommonSchemaData(properties, log); /* Check data and metadata is missing type. */ assertEquals(0, log.getData().getProperties().length()); assertNull(log.getExt().getMetadata()); }
@Test public void invalidBaseType() { /* When using invalid base type. */ MockCommonSchemaLog log = new MockCommonSchemaLog(); log.setExt(new Extensions()); List<TypedProperty> properties = new ArrayList<>(); LongTypedProperty a = new LongTypedProperty(); a.setName("baseType"); a.setValue(1); properties.add(a); CommonSchemaDataUtils.addCommonSchemaData(properties, log); /* Check data and metadata is missing type. */ assertEquals(0, log.getData().getProperties().length()); assertNull(log.getExt().getMetadata()); }
log.setExt(new Extensions()); checkSerialization(serializer, log);