CSV export of target data from Target Filter View.
Added a CSV export functionality to Target Filter Details View.
Column separator is hardcoded to ";" (semicolon). Column entries are put into double quotes. Can be opened by Excel with one click.

Thanks for your feedback and suggestions! I've refactored the whole feature as you suggested.
However, writing a unit test now seems more complicated than the business code itself. I'm a little bit unsure what's the right approach here, so perhaps you can provide some advice. As for my understanding, we need to create a test class that extends
AbstractJpaIntegrationTest class. Then we need to create several Targets and some TargetFilters. Then we need to create a reference object (expected result), which is of type OutputStream. Then finally we need to compare the produced OutputStream object with the expected (reference) object. Is that somewhat correct or am I thinking too complicated?
Sorry for the late reply and thanks a lot for adapting the PR! Regarding the test: it depends if you would like to implement the Integration test or a Unit test :) I would suggest to go with the Unit test here by mocking the targetManagement (the only real dependency of TargetDataCsvExporter) and using the ByteArrayOutputStream as your OutputStream. In that case you could just make targetManagement#findByTargetFilterQuery to return some targets and verify if they were converted correctly by using ByteArrayOutputStream#toByteArray(). Moreover, you could even spy on the OutputStream and verify the OutputStream#write calls and their arguments, but that is up to you ;) In case you have further questions/concerns feel free to contact me!
Hi @bogdan-bondar , my name is Krishna and I am a new employee at devolo. I will take over this (and other) PR from Sergey.
I am facing an issue implementing your suggestion for unit testing. How do I get the targetManagement#findByTargetFilterQuery to return targets? The only way I am aware of is by using TestdataFactory to create targets, but that does not work: The test class for TargetDataCsvExporter is in a different module (hawkbit-ui) and even if I add hawkbit-repository jpa as a module depedency, I cannot import AbstractJpaIntegrationTest (to be able to use testdataFactory).
Hi @krishna-devolo ! You don't need to use neither TestdataFactory nor AbstractJpaIntegrationTest, both of this classes assume there is a Spring Application Context present by auto wiring required dependencies. For your changes however it is sufficient to only unit test the TargetDataCsvExporter. In order to do it you can just manually create test JpaTargets and mock the targetManagement, something like when(targetManagement.findByRsql(any(), anyString())) .thenReturn(new PageImpl<>(Collections.singletonList(targetInPage1), PageRequest.of(0, 1), 2)) .thenReturn(new PageImpl<>(Collections.singletonList(targetInPage2), PageRequest.of(1, 1), 2));, where targetInPage1 and targetInPage2 are created manually by new JpaTarget("targetInPage1") and populating all the fields as necessary
In order to do it you can just manually create test
JpaTargets and mock thetargetManagement, something likewhen(targetManagement.findByRsql(any(), anyString())) .thenReturn(new PageImpl<>(Collections.singletonList(targetInPage1), PageRequest.of(0, 1), 2)) .thenReturn(new PageImpl<>(Collections.singletonList(targetInPage2), PageRequest.of(1, 1), 2));, wheretargetInPage1andtargetInPage2are created manually bynew JpaTarget("targetInPage1")and populating all the fields as necessary
Hey @bogdan-bondar. Manually creating JpaTargets using new JpaTarget("targetInPage1") runs into a NullPointerException; I had the same issue when I earlier tried to use AbstractJpaIntegrationTest and TestdataFactory. Could it be the case that creating JpaTargets also requires Spring Application Context?
No, it does not. The reason you are getting the NullPointerException is due to a missing SecurityTokenGenerator. Try using new JpaTarget("targetInPage1", null);