Package org.apache.sling.hamcrest
Class ResourceMatchers
- java.lang.Object
-
- org.apache.sling.hamcrest.ResourceMatchers
-
public final class ResourceMatchers extends Object
A collection ofMatchers that work on the Resource API level
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource>containsChildren(String... children)Matches resources which have exactly the children with the names given inchildren.static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource>containsChildrenInAnyOrder(String... children)Matches resources which have exactly the children with the names given inchildren.static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource>hasChildren(String... children)Matches resources which have amongst their children the specifiedchildren.static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource>name(String name)Matches only if the resource has the given namestatic org.hamcrest.Matcher<org.apache.sling.api.resource.Resource>nameAndProps(String name, Object... properties)Matches resources which has the given name and at least the specifiedpropertiesdefined with matching valuesstatic org.hamcrest.Matcher<org.apache.sling.api.resource.Resource>nameAndProps(String name, Map<String,Object> properties)Matches resources which has the given name and at least the specifiedpropertiesdefined with matching valuesstatic org.hamcrest.Matcher<org.apache.sling.api.resource.Resource>path(String path)Matches only if the resource has the given pathstatic org.hamcrest.Matcher<org.apache.sling.api.resource.Resource>props(Object... properties)Matches resources which has at least the specifiedpropertiesdefined with matching valuesstatic org.hamcrest.Matcher<org.apache.sling.api.resource.Resource>props(Map<String,Object> properties)Matches resources which has at least the specifiedpropertiesdefined with matching valuesstatic org.hamcrest.Matcher<org.apache.sling.api.resource.Resource>resourceType(String resourceType)Matches resources with a resource type set to the specifiedresourceType(exactly).static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource>resourceTypeOrDerived(String resourceType)Matches resources with a resource type set to the specifiedresourceTypeor one of its sub types.
-
-
-
Method Detail
-
hasChildren
public static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource> hasChildren(String... children)
Matches resources which have amongst their children the specifiedchildren. Child resources not contained in the specifiedchildrenare not validated. The order of the children does not matter.assertThat(resource, hasChildren('child1', 'child2'));- Parameters:
children- the expected children, notnullor empty- Returns:
- a matcher instance
-
containsChildren
public static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource> containsChildren(String... children)
Matches resources which have exactly the children with the names given inchildren. The order is validated as well.assertThat(resource, containsChildren('child1', 'child2'));- Parameters:
children- the expected children, notnullor empty- Returns:
- a matcher instance
-
containsChildrenInAnyOrder
public static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource> containsChildrenInAnyOrder(String... children)
Matches resources which have exactly the children with the names given inchildren. The order is not validated.assertThat(resource, containsChildrenInAnyOrder('child1', 'child2'));- Parameters:
children- the expected children, notnullor empty- Returns:
- a matcher instance
-
path
public static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource> path(String path)
Matches only if the resource has the given pathassertThat(resource, hasName('/a/b/c'));- Parameters:
path- the resources path, notnullor empty- Returns:
- a matcher instance
-
name
public static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource> name(String name)
Matches only if the resource has the given nameassertThat(resource, resourceWithName('resource1'));- Parameters:
name- the resources name, notnullor empty- Returns:
- a matcher instance
-
resourceType
public static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource> resourceType(String resourceType)
Matches resources with a resource type set to the specifiedresourceType(exactly). In order to check for resource types allowing more specific ones useresourceTypeOrDerived(String).assertThat(resource, resourceType('my/app'));- Parameters:
resourceType- the resource type to match- Returns:
- a matcher instance
-
resourceTypeOrDerived
public static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource> resourceTypeOrDerived(String resourceType)
Matches resources with a resource type set to the specifiedresourceTypeor one of its sub types. In order to check for exact resource types only useresourceType(String).assertThat(resource, resourceTypeOrDerived('my/app'));- Parameters:
resourceType- the resource type to match- Returns:
- a matcher instance
- Since:
- 1.1.0
- See Also:
Resource.isResourceType(String),resourceType(String)
-
props
public static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource> props(Map<String,Object> properties)
Matches resources which has at least the specifiedpropertiesdefined with matching valuesValues not declared in the the
propertiesparameter are not validated.Map<String, Object> expectedProperties = new HashMap<>(); expectedProperties.put("jcr:title", "Node title"); expectedProperties.put("jcr:text", "Some long text"); assertThat(resource, resourceWithProps(expectedProperties));- Parameters:
properties- the properties to match- Returns:
- a matcher instance
-
props
public static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource> props(Object... properties)
Matches resources which has at least the specifiedpropertiesdefined with matching valuesValues not declared in the the
propertiesparameter are not validated.Map<String, Object> expectedProperties = new HashMap<>(); expectedProperties.put("jcr:title", "Node title"); expectedProperties.put("jcr:text", "Some long text"); assertThat(resource, resourceWithProps(expectedProperties));- Parameters:
properties- the properties to match- Returns:
- a matcher instance
-
nameAndProps
public static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource> nameAndProps(String name, Map<String,Object> properties)
Matches resources which has the given name and at least the specifiedpropertiesdefined with matching valuesValues not declared in the the
propertiesparameter are not validated.Map<String, Object> expectedProperties = new HashMap<>(); expectedProperties.put("jcr:title", "Node title"); expectedProperties.put("jcr:text", "Some long text"); assertThat(resource, resourceWithProps(expectedProperties));- Parameters:
name- the expected name of the resourceproperties- the properties to match- Returns:
- a matcher instance
-
nameAndProps
public static org.hamcrest.Matcher<org.apache.sling.api.resource.Resource> nameAndProps(String name, Object... properties)
Matches resources which has the given name and at least the specifiedpropertiesdefined with matching valuesValues not declared in the the
propertiesparameter are not validated.Map<String, Object> expectedProperties = new HashMap<>(); expectedProperties.put("jcr:title", "Node title"); expectedProperties.put("jcr:text", "Some long text"); assertThat(resource, resourceWithProps(expectedProperties));- Parameters:
name- the expected name of the resourceproperties- the properties to match- Returns:
- a matcher instance
-
-