本文整理汇总了Java中play.test.TestServer类的典型用法代码示例。如果您正苦于以下问题:Java TestServer类的具体用法?Java TestServer怎么用?Java TestServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestServer类属于play.test包,在下文中一共展示了TestServer类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
}
}
开发者ID:stefanil,项目名称:play2-prototypen,代码行数:34,代码来源:CommonBrowserNavigationTest.java
示例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);
}
});
}
开发者ID:gitpitch,项目名称:gitpitch,代码行数:19,代码来源:FunctionalTest.java
示例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);
}
});
}
开发者ID:gitpitch,项目名称:gitpitch,代码行数:19,代码来源:FunctionalTest.java
示例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);
}
});
}
开发者ID:gitpitch,项目名称:gitpitch,代码行数:19,代码来源:FunctionalTest.java
示例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);
}
});
}
开发者ID:gitpitch,项目名称:gitpitch,代码行数:19,代码来源:FunctionalTest.java
示例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);
}
});
}
开发者ID:gitpitch,项目名称:gitpitch,代码行数:19,代码来源:FunctionalTest.java
示例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);
}
});
}
开发者ID:gitpitch,项目名称:gitpitch,代码行数:19,代码来源:FunctionalTest.java
示例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);
}
});
}
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:27,代码来源:FunctionalTest.java
示例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);
}
});
}
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:26,代码来源:FunctionalTest.java
示例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);
}
开发者ID:glowroot,项目名称:glowroot,代码行数:18,代码来源:Play2xIT.java
示例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);
}
});
}
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:30,代码来源:FunctionalTest.java
示例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);
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:13,代码来源:HttpAuthenticationFilterTest.java
示例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);
}
});
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:15,代码来源:HttpAuthenticationFilterTest.java
示例16: unauthorizedWhenEnabled
import play.test.TestServer; //导入依赖的package包/类
@Test
public void unauthorizedWhenEnabled() throws Exception {
final TestServer testServer = testServer(true);
running(testServer, () -> {
try (WSClient wsClient = WS.newClient(testServer.port())) {
final WSResponse response = wsClient
.url(URI)
.get().toCompletableFuture().get();
assertThat(response.getStatus()).isEqualTo(Http.Status.UNAUTHORIZED);
assertThat(response.getHeader(Http.HeaderNames.WWW_AUTHENTICATE).equals(AUTHENTICATE_HEADER_CONTENT));
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:16,代码来源:HttpAuthenticationFilterTest.java
示例17: createOlderPlayServer
import play.test.TestServer; //导入依赖的package包/类
private static TestServer createOlderPlayServer() throws Exception {
Class<?> globalSettingsClass = Class.forName("play.GlobalSettings");
Class<?> fakeApplicationClass = Class.forName("play.test.FakeApplication");
Constructor<?> fakeApplicationConstructor = fakeApplicationClass.getConstructor(
File.class, ClassLoader.class, Map.class, List.class, globalSettingsClass);
Object app = fakeApplicationConstructor.newInstance(new File("."),
PlayWrapper.class.getClassLoader(), ImmutableMap.of(), ImmutableList.of(),
null);
Constructor<TestServer> testServerConstructor =
TestServer.class.getConstructor(int.class, fakeApplicationClass);
return testServerConstructor.newInstance(port, app);
}
开发者ID:glowroot,项目名称:glowroot,代码行数:13,代码来源:Play2xIT.java
示例18: createEvenOlderPlayServer
import play.test.TestServer; //导入依赖的package包/类
private static TestServer createEvenOlderPlayServer() throws Exception {
Class<?> fakeApplicationClass = Class.forName("play.test.FakeApplication");
Constructor<?> fakeApplicationConstructor = fakeApplicationClass.getConstructor(
File.class, ClassLoader.class, Map.class, List.class);
Object app = fakeApplicationConstructor.newInstance(new File("."),
PlayWrapper.class.getClassLoader(), ImmutableMap.of(), ImmutableList.of());
Constructor<TestServer> testServerConstructor =
TestServer.class.getConstructor(int.class, fakeApplicationClass);
return testServerConstructor.newInstance(port, app);
}
开发者ID:glowroot,项目名称:glowroot,代码行数:11,代码来源:Play2xIT.java
示例19: configure
import play.test.TestServer; //导入依赖的package包/类
@Override
protected void configure() {
bind(TestBrowser.class).toInstance(testBrowser);
bind(TestServer.class).toInstance(testServer);
bind(Integer.class).annotatedWith(Names.named("PORT")).toInstance(PORT);
}
开发者ID:Arquisoft,项目名称:ObservaTerra42,代码行数:7,代码来源:CucumberModule.java
注:本文中的play.test.TestServer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论