{"id":21409672,"url":"https://github.com/edgar-code-repository/spring-boot-cucumber-demo","last_synced_at":"2026-01-03T11:49:46.506Z","repository":{"id":150026293,"uuid":"597274166","full_name":"edgar-code-repository/spring-boot-cucumber-demo","owner":"edgar-code-repository","description":"Behavior driven development with Spring Boot and Cucumber.","archived":false,"fork":false,"pushed_at":"2023-03-05T23:17:33.000Z","size":486,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T04:29:30.713Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edgar-code-repository.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-04T03:00:37.000Z","updated_at":"2023-02-06T01:26:09.000Z","dependencies_parsed_at":"2023-04-12T20:24:31.579Z","dependency_job_id":null,"html_url":"https://github.com/edgar-code-repository/spring-boot-cucumber-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgar-code-repository%2Fspring-boot-cucumber-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgar-code-repository%2Fspring-boot-cucumber-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgar-code-repository%2Fspring-boot-cucumber-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgar-code-repository%2Fspring-boot-cucumber-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edgar-code-repository","download_url":"https://codeload.github.com/edgar-code-repository/spring-boot-cucumber-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243910454,"owners_count":20367537,"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":[],"created_at":"2024-11-22T17:28:02.783Z","updated_at":"2026-01-03T11:49:46.468Z","avatar_url":"https://github.com/edgar-code-repository.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"CUCUMBER DEMO\n-----------------------------------------------------------------\n\nBehaviour driven development with Spring Boot and Cucumber.\n\nA few Cucumber examples are created to test Rest endpoints.\n\n![CucumberExecution](screenshots/cucumber_tests_execution.png)\n\n-----------------------------------------------------------------\n\n**Dependencies added to pom.xml file**\n\n```\n\n    \u003cdependency\u003e\n        \u003cgroupId\u003eio.cucumber\u003c/groupId\u003e\n        \u003cartifactId\u003ecucumber-java\u003c/artifactId\u003e\n        \u003cversion\u003e${cucumber.version}\u003c/version\u003e\n        \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n    \n    \u003cdependency\u003e\n        \u003cgroupId\u003eio.cucumber\u003c/groupId\u003e\n        \u003cartifactId\u003ecucumber-junit\u003c/artifactId\u003e\n        \u003cversion\u003e${cucumber.version}\u003c/version\u003e\n        \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n    \n    \u003cdependency\u003e\n        \u003cgroupId\u003eio.cucumber\u003c/groupId\u003e\n        \u003cartifactId\u003ecucumber-spring\u003c/artifactId\u003e\n        \u003cversion\u003e${cucumber.version}\u003c/version\u003e\n        \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n\n```\n-----------------------------------------------------------------\n\n**Cucumber configuration**\n\nIn this configuration class we can tell where to find the Cucumber features \nfiles and where the glue classes are located (steps):\n\n```\n\n    @RunWith(Cucumber.class)\n    @CucumberOptions(\n            features = {\"src/test/resources/features\"},\n            plugin = {\"pretty\"},\n            glue = {\"com.example.demo.cucumber.base\", \"com.example.demo.cucumber.steps\"})\n    public class CucumberRunner {\n    \n    }\n\n```\n\n-----------------------------------------------------------------\n\n**Book.feature** is located in the directory **src/test/resources/features**\nand contains the cucumber tests related to the **class BookController.java**\n\n```\n\n    Feature: Book feature\n    \n        Scenario: Add book to catalog\n        Given given a book with id \"101\" title \"Book A\" author \"John Doe\" and published in 1980\n        When  the book is added to the catalog\n        Then  execution returns success with code 201\n\n\n        Scenario: Retrieve books from catalog\n        Given given that we have some new books\n        When  the books are added to the catalog\n        Then  books are retrieved successfully\n\n\n        Scenario: Update book from catalog\n        Given given a book with id \"999\" title \"Book 999\" author \"John Doe\" and published in 1985\n        When the book is added to the catalog\n        And the book with id \"999\" title \"Book 999 update\" author \"John Doe\" and published in 1984 is updated\n        Then execution returns success with code 200\n\n\n        Scenario: Delete book from catalog\n        Given given a book with id \"999\" title \"Book 999\" author \"John Doe\" and published in 1985\n        When the book with id \"999\" is deleted\n        Then execution returns success with code 200\n\n```\n\n-----------------------------------------------------------------\n\nThe feature file executes the logic in the class **BookSteps.java**,\nwhich is located in the directory **src/test/com/example/demo**.\n\n```\n\npublic class BookSteps extends TestBase {\n\n    private BookDTO bookDTO;\n    private List\u003cBookDTO\u003e bookList;\n    private ResponseEntity\u003cBookResponse\u003e bookResponse;\n\n    @Given(\"^given a book with id \\\"([^\\\"]*)\\\" title \\\"([^\\\"]*)\\\" author \\\"([^\\\"]*)\\\" and published in (\\\\d+)$\")\n    public void given_a_new_book(String id, String title, String author, int year) throws Throwable {\n        log.info(\"Given a new book with id: \" + id);\n\n        bookDTO = new BookDTO();\n        bookDTO.setId(id);\n        bookDTO.setTitle(title);\n        bookDTO.setAuthor(author);\n        bookDTO.setYear(year);\n    }\n\n    @Given(\"^that we have some new books$\")\n    public void given_some_new_books() throws Throwable {\n        log.info(\"Given some new books...\");\n\n        bookList = new ArrayList\u003c\u003e();\n\n        BookDTO bookDTO = new BookDTO();\n        bookDTO.setId(\"1001\");\n        bookDTO.setTitle(\"Book 1001\");\n        bookDTO.setAuthor(\"author\");\n        bookDTO.setYear(1991);\n\n        bookList.add(bookDTO);\n\n        bookDTO = new BookDTO();\n        bookDTO.setId(\"1002\");\n        bookDTO.setTitle(\"Book 1002\");\n        bookDTO.setAuthor(\"author\");\n        bookDTO.setYear(1992);\n\n        bookList.add(bookDTO);\n\n        bookDTO = new BookDTO();\n        bookDTO.setId(\"1003\");\n        bookDTO.setTitle(\"Book 1003\");\n        bookDTO.setAuthor(\"author\");\n        bookDTO.setYear(1993);\n\n        bookList.add(bookDTO);\n\n    }\n\n    @When(\"^the book is added to the catalog$\")\n    public void a_book_is_added() {\n        String urlAddBook = baseUrl;\n        log.info(\"A book is added calling url: \" + urlAddBook);\n\n        HttpEntity\u003cBookDTO\u003e entity = new HttpEntity\u003c\u003e(bookDTO, null);\n        this.bookResponse = restTemplate.exchange(urlAddBook, HttpMethod.POST, entity, BookResponse.class);\n    }\n\n    @When(\"^the books are added to the catalog$\")\n    public void books_are_added() {\n        log.info(\"Books are added...\");\n\n        String urlAddBook = baseUrl;\n\n        if (bookList != null \u0026\u0026 bookList.size() \u003e 0) {\n            log.info(\"Books size: \" + bookList.size());\n\n            for (BookDTO book: bookList) {\n                HttpEntity\u003cBookDTO\u003e entity = new HttpEntity\u003c\u003e(book, headers);\n                ResponseEntity\u003cBookResponse\u003e bookResponse = restTemplate.exchange(urlAddBook, HttpMethod.POST, entity, BookResponse.class);\n\n                log.info(\"book added response status: \" + bookResponse.getStatusCode().value());\n                if (bookResponse.getStatusCodeValue() != HttpStatus.CREATED.value()) {\n                    fail();\n                }\n                log.info(\"book id: \" + bookResponse.getBody().getBookDTO().getId());\n            }\n        }\n        else {\n            fail();\n        }\n\n    }\n\n    @When(\"^the book with id \\\"([^\\\"]*)\\\" title \\\"([^\\\"]*)\\\" author \\\"([^\\\"]*)\\\" and published in (\\\\d+) is updated$\")\n    public void update_book(String id, String title, String author, int year) throws Throwable {\n        log.info(\"Update book with id : \" + id);\n\n        bookDTO = new BookDTO();\n        bookDTO.setId(id);\n        bookDTO.setTitle(title);\n        bookDTO.setAuthor(author);\n        bookDTO.setYear(year);\n\n        String urlGetBook = baseUrl + \"/\" + bookDTO.getId();\n        seCreaHeader();\n\n        HttpEntity\u003cBookDTO\u003e entity = new HttpEntity\u003c\u003e(bookDTO, headers);\n        this.bookResponse = restTemplate.exchange(urlGetBook, HttpMethod.PUT, entity, BookResponse.class);\n    }\n\n    @When(\"^the book with id \\\"([^\\\"]*)\\\" is deleted$\")\n    public void delete_book(String id) throws Throwable {\n        log.info(\"Delete book with id : \" + id);\n\n        String urlGetBook = baseUrl + \"/\" + id;\n        seCreaHeader();\n\n        HttpEntity\u003cBookDTO\u003e entity = new HttpEntity\u003c\u003e(null, headers);\n        this.bookResponse = restTemplate.exchange(urlGetBook, HttpMethod.DELETE, entity, BookResponse.class);\n    }\n\n    @Then(\"^execution returns success with code (\\\\d+)$\")\n    public void execution_returns_code(int httpCode) {\n        log.info(\"Execution returns with code : \" + httpCode);\n\n        if (bookResponse != null) {\n            assertThat(bookResponse.getStatusCodeValue()).isEqualTo(httpCode);\n        } else {\n            fail();\n        }\n    }\n\n    @Then(\"^books are retrieved successfully$\")\n    public void books_retrieved_successfully() throws Throwable {\n        log.info(\"Books retrieved succesfully...\");\n\n        seCreaHeader();\n\n        if (bookList != null \u0026\u0026 bookList.size() \u003e 0) {\n            for (BookDTO book: bookList) {\n                String urlGetBook = baseUrl + \"/\" + book.getId();\n                HttpEntity entity = new HttpEntity\u003c\u003e(null, headers);\n                ResponseEntity\u003cBookResponse\u003e bookResponse = restTemplate.exchange(urlGetBook, HttpMethod.GET, entity, BookResponse.class);\n                log.info(\"bookResponse status: \" + bookResponse.getStatusCode().value());\n\n                if (bookResponse == null || bookResponse.getStatusCodeValue() != 200 ) {\n                    fail();\n                }\n                else {\n                    log.info(\"Get book success...\");\n                    assertThat(bookResponse.getBody() != null);\n                    assertThat(bookResponse.getBody().getBookDTO() != null);\n                    assertThat(bookResponse.getBody().getBookDTO().getId() == book.getId());\n                }\n\n            }\n        }\n        else {\n            fail();\n        }\n\n    }\n\n```\n\n-----------------------------------------------------------------\n\n**Create book endpoint (book with id 101):**\n\n![SaveBook1](screenshots/save-book-1.png)\n\n-----------------------------------------------------------------\n\n**Create book endpoint (book with id 102):**\n\n![SaveBook2](screenshots/save-book-2.png)\n\n-----------------------------------------------------------------\n\n**Retrieve all books endpoint:**\n\n![GetBooks](screenshots/retrieve-all-books.png)\n\n-----------------------------------------------------------------\n\n**Update book endpoint (book with id 101):**\n\n![UpdateBook1](screenshots/update-book-1.png)\n\n-----------------------------------------------------------------\n\n**Delete book endpoint (book with id 102):**\n\n![DeleteBook2](screenshots/delete-book-2.png)\n\n-----------------------------------------------------------------\n\n**Retrieve all books again:**\n\n![GetBooksAgain](screenshots/retrieve-books-again.png)\n\n-----------------------------------------------------------------","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedgar-code-repository%2Fspring-boot-cucumber-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedgar-code-repository%2Fspring-boot-cucumber-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedgar-code-repository%2Fspring-boot-cucumber-demo/lists"}