#BAEL-913 serenitybdd and spring (#1845)

This commit is contained in:
Tian Baoqiang
2017-05-16 04:01:28 -05:00
committed by Grzegorz Piwowarek
parent 9f88ff0d2e
commit e2aabe819e
19 changed files with 802 additions and 13 deletions
@@ -0,0 +1,28 @@
package com.baeldung.serenity.spring;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author aiet
*/
@RequestMapping(value = "/konamicode", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RestController
public class KonamiCodeController {
private final String classicCode = "↑↑↓↓←→←→BA";
@GetMapping("/classic")
public String classicCode() {
return classicCode;
}
@GetMapping("/cheatable")
public boolean cheatCheck(@RequestParam String cheatcode){
return classicCode.equals(cheatcode);
}
}
@@ -0,0 +1,39 @@
package com.baeldung.serenity.spring;
import org.springframework.stereotype.Service;
/**
* refer to <a href="https://en.wikipedia.org/wiki/Konami_Code">Konami Code</a>
*/
@Service
public class KonamiCodeService {
private String classicCode = "↑↑↓↓←→←→BA";
public String getClassicCode() {
return classicCode;
}
public void alterClassicCode(String newCode) {
classicCode = newCode;
}
public boolean cheatWith(String cheatcode) {
if ("↑↑↓↓←→←→BA".equals(cheatcode)) {
stageLeft++;
return true;
}
return false;
}
private int stageLeft = 1;
public void clearStage() {
stageLeft = 0;
}
public int stageLeft() {
return stageLeft;
}
}
@@ -0,0 +1,41 @@
package com.baeldung.serenity.spring;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
/**
* @author aiet
*/
@RequestMapping(value = "/konamicode", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RestController
public class KonamiCodeServiceInjectionController {
private KonamiCodeService konamiCodeService;
public KonamiCodeServiceInjectionController(KonamiCodeService konamiCodeService) {
this.konamiCodeService = konamiCodeService;
}
@PutMapping("/stages")
public void clearStage(@RequestParam String action) {
if ("clear".equals(action)) {
konamiCodeService.clearStage();
}
}
@GetMapping("/classic")
public String classicCode() {
return konamiCodeService.getClassicCode();
}
@GetMapping("/cheatable")
public boolean cheatCheck(@RequestParam String cheatcode) {
return konamiCodeService.cheatWith(cheatcode);
}
@GetMapping("/stages")
public int stageLeft() {
return konamiCodeService.stageLeft();
}
}