DeleteHandler extends BaseManagementHandler implements RequestHandler { @Override protected Result persist(ResourceInstance resource, RequestBody body) { Result result; try { RequestStatus status = getPersistenceManager().delete(resource, body); result = createResult(status); if (result.isSynchronous()) { result.setResultStatus(new ResultStatus(ResultStatus.STATUS.OK)); } else { result.setResultStatus(new ResultStatus(ResultStatus.STATUS.ACCEPTED)); } } catch (AuthorizationException e) { result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.FORBIDDEN, e.getMessage())); } catch (SystemException e) { result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.SERVER_ERROR, e)); } catch (NoSuchParentResourceException e) { result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.NOT_FOUND, e)); } catch (NoSuchResourceException e) { if (resource.isCollectionResource()) { result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.OK, e)); } else if (e.getCause() instanceof ConfigGroupNotFoundException){ result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.ACCEPTED, e)); } else { result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.NOT_FOUND, e)); } } catch (UnsupportedPropertyException e) { result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, e)); } return result; }    }
@Test public void testIdempotentPersist() throws Exception { Request request = createNiceMock(Request.class); RequestBody body = createNiceMock(RequestBody.class); ResourceInstance resource = createNiceMock(ResourceInstance.class); PersistenceManager pm = createNiceMock(PersistenceManager.class); RequestStatus status = createNiceMock(RequestStatus.class); Resource resource1 = createNiceMock(Resource.class); Resource requestResource = createNiceMock(Resource.class); ConfigGroupNotFoundException configGroupNotFoundException = createNiceMock(ConfigGroupNotFoundException.class); Query query = createNiceMock(Query.class); expect(request.getResource()).andReturn(resource).anyTimes(); expect(request.getBody()).andReturn(body).atLeastOnce(); expect(pm.delete(resource, body)).andThrow( new NoSuchResourceException("Configgroup not exist", configGroupNotFoundException)); replay(request, body, resource, pm, status, resource1, requestResource, query); Result result = new TestDeleteHandler(pm).persist(resource, body); assertNotNull(result); assertEquals(ResultStatus.STATUS.ACCEPTED, result.getStatus().getStatus()); }