我正在尝试为我的服务编写一个测试,该测试与另一个从数据库返回项目的服务建立连接。我的问题是我在测试中设置了连接属性并启动了服务。这怎么可能是模拟或类似的?我的启动服务方法:public void doStartService() { super.doStartService(); PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(); manager.setDefaultMaxPerRoute(maxConnectionsPerRoute); manager.setMaxTotal(maxConnections); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(connectTimeout) .setSocketTimeout(socketTimeout) .setRedirectsEnabled(false).build(); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setDefaultRequestConfig(requestConfig); builder.setConnectionManager(manager); client = builder.build(); }我的设置测试方法和一种测试方法:private ProductCatalogIntegrationService service; @Before public void setup() { service = new Service(); service.setConnectTimeout(10000); service.setSocketTimeout(10000); service.setMaxConnections(10); service.setMaxConnectionsPerRoute(10); service.setUrl("http://localhost:8888/products"); service.doStartService(); } @Test public void testReturnProductById() { service.setProductById(GET_PRODUCT_BY_ID); // set url from get product by id, by this url my other service goes to the database jsonItem = service.getProductById("1"); //get product by id 1 assertEquals(jsonItem.getId(), FIRST_PRODUCT_ID); // I compare the id on which I made the request to the database, so that I came and was wrapped in a class wrapper }如何正确执行,以免在测试中配置连接?
添加回答
举报
0/150
提交
取消