Skip to content

Commit

Permalink
Handle datasetid addition in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gasserluc committed Oct 18, 2024
1 parent fccc332 commit cf929a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private Attribute parseNgsiLdAttribute(String key, JSONObject value, boolean fla
addAttributeIfValid(subAttributes, subAttribute);
}
} else if (object instanceof JSONObject) {
Attribute subAttribute = parseNgsiLdSubAttribute(keyOne, value.getJSONObject(keyOne));
Attribute subAttribute = parseNgsiLdSubAttribute(keyOne, value.getJSONObject(keyOne));
addAttributeIfValid(subAttributes, subAttribute);
} else {
logger.warn("Sub Attribute {} has unexpected value type: {}", keyOne, object.getClass());
Expand All @@ -150,6 +150,9 @@ private Attribute parseNgsiLdAttribute(String key, JSONObject value, boolean fla
"parametername", "Property", "", "", "", "", key.toLowerCase(), false, null
);
subAttributes.add(parameterName);
if (Objects.equals(datasetId, "")){
datasetId = "default";
}
Attribute parameterDatasetId = new Attribute(
"datasetid", "Property", "", "", "", "", datasetId.toLowerCase(), false, null
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ public void testListOfFieldsWithFlattenedObservations() throws IOException {

Map<String, NGSIConstants.POSTGRESQL_COLUMN_TYPES> typedFields =
postgreSQLBackend.listOfFields(entity, "urn:ngsi-ld:Dataset:", false, Collections.emptySet());
assertEquals(26, typedFields.size());
assertEquals(27, typedFields.size());
Set<String> keys = typedFields.keySet();
assertTrue(keys.contains(GENERIC_MEASURE));
assertTrue(keys.contains(GENERIC_MEASURE + "_observedat"));
assertTrue(keys.contains(GENERIC_MEASURE + "_unitcode"));
assertTrue(keys.contains(GENERIC_MEASURE + "_parametername"));
assertTrue(keys.contains(GENERIC_MEASURE + "_datasetid"));
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public void testEntityWithFlattenObservations() throws IOException {
// the entity under test has four observations
assertEquals(4, measureAttributes.size());
Attribute measureAttribute = measureAttributes.get(0);
// each observation should have two sub-attributes: parametername and unitcode
assertEquals(2, measureAttribute.subAttrs.size());
// each observation should have three sub-attributes: parametername, unitcode and datasetId
assertEquals(3, measureAttribute.subAttrs.size());
assertTrue(measureAttribute.subAttrs.stream().allMatch(attribute ->
attribute.getAttrName().equals("parametername") || attribute.getAttrName().equals("unitcode")
attribute.getAttrName().equals("parametername") || attribute.getAttrName().equals("unitcode") || attribute.getAttrName().equals("datasetid")
));
}
}

0 comments on commit cf929a4

Please sign in to comment.