我想测试以下响应:
{projetos=[{"id":null,"valorEconomico":null,"servicosPrestados":null,"serviceType":"mock","autenticado":null,"dtFim":"2019-10-16T14:25:49.498+0000","dtInicio":"2019-10-16T14:25:49.498+0000","tecnologias":"mock","dsProjeto":"projeto1","un":null,"nrHoras":null,"setor":null,"statusProjetoDescricao":null,"gerenteProjetoEmail":null,"gerenteProjetoNome":null,"nomeCliente":null,"cometarios":null}],
servicesTypes=["MOCK"]}
我正在尝试使用这种方法:
private void checkAtributesIProjeto(ResultActions resultActions, Boolean isArray) throws Exception {
String jsonIndex = isArray ? "$[0]." : "$.";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+0000");
df.setTimeZone(TimeZone.getTimeZone("GMT+0000"));
resultActions.andExpect(jsonPath(jsonIndex + "dsProjeto", is(projeto.getDsProjeto())))
.andExpect(jsonPath(jsonIndex + "setor", is(projeto.getSetor())))
.andExpect(jsonPath(jsonIndex + "un", is(projeto.getUn())))
.andExpect(jsonPath(jsonIndex + "dtInicio", is(df.format(projeto.getDtInicio()))))
.andExpect(jsonPath(jsonIndex + "dtFim", is(df.format(projeto.getDtFim()))))
.andExpect(jsonPath(jsonIndex + "valorEconomico").value(projeto.getValorEconomico()))
.andExpect(jsonPath(jsonIndex + "nrHoras", is(projeto.getNrHoras())))
.andExpect(jsonPath(jsonIndex + "autenticado", is(projeto.getAutenticado())))
.andExpect(jsonPath(jsonIndex + "servicosPrestados", is(projeto.getServicosPrestados())))
.andExpect(jsonPath(jsonIndex + "tecnologias", is(projeto.getTecnologias())))
.andExpect(jsonPath(jsonIndex + "serviceType", is(projeto.getServiceType())))
.andExpect(jsonPath("$.servicesTypes", hasSize(1)))
.andExpect(jsonPath("$.servicesTypes", hasItem("MOCK")));
}
但是会发生以下错误:
java.lang.AssertionError: No value at JSON path "$.servicesTypes"
我究竟做错了什么?