|
| 1 | +# Library DEMO |
| 2 | + |
| 3 | +### Requirements |
| 4 | + |
| 5 | +- JDK 17 |
| 6 | +- Maven 3.9.5 |
| 7 | +- Docker or PostgreSQL |
| 8 | + |
| 9 | +### About the DEMO |
| 10 | + |
| 11 | +This is a Spring Boot application implementing a GraphQL service to handle requests related to books and authors. |
| 12 | + |
| 13 | +The controller provides four queries: |
| 14 | + |
| 15 | +- `getBookByName`: Returns a book based on the specified name. |
| 16 | +- `getAllBooks`: Retrieves all books present in the repository. |
| 17 | +- `getAuthorById`: Fetches an author based on the provided ID. |
| 18 | +- `getAllAuthors`: Retrieves all authors available in the repository. |
| 19 | + |
| 20 | +# Getting Started |
| 21 | + |
| 22 | +Follow the steps to start the application: |
| 23 | + |
| 24 | +## Clone |
| 25 | +- First, clone the repository: |
| 26 | + |
| 27 | + ```bash |
| 28 | + git clone https://github.com/keploy/samples-java |
| 29 | + ``` |
| 30 | + Navigate to the project folder: |
| 31 | + |
| 32 | + ```bash |
| 33 | + cd samples-java/spring-boot-postgres-graphql |
| 34 | + ``` |
| 35 | + |
| 36 | +## Quick Keploy Installation |
| 37 | + |
| 38 | +- Depending on your OS and preference (Docker/Native), you can set up Keploy using the one-click installation method: |
| 39 | + ```bash |
| 40 | + curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh |
| 41 | + ``` |
| 42 | + |
| 43 | +## Setup DB |
| 44 | + |
| 45 | +### Use postgres docker image |
| 46 | + |
| 47 | +If you have Docker installed and prefer a PostgreSQL instance in a container, follow these steps: |
| 48 | +1. Build the Docker image: |
| 49 | + |
| 50 | + ```bash |
| 51 | + docker build -t postgres_library:demo ./postgres_demo_docker |
| 52 | + ``` |
| 53 | + |
| 54 | +2. Run a container from the generated image: |
| 55 | + |
| 56 | + ```bash |
| 57 | + docker run -d -p 5432:5432 --name postgres postgres_library:demo |
| 58 | + ``` |
| 59 | + |
| 60 | +## Use of Keploy |
| 61 | + |
| 62 | +1. Your application is ready to be executed!! |
| 63 | + To start Keploy in record mode, in the root directory, run: |
| 64 | + |
| 65 | + ```bash |
| 66 | + keploy record -c "mvn spring-boot:run" |
| 67 | + ``` |
| 68 | + |
| 69 | +### Query from GraphQL GUI |
| 70 | + |
| 71 | +Now, go to `localhost:8081/graphiql` and access the GraphQL interface to make requests to the application. |
| 72 | + - Make a `getAllBooks` query: |
| 73 | + |
| 74 | + ```graphql |
| 75 | + query { |
| 76 | + getAllBooks { |
| 77 | + name |
| 78 | + author { |
| 79 | + id |
| 80 | + firstName |
| 81 | + lastName |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + ``` |
| 86 | + |
| 87 | + - Make a `getBookByName` query: |
| 88 | + |
| 89 | + ```graphql |
| 90 | + query { |
| 91 | + getBookByName(name: "The Secret of the Moon") { |
| 92 | + id |
| 93 | + name |
| 94 | + pageCount |
| 95 | + author { |
| 96 | + firstName |
| 97 | + lastName |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + ``` |
| 102 | + |
| 103 | + - Make a `getAllAuthors` query: |
| 104 | + |
| 105 | + ```graphql |
| 106 | + query { |
| 107 | + getAllAuthors { |
| 108 | + id |
| 109 | + firstName |
| 110 | + lastName |
| 111 | + } |
| 112 | + } |
| 113 | + ``` |
| 114 | + |
| 115 | + - Make a `getAuthorById` query: |
| 116 | + |
| 117 | + ```graphql |
| 118 | + query { |
| 119 | + getAuthorById(id: 2) { |
| 120 | + firstName |
| 121 | + } |
| 122 | + } |
| 123 | + ``` |
| 124 | + |
| 125 | +You can experiment with the data you want to retrieve from the query by removing or rearranging fields. |
| 126 | + |
| 127 | + The generated tests and mocks are stored in the `Keploy` directory in the current working directory. |
| 128 | + |
| 129 | + |
| 130 | +### Execute tests |
| 131 | + |
| 132 | +To test the app, start Keploy in test mode. In the root directory, run: |
| 133 | + |
| 134 | + ```bash |
| 135 | + keploy test -c "mvn spring-boot:run" --delay 15 |
| 136 | + ``` |
| 137 | + |
| 138 | + This will run the tests and generate the report in the `Keploy/reports` directory in the current working directory. |
| 139 | + |
0 commit comments