-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable metadata schema validation (#504)
- Loading branch information
Showing
12 changed files
with
144 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
tests/downgrade.site/devices/DWN-1/expected/metadata_norm.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
tests/downgrade.site/devices/DWN-2/expected/metadata_norm.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,6 @@ | |
"DWN-2" : "devices/DWN-2" | ||
}, | ||
"Version" : { | ||
"main" : "1.3.14-90-g266b9b3" | ||
"main" : "1.3.14-92-g6b250906" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
{ | ||
"system": { | ||
"location": { | ||
"site": "AA-TEST-SITE" | ||
"site": "US-SFO-XYY" | ||
}, | ||
"physical_tag": { | ||
"asset": { | ||
"guid": "bim://04aEp5ymD_$u5IxhJN2aGi", | ||
"site": "US-SFO-XYY", | ||
"name": "AHU-1" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"version": "1.4.0", | ||
"timestamp": "2018-08-26T21:39:29.364Z", | ||
"description": "Generic test example metadata file", | ||
"cloud": { | ||
"auth_type": "ES256" | ||
}, | ||
"pointset": { | ||
"points": { | ||
"return_air_temperature_sensor": { | ||
"units": "Degrees-Celsius", | ||
"baseline_value": 20, | ||
"baseline_tolerance": 2 | ||
}, | ||
"room_setpoint": { | ||
"writable": true, | ||
"units": "Degrees-Celsius", | ||
"baseline_value": 20, | ||
"baseline_state": "applied" | ||
} | ||
} | ||
}, | ||
"discovery": { | ||
"families": { | ||
"bacnet": { | ||
} | ||
} | ||
}, | ||
"testing": { | ||
"targets": { | ||
"invalid": { | ||
"target_point": "return_air_temperature_sensor", | ||
"target_value": -20 | ||
}, | ||
"failure": { | ||
"target_point": "room_setpoint", | ||
"target_value": -20 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1 schema violations found | ||
object has missing required properties (["system"]) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
validator/src/test/java/com/google/daq/mqtt/registrar/LocalDeviceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.google.daq.mqtt.registrar; | ||
|
||
import static com.google.udmi.util.JsonUtil.convertTo; | ||
import static com.google.udmi.util.JsonUtil.stringify; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.github.fge.jsonschema.main.JsonSchema; | ||
import com.google.udmi.util.GeneralUtils; | ||
import com.google.udmi.util.JsonUtil; | ||
import java.util.Date; | ||
import java.util.Map; | ||
import org.junit.Test; | ||
import udmi.schema.Metadata; | ||
|
||
/** | ||
* Unit tests for LocalDevice. | ||
*/ | ||
public class LocalDeviceTest { | ||
|
||
public static final String DEVICE_ID = "test_device"; | ||
public static final Map<String, JsonSchema> SCHEMAS = null; | ||
public static final int FAKE_TIME = 1298213; | ||
public static String MERGE_DATA = "{ \"testing\": 10 }"; | ||
|
||
@Test | ||
public void getMergedEmptyMetadata() { | ||
LocalDevice localDevice = getTestInstance(null); | ||
JsonNode toMerge = JsonUtil.fromString(JsonNode.class, MERGE_DATA); | ||
String original = stringify(toMerge); | ||
JsonNode result = localDevice.getMergedMetadata(toMerge); | ||
assertEquals("merged results with no side defaults", original, stringify(result)); | ||
} | ||
|
||
@Test | ||
public void getMergedSiteMetadata() { | ||
Metadata siteMetadata = getSiteMetadata(); | ||
Metadata augmentedData = GeneralUtils.deepCopy(siteMetadata); | ||
Metadata toMerge = new Metadata(); | ||
toMerge.timestamp = new Date(FAKE_TIME + 1); | ||
augmentedData.timestamp = toMerge.timestamp; | ||
toMerge.description = "testing"; | ||
augmentedData.description = toMerge.description; | ||
LocalDevice localDevice = getTestInstance(siteMetadata); | ||
Metadata result = convertTo(Metadata.class, | ||
localDevice.getMergedMetadata(convertTo(JsonNode.class, toMerge))); | ||
assertEquals("merged results with no side defaults", stringify(augmentedData), | ||
stringify(result)); | ||
} | ||
|
||
private Metadata getSiteMetadata() { | ||
Metadata metadata = new Metadata(); | ||
metadata.timestamp = new Date(FAKE_TIME); | ||
metadata.version = "testing"; | ||
return metadata; | ||
} | ||
|
||
private LocalDevice getTestInstance(Metadata siteMetadata) { | ||
return new LocalDevice(null, null, DEVICE_ID, SCHEMAS, null, siteMetadata); | ||
} | ||
} |