Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow omitting all optional SampledValue fields #140

Merged
merged 1 commit into from
Apr 8, 2021

Conversation

robert-s-ubi
Copy link
Contributor

According to the OCPP specification, all fields of the SampledValue
class except for "value" are optional and may be omitted.

However, the Java class implementation in this library initialized all
fields but "phase" to their default values, and prevented resetting all
but the enum fields to null. Most prominently, the "unit" field was
initialized to "Wh" and could not be reset, preventing the generation of
compliant messages for "Frequency" and "Power.Factor" measurands, for
which the "unit" field needs to be omitted.

Remove the initialization of fields to their default values from the
class constructors, so that they are left as null and will be omitted
when serializing the object.

Exempt null references from the validations in the field setter methods,
so that all fields can be set to null.

Add returning the default value in the field getter methods in case the
stored field value is null, where applicable.

Most importantly, for the "unit" field, only replace null with "Wh" for
"Energy" type measurands. This ensures the null is retained for the
"Frequency" and "Power.Factor" measurands, in compliance with the OCPP
specification.

According to the OCPP specification, all fields of the SampledValue
class except for "value" are optional and may be omitted.

However, the Java class implementation in this library initialized all
fields but "phase" to their default values, and prevented resetting all
but the enum fields to null. Most prominently, the "unit" field was
initialized to "Wh" and could not be reset, preventing the generation of
compliant messages for "Frequency" and "Power.Factor" measurands, for
which the "unit" field needs to be omitted.

Remove the initialization of fields to their default values from the
class constructors, so that they are left as null and will be omitted
when serializing the object.

Exempt null references from the validations in the field setter methods,
so that all fields can be set to null.

Add returning the default value in the field getter methods in case the
stored field value is null, where applicable.

Most importantly, for the "unit" field, only replace null with "Wh" for
"Energy" type measurands. This ensures the null is retained for the
"Frequency" and "Power.Factor" measurands, in compliance with the OCPP
specification.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 42.579% when pulling ad62940 on ubitricity:master into 9ce7411 on ChargeTimeEU:master.

@TVolden
Copy link
Member

TVolden commented Mar 28, 2021

Hi @robert-s-ubi ,

Thanks for your contribution, I really appreciate it.

For some reason the unit test for v2.0's boot notification is failing:
https://github.com/ChargeTimeEU/Java-OCA-OCPP/blob/master/ocpp-v2_0/src/test/java/eu/chargetime/ocpp/model/basic/test/BootNotificationConfirmationTest.java

I don't really understand why they fail, but I'll try to investigate it when I have more time (got some assignments due soon).

@robert-s-ubi
Copy link
Contributor Author

Hi Thomas,

I cannot reproduce any build or test failures, this commit builds with no issues on my machine:

$ mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Java-OCA-OCPP common [jar]
[INFO] Java-OCA-OCPP [pom]
[INFO] Java-OCA-OCPP OCPP-J [jar]
[INFO] Java-OCA-OCPP v1.6 [jar]
[INFO] Java-OCA-OCPP v1.6 - Integration test [jar]
[INFO] Java-OCA-OCPP v2.0 [jar]
[INFO] Java-OCA-OCPP v2.0 - Integration test [jar]
[INFO]
[INFO] ---------------------< eu.chargetime.ocpp:common >----------------------
[INFO] Building Java-OCA-OCPP common 0.5-SNAPSHOT [1/7]
[INFO] --------------------------------[ jar ]---------------------------------

[...]

Running eu.chargetime.ocpp.model.test.BootNotificationConfirmationTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec

[...]

Running eu.chargetime.ocpp.model.basic.test.BootNotificationConfirmationTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec

[...]

[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ v2_0-test ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Java-OCA-OCPP common 0.5-SNAPSHOT .................. SUCCESS [ 20.061 s]
[INFO] Java-OCA-OCPP 0.5-SNAPSHOT ......................... SUCCESS [ 6.452 s]
[INFO] Java-OCA-OCPP OCPP-J 0.1-SNAPSHOT .................. SUCCESS [ 3.649 s]
[INFO] Java-OCA-OCPP v1.6 0.5-SNAPSHOT .................... SUCCESS [ 1.605 s]
[INFO] Java-OCA-OCPP v1.6 - Integration test 0.5-SNAPSHOT . SUCCESS [ 19.300 s]
[INFO] Java-OCA-OCPP v2.0 0.1-SNAPSHOT .................... SUCCESS [ 0.745 s]
[INFO] Java-OCA-OCPP v2.0 - Integration test 0.1-SNAPSHOT . SUCCESS [ 0.362 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 52.283 s
[INFO] Finished at: 2021-03-28T13:10:39+02:00
[INFO] ------------------------------------------------------------------------
$

The Travis CI build is failing due to an issue with the coverall service_job_id, but that is only about uploading the coverage report, if I understand correctly. A "dry run" of the same command shown at the end of the Job log:

mvn -DdryRun=true clean org.jacoco:jacoco-maven-plugin:prepare-agent test org.jacoco:jacoco-maven-plugin:report org.eluder.coveralls:coveralls-maven-plugin:report -B

also finishes successfully.

@robert-s-ubi
Copy link
Contributor Author

I'd really like to have this merged, as I have further changes and I would not want to have them pile up. Is there anything I can do to get this pull request further along?

@TVolden TVolden merged commit 441adb1 into ChargeTimeEU:master Apr 8, 2021
@TVolden
Copy link
Member

TVolden commented Apr 8, 2021

I'll merge it in now, so you can get on with your work.

Thanks again for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants