2024 Nov 06 8:53 AM - edited 2024 Nov 06 8:53 AM
Hi,
I have a managed RAP entity with a behavior implementation method that tries to read active and draft entities. I already know it works in practice through testing it in my Fiori app.
In my unit test for the class, I mock the entities using the test double framework and call my method, which should be able to read entities inserted into the cds or sql test double frameworks. For active entities, my method works with no problem and is able to get a READ result.
However, for draft entities, I could not find a way to create them using the test double framework and our READ gets no result. I tried to insert the persistent draft table as a dependency in the CDS test environment and to insert it through the sql test environment instead, as well, but this did not result in a READ result in the method.
The only thing that did work was a workaround/hack to insert the data I wanted into the CDS test environment as an active entity and then execute the EDIT method on it.
I also could not find any tutorial or documentation about this. The only thing I found was a blog post where someone used the same workaround as me:
But I wanted to know if there is a "best practice" for doing this or if it is actually intended to use the EDIT workaround.
Thank you,
Zena
Request clarification before answering.
Hi Zena,
I was also in the situation you described. For me the solution was to mock and maintain not only the entities that I was testing, but also the database table SDRAFT_ADMIN. This allowed me to reach draft entities inserted through the test double framework with EML statements. I have found that the smallest set of fields needed to be maintained for the read statement to succeed is the following: DRAFT_ENTITY, DRAFT_KEY, CREATED_BY, LAST_CHANGED_BY, CREATED_AT, LAST_CHANGED_AT. It is important to node, that the DRAFT_ENTITY field's value must be the name of the entity, of which you are willing to create a draft instance and must be in uppercase form.
Hope this helps you avoiding the use of the workaround you mentioned above.
Best regards,
Szabolcs
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
9 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.