contract-testing-demo
pact and java contract testing with micro-commits
AlligatorController.java
(906B)
1 package app.alligator;
2
3 import org.springframework.web.bind.annotation.GetMapping;
4 import org.springframework.web.bind.annotation.PathVariable;
5 import org.springframework.web.bind.annotation.RestController;
6
7 @RestController
8 public class AlligatorController {
9
10 private final AlligatorRepository alligatorRepository;
11
12 public AlligatorController(AlligatorRepository alligatorRepository) {
13 this.alligatorRepository = alligatorRepository;
14 }
15
16 @GetMapping("/alligators/{name}")
17 public Alligator getByName(@PathVariable String name) {
18 Alligator alligator;
19
20 try {
21 alligator = alligatorRepository.getByName(name);
22 } catch (Exception exception) {
23 throw new AlligatorRepositoryUnavailableException();
24 }
25
26 if (alligator == null) {
27 throw new AlligatorNotFoundException();
28 }
29
30 return alligator;
31 }
32 }