private Response handleFailure(Action action, String message) { action.setStatus(CreationStatus.FAILED.value()); action.setFault(new Fault()); action.getFault().setReason(message); return Response.ok().entity(action).build(); }
@Override protected Action deprecatedPopulate(Action model, List entity) { model.setId(asString(ids)); if (model.isSetFault()) { setReason(model.getFault()); } return model; }
@Mapping(from = List.class, to = Action.class) public static Action map(List<AsyncTaskStatus> entity, Action template) { Action model = template != null ? template : new Action(); CreationStatus asyncStatus = null; for (AsyncTaskStatus task : entity) { asyncStatus = AsyncTaskMapper.map(task, asyncStatus); } model.setStatus(asyncStatus.value()); if (asyncStatus == CreationStatus.FAILED) { model.setFault(new Fault()); for (AsyncTaskStatus task : entity) { if (task.getException() != null) { model.getFault().setDetail(task.getException().toString()); break; } } } return model; } }
@Test public void testFenceStatusFailure() { FenceOperationResult retVal = new FenceOperationResult(FenceOperationResult.Status.ERROR, PowerStatus.UNKNOWN, "some_error"); setUpEntityQueryExpectations(QueryType.GetVdsFenceStatus, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, retVal); Action action = new Action(); action.setFenceType(FenceType.STATUS.value()); Response response = resource.fence(action); Action actionReturned = (Action)response.getEntity(); assertEquals(actionReturned.getStatus(), CreationStatus.FAILED.value()); assertNotNull(actionReturned.getFault()); assertEquals("some_error", actionReturned.getFault().getReason()); }
to.setFault(adaptOut(from.getFault()));