[MAGNOLIA-5784] NodeMatchers improvements: Property matchers Created: 23/May/14  Updated: 04/Feb/15  Resolved: 23/May/14

Status: Closed
Project: Magnolia
Component/s: testing
Affects Version/s: None
Fix Version/s: 5.3

Type: Improvement Priority: Neutral
Reporter: Magnolia International Assignee: Magnolia International
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)

 Description   

It'd be useful to have matchers like hasProperty() where we can match on the property's name, value, or anything.

Example use cases:

assertThat(node, allOf(
                hasProperty(propertyName(containsString("y"))),
                hasProperty("abc", containsString("oo")),
                hasProperty(
                        Matchers.<Property>allOf(
                                propertyName(containsString("ef")),
                                propertyValue(isA(Long.class))
                        )
                )
        ));
        // It's a pity we have to help the either().or() matcher with generics here, but I couldn't find a way around that. Other option is to use anyOf() which I find less readable.
        assertThat(node, everyProperty(Matchers.<Property>either(propertyName(startsWith("jcr:"))).or(propertyValue(equalTo("mgnl:dummyNode")))));


 Comments   
Comment by Magnolia International [ 23/May/14 ]

Pushed on the MAGNOLIA-5784-PropertyMatchers branch.
Usages found in our codebase in task-management, pages and dam modules. All pass with no changes. One assertion was workflow, I just fixed it - the new methods don't support relative paths for properties anymore.

Generated at Mon Feb 12 04:08:21 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.