{"id":21726970,"url":"https://github.com/wttech/stubway","last_synced_at":"2025-04-12T23:34:02.029Z","repository":{"id":38612562,"uuid":"499425329","full_name":"wttech/stubway","owner":"wttech","description":null,"archived":false,"fork":false,"pushed_at":"2022-10-10T13:50:44.000Z","size":614,"stargazers_count":4,"open_issues_count":10,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2023-03-12T05:02:18.954Z","etag":null,"topics":["aem","aem-tools","hacktoberfest","java","stubs"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wttech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-03T07:49:07.000Z","updated_at":"2022-10-05T15:39:11.000Z","dependencies_parsed_at":"2023-01-19T16:17:51.042Z","dependency_job_id":null,"html_url":"https://github.com/wttech/stubway","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wttech%2Fstubway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wttech%2Fstubway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wttech%2Fstubway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wttech%2Fstubway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wttech","download_url":"https://codeload.github.com/wttech/stubway/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226438817,"owners_count":17625107,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aem","aem-tools","hacktoberfest","java","stubs"],"created_at":"2024-11-26T03:42:36.655Z","updated_at":"2024-11-26T03:42:37.409Z","avatar_url":"https://github.com/wttech.png","language":"Java","readme":"[![WTT logo](docs/wtt-logo.png)](https://www.wundermanthompson.com/service/technology)\n\n# Stubway\n\nSimple, easy-to-use and fast way to make tests stable.\n\n### What is Stubway?\n\nStubway allows less code-oriented people to easily create and maintain stubs for a specific request and response.\n\nStubway is a dependency free tool (Java code only) for AEM, used on platforms which restrict third party libraries and \nframeworks. This also makes Stubway easy to maintain and develop for anyone familiar with Java language.\n\n### How to use?\nTo use Stubway: \n* Install Stubway package on your AEM author and/or publish instance\n* To get example stubs, install stubway.ui.content-\u003cversion\u003e.zip \n* Start creating your own stubs!\n\n#### How to create stub for GET REST returning 200 OK and json? \n\nTo create GET REST response for request sent to http://localhost:4503/content/books\nwith one query parameter `type=fantasy` (http://localhost:4503/content/books?type=fantasy), you need to perform \nthe following steps:\n\n**Step 1.** Go to CRXDE Lite http://localhost:4503/crx/de (NOTE: stubway is not accessible through /siteadmin view)\n\n**Step 2.** Under `/content` create new node `books` (this name is important - it matches the path at REST endpoint) \nand choose `nt:unstructured` in Type field.\n\n![create node](docs/demo/create_node.png)\n\n**Step 3.** Add property `sling:resourceType` with value `stubway/stub` for `/content/books` node:\n \n![add_resource node](docs/demo/add_resource.png)\n\n**Step 4.** Under `/content/books` node create new file `get-fantasy.json` (file name is irrelevant)\n\n![create_file](docs/demo/create_file.png)\n\n**Step 5.** Click on `get-fantasy.json` and put content of json file. This will be the GET REST response. \n\n```json\n{\n    \"nbrOfBooks\" : \"4\",\n    \"books\" : [\n        {\n            \"author\" : \"Author 1\",\n            \"title\" : \"Fantasy Title 1\"\n        },\n        {\n            \"author\" : \"Author 2\",\n            \"title\" : \"Fantasy Title 2\"\n        },\n        {\n            \"author\" : \"Author 3\",\n            \"title\" : \"Fantasy Title 3\"\n        },\n        {\n            \"author\" : \"Author 4\",\n            \"title\" : \"Fantasy Title 4\"\n        }\n    ]\n}\n```\n\nAdd the following properties: \n\n`jcr:mixinTypes` type: Name, value: cq:ComponentMixin\n\n`stub.method` type: String, value: GET \u003c-- this property indicates the method of REST request. It can have the following\nvalues: GET, POST, PUT, DELETE (coming more in future).\n\n`type` type: String, value: fantasy \u003c-- this property matches the query parameter `type`. `fantasy` value will match \n`?type=fantasy` requests\n\nYou may also use regular expression patterns as the value of the property. To indicate that the value of a specific\nproperty should be treated as a regex pattern and matched against the value of the named URL query parameter, you must\nadd the \".regex\" suffix to the property name:\n\n`type.regex` type: String, value: ^hist.*$ \u003c-- this property matches the query parameter `type`. `^hist.*$` value\nwill match both `?type=history` or `?type=historical fiction` requests.\n\nWhen the body of a request is in JSON format, you may create properties to match values inside the JSON data, by simply\nadding the \"body.\" prefix to the property name:\n\n`body.language` type: String, value: English \u003c-- this property matches a JSON key with name `language` and value\n`English` in the body of the request.\n\nYou also have the option to specify values to be included or replaced in the response headers. Response headers are\nidentified with the \"stub.res.\" prefix and may refer to standard HTTP headers or custom proprietary ones:\n\n`stub.res.Server` type: String, value: Stubway/1.0.0 \u003c-- this property will include the `Server` HTTP header in the\nresponse. The value of the header will be `Stubway/1.0.0`.\n\n![add_resource node](docs/demo/get-fantasy.png)\n\nSave the changes.\n\n**Step 6.** Test your new stub. \n\nIn REST client (i.e. Postman), run GET request: http://localhost:4503/content/books?type=fantasy\n\nYou should receive json response as it was configured in previous step: \n\n#### How to create stub returning different HTTP Status Code?\n\nYou can create stubs returning any HTTP Status Code (https://restfulapi.net/http-status-codes/)\n`stub.statusCode` property with proper value in the file node. For example, if you want your stub to return \n401 (Unauthorized):\n\n![add_status_code](docs/demo/status_code.png)\n\n\n#### More examples? \n\nFind more examples under `/content/stubway` (provided in stubway.ui.content-\u003cversion\u003e.zip package).\n\nPlease note that the stubs provided in that package will respond to requests with the following base URL:\n\n`http://localhost:4503/content/stubway/library/\u003cendpoint\u003e`\n\nReflecting the full path of their respective nodes, as seen in CRXDE Lite\n\n#### Prerequisites\n\nBefore you start creating your own stubs, make sure that you have:\n* Java 8 or higher installed,\n* Maven installed,\n* AEM 6.4.X or higher up and running.\n\n#### Installation\n\nGo to the project root directory and run the following command with Maven 3:\n\n    mvn clean install\n\nWhen AEM instance is up, build and deploy the whole package using the following command:\n\n    mvn clean install -PautoInstallPackage\n\nTo deploy it to a publish instance, run:\n\n    mvn clean install -PautoInstallPackagePublish\n\nAlternatively run:\n\n    mvn clean install -PautoInstallPackage -Daem.port=4503\n\nThe maven execution should complete with success status, listing all the deployed bundles:\n\n```\n[INFO] ------------------------------------------------------------------------\n[INFO] Reactor Summary for Stubway 1.0.0:\n[INFO]\n[INFO] Stubway ............................................ SUCCESS [  0.355 s]\n[INFO] Stubway - Core ..................................... SUCCESS [  3.224 s]\n[INFO] Stubway - UI apps .................................. SUCCESS [  0.716 s]\n[INFO] Stubway - UI content ............................... SUCCESS [  0.594 s]\n[INFO] Stubway - All ...................................... SUCCESS [  0.316 s]\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n```\n\nTo deploy only one of those bundles to the author instance, go the respective folder and run:\n\n    mvn clean install -PautoInstallBundle\n    \n### Testing \n\nGo to [\"how to test\"](stubway.tests/README.md) documentation.\n\n## Support\n\nDo you have any questions? Have you found a bug? \n\nRaise it using a proper [issue template](/.github/ISSUE_TEMPLATE.md). We will do our best to get back with a quick \nreply.\n\nDo you want to contribute? \n\nThat's amazing! See our [Contributing](/CONTRIBUTING.md) guide to get started.\n\n\n## License\n\nStubway project is licensed under the terms of the [Apache 2.0 license](LICENSE.md).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwttech%2Fstubway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwttech%2Fstubway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwttech%2Fstubway/lists"}