Skip to content

FINERACT-1047 Integration test for Audit trails(Create) - #1100

Merged
vorburger merged 1 commit into
apache:developfrom
thesmallstar:it700
Jun 26, 2020
Merged

FINERACT-1047 Integration test for Audit trails(Create)#1100
vorburger merged 1 commit into
apache:developfrom
thesmallstar:it700

Conversation

@thesmallstar

@thesmallstar thesmallstar commented Jun 22, 2020

Copy link
Copy Markdown
Member

FINERACT-1047

Description

Integration Tests are divided into two parts:

  1. Creation
  2. Verifying for different routes provided, like: limit,orderby etc.

This PR deals with the first part.

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

Our guidelines for code reviews is at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide

@vorburger vorburger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@thesmallstar I have some minor feedback. This is more about improving style of ITs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

very minor feedback FYI, more for your learning: We usually use the abstract List instead of the concrete ArrayList implementation as type of the variable. Even better, since we are now on Java 11, why not start using var instead? Try just var responseAuditIDs = Utils.performServerGet(requestSpec, responseSpec, AUDIT_URL, "id"); (and don't use final var, that's just ugly).

Suggested change
final ArrayList<Integer> responseAuditIDs = Utils.performServerGet(requestSpec, responseSpec, AUDIT_URL, "id");
final List<Integer> responseAuditIDs = Utils.performServerGet(requestSpec, responseSpec, AUDIT_URL, "id");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

understood!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For a new class like AuditHelper, I would go with the pattern of passing this.requestSpec, this.responseSpec to the constructor, and then have a method like verifyAuditCreatedOnServer not require it. Actually, even better, how about only passing the requestSpec and even just hard-code the responseSpec without having to pass it. This would make ITs more readable.

Suggested change
AuditHelper.verifyAuditCreatedOnServer(this.requestSpec, this.responseSpec, clientId, "CREATE", "CLIENT");
AuditHelper.verifyAuditCreatedOnServer(this.requestSpec, this.responseSpec, clientId, "CREATE", "CLIENT");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was actually going to point this on #1019, HideUtilityClassConstructor checks if it is utility class by its name, to do this(using non-private constructor) we would need to either suppress the warning for that checkstyle then or call this something that does not have Helper or util in its name. What do you suggest?

@thesmallstar

Copy link
Copy Markdown
Member Author

@vorburger I was a little worried about this approach though and thought of changing this to something more robust.

The problem:
We are checking count for the entries like this: Get me the count of audit trails whose resource-id is x it was activated and is of type client. Here, the same event can occur twice and hence two audits will be returned, which does not necessarily mean that the test failed(since we are checking count to be equal to one)

The solution:
Calculate the count before the action(create, update, activate) and check if count incremented by one, after the action.

Why the old approach is still correct?
Two reasons: Every entity is created for the first time, no action is performed twice.

Just that I thought it was fundamentally wrong to check count to be one(not a general case), I hope I am not too confusing. Which approach will you prefer?

@vorburger

Copy link
Copy Markdown
Member

@thesmallstar yes that's a very good point.. you are absolutely right, of course, this test could fail if it runs against a DB that already contains data, for example if it runs after other tests, which makes it potentially flaky and brittle. Change it like you suggested! Maybe instead of only testing that it's +1 more, you could assert on the content of the audit record itself as well?

PS: There's a bigger issue about test isolation underlying this, but we're not going to solve this here.

@vorburger vorburger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

improve as discussed

@thesmallstar
thesmallstar force-pushed the it700 branch 2 times, most recently from 9c47929 to dfa2bd5 Compare June 24, 2020 12:12
@thesmallstar

Copy link
Copy Markdown
Member Author

@vorburger I have made the suggested changes. I am not supposed to user var in this case(right?).

@vorburger
vorburger merged commit a5afb0b into apache:develop Jun 26, 2020
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.

2 participants