微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Java akka http模拟请求

如何解决Java akka http模拟请求

我正在尝试开发一个演员,以响应另一个演员发出的某些请求。
基本上,这个参与者(在收到特定消息时)会创建一个HTTP请求,所以我的疑问是:

如何测试akka HTTP actor?
值得嘲笑一切吗?

private boolean createHttpPostRequest(Object r)
    {
        String body = null;

        try {
            body = createBody(report);
        } catch (IOException e) {
            logger.error("Unable to create body Report "+e.getMessage());
        }

        HttpResponse response = null;

        try {
            clearPendingRequest();
            response = this.http.singleRequest(HttpRequest.create().withMethod(HttpMethods.POST)
                    .withEntity(HttpEntities.create(
                            ContentTypes.APPLICATION_JSON,body))
                    .withUri(this.uri))
                    .toCompletableFuture()
                    .get();
        } catch (InterruptedException e) {
            logger.error("Interrupted Exception "+e.getMessage());
            return false;
        } catch (ExecutionException e) 
        {
            logger.error("Unable to send request!");
            return false;
        }

        if(response.status() == StatusCodes.OK)
            logger.info("Request sent!");

        return true;
    }

我的问题是:如何测试这种方法
如果我没有提供来自singleRequest的答案的端点,该如何测试肯定的情况?
在这种情况下,我还将HTTP配置为https) Tks

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。