有几个关于模拟 WebClient 对象的问题提供了有用的答案。但我在用身体发帖时仍然遇到问题。我只是使用Mockito而不是mockwebserver。
这是我正在测试的方法:
public class RestClient extends BaseRestClient {
...
public <T,G> Mono<T> post(String url, G req, Class<T> resp) throws IOException {
Mono<T> response = null;
response = this.getWebClient().post()
.uri(url)
.header(HttpHeaders.CONTENT_TYPE,JSON_CONTENT_TYPE)
.accept(MediaType.APPLICATION_JSON)
//.body(BodyInserters.fromObject(req))
.header(HttpHeaders.AUTHORIZATION, BEARER + token)
.retrieve()
.bodyToMono(resp).log();
return response.map(resp::cast);
}
...
Run Code Online (Sandbox Code Playgroud)
请注意注释掉的正文线。
这是与上面的代码配合良好的测试 - 再次注意测试中注释掉的行:
@Mock
WebClient webClient;
@Mock
WebClient.RequestBodyUriSpec requestBodyUriSpec;
@Mock
WebClient.RequestHeadersSpec requestHeadersSpec;
@Mock
WebClient.RequestBodySpec requestBodySpec;
@Mock
WebClient.ResponseSpec responseSpec;
@InjectMocks
RestClient restClient;
@Test
public void postTest() throws IOException {
when(webClient.post()).thenReturn(requestBodyUriSpec);
when(requestBodyUriSpec.uri(anyString())).thenReturn(requestBodySpec);
when(requestBodySpec.header(any(),any())).thenReturn(requestBodySpec); …Run Code Online (Sandbox Code Playgroud) 首先,我要感谢" Paul Etienne "提出的有用的问题和答案!下面的答案稍微详细一点,并考虑到最后一个版本的JHipster(3/17/2018).
问题很明确:如何在JHipster项目中向User实体添加新数据字段.
我试图在另一个实体组件中显示一个实体组件。
我在网上找到了一些有关共享模块的信息,我也检查了这篇文章,但它仍然不适合我。
JDL-Studio recognizes "ImageBlob" as a predefined datatype.
By importing the JDL file an entity class with a byte-array attribute will be created as well as a front-end component to browse an image file and also some components to display the image.
与Video不同。我的意思是,如果您使用“ VideoBlob”,它仍会创建字节数组属性以及用于浏览和上传视频文件的前端组件,但是除非您手动处理,否则无法观看或下载视频。
我想同样的问题也适用于音频类型。
您能否让我知道您对此的首选解决方案?
我使用 Yarn 安装了 JHipster 生成器:
纱线全局添加生成器-jhipster
现在我有两个顾虑:
1- 如果我改变主意并想在使用 yeoman 命令时生成由“npm”管理的新 JHipster 项目怎么办?
我的意思是:
嘻嘻嘻嘻
我应该再次安装 JHipster 生成器,这次使用“npm”吗?
我的意思是:
npm install -g generator-jhipster
2-我应该如何在已经使用“yarn”作为依赖项/包管理器的项目上从“yarn”切换到“npm”?