本文整理汇总了Java中play.test.TestServer类的典型用法代码示例。如果您正苦于以下问题:Java TestServer类的具体用法?Java TestServer怎么用?Java TestServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestServer类属于play.test包,在下文中一共展示了TestServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: navAdminFirefox17
import play.test.TestServer; //导入依赖的package包/类
/**
* @author andre.tschirch
*
* Example test method for using specific Firefox version e.g. v17.
*
* Test method for running a successful login and the right presentation of
* the activity state of the admin navigation link, which must be active,
* for browser Firefox.
*/
// @Test
public void navAdminFirefox17() {
ProfilesIni profile = new ProfilesIni();
FirefoxProfile firefoxProfile = profile.getProfile("firefox17");
WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File("D:/schatzsuche/firefox17/firefox.exe")), firefoxProfile);
TestBrowser browser = Helpers.testBrowser(driver, 3333);
TestServer server = Helpers.testServer(3333, Helpers.fakeApplication());
TestServer startedServer = null;
try {
server.start();
startedServer = server;
new NavAdminCallbackComposite().invoke(browser);
} catch(Throwable t) {
throw new RuntimeException(t);
} finally {
if(browser != null) {
browser.quit();
}
if(startedServer != null) {
startedServer.stop();
}
}
}
示例2: testsWithServer
import play.test.TestServer; //导入依赖的package包/类
@Test
public void testsWithServer() throws Exception {
final TestServer testServer = testServer(fakeApplication());
running(testServer, () -> {
try (final WSClient wsClient = WS.newClient(testServer.port())) {
final WSResponse wsResponse = wsClient
.url("/playbasics/show2")
.setQueryString("name=John")
.get().toCompletableFuture().get();
assertThat(wsResponse.getStatus()).isEqualTo(OK);
assertThat(wsResponse.getBody()).isEqualTo("Hello John!");
} catch (IOException | InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
});
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java-training,代码行数:17,代码来源:MyControllerMixScopeTest.java
示例3: testSlideshowPitchFound
import play.test.TestServer; //导入依赖的package包/类
@Test
public void testSlideshowPitchFound() throws Exception {
TestServer server = testServer(3333);
running(server, () -> {
try {
WSClient ws = play.libs.ws.WS.newClient(3333);
CompletionStage<WSResponse> completionStage =
ws.url(SLIDESHOW_PITCH_FOUND).get();
WSResponse response = completionStage.toCompletableFuture().get();
ws.close();
assertEquals(OK, response.getStatus());
assertEquals(CONTENT_TYPE_HTML, response.getHeader(CONTENT_TYPE));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
}
示例4: testSlideshowPitchNotFound
import play.test.TestServer; //导入依赖的package包/类
@Test
public void testSlideshowPitchNotFound() throws Exception {
TestServer server = testServer(3333);
running(server, () -> {
try {
WSClient ws = play.libs.ws.WS.newClient(3333);
CompletionStage<WSResponse> completionStage =
ws.url(SLIDESHOW_PITCH_NOT_FOUND).get();
WSResponse response = completionStage.toCompletableFuture().get();
ws.close();
assertEquals(OK, response.getStatus());
assertEquals(CONTENT_TYPE_HTML, response.getHeader(CONTENT_TYPE));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
}
示例5: testMarkdownPitchFound
import play.test.TestServer; //导入依赖的package包/类
@Test
public void testMarkdownPitchFound() throws Exception {
TestServer server = testServer(3333);
running(server, () -> {
try {
WSClient ws = play.libs.ws.WS.newClient(3333);
CompletionStage<WSResponse> completionStage =
ws.url(MARKDOWN_PITCH_FOUND).get();
WSResponse response = completionStage.toCompletableFuture().get();
ws.close();
assertEquals(OK, response.getStatus());
assertEquals(CONTENT_TYPE_MD, response.getHeader(CONTENT_TYPE));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
}
示例6: testMarkdownPitchNotFound
import play.test.TestServer; //导入依赖的package包/类
@Test
public void testMarkdownPitchNotFound() throws Exception {
TestServer server = testServer(3333);
running(server, () -> {
try {
WSClient ws = play.libs.ws.WS.newClient(3333);
CompletionStage<WSResponse> completionStage =
ws.url(MARKDOWN_PITCH_NOT_FOUND).get();
WSResponse response = completionStage.toCompletableFuture().get();
ws.close();
assertEquals(OK, response.getStatus());
assertEquals(CONTENT_TYPE_MD, response.getHeader(CONTENT_TYPE));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
}
示例7: testUnsupportedEndpoint
import play.test.TestServer; //导入依赖的package包/类
@Test
public void testUnsupportedEndpoint() throws Exception {
TestServer server = testServer(SERVER_TEST_PORT);
running(server, () -> {
try {
WSClient ws = play.libs.ws.WS.newClient(SERVER_TEST_PORT);
CompletionStage<WSResponse> completionStage =
ws.url(UNSUPPORTED_ENDPOINT).get();
WSResponse response = completionStage.toCompletableFuture().get();
ws.close();
assertEquals(OK, response.getStatus());
assertEquals(CONTENT_TYPE_HTML, response.getHeader(CONTENT_TYPE));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
}
示例8: testInvalidEndpoint
import play.test.TestServer; //导入依赖的package包/类
@Test
public void testInvalidEndpoint() throws Exception {
TestServer server = testServer(SERVER_TEST_PORT);
running(server, () -> {
try {
WSClient ws = play.libs.ws.WS.newClient(SERVER_TEST_PORT);
CompletionStage<WSResponse> completionStage =
ws.url(INVALID_ENDPOINT).get();
WSResponse response = completionStage.toCompletableFuture().get();
ws.close();
assertEquals(SEE_OTHER, response.getStatus());
assertEquals(CONTENT_TYPE_UNDEF, response.getHeader(CONTENT_TYPE));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
}
示例9: testAcceptWebSocket
import play.test.TestServer; //导入依赖的package包/类
@Test
public void testAcceptWebSocket() {
TestServer server = testServer(19001);
running(server, () -> {
try {
AsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder().setMaxRequestRetry(0).build();
AsyncHttpClient client = new DefaultAsyncHttpClient(config);
WebSocketClient webSocketClient = new WebSocketClient(client);
try {
String serverURL = "ws://localhost:19001/ws";
WebSocketClient.LoggingListener listener = new WebSocketClient.LoggingListener();
CompletableFuture<WebSocket> completionStage = webSocketClient.call(serverURL, listener);
await().until(() -> {
assertThat(completionStage).isDone();
});
} finally {
//noinspection ThrowFromFinallyBlock
client.close();
}
} catch (Exception e) {
fail("Unexpected exception", e);
}
});
}
示例10: testRejectWebSocket
import play.test.TestServer; //导入依赖的package包/类
@Test
public void testRejectWebSocket() {
TestServer server = testServer(37117);
running(server, () -> {
try {
AsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder().setMaxRequestRetry(0).build();
AsyncHttpClient client = new DefaultAsyncHttpClient(config);
WebSocketClient webSocketClient = new WebSocketClient(client);
try {
String serverURL = "ws://localhost:37117/ws";
WebSocketClient.LoggingListener listener = new WebSocketClient.LoggingListener(message -> {});
CompletableFuture<WebSocket> completionStage = webSocketClient.call(serverURL, listener);
await().until(completionStage::isDone);
assertThat(completionStage)
.hasFailedWithThrowableThat()
.hasMessageContaining("Invalid Status Code 403");
} finally {
client.close();
}
} catch (Exception e) {
fail("Unexpected exception", e);
}
});
}
示例11: createNewerPlayServer
import play.test.TestServer; //导入依赖的package包/类
private static TestServer createNewerPlayServer() throws Exception {
Class<?> environmentClass = Class.forName("play.Environment");
Class<?> builderClass = Class.forName("play.inject.guice.GuiceApplicationBuilder");
Method inMethod = builderClass.getMethod("in", environmentClass);
Method buildMethod = builderClass.getMethod("build");
Object env = environmentClass.getConstructor(File.class).newInstance(new File("."));
Object builder = builderClass.newInstance();
builder = inMethod.invoke(builder, env);
Object app = buildMethod.invoke(builder);
Class<?> applicationClass = Class.forName("play.Application");
Constructor<TestServer> testServerConstructor =
TestServer.class.getConstructor(int.class, applicationClass);
return testServerConstructor.newInstance(port, app);
}
示例12: testsWithBrowser
import play.test.TestServer; //导入依赖的package包/类
@Test
public void testsWithBrowser() throws Exception {
final TestServer testServer = testServer(fakeApplication());
running(testServer, HTMLUNIT, browser -> {
browser.goTo("/playbasics/show5");
browser.fill("form input[name=name]").with("John");
browser.submit("button[type=submit]");
assertThat(browser.title()).isEqualTo("Hello you!");
assertThat(browser.url()).isEqualTo("/playbasics/show5");
assertThat(browser.text("p.message")).containsOnly("Hello John!");
});
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java-training,代码行数:14,代码来源:MyControllerMixScopeTest.java
示例13: testRejectWebSocket
import play.test.TestServer; //导入依赖的package包/类
@Test
public void testRejectWebSocket() {
TestServer server = testServer(31337);
running(server, () -> {
try {
AsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder().setMaxRequestRetry(0).build();
AsyncHttpClient client = new DefaultAsyncHttpClient(config);
WebSocketClient webSocketClient = new WebSocketClient(client);
try {
// localhost:31337 is not an acceptable origin to the server, so this will fail...
String serverURL = "ws://localhost:31337/ws";
WebSocketClient.LoggingListener listener = new WebSocketClient.LoggingListener();
CompletableFuture<WebSocket> completionStage = webSocketClient.call(serverURL, listener);
await().until(() -> {
assertThat(completionStage)
.hasFailedWithThrowableThat()
.hasMessageContaining("Invalid Status Code 403");
});
} finally {
//noinspection ThrowFromFinallyBlock
client.close();
}
} catch (Exception e) {
fail("Unexpected exception", e);
}
});
}
示例14: testServer
import play.test.TestServer; //导入依赖的package包/类
private TestServer testServer(final boolean isAuthEnabled) {
final Router router = new RoutingDsl()
.GET(URI).routeTo(() -> ok())
.build();
final Application app = new GuiceApplicationBuilder()
.configure("play.http.filters", "com.commercetools.sunrise.httpauth.basic.BasicHttpAuthenticationFilters")
.overrides(
bind(HttpAuthentication.class).toInstance(httpAuthentication(isAuthEnabled)),
bind(play.api.routing.Router.class).toInstance(router.asScala()))
.build();
return Helpers.testServer(app);
}
示例15: allowsAccessWhenDisabled
import play.test.TestServer; //导入依赖的package包/类
@Test
public void allowsAccessWhenDisabled() throws Exception {
final TestServer testServer = testServer(false);
running(testServer, () -> {
try (WSClient wsClient = WS.newClient(testServer.port())) {
final WSResponse response = wsClient
.url(URI)
.get().toCompletableFuture().get();
assertThat(response.getStatus()).isEqualTo(Http.Status.OK);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}