-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from mmauksch/validateMeterValues
add stricter validation for Metervalues as described in #241
- Loading branch information
Showing
3 changed files
with
34 additions
and
2 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
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
32 changes: 32 additions & 0 deletions
32
ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/core/MeterValuesRequestTest.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,32 @@ | ||
package eu.chargetime.ocpp.model.core; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
public class MeterValuesRequestTest extends TestCase { | ||
|
||
public void testEmptyMeterValuesArray_FailsValidation() { | ||
MeterValuesRequest request = new MeterValuesRequest(1); | ||
request.setTransactionId(2); | ||
request.setMeterValue(new MeterValue[]{}); | ||
assertFalse(request.validate()); | ||
} | ||
|
||
public void testEmptySampledValuesArray_failsValidation() { | ||
MeterValuesRequest request = new MeterValuesRequest(1); | ||
MeterValue measured = new MeterValue(ZonedDateTime.now(), new SampledValue[]{}); | ||
request.setTransactionId(2); | ||
request.setMeterValue(new MeterValue[]{measured}); | ||
assertFalse(request.validate()); | ||
} | ||
|
||
public void testMeterValuesWithAtLeastOneMeasurementPassesValidation() { | ||
MeterValuesRequest request = new MeterValuesRequest(1); | ||
SampledValue sample = new SampledValue("5"); | ||
MeterValue measured = new MeterValue(ZonedDateTime.now(), new SampledValue[]{sample}); | ||
request.setTransactionId(2); | ||
request.setMeterValue(new MeterValue[]{measured}); | ||
assertTrue(request.validate()); | ||
} | ||
} |