use of co.rsk.rpc.CorsConfiguration in project rskj by rsksmart.
the class Web3HttpServerTest method smokeTest.
private void smokeTest(String contentType, String host, InetAddress rpcAddress, List<String> rpcHost) throws Exception {
Web3 web3Mock = Mockito.mock(Web3.class);
String mockResult = "output";
Mockito.when(web3Mock.web3_sha3(Mockito.anyString())).thenReturn(mockResult);
CorsConfiguration mockCorsConfiguration = Mockito.mock(CorsConfiguration.class);
Mockito.when(mockCorsConfiguration.hasHeader()).thenReturn(true);
Mockito.when(mockCorsConfiguration.getHeader()).thenReturn("*");
// new ServerSocket(0).getLocalPort();
int randomPort = 9999;
List<ModuleDescription> filteredModules = Collections.singletonList(new ModuleDescription("web3", "1.0", true, Collections.emptyList(), Collections.emptyList()));
JsonRpcWeb3FilterHandler filterHandler = new JsonRpcWeb3FilterHandler("*", rpcAddress, rpcHost);
JsonRpcWeb3ServerHandler serverHandler = new JsonRpcWeb3ServerHandler(web3Mock, filteredModules);
Web3HttpServer server = new Web3HttpServer(InetAddress.getLoopbackAddress(), randomPort, 0, Boolean.TRUE, mockCorsConfiguration, filterHandler, serverHandler);
server.start();
try {
Response response = sendJsonRpcMessage(randomPort, contentType, host);
JsonNode jsonRpcResponse = OBJECT_MAPPER.readTree(response.body().string());
assertThat(response.code(), is(HttpResponseStatus.OK.code()));
assertThat(jsonRpcResponse.at("/result").asText(), is(mockResult));
} finally {
server.stop();
}
}
Aggregations