我的端点看起来像
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getVariables(@QueryParam("_activeonly") @DefaultValue("no") @Nonnull final Active active) {
switch (active) {
case yes:
return Response.ok(VariablePresentation.getPresentationVariables(variableManager.getActiveVariables())).build();
case no:
return Response.ok(VariablePresentation.getPresentationVariables(variableManager.getVariables())).build();
}
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
Active
在哪里
public enum Active {
yes,
no;
}
我将其测试为
@Test
public void testGetAllVariablesUnknownActionFail() throws Exception {
final ClientRequest clientRequest = new ClientRequest("http://localhost:9090/market/rest/variables?_activeonly=unknown");
final ClientResponse<String> clientResponse = clientRequest.get(String.class);
assertEquals(400, clientResponse.getStatus());
}
当我期待HTTP 400
时,我收到HTTP 200
: expected:<400> but was:<200>
这是否意味着如果我传入了一些未映射到枚举的不正确的值@DefaultValue
?