Added a project to github today
There is a version running on heroku too see
or the demo game
tictactoe – http://bjason-tictactoe.herokuapp.com/swagger/home.xhtml
It’s a springfox swagger implementation of oauth using spring(with hibernate/h2), jsf, cucumber and selenium
Quick note, the tests use Selenium and are set to use Firefox and Chrome. See file JsfFeatureSteps.java in package bjason.swagger.jsf. Also note that to test Chrome at least I’ve had to include copies of chromedrive for Linux. You’ll need copies for other platforms from here https://sites.google.com/a/chromium.org/chromedriver/
What does the game do? It just allows 2 players to have a game of tic tac toe. It doesn’t check who wins, so it isn’t finished. it just shows the use of a simple rest api.
Note the use of spring profile below, as default is to deploy to heroku (postgress) rather than in memory h2 db.
to run up to play tictactoe as well as see the swagger gui
mvnw clean spring-boot:run -Dspring.profiles.active=local
then visit http://127.0.0.1:8080/swagger/swagger-ui.html
or to play the game
Swagger requires a recent version of the browser, be that Chrome, Firefox or IE. The oauth functionality uses Object.assign which is added in ECMAScript 6th edition.
I’ve included the swagger-ui here, as I’ve tested this works, at least for my 2 browsers, Chrome and Firefox.
To run selenium tests
mvnw package -Dspring.profiles.active=local
test class JsfFeatureSteps.java sets up the use of 2 browsers. If you aren’t using Chrome or Firefox, or are a
non Linux 64 bit please visit http://www.seleniumhq.org/download/ to see links to the various third party drivers
you may need to change this entry if using windows
“./chromedriver.” + System.getProperty(“os.name”) + “.”
to simple reference the drive explicitly, e.g. System.setProperty(“webdriver.chrome.driver”,”chromedrive.exe”);
the test is setup to use 2 browsers, Chrome and Firefox. To change simply set these lines accordingly.
_chromePlayer2 = new ChromeDriver();
_firefoxPlayer1 = new FirefoxDriver();
I chose these browsers simply because they are the 2 I use for testing on my system.
this file creates the actual game resources. Using lots of swagger annotations it defines the interface alongside the implementation.
It is here that the rest api definitions have their scope’s defined as well. There’s a lot of annotations but the entire api is configured in one place,
then the actual code just implements the api functionality. The authorisation is specified here but actually implemented in CheckBearer.java.
this class extends HandlerInterceptorAdapter and implements the check to ensure the token is valid. Massive cheat here as I use a
spring bean rather than call the check externally via a rest call or similar.
CheckBearer is added as an intercepter in HelloworldApplication..java
this class implements the rest api’s to support oauth operations. It supports the GET that the tictactoe web app makes to get a token, along
with the POST create of a token that authorization/authorization_server.html uses before it redirects back to the calling tictactoe web app
this page is simply the simple page that the oauth provider implements, here you just enter an email address that isnt validated and it will then
create a token and allow a redirect back to the app using the specified redirect_uri
the app is using h2 in memory db to store information about the game in progress.
Sets up JSF servlet, adds a logging filter plus adds the CheckBearer for calls to the tictactoe rest resources.
<2h>WEB-INF/ faces-config.xml and web.xml
This is needed just to keep JSF happy. Otherwise not required.
setup is via src/test/resources/bjason/swagger/jsf/jsf.feature, and classes CucumberJsfTest.java and JsfFeatureSteps. I’ve described the
scenarios for driving the GUI pages using selenium. Sorry no proper unit tests.