Java Code Examples for org.mockserver.integration.ClientAndServer#stop()

The following examples show how to use org.mockserver.integration.ClientAndServer#stop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpClientTest.java    From pmq with Apache License 2.0 7 votes vote down vote up
@Test
public void getErrorTest() throws IOException {
	ClientAndServer mockClient = new ClientAndServer(5000);
	try {
		mockClient.when(HttpRequest.request().withMethod("GET"))
				.respond(HttpResponse.response().withStatusCode(700).withBody("1"));
		HttpClient httpClient = new HttpClient();
		boolean rs = false;
		try {
			assertEquals("1", httpClient.get("http://localhost:5000/hs"));
		} catch (Exception e) {
			rs = true;
		}
		assertEquals(true, rs);
	} finally {
		mockClient.stop(true);
	}
}
 
Example 2
Source File: HttpClientTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@Test
public void getError1Test() throws IOException {
	ClientAndServer mockClient = new ClientAndServer(5000);
	try {
		mockClient.when(HttpRequest.request().withMethod("GET"))
				.respond(HttpResponse.response().withStatusCode(700).withBody("1"));
		HttpClient httpClient = new HttpClient();
		boolean rs = false;
		try {
			assertEquals("1", httpClient.get("http://localhost:50001/hs"));
		} catch (Exception e) {
			rs = true;
		}
		assertEquals(true, rs);
	} finally {
		mockClient.stop(true);
	}
}
 
Example 3
Source File: HttpClientTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@Test
public void postErrorTest() throws IOException {
	ClientAndServer mockClient = new ClientAndServer(5000); 
	try {
		mockClient.when(HttpRequest.request().withMethod("POST"))
				.respond(HttpResponse.response().withStatusCode(700).withBody("1"));
		HttpClient httpClient = new HttpClient();
		boolean rs = false;
		try {
			assertEquals("1", httpClient.post("http://localhost:5000/hs", "1"));
		} catch (Exception e) {
			rs = true;
		}
		assertEquals(true, rs);
	} finally {
		mockClient.stop(true);
	}
}
 
Example 4
Source File: HttpClientTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@Test
public void postError1Test() throws IOException {
	ClientAndServer mockClient = new ClientAndServer(5000);
	try {
		mockClient.when(HttpRequest.request().withMethod("POST"))
				.respond(HttpResponse.response().withStatusCode(200).withBody("1"));
		HttpClient httpClient = new HttpClient();
		boolean rs = false;
		try {
			assertEquals("1", httpClient.post("http://localhost:5001/hs", "1"));
		} catch (Exception e) {
			rs = true;
		}
		assertEquals(true, rs);
	} finally {
		mockClient.stop(true);
	}
}
 
Example 5
Source File: HttpClientTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@Test
public void postError2Test() throws IOException {
	ClientAndServer mockClient = new ClientAndServer(5000);
	try {
		mockClient.when(HttpRequest.request().withMethod("POST"))
				.respond(HttpResponse.response().withStatusCode(700).withBody("1"));
		HttpClient httpClient = new HttpClient();
		boolean rs = false;
		try {
			assertEquals(1, httpClient.post("http://localhost:5000/hs", "1", TestDemo.class).getT());
		} catch (Exception e) {
			rs = true;
		}
		assertEquals(true, rs);
	} finally {
		mockClient.stop(true);
	}
}
 
Example 6
Source File: HttpClientTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@Test
public void postError3Test() throws IOException {
	ClientAndServer mockClient = new ClientAndServer(5000);
	try {
		mockClient.when(HttpRequest.request().withMethod("POST"))
				.respond(HttpResponse.response().withStatusCode(200).withBody("1"));
		HttpClient httpClient = new HttpClient();
		boolean rs = false;
		try {
			assertEquals(1, httpClient.post("http://localhost:5001/hs", "1", TestDemo.class).getT());
		} catch (Exception e) {
			rs = true;
		}
		assertEquals(true, rs);
	} finally {
		mockClient.stop(true);
	}
}
 
Example 7
Source File: OdooXmlRpcProxyTest.java    From openerp-java-api with Apache License 2.0 6 votes vote down vote up
@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);
	}

}
 
Example 8
Source File: HttpClientTest.java    From pmq with Apache License 2.0 5 votes vote down vote up
@Test
public void checkTest() throws IOException {
	ClientAndServer mockClient = new ClientAndServer(5000);
	try {
		mockClient.when(HttpRequest.request().withMethod("GET"))
				.respond(HttpResponse.response().withStatusCode(200));
		HttpClient httpClient = new HttpClient();
		assertEquals(true, httpClient.check("http://localhost:5000/hs"));
	} finally {
		mockClient.stop(true);
	}
}
 
Example 9
Source File: HttpClientTest.java    From pmq with Apache License 2.0 5 votes vote down vote up
@Test
public void getTest() throws IOException {
	ClientAndServer mockClient = new ClientAndServer(5000);
	try {
		mockClient.when(HttpRequest.request().withMethod("GET"))
				.respond(HttpResponse.response().withStatusCode(200).withBody("1"));
		HttpClient httpClient = new HttpClient();
		assertEquals("1", httpClient.get("http://localhost:5000/hs"));
	} finally {
		mockClient.stop(true);
	}
}
 
Example 10
Source File: HttpClientTest.java    From pmq with Apache License 2.0 5 votes vote down vote up
@Test
public void postTest() throws IOException, BrokerException {
	ClientAndServer mockClient = new ClientAndServer(5000);
	try {
		mockClient.when(HttpRequest.request().withMethod("POST"))
				.respond(HttpResponse.response().withStatusCode(200).withBody("1"));
		HttpClient httpClient = new HttpClient();
		assertEquals("1", httpClient.post("http://localhost:5000/hs", "1"));
	} finally {
		mockClient.stop(true);
	}
}
 
Example 11
Source File: HttpClientTest.java    From pmq with Apache License 2.0 5 votes vote down vote up
@Test
public void post1Test() throws IOException, BrokerException {
	ClientAndServer mockClient = new ClientAndServer(5000);
	try {
		mockClient.when(HttpRequest.request().withMethod("POST"))
				.respond(HttpResponse.response().withStatusCode(200).withBody("{\"t\":1}"));
		HttpClient httpClient = new HttpClient();
		assertEquals(1, httpClient.post("http://localhost:5000/hs", "1", TestDemo.class).getT());
	} finally {
		mockClient.stop(true);
	}
}