当前位置: 首页>>代码示例>>Java>>正文


Java WS.newClient方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:16,代码来源:HTTPStackTest.java

示例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();
    }
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:16,代码来源:HTTPStackTest.java

示例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();
    }
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:18,代码来源:HTTPStackTest.java

示例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();
    }
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:16,代码来源:HTTPStackTest.java

示例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();
    }
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:17,代码来源:HTTPStackTest.java

示例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();
    }
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:13,代码来源:HTTPStackTest.java

示例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());
  }
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:25,代码来源:HTTPStackTest.java

示例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();
    }
}
 
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:12,代码来源:HomeControllerTest.java

示例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();
    }
}
 
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:13,代码来源:IntegrationTest.java

示例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


注:本文中的play.libs.ws.WS.newClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。