Skip to content

Commit d252d67

Browse files
authored
add instructor into readme (#32)
* add instructor into readme * add e2e testing * update make command --------- Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
1 parent 8447be9 commit d252d67

File tree

7 files changed

+54
-6
lines changed

7 files changed

+54
-6
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ jobs:
2626
sudo curl -L https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
2727
sudo chmod +x /usr/local/bin/docker-compose
2828
export OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
29-
make test-e2e
29+
make run-e2e

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
build-image:
22
docker build . -t ghcr.io/devops-ws/learn-springboot:master
3-
test-e2e:
3+
run-e2e:
44
cd e2e && ./start.sh
55
run-demo:
66
cd e2e && docker compose up server

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This project aims to verify [linuxsuren/api-testing](https://github.com/LinuxSuR
44
Run E2E testing:
55

66
```shell
7-
make build-image test-e2e
7+
make build-image run-e2e
88
```
99

1010
Run with Maven command:
@@ -13,11 +13,19 @@ Run with Maven command:
1313
mvn spring-boot:run
1414
```
1515

16+
Run in container:
17+
18+
```shell
19+
docker run -p 8080:8080 ghcr.io/devops-ws/learn-springboot:master
20+
```
21+
1622
Change the listen port:
1723
```shell
1824
java -jar demo.jar --server.port=8081
1925
```
2026

27+
The default username is `admin`, and password is: `123456`.
28+
2129
## OpenAPI definition
2230
You can visit it via: http://localhost:8080/v3/api-docs
2331

e2e/test-suite.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ api: |
55
{{default "http://localhost:8080" (env "SERVER")}}
66
param:
77
auth: Basic {{ base64 "admin:123456" }}
8+
randNum: |
9+
{{randInt 1 1000}}
810
items:
911
- name: health
1012
request:
@@ -120,3 +122,13 @@ items:
120122
expect:
121123
header:
122124
Content-Type: application/octet-stream
125+
126+
## cache
127+
- name: cache
128+
request:
129+
api: /cache?delay={{ .param.randNum }}
130+
header:
131+
Authorization: "{{ .param.auth }}"
132+
expect:
133+
bodyFieldsExpect:
134+
pageCount: "{{ .param.randNum }}"

src/main/java/io/github/devopsws/demo/DemoApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
import org.springframework.boot.SpringApplication;
66
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.cache.annotation.EnableCaching;
78

89
@EnableTRpc
10+
@EnableCaching
911
@SpringBootApplication
1012
public class DemoApplication {
1113

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.github.devopsws.demo.service;
2+
3+
import io.github.devopsws.demo.model.Book;
4+
import org.springframework.cache.annotation.Cacheable;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
@RestController
10+
@RequestMapping("/cache")
11+
public class CacheService {
12+
13+
@GetMapping("")
14+
@Cacheable("books")
15+
public Book index(Integer delay) {
16+
System.out.println("getting book with cache feature");
17+
if (delay == null) {
18+
delay = 0;
19+
}
20+
try {
21+
Thread.sleep(delay);
22+
} catch (Exception e) {
23+
e.printStackTrace();
24+
}
25+
26+
Book book = new Book("book-1", "Effective Java", delay, "author-1");
27+
return book;
28+
}
29+
}

src/main/java/io/github/devopsws/demo/service/GraphQL.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
import org.springframework.graphql.data.method.annotation.Argument;
44
import org.springframework.graphql.data.method.annotation.QueryMapping;
55
import org.springframework.graphql.data.method.annotation.MutationMapping;
6-
import org.springframework.graphql.data.method.annotation.SchemaMapping;
76
import org.springframework.stereotype.Controller;
87
import io.github.devopsws.demo.model.Book;
9-
import org.springframework.security.access.annotation.Secured;
10-
import org.springframework.security.access.prepost.PreAuthorize;
118

129
@Controller
1310
public class GraphQL {

0 commit comments

Comments
 (0)