|
Play Framework/Scala example source code file (WithServer.java)
The WithServer.java Play Framework example source code/* * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com> */ package play.test; import org.junit.After; import org.junit.Before; /** * Provides a server to JUnit tests. Make your test class extend this class and an HTTP server will be started before each test is invoked. * You can setup the fake application and port to use by overriding the provideFakeApplication and providePort methods. * Within a test, the running application and the TCP port are available through the app and port fields, respectively. */ public class WithServer { protected FakeApplication app; protected int port; protected TestServer testServer; /** * Override this method to setup the fake application to use. * * @return The fake application used by the server */ protected FakeApplication provideFakeApplication() { return Helpers.fakeApplication(); } /** * Override this method to setup the port to use. * * @return The TCP port used by the server */ protected int providePort() { return play.api.test.Helpers.testServerPort(); } @Before public void startServer() { if (testServer != null) { testServer.stop(); } app = provideFakeApplication(); port = providePort(); testServer = Helpers.testServer(port, app); testServer.start(); } @After public void stopServer() { if (testServer != null) { testServer.stop(); testServer = null; app = null; } } } Other Play Framework source code examplesHere is a short list of links related to this Play Framework WithServer.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.