Skip to content

Commit

Permalink
Merge pull request #825 from Pengpengwanga/api
Browse files Browse the repository at this point in the history
Check the formula string is null
  • Loading branch information
yixingjia authored May 17, 2021
2 parents 2ad3686 + 0859388 commit ec6b918
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3007,6 +3007,22 @@ else if(String.format(MetricKeyName.PDU_HUMIDITY_LOCATIONX, "OUTLET").
realtimeDataRepository.deleteById(humdityRealTimeData.getId());
}

@Test
public void testGetServerMetricsByIDFormulaIsEmpty() {
Asset asset = createAsset();
long time = System.currentTimeMillis();
int duration = 30*60*1000;
long startTime = time - duration;
Map<String, String> formulars = new HashMap<String, String>();
asset.setMetricsformulars(formulars);
asset = assetRepository.save(asset);

List<MetricData> metricDatas =
assetService.getMetricsByID(asset.getId(), startTime, duration);
TestCase.assertEquals(0, metricDatas.size());
assetRepository.deleteById(asset.getId());
}

@Test
public void testGetServerMetricsByID() {
Asset asset = createAsset();
Expand Down Expand Up @@ -3395,6 +3411,13 @@ public void testGetMetricDataForOther() {
realtimeDataRepository.deleteById(realTimeData.getId());
}

@Test
public void testMetricFormulaStringIsNull() {
Asset asset = createAsset();
Map<String,String> formulaInfo = asset.metricsFormulaToMap(null, new TypeReference<Map<String, String>>(){});
TestCase.assertEquals(null, formulaInfo);
}

RealTimeData createPduRealTimeData(Long time) {
RealTimeData realTimeData = createServerPDURealTimeData(time);
List<ValueUnit> valueunits = realTimeData.getValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ public void setTenant(Tenant tenant) {

public <T> T metricsFormulaToMap(String formulasInfo, TypeReference<T> type){
ObjectMapper mapper = new ObjectMapper();
if(formulasInfo == null) {
return null;
}
try {
return mapper.readValue(formulasInfo, type);
} catch (IOException e) {
Expand Down

0 comments on commit ec6b918

Please sign in to comment.