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

[knx] Add integration tests #15727

Merged
merged 3 commits into from
Dec 16, 2023
Merged

[knx] Add integration tests #15727

merged 3 commits into from
Dec 16, 2023

Conversation

holgerfriedrich
Copy link
Member

@holgerfriedrich holgerfriedrich commented Oct 9, 2023

  • Add integration tests which include decoding and encoding KNX frames, and the handling by Calimero library as well. This ensures that the KNX wire format is handled properly.
  • Add itests for all main DPT numbers supported by Calimero.
  • Add a mechanism to check for new missing DPT main numbers when new Calimero release is integrated.

The idea of this PR is basically to check the whole way from bytes on the KNX bus through Calimero, into the plugin, and back again via Calimero down to the bus again. The implementation overwrites KNXNetworkLink to implement a test interface. Calimero is then set up on top.

The benefit of this approach is that we now cover large parts of the handling of KNX frame in the Calimero library, without the need of setting up real itests including bus communication to mimic the KNX communication.

PR is ready for review, tests for more DPT subtypes can be added later.

@J-N-K
Copy link
Member

J-N-K commented Oct 10, 2023

Maybe we can test both at once and return the send frame as incoming frame from the bus?

@holgerfriedrich
Copy link
Member Author

Maybe we can test both at once and return the send frame as incoming frame from the bus?

Exactly. Now a CEMI frame is generated from the data, which is used to send an indication to all listeners. A ProcessCommunicator impl gets the data and supplies it to a dummy ProcessListener, where the test can grab the information. This is close to the way we supply data from KNX to ValueDecoder.decode().

Concept is working, test for 251.600 is there.

PR needs some generalization and other data types to be covered.

@holgerfriedrich holgerfriedrich removed the work in progress A PR that is not yet ready to be merged label Oct 15, 2023
@holgerfriedrich holgerfriedrich changed the title [knx] Enhance tests [knx] Add integration tests Oct 15, 2023
@holgerfriedrich
Copy link
Member Author

Generalization to other DPTs is done, tests for different DPTs have been added.
Extending the tests to more DPTs is not scope of this PR.

@holgerfriedrich holgerfriedrich force-pushed the pr-knx-tests branch 4 times, most recently from 73527c2 to f36d2ed Compare October 22, 2023 07:19
@holgerfriedrich
Copy link
Member Author

Cleaned up the commit history, as this should not be squashed during merge.
Ready for review.

@holgerfriedrich holgerfriedrich added the enhancement An enhancement or new feature for an existing add-on label Oct 22, 2023
* Add integration tests which include decoding and encoding KNX
frames, and the handling by Calimero library as well. This ensures
that the KNX wire format is handled properly.
* Add itests for DPT1 and color DPTs 251.600 and 232.600.

Signed-off-by: Holger Friedrich <[email protected]>
- Change default type of DPT14 to QuantityType
- Allow for parsing DPT20, DPT21, DPT22 as DecimalType in addition to String
- Add DPTs for color transitions, mapped to String:
  DPT243.600, DPT249.600, DPT250.600, DPT252.600, DPT253.600, DPT254.600
- Adapt handling of DST flag in DPT19.001

Signed-off-by: Holger Friedrich <[email protected]>
@holgerfriedrich
Copy link
Member Author

Fixed a few typos in the code comments. Ready for review.

@holgerfriedrich
Copy link
Member Author

@J-N-K can I ask you to have a short look into this PR?
Maybe you can remember why we had the code handling "no-day" for DPT 19.001. I removed this in 534f593 as I could not reproduce this (neither for German nor English locale, and the source code of Calimero does not contain it as well).

Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general looks good an very useful.

bundles/org.openhab.binding.knx/doc/dpt.txt Show resolved Hide resolved
import tuwien.auto.calimero.process.ProcessCommunicatorImpl;

/**
* Integration test to check conversion from raw KNX frame data to OH data types and back.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an integration test in the sense we usually use it in the openHAB context. We call a test an integration test if it starts the whole framework and executes tests in a running application.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that as well. Looking from the perspective of the binding code, it is more than a unit test, as we involve the full Calimero stack. How would you call it? Back2Back? E2E? Though, E2E is typically considered even more as integration test....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@J-N-K Do you have a proposal? Or should we merge as it is?

…ing/knx/internal/dpt/ValueDecoder.java

Co-authored-by: J-N-K <[email protected]>
Signed-off-by: Holger Friedrich <[email protected]>
@holgerfriedrich
Copy link
Member Author

@kaikreuzer I would like to see this in the next milestone build if possible. It should be merged as 2 separate commits to keep the records. I think we have only one open point above: can we call this an integration test or shall I change the naming to something different.... WDYT?

@kaikreuzer
Copy link
Member

I'll leave merging this to @J-N-K as he already did the initial review.

Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that the benefit of having these tests outweigh any potential confusion due to the naming. Since no-one seems to have a better proposal, we should merge as-is.

@J-N-K J-N-K added this to the 4.1 milestone Dec 16, 2023
@J-N-K J-N-K merged commit 4ba325d into openhab:main Dec 16, 2023
3 checks passed
@holgerfriedrich holgerfriedrich deleted the pr-knx-tests branch December 16, 2023 11:53
@holgerfriedrich
Copy link
Member Author

holgerfriedrich commented Dec 16, 2023

thank you!

austvik pushed a commit to austvik/openhab-addons that referenced this pull request Mar 27, 2024
* [knx] Add integration tests
* [knx] Adapt handling of DPTs

Signed-off-by: Holger Friedrich <[email protected]>
Signed-off-by: Jørgen Austvik <[email protected]>
joni1993 pushed a commit to joni1993/openhab-addons that referenced this pull request Oct 15, 2024
* [knx] Add integration tests
* [knx] Adapt handling of DPTs

Signed-off-by: Holger Friedrich <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants