Skip to content

Latest commit

 

History

History

moco

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

AEM Stubs - Moco

Allows providing stubs (or mocks) by implementing Groovy script basing on Moco framework.

Sample stub mapping (hello-world.stub.json):

[
  {
    "request" :
    {
      "uri" : "/hello-world"
    },
    "response" :
    {
      "text" : "Hello! I am sample stub."
    }
  }
]

Sample stub script (hello-world.stub.groovy):

stubs.server
        .get(by(uri("/hello-world")))
        .response("Hello! I am sample stub.")

stubs.server
        .get(by(uri("/read_query_file")))
        .response(jcr(template('/conf/stubs/moco/samples/${req.queries["id"]}.json')))

stubs.server
        .get(
                and(
                        by(uri("/secured")),
                        eq(query("password"), "secret")
                )
        )
        .response("Secured endpoint revealed!")

stubs.server
        .get(by(uri("/current-date")))
        .response(template('Today date is "${date}"', "date", suppliedVar({ new Date() })))

Table of contents

Installation

Download appropriate distribution from releases section:

  • moco-all - Moco framework only with Groovy OSGi bundle included,
  • moco-app - Moco framework only without Groovy OSGi bundle included.
  • all - Moco and WireMock frameworks with Groovy OSGi bundle included,
  • app - Moco and WireMock frameworks without Groovy OSGi bundle included.

Documentation

To create stubs for web services or more basically mock any data, it is needed to only create a stub script under pre-configured path, e.g /conf/stubs/moco/hello.groovy.

stubs.server
        .get(by(uri("/hello-world")))
        .response("Hello! I am sample stub.")

Above stub will be accessible at URL http://localhost:5555/hello-world. Note that port 5555 is configurable via OSGi configuration.

OSGi configuration

Be aware of common / Moco agnostic OSGi configuration at first.

Then check see Moco specific OSGi configuration below:

Moco Stubs

Stub script API

At first, see common script API.

Pre-defined variables:

Default imports (not needed to be specified explicitly in scripts):

Useful links

Known issues

None.