Git Product home page Git Product logo

assertj-sling's Introduction

AssertJ for Sling

Implemented to speed up testing of Sling applications.

Usage

  1. Asserting Resource Properties:

Assert that the resource has the specified resource type.

hasResourceType(String expectedResourceType)

assertThat(resource)
    .hasResourceType("sling:Folder");

Assert that the resource has the specified resource super type.

hasResourceSuperType(String expectedSuperType)

assertThat(resource)
   .hasResourceSuperType("sling:Folder");

Assert that the resource has the specified resource path.

hasResourcePath(String expectedPath)

assertThat(resource)
    .hasResourcePath("/content/sling/en");

Assert that the resource has the specified name.

hasResourceName(String expectedName)

assertThat(resource)
    .hasResourceName("jcr:content"); 
  1. Child Resource Assertions:

Assert that the resource has children.

hasChildren()

    assertThat(resource)
        .hasChildren();

Assert that the resource has a specific child resource.

hasChildResource(String childResourcePath)

assertThat(resource)
    .hasChildResource("jcr:content");           

Asserts properties or conditions on a child resource.

childResourceSatisfies(String childResourcePath, Consumer<Resource> assertion)

assertThat(resource)
    .childResourceSatisfies(
        "jcr:content", 
        content -> assertThat(content).hasProperty("jcr:title"));    
  1. Resource Property Assertions:

Assert that the resource has a specific property.

hasProperty(String propertyName)

assertThat(resource)
    .hasProperty("jcr:title");
  1. Resource Value Assertions (for ValueMap):

Assert that a property in the resource's ValueMap has a specific value.

hasPropertyValue(String propertyName, Object expectedValue)

assertThat(resource)
    .hasPropertyValue("jcr:title", "Sling");

Assert that a property in the ValueMap matches a given predicate.

propertyValueSatisfies(String propertyName, Class<PT> clazz, Consumer<PT> assertion)

assertThat(resource)
    .propertyValueSatisfies(
        "jcr:title", 
        String.class, 
        title -> assertThat(title).isEqualTo("Title"));

Extracting property values

extracting(Object... keys)

assertThat(resource)
    .extracting("jcr:title", "jcr:description")
    .containsExactly("Title", "Description");
  1. Resource Adaptation Assertions:

Assert that the resource can be adapted to a specific type.

canAdaptTo(Class<T> type)

assertThat(resource)
    .canAdaptTo(TitleModel.class);    
  1. Resource Existence Assertions:

Assert that the resource exists.

exists()

assertThat(resource)
    .exists();

assertj-sling's People

Contributors

mirashopsiup avatar

Watchers

Mark VDH avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.