Skip to content

Commit

Permalink
add mock exception
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/release.yml
  • Loading branch information
JaredTan95 committed Jan 12, 2024
1 parent 35c26c4 commit 2d6febe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public ResponseEntity<Advertise[]> findByAdKey(@PathVariable String key) {

@GetMapping("/{id}")
public ResponseEntity<Advertise> findById(@PathVariable Long id) {
if ( id % 2 ==0){
throw new RuntimeException("mock runtime exception in GET:/ad ");
}
return this.restTemplate.getForEntity("http://" + dataServiceName + "/ad/{id}", Advertise.class, id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public Iterable<Ad> getAllAds() {
@ResponseBody
public Ad getAdById(@PathVariable("id") int id) {
// This returns a JSON or XML with the users
if ( id % 2 ==0){
throw new RuntimeException("mock runtime exception");
}
return adRepository.findById(id).orElse(new Ad());
}

Expand All @@ -63,7 +66,11 @@ public Iterable<Ad> findAdvertiseByAdKey(@PathVariable("adKey") String adKey) {
public Info call() {
Random random = new Random();
Info info = new Info();
info.setID(String.format("%d%d", System.currentTimeMillis(), random.nextInt(10)));
int id = random.nextInt(10);
if ( id % 2 ==0){
throw new NullPointerException("mock nil pointer exception");
}
info.setID(String.format("%d%d", System.currentTimeMillis(),id ));
info.setHostName(System.getenv("HOSTNAME"));
info.setVersion(System.getenv("VERSION"));
return info;
Expand Down

0 comments on commit 2d6febe

Please sign in to comment.