本文整理汇总了Java中play.libs.ws.WS.newClient方法的典型用法代码示例。如果您正苦于以下问题:Java WS.newClient方法的具体用法?Java WS.newClient怎么用?Java WS.newClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.libs.ws.WS
的用法示例。
在下文中一共展示了WS.newClient方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIndex
import play.libs.ws.WS; //导入方法依赖的package包/类
/**
* Test method for {@link controllers.CidadeController#index()}.
*/
@Test
public void testIndex() {
String url = "/api";
try (WSClient ws = WS.newClient(this.testServer.port())) {
CompletionStage<WSResponse> stage = ws.url(url).get();
WSResponse response = stage.toCompletableFuture().get();
assertEquals(OK, response.getStatus());
} catch (InterruptedException | ExecutionException | IOException e) {
e.printStackTrace();
}
}
示例2: testCidadeInexistente
import play.libs.ws.WS; //导入方法依赖的package包/类
/**
* Test method for {@link controllers.CidadeController#get(Long)}.
*/
@Test
public void testCidadeInexistente() {
String url = "/api/cidade/0";
try (WSClient ws = WS.newClient(this.testServer.port())) {
CompletionStage<WSResponse> stage = ws.url(url).get();
WSResponse response = stage.toCompletableFuture().get();
assertEquals(NOT_FOUND, response.getStatus());
} catch (InterruptedException | ExecutionException | IOException e) {
e.printStackTrace();
}
}
示例3: testCidadeExistenteEmas
import play.libs.ws.WS; //导入方法依赖的package包/类
/**
* Test method for {@link controllers.CidadeController#get(Long)}.
*/
@Test
public void testCidadeExistenteEmas() throws Exception {
String url = "/api/cidade/2505907";
try (WSClient ws = WS.newClient(this.testServer.port())) {
CompletionStage<WSResponse> stage = ws.url(url).get();
WSResponse response = stage.toCompletableFuture().get();
assertEquals(OK, response.getStatus());
Cidade cidade = Json.fromJson(response.asJson(), Cidade.class);
assertEquals(2505907, cidade.getId().longValue());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
示例4: testCidadesSimilaresAUmaInexistente
import play.libs.ws.WS; //导入方法依赖的package包/类
/**
* Test method for {@link controllers.CidadeController#get(Long)}.
*/
@Test
public void testCidadesSimilaresAUmaInexistente() throws Exception {
String url = "/api/cidade/0/similares";
try (WSClient ws = WS.newClient(this.testServer.port())) {
CompletionStage<WSResponse> stage = ws.url(url).get();
WSResponse response = stage.toCompletableFuture().get();
assertEquals(NOT_FOUND, response.getStatus());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
示例5: testCidadesSimilaresAEmas
import play.libs.ws.WS; //导入方法依赖的package包/类
/**
* Test method for {@link controllers.CidadeController#get(Long)}.
*/
@Test
public void testCidadesSimilaresAEmas() throws Exception {
String url = "/api/cidade/2505907/similares";
try (WSClient ws = WS.newClient(this.testServer.port())) {
CompletionStage<WSResponse> stage = ws.url(url).get();
WSResponse response = stage.toCompletableFuture().get();
assertEquals(OK, response.getStatus());
assertTrue(response.asJson().elements().hasNext());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
示例6: test404
import play.libs.ws.WS; //导入方法依赖的package包/类
@Test
public void test404() throws Exception {
String url = "http://localhost:" + this.testServer.port() + "/api/alou";
try (WSClient ws = WS.newClient(this.testServer.port())) {
CompletionStage<WSResponse> stage = ws.url(url).get();
WSResponse response = stage.toCompletableFuture().get();
assertEquals(NOT_FOUND, response.getStatus());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
示例7: testSaveMensagem
import play.libs.ws.WS; //导入方法依赖的package包/类
@Test
@Ignore
public void testSaveMensagem() throws Exception {
String url = "/api/mensagem";
WSClient ws = WS.newClient(this.testServer.port());
CompletionStage<WSResponse> stage = ws.url(url).get();
WSResponse response = stage.toCompletableFuture().get();
assertEquals(OK, response.getStatus());
assertFalse(response.asJson().elements().hasNext());
stage = ws.url(url).post(Json.parse("{\"titulo\": \"Urgente!\", \"conteudo\": \"Siga em frente... olhe para o lado!\",\"autor\": \"Ministério da Justiça\"}"));
response = stage.toCompletableFuture().get();
assertEquals(OK, response.getStatus());
stage = ws.url(url).get();
response = stage.toCompletableFuture().get();
assertEquals(OK, response.getStatus());
JsonNode jsonNode = response.asJson().elements().next();
Mensagem mensagem = Json.fromJson(jsonNode, Mensagem.class);
assertNotNull(mensagem);
assertNotNull(mensagem.getId());
}
示例8: processesFormByGet
import play.libs.ws.WS; //导入方法依赖的package包/类
@Test
public void processesFormByGet() throws Exception {
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!");
}
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java-training,代码行数:12,代码来源:MyControllerWithServerTest.java
示例9: testInServer
import play.libs.ws.WS; //导入方法依赖的package包/类
@Test
public void testInServer() throws Exception {
String url = "http://localhost:" + this.testServer.port() + "/";
try (WSClient ws = WS.newClient(this.testServer.port())) {
CompletionStage<WSResponse> stage = ws.url(url).get();
WSResponse response = stage.toCompletableFuture().get();
assertEquals(OK, response.getStatus());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
示例10: testInServerThroughUrl
import play.libs.ws.WS; //导入方法依赖的package包/类
@Test
public void testInServerThroughUrl() throws Exception {
// Tests using a scoped WSClient to talk to the server through a port.
try (WSClient ws = WS.newClient(this.testServer.port())) {
CompletionStage<WSResponse> stage = ws.url("/").get();
WSResponse response = stage.toCompletableFuture().get();
String body = response.getBody();
assertThat(body, containsString("Add Person"));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
示例11: authorizedWhenEnabledAndCredentialsProvided
import play.libs.ws.WS; //导入方法依赖的package包/类
@Test
public void authorizedWhenEnabledAndCredentialsProvided() throws Exception {
try (WSClient wsClient = WS.newClient(testServer.port())) {
final WSResponse response = wsClient
.url(URI)
.setAuth(USERNAME, PASSWORD, WSAuthScheme.BASIC)
.get().toCompletableFuture().get();
assertThat(response.getStatus()).isEqualTo(Http.Status.OK);
}
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:11,代码来源:BasicHttpAuthenticationFilterTest.java
示例12: unauthorizedWhenEnabledAndWrongCredentialsProvided
import play.libs.ws.WS; //导入方法依赖的package包/类
@Test
public void unauthorizedWhenEnabledAndWrongCredentialsProvided() throws Exception {
try (WSClient wsClient = WS.newClient(testServer.port())) {
final WSResponse response = wsClient
.url(URI)
.setAuth(USERNAME, "wrong", WSAuthScheme.BASIC)
.get().toCompletableFuture().get();
assertThat(response.getStatus()).isEqualTo(Http.Status.UNAUTHORIZED);
assertThat(response.getHeader(Http.HeaderNames.WWW_AUTHENTICATE)).isNull();
}
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:12,代码来源:BasicHttpAuthenticationFilterTest.java
示例13: unauthorizedWhenEnabledAndNoCredentialsProvided
import play.libs.ws.WS; //导入方法依赖的package包/类
@Test
public void unauthorizedWhenEnabledAndNoCredentialsProvided() throws Exception {
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)).contains(REALM);
}
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:11,代码来源:BasicHttpAuthenticationFilterTest.java