Skip to content

Commit 400b769

Browse files
authored
feat: keploy integrate and add mocks (#18)
Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com> Signed-off-by: Sarthak Shyngle <50234097+Sarthak160@users.noreply.github.com>
1 parent b1c0d9c commit 400b769

44 files changed

Lines changed: 1298 additions & 17 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,17 @@
3030
</dependency>
3131

3232
<!-- local-->
33-
<!-- <dependency>-->
34-
<!-- <groupId>io.keploy</groupId>-->
35-
<!-- <artifactId>keploy-sdk</artifactId>-->
36-
<!-- <version>0.0.1-SNAPSHOT</version>-->
37-
<!-- </dependency>-->
38-
39-
<!-- deployed-->
4033
<dependency>
4134
<groupId>io.keploy</groupId>
4235
<artifactId>keploy-sdk</artifactId>
43-
<version>1.1.1</version>
36+
<version>1.2.2</version>
4437
</dependency>
4538

46-
39+
<dependency>
40+
<groupId>org.mariadb.jdbc</groupId>
41+
<artifactId>mariadb-java-client</artifactId>
42+
<version>2.7.1</version>
43+
</dependency>
4744
<dependency>
4845
<groupId>org.springframework.boot</groupId>
4946
<artifactId>spring-boot-starter-data-jpa</artifactId>
@@ -91,6 +88,12 @@
9188
<version>1.18.24</version>
9289
<scope>provided</scope>
9390
</dependency>
91+
<!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 -->
92+
<dependency>
93+
<groupId>com.oracle.database.jdbc</groupId>
94+
<artifactId>ojdbc5</artifactId>
95+
<version>11.2.0.4</version>
96+
</dependency>
9497
</dependencies>
9598

9699
<build>

src/main/java/com/example/demo/controller/EmployeeController.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
import org.springframework.http.ResponseEntity;
88
import org.springframework.web.bind.annotation.*;
99

10+
import javax.validation.Valid;
1011
import java.time.Instant;
11-
12+
import java.util.HashMap;
13+
import java.util.List;
14+
import java.util.Map;
1215

1316
@RestController
1417
@RequestMapping("/api/")
@@ -17,6 +20,12 @@ public class EmployeeController {
1720
@Autowired
1821
private EmployeeRepository employeeRepository;
1922

23+
//get employees
24+
@GetMapping("employees")
25+
public List<Employee> getAllEmployee() {
26+
return this.employeeRepository.findAll();
27+
}
28+
2029
//get employee by id
2130
@GetMapping("employees/{id}")
2231
public ResponseEntity<Employee> getEmployeeById(@PathVariable(value = "id") Long employeeId) throws ResourceNotFoundException {
@@ -30,4 +39,27 @@ public Employee createEmployee(@RequestBody Employee employee) {
3039
employee.setTimestamp(Instant.now().getEpochSecond());
3140
return this.employeeRepository.save(employee);
3241
}
33-
}
42+
43+
//update employee
44+
@PutMapping("employees/{id}")
45+
public ResponseEntity<Employee> updateEmployee(@PathVariable(value = "id") Long employeeId, @Valid @RequestBody Employee employeeDetails) throws ResourceNotFoundException {
46+
47+
Employee employee = employeeRepository.findById(employeeId).orElseThrow(() -> new ResourceNotFoundException("Employee not found for this id :: " + employeeId));
48+
employee.setEmail(employeeDetails.getEmail());
49+
employee.setFirstName(employeeDetails.getFirstName());
50+
employee.setLastName(employeeDetails.getLastName());
51+
employee.setTimestamp(Instant.now().getEpochSecond());
52+
return ResponseEntity.ok(this.employeeRepository.save(employee));
53+
}
54+
55+
//delete employee
56+
@DeleteMapping("employees/{id}")
57+
public Map<String, Boolean> deleteEmployee(@PathVariable(value = "id") Long employeeId) throws ResourceNotFoundException {
58+
Employee employee = employeeRepository.findById(employeeId).orElseThrow(() -> new ResourceNotFoundException("Employee not found for this id :: " + employeeId));
59+
this.employeeRepository.delete(employee);
60+
Map<String, Boolean> response = new HashMap<>();
61+
response.put("deleted", Boolean.TRUE);
62+
63+
return response;
64+
}
65+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
spring.datasource.url=jdbc:postgresql://localhost:5439/keploy-test
22
spring.datasource.username=keploy-user
33
spring.datasource.password=keploy
4-
spring.jpa.show-sql=true
4+
#spring.jpa.show-sql=true
55
#spring.datasource.driverClassName=io.keploy.ksql.KDriver
66
spring.jpa.properties.hibernate.format_sql=true
77
## Hibernate Properties
@@ -11,8 +11,8 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
1111
spring.jpa.hibernate.ddl-auto=update
1212

1313
# in order to populate some initial data for testing mark it as true.
14-
spring.jpa.defer-datasource-initialization=true
15-
spring.sql.init.mode=always
14+
#spring.jpa.defer-datasource-initialization=true
15+
#spring.sql.init.mode=always
1616

1717
server.port=8080
1818
logging.level.root=INFO
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: api.keploy.io/v1beta1
2+
kind: Http
3+
name: test-1
4+
spec:
5+
metadata: {}
6+
req:
7+
method: POST
8+
proto_major: 1
9+
proto_minor: 1
10+
url: /api/employees
11+
header:
12+
accept: '*/*'
13+
accept-encoding: gzip, deflate, br
14+
cache-control: no-cache
15+
connection: keep-alive
16+
content-length: "101"
17+
content-type: application/json
18+
host: localhost:8080
19+
user-agent: PostmanRuntime/7.29.2
20+
body: "{\n \"firstName\": \"Sam\",\n \"lastName\": \"Tyson\", \n \"email\": \"mt@gmail.com\",\n \"timestamp\":1\n}"
21+
resp:
22+
status_code: 200
23+
header: {}
24+
body: '{"id":1,"firstName":"Sam","lastName":"Tyson","email":"mt@gmail.com","timestamp":1671896801}'
25+
status_message: OK
26+
proto_major: 1
27+
proto_minor: 1
28+
objects:
29+
- type: error
30+
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
31+
mocks:
32+
- test-1-0
33+
assertions:
34+
noise:
35+
- body.timestamp
36+
- body.id
37+
created: 1671896802
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: api.keploy.io/v1beta1
2+
kind: Http
3+
name: test-10
4+
spec:
5+
metadata: {}
6+
req:
7+
method: POST
8+
proto_major: 1
9+
proto_minor: 1
10+
url: /api/employees
11+
header:
12+
accept: '*/*'
13+
accept-encoding: gzip, deflate, br
14+
cache-control: no-cache
15+
connection: keep-alive
16+
content-length: "103"
17+
content-type: application/json
18+
host: localhost:8080
19+
user-agent: PostmanRuntime/7.29.2
20+
body: "{\n \"firstName\": \"Trent\",\n \"lastName\": \"Boult\", \n \"email\": \"mt@gmail.com\",\n \"timestamp\":1\n}"
21+
resp:
22+
status_code: 200
23+
header: {}
24+
body: '{"id":8,"firstName":"Trent","lastName":"Boult","email":"mt@gmail.com","timestamp":1671974006}'
25+
status_message: OK
26+
proto_major: 1
27+
proto_minor: 1
28+
objects:
29+
- type: error
30+
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
31+
mocks:
32+
- test-10-0
33+
assertions:
34+
noise:
35+
- body.timestamp
36+
created: 1671974006
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: api.keploy.io/v1beta1
2+
kind: Http
3+
name: test-11
4+
spec:
5+
metadata: {}
6+
req:
7+
method: GET
8+
proto_major: 1
9+
proto_minor: 1
10+
url: /api/employees
11+
header:
12+
accept: '*/*'
13+
accept-encoding: gzip, deflate, br
14+
cache-control: no-cache
15+
connection: keep-alive
16+
content-length: "103"
17+
content-type: application/json
18+
host: localhost:8080
19+
user-agent: PostmanRuntime/7.29.2
20+
body: ""
21+
resp:
22+
status_code: 200
23+
header: {}
24+
body: '[{"id":1,"firstName":"Sam","lastName":"Tyson","email":"mt@gmail.com","timestamp":1671896801},{"id":2,"firstName":"Sam","lastName":"Tyson","email":"mt@gmail.com","timestamp":1671896805},{"id":3,"firstName":"Sam","lastName":"Tyson","email":"mt@gmail.com","timestamp":1671897026},{"id":4,"firstName":"Sam","lastName":"Tyson","email":"mt@gmail.com","timestamp":1671897029},{"id":5,"firstName":"Sam","lastName":"Tyson","email":"mt@gmail.com","timestamp":1671897896},{"id":6,"firstName":"Tom","lastName":"Tyson","email":"mt@gmail.com","timestamp":1671898758},{"id":7,"firstName":"mom","lastName":"Tyson","email":"mt@gmail.com","timestamp":1671901970},{"id":8,"firstName":"Trent","lastName":"Boult","email":"mt@gmail.com","timestamp":1671974006}]'
25+
status_message: OK
26+
proto_major: 1
27+
proto_minor: 1
28+
objects:
29+
- type: error
30+
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
31+
mocks:
32+
- test-11-0
33+
assertions:
34+
noise: []
35+
created: 1671974030
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: api.keploy.io/v1beta1
2+
kind: Http
3+
name: test-12
4+
spec:
5+
metadata: {}
6+
req:
7+
method: POST
8+
proto_major: 1
9+
proto_minor: 1
10+
url: /api/employees
11+
header:
12+
accept: '*/*'
13+
accept-encoding: gzip, deflate, br
14+
cache-control: no-cache
15+
connection: keep-alive
16+
content-length: "103"
17+
content-type: application/json
18+
host: localhost:8080
19+
user-agent: PostmanRuntime/7.29.2
20+
body: "{\n \"firstName\": \"Harry\",\n \"lastName\": \"Brook\", \n \"email\": \"mt@gmail.com\",\n \"timestamp\":1\n}"
21+
resp:
22+
status_code: 200
23+
header: {}
24+
body: '{"id":9,"firstName":"Harry","lastName":"Brook","email":"mt@gmail.com","timestamp":1671974094}'
25+
status_message: OK
26+
proto_major: 1
27+
proto_minor: 1
28+
objects:
29+
- type: error
30+
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
31+
mocks:
32+
- test-12-0
33+
assertions:
34+
noise:
35+
- body.timestamp
36+
created: 1671974094
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: api.keploy.io/v1beta1
2+
kind: Http
3+
name: test-13
4+
spec:
5+
metadata: {}
6+
req:
7+
method: GET
8+
proto_major: 1
9+
proto_minor: 1
10+
url: /api/employees/6
11+
header:
12+
accept: '*/*'
13+
accept-encoding: gzip, deflate, br
14+
cache-control: no-cache
15+
connection: keep-alive
16+
content-length: "103"
17+
content-type: application/json
18+
host: localhost:8080
19+
user-agent: PostmanRuntime/7.29.2
20+
body: ""
21+
resp:
22+
status_code: 200
23+
header: {}
24+
body: '{"id":6,"firstName":"Tom","lastName":"Tyson","email":"mt@gmail.com","timestamp":1671898758}'
25+
status_message: OK
26+
proto_major: 1
27+
proto_minor: 1
28+
objects:
29+
- type: error
30+
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
31+
mocks:
32+
- test-13-0
33+
assertions:
34+
noise: []
35+
created: 1671974113
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: api.keploy.io/v1beta1
2+
kind: Http
3+
name: test-14
4+
spec:
5+
metadata: {}
6+
req:
7+
method: DELETE
8+
proto_major: 1
9+
proto_minor: 1
10+
url: /api/employees/6
11+
header:
12+
accept: '*/*'
13+
accept-encoding: gzip, deflate, br
14+
cache-control: no-cache
15+
connection: keep-alive
16+
content-length: "103"
17+
content-type: application/json
18+
host: localhost:8080
19+
user-agent: PostmanRuntime/7.29.2
20+
body: ""
21+
resp:
22+
status_code: 200
23+
header: {}
24+
body: '{"deleted":true}'
25+
status_message: OK
26+
proto_major: 1
27+
proto_minor: 1
28+
objects:
29+
- type: error
30+
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
31+
mocks:
32+
- test-14-0
33+
assertions:
34+
noise: []
35+
created: 1671974119
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: api.keploy.io/v1beta1
2+
kind: Http
3+
name: test-15
4+
spec:
5+
metadata: {}
6+
req:
7+
method: PUT
8+
proto_major: 1
9+
proto_minor: 1
10+
url: /api/employees/9
11+
header:
12+
accept: '*/*'
13+
accept-encoding: gzip, deflate, br
14+
cache-control: no-cache
15+
connection: keep-alive
16+
content-length: "103"
17+
content-type: application/json
18+
host: localhost:8080
19+
user-agent: PostmanRuntime/7.29.2
20+
body: "{\n \"firstName\": \"Barry\",\n \"lastName\": \"Brook\", \n \"email\": \"mt@gmail.com\",\n \"timestamp\":1\n}"
21+
resp:
22+
status_code: 200
23+
header: {}
24+
body: '{"id":9,"firstName":"Barry","lastName":"Brook","email":"mt@gmail.com","timestamp":1671974135}'
25+
status_message: OK
26+
proto_major: 1
27+
proto_minor: 1
28+
objects:
29+
- type: error
30+
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
31+
mocks:
32+
- test-15-0
33+
assertions:
34+
noise:
35+
- body.timestamp
36+
created: 1671974135

0 commit comments

Comments
 (0)