Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 12 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,17 @@
</dependency>

<!-- local-->
<!-- <dependency>-->
<!-- <groupId>io.keploy</groupId>-->
<!-- <artifactId>keploy-sdk</artifactId>-->
<!-- <version>0.0.1-SNAPSHOT</version>-->
<!-- </dependency>-->

<!-- deployed-->
<dependency>
<groupId>io.keploy</groupId>
<artifactId>keploy-sdk</artifactId>
<version>1.1.1</version>
<version>1.2.2</version>
</dependency>


<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down Expand Up @@ -91,6 +88,12 @@
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc5</artifactId>
<version>11.2.0.4</version>
</dependency>
</dependencies>

<build>
Expand Down
36 changes: 34 additions & 2 deletions src/main/java/com/example/demo/controller/EmployeeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.Instant;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/")
Expand All @@ -17,6 +20,12 @@ public class EmployeeController {
@Autowired
private EmployeeRepository employeeRepository;

//get employees
@GetMapping("employees")
public List<Employee> getAllEmployee() {
return this.employeeRepository.findAll();
}

//get employee by id
@GetMapping("employees/{id}")
public ResponseEntity<Employee> getEmployeeById(@PathVariable(value = "id") Long employeeId) throws ResourceNotFoundException {
Expand All @@ -30,4 +39,27 @@ public Employee createEmployee(@RequestBody Employee employee) {
employee.setTimestamp(Instant.now().getEpochSecond());
return this.employeeRepository.save(employee);
}
}

//update employee
@PutMapping("employees/{id}")
public ResponseEntity<Employee> updateEmployee(@PathVariable(value = "id") Long employeeId, @Valid @RequestBody Employee employeeDetails) throws ResourceNotFoundException {

Employee employee = employeeRepository.findById(employeeId).orElseThrow(() -> new ResourceNotFoundException("Employee not found for this id :: " + employeeId));
employee.setEmail(employeeDetails.getEmail());
employee.setFirstName(employeeDetails.getFirstName());
employee.setLastName(employeeDetails.getLastName());
employee.setTimestamp(Instant.now().getEpochSecond());
return ResponseEntity.ok(this.employeeRepository.save(employee));
}

//delete employee
@DeleteMapping("employees/{id}")
public Map<String, Boolean> deleteEmployee(@PathVariable(value = "id") Long employeeId) throws ResourceNotFoundException {
Employee employee = employeeRepository.findById(employeeId).orElseThrow(() -> new ResourceNotFoundException("Employee not found for this id :: " + employeeId));
this.employeeRepository.delete(employee);
Map<String, Boolean> response = new HashMap<>();
response.put("deleted", Boolean.TRUE);

return response;
}
}
6 changes: 3 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spring.datasource.url=jdbc:postgresql://localhost:5439/keploy-test
spring.datasource.username=keploy-user
spring.datasource.password=keploy
spring.jpa.show-sql=true
#spring.jpa.show-sql=true
#spring.datasource.driverClassName=io.keploy.ksql.KDriver
spring.jpa.properties.hibernate.format_sql=true
## Hibernate Properties
Expand All @@ -11,8 +11,8 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update

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

server.port=8080
logging.level.root=INFO
37 changes: 37 additions & 0 deletions src/test/e2e/keploy-tests/test-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: api.keploy.io/v1beta1
kind: Http
name: test-1
spec:
metadata: {}
req:
method: POST
proto_major: 1
proto_minor: 1
url: /api/employees
header:
accept: '*/*'
accept-encoding: gzip, deflate, br
cache-control: no-cache
connection: keep-alive
content-length: "101"
content-type: application/json
host: localhost:8080
user-agent: PostmanRuntime/7.29.2
body: "{\n \"firstName\": \"Sam\",\n \"lastName\": \"Tyson\", \n \"email\": \"mt@gmail.com\",\n \"timestamp\":1\n}"
resp:
status_code: 200
header: {}
body: '{"id":1,"firstName":"Sam","lastName":"Tyson","email":"mt@gmail.com","timestamp":1671896801}'
status_message: OK
proto_major: 1
proto_minor: 1
objects:
- type: error
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
mocks:
- test-1-0
assertions:
noise:
- body.timestamp
- body.id
created: 1671896802
36 changes: 36 additions & 0 deletions src/test/e2e/keploy-tests/test-10.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: api.keploy.io/v1beta1
kind: Http
name: test-10
spec:
metadata: {}
req:
method: POST
proto_major: 1
proto_minor: 1
url: /api/employees
header:
accept: '*/*'
accept-encoding: gzip, deflate, br
cache-control: no-cache
connection: keep-alive
content-length: "103"
content-type: application/json
host: localhost:8080
user-agent: PostmanRuntime/7.29.2
body: "{\n \"firstName\": \"Trent\",\n \"lastName\": \"Boult\", \n \"email\": \"mt@gmail.com\",\n \"timestamp\":1\n}"
resp:
status_code: 200
header: {}
body: '{"id":8,"firstName":"Trent","lastName":"Boult","email":"mt@gmail.com","timestamp":1671974006}'
status_message: OK
proto_major: 1
proto_minor: 1
objects:
- type: error
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
mocks:
- test-10-0
assertions:
noise:
- body.timestamp
created: 1671974006
35 changes: 35 additions & 0 deletions src/test/e2e/keploy-tests/test-11.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: api.keploy.io/v1beta1
kind: Http
name: test-11
spec:
metadata: {}
req:
method: GET
proto_major: 1
proto_minor: 1
url: /api/employees
header:
accept: '*/*'
accept-encoding: gzip, deflate, br
cache-control: no-cache
connection: keep-alive
content-length: "103"
content-type: application/json
host: localhost:8080
user-agent: PostmanRuntime/7.29.2
body: ""
resp:
status_code: 200
header: {}
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}]'
status_message: OK
proto_major: 1
proto_minor: 1
objects:
- type: error
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
mocks:
- test-11-0
assertions:
noise: []
created: 1671974030
36 changes: 36 additions & 0 deletions src/test/e2e/keploy-tests/test-12.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: api.keploy.io/v1beta1
kind: Http
name: test-12
spec:
metadata: {}
req:
method: POST
proto_major: 1
proto_minor: 1
url: /api/employees
header:
accept: '*/*'
accept-encoding: gzip, deflate, br
cache-control: no-cache
connection: keep-alive
content-length: "103"
content-type: application/json
host: localhost:8080
user-agent: PostmanRuntime/7.29.2
body: "{\n \"firstName\": \"Harry\",\n \"lastName\": \"Brook\", \n \"email\": \"mt@gmail.com\",\n \"timestamp\":1\n}"
resp:
status_code: 200
header: {}
body: '{"id":9,"firstName":"Harry","lastName":"Brook","email":"mt@gmail.com","timestamp":1671974094}'
status_message: OK
proto_major: 1
proto_minor: 1
objects:
- type: error
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
mocks:
- test-12-0
assertions:
noise:
- body.timestamp
created: 1671974094
35 changes: 35 additions & 0 deletions src/test/e2e/keploy-tests/test-13.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: api.keploy.io/v1beta1
kind: Http
name: test-13
spec:
metadata: {}
req:
method: GET
proto_major: 1
proto_minor: 1
url: /api/employees/6
header:
accept: '*/*'
accept-encoding: gzip, deflate, br
cache-control: no-cache
connection: keep-alive
content-length: "103"
content-type: application/json
host: localhost:8080
user-agent: PostmanRuntime/7.29.2
body: ""
resp:
status_code: 200
header: {}
body: '{"id":6,"firstName":"Tom","lastName":"Tyson","email":"mt@gmail.com","timestamp":1671898758}'
status_message: OK
proto_major: 1
proto_minor: 1
objects:
- type: error
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
mocks:
- test-13-0
assertions:
noise: []
created: 1671974113
35 changes: 35 additions & 0 deletions src/test/e2e/keploy-tests/test-14.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: api.keploy.io/v1beta1
kind: Http
name: test-14
spec:
metadata: {}
req:
method: DELETE
proto_major: 1
proto_minor: 1
url: /api/employees/6
header:
accept: '*/*'
accept-encoding: gzip, deflate, br
cache-control: no-cache
connection: keep-alive
content-length: "103"
content-type: application/json
host: localhost:8080
user-agent: PostmanRuntime/7.29.2
body: ""
resp:
status_code: 200
header: {}
body: '{"deleted":true}'
status_message: OK
proto_major: 1
proto_minor: 1
objects:
- type: error
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
mocks:
- test-14-0
assertions:
noise: []
created: 1671974119
36 changes: 36 additions & 0 deletions src/test/e2e/keploy-tests/test-15.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: api.keploy.io/v1beta1
kind: Http
name: test-15
spec:
metadata: {}
req:
method: PUT
proto_major: 1
proto_minor: 1
url: /api/employees/9
header:
accept: '*/*'
accept-encoding: gzip, deflate, br
cache-control: no-cache
connection: keep-alive
content-length: "103"
content-type: application/json
host: localhost:8080
user-agent: PostmanRuntime/7.29.2
body: "{\n \"firstName\": \"Barry\",\n \"lastName\": \"Brook\", \n \"email\": \"mt@gmail.com\",\n \"timestamp\":1\n}"
resp:
status_code: 200
header: {}
body: '{"id":9,"firstName":"Barry","lastName":"Brook","email":"mt@gmail.com","timestamp":1671974135}'
status_message: OK
proto_major: 1
proto_minor: 1
objects:
- type: error
data: H4sIAAAAAAAA/wEAAP//AAAAAAAAAAA=
mocks:
- test-15-0
assertions:
noise:
- body.timestamp
created: 1671974135
Loading