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


Java ClientAndServer.stop方法代码示例

本文整理汇总了Java中org.mockserver.integration.ClientAndServer.stop方法的典型用法代码示例。如果您正苦于以下问题:Java ClientAndServer.stop方法的具体用法?Java ClientAndServer.stop怎么用?Java ClientAndServer.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mockserver.integration.ClientAndServer的用法示例。


在下文中一共展示了ClientAndServer.stop方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: should_return_server_version

import org.mockserver.integration.ClientAndServer; //导入方法依赖的package包/类
@Test
public void should_return_server_version() throws Exception {
	// Make sure SSL works by adding MockServer CA certificate to context
	SSLSocketFactory previousFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
	HttpsURLConnection.setDefaultSSLSocketFactory(SSLFactory.getInstance().sslContext().getSocketFactory());
	ClientAndServer mockServer = ClientAndServer.startClientAndServer(port);
	try {
		// Given: the server expects a request of its version
		mockServer
				.when(request().withMethod("POST").withPath("/xmlrpc/2/db")
						.withBody(new StringBody(
								"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>server_version</methodName><params/></methodCall>")))
				.respond(response().withStatusCode(200).withBody(
						"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><string>9.0e</string></value>\n</param>\n</params>\n</methodResponse>\n"));

		// When: Server version is requested
		Version version = OdooXmlRpcProxy.getServerVersion(RPCProtocol.RPC_HTTPS, host, port);

		// Then: the server version is returned
		assertThat(version).as("Server version").isNotNull().hasToString("9.0e");
	} finally {
		mockServer.stop();
		HttpsURLConnection.setDefaultSSLSocketFactory(previousFactory);
	}

}
 
开发者ID:DeBortoliWines,项目名称:openerp-java-api,代码行数:27,代码来源:OdooXmlRpcProxyTest.java

示例2: refreshUrlIsCorrect

import org.mockserver.integration.ClientAndServer; //导入方法依赖的package包/类
@Test
public void refreshUrlIsCorrect() throws IOException {
  final int PORT = 7552;
  final String REFRESH_ADDRESS = "http://localhost:" + PORT + "/refresh";

  long tokenExpires = 0;

  Configuration conf = buildConf("refresh token key",
      Long.toString(tokenExpires),
      "joebob",
      REFRESH_ADDRESS);

  Timer mockTimer = mock(Timer.class);
  when(mockTimer.now()).thenReturn(tokenExpires + 1000l);

  AccessTokenProvider tokenProvider =
      new ConfRefreshTokenBasedAccessTokenProvider(mockTimer);
  tokenProvider.setConf(conf);

  // Build mock server to receive refresh request

  ClientAndServer mockServer  = startClientAndServer(PORT);

  HttpRequest expectedRequest = request()
      .withMethod("POST")
      .withPath("/refresh")
      // Note, OkHttp does not sort the param values, so we need to
      // do it ourselves via the ordering provided to ParameterBody...
      .withBody(
          ParameterBody.params(
              Parameter.param(CLIENT_ID, "joebob"),
              Parameter.param(GRANT_TYPE, REFRESH_TOKEN),
              Parameter.param(REFRESH_TOKEN, "refresh token key")));

  MockServerClient mockServerClient = new MockServerClient("localhost", PORT);

  // https://tools.ietf.org/html/rfc6749#section-5.1
  Map<String, Object> map = new TreeMap<>();

  map.put(EXPIRES_IN, "0987654321");
  map.put(TOKEN_TYPE, BEARER);
  map.put(ACCESS_TOKEN, "new access token");

  ObjectMapper mapper = new ObjectMapper();
  
  HttpResponse resp = response()
      .withStatusCode(HttpStatus.SC_OK)
      .withHeaders(
          CONTENT_TYPE_APPLICATION_JSON
      )
      .withBody(mapper.writeValueAsString(map));

  mockServerClient
      .when(expectedRequest, exactly(1))
      .respond(resp);

  assertEquals("new access token", tokenProvider.getAccessToken());

  mockServerClient.verify(expectedRequest);

  mockServerClient.clear(expectedRequest);
  mockServer.stop();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:64,代码来源:TestRefreshTokenTimeBasedTokenRefresher.java

示例3: refreshUrlIsCorrect

import org.mockserver.integration.ClientAndServer; //导入方法依赖的package包/类
@Test
public void refreshUrlIsCorrect() throws IOException {
  final int PORT = ServerSocketUtil.getPort(0, 20);
  final String REFRESH_ADDRESS = "http://localhost:" + PORT + "/refresh";

  long tokenExpires = 0;

  Configuration conf = buildConf("myreallycoolcredential",
      Long.toString(tokenExpires),
      CLIENT_ID_FOR_TESTING,
      REFRESH_ADDRESS);

  Timer mockTimer = mock(Timer.class);
  when(mockTimer.now()).thenReturn(tokenExpires + 1000l);

  AccessTokenProvider credProvider =
      new ConfCredentialBasedAccessTokenProvider(mockTimer);
  credProvider.setConf(conf);
  
  // Build mock server to receive refresh request
  ClientAndServer mockServer  = startClientAndServer(PORT);

  HttpRequest expectedRequest = request()
      .withMethod("POST")
      .withPath("/refresh")
      .withBody( 
      // Note, OkHttp does not sort the param values, so we need to do
      // it ourselves via the ordering provided to ParameterBody...
          ParameterBody.params(
              Parameter.param(CLIENT_SECRET, "myreallycoolcredential"),
              Parameter.param(GRANT_TYPE, CLIENT_CREDENTIALS),
              Parameter.param(CLIENT_ID, CLIENT_ID_FOR_TESTING)
              ));

  MockServerClient mockServerClient = new MockServerClient("localhost", PORT);

  // https://tools.ietf.org/html/rfc6749#section-5.1
  Map<String, Object> map = new TreeMap<>();
  
  map.put(EXPIRES_IN, "0987654321");
  map.put(TOKEN_TYPE, "bearer");
  map.put(ACCESS_TOKEN, "new access token");

  ObjectMapper mapper = new ObjectMapper();
  
  HttpResponse resp = response()
      .withStatusCode(HttpStatus.SC_OK)
      .withHeaders(
          CONTENT_TYPE_APPLICATION_JSON
      )
      .withBody(mapper.writeValueAsString(map));

  mockServerClient
      .when(expectedRequest, exactly(1))
      .respond(resp);

  assertEquals("new access token", credProvider.getAccessToken());

  mockServerClient.verify(expectedRequest);

  mockServerClient.clear(expectedRequest);
  mockServer.stop();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:64,代码来源:TestClientCredentialTimeBasedTokenRefresher.java


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