Skip to content

fixed README.md #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 98 additions & 74 deletions spring-boot-postgres-graphql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,65 @@ The controller provides four queries:
Follow the steps to start the application:

## Clone

- First, clone the repository:

```bash
git clone https://github.com/keploy/samples-java
```
```bash
git clone https://github.com/keploy/samples-java
```

Navigate to the project folder:

```bash
cd samples-java/spring-boot-postgres-graphql
```
```bash
cd samples-java/spring-boot-postgres-graphql
```

## Quick Keploy Installation

- Depending on your OS and preference (Docker/Native), you can set up Keploy using the one-click installation method:
```bash
curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh
```

## Setup DB

You have two possible cases:

### Use your postgres installation

If you already have PostgreSQL installed on your machine and want to use this installation, follow these steps:

1. If not already started, launch the PostgreSQL service:

```bash
curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh
sudo service postgresql start
```

## Setup DB
2. Set the password for the postgres user (or alternatively, modify the application.properties file within the project):
```bash
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'root';"
```
3. Create the demo database:

```bash
sudo -u postgres createdb library_demo
```

### Use postgres docker image

If you have Docker installed and prefer a PostgreSQL instance in a container, follow these steps:

1. Build the Docker image:

```bash
docker build -t postgres_library:demo ./postgres_demo_docker
```
```bash
docker build -t postgres_library:demo ./postgres_demo_docker
```

2. Run a container from the generated image:

```bash
docker run -d -p 5432:5432 --name postgres postgres_library:demo
```
```bash
docker run -d -p 5432:5432 --name postgres postgres_library:demo
```

## Use of Keploy

Expand All @@ -69,71 +94,70 @@ If you have Docker installed and prefer a PostgreSQL instance in a container, fo
### Query from GraphQL GUI

Now, go to `localhost:8081/graphiql` and access the GraphQL interface to make requests to the application.
- Make a `getAllBooks` query:

```graphql
query {
getAllBooks {
name
author {
id
firstName
lastName
}
}
}
```

- Make a `getBookByName` query:

```graphql
query {
getBookByName(name: "The Secret of the Moon") {
id
name
pageCount
author {
firstName
lastName
}
}
}
```

- Make a `getAllAuthors` query:

```graphql
query {
getAllAuthors {
id
firstName
lastName
}
}
```

- Make a `getAuthorById` query:

```graphql
query {
getAuthorById(id: 2) {
firstName
}
}
```

You can experiment with the data you want to retrieve from the query by removing or rearranging fields.
- Make a `getAllBooks` query:

```graphql
query {
getAllBooks {
name
author {
id
firstName
lastName
}
}
}
```

- Make a `getBookByName` query:

```graphql
query {
getBookByName(name: "The Secret of the Moon") {
id
name
pageCount
author {
firstName
lastName
}
}
}
```

- Make a `getAllAuthors` query:

```graphql
query {
getAllAuthors {
id
firstName
lastName
}
}
```

- Make a `getAuthorById` query:

```graphql
query {
getAuthorById(id: 2) {
firstName
}
}
```

The generated tests and mocks are stored in the `Keploy` directory in the current working directory.
You can experiment with the data you want to retrieve from the query by removing or rearranging fields.

The generated tests and mocks are stored in the `Keploy` directory in the current working directory.

### Execute tests

To test the app, start Keploy in test mode. In the root directory, run:

```bash
keploy test -c "mvn spring-boot:run" --delay 15
```

This will run the tests and generate the report in the `Keploy/reports` directory in the current working directory.
```bash
keploy test -c "mvn spring-boot:run" --delay 15
```

This will run the tests and generate the report in the `Keploy/reports` directory in the current working directory.