@Test public void testDELETEValidVisibility() throws PersistenceException { request.setId(URL_ID); doReturn(new SimpleObject()).when(mockObjectPersister).retrieve(anyString()); doReturn(true).when(mockVisibilityFilter).isVisible(any(), any()); DataObjectResponse<SimpleObject> response = processor.handleDELETE(request); Assert.assertFalse(response.isError()); verify(mockObjectPersister, times(1)).delete(anyString()); }
@Override public DataObjectResponse<T> handleDELETE(DataObjectRequest<T> request) { if(getRequestValidator() != null) getRequestValidator().validateDELETE(request); try { DefaultDataObjectResponse<T> response = new DefaultDataObjectResponse<>(); if(request.getId() != null) { T object = objectPersister.retrieve(request.getId()); if(object != null) { if(! visibilityFilterMap.get(VisibilityMethod.DELETE).isVisible(request, object)) return new DefaultDataObjectResponse<>( ErrorResponseFactory.unauthorized( String.format(AUTHORIZATION_EXCEPTION, object.getCustomerId()), request.getCID())); objectPersister.delete(request.getId()); response.add(object); } } return response; } catch(PersistenceException e) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.badRequest( new BadRequestException(String.format(UNABLE_TO_DELETE_EXCEPTION, request.getId()), e), request.getCID())); } }
DataObjectRequestProcessor implements RequestProcessor<DataObjectResponse<T>, DataObjectRequest<T>> { @Override public DataObjectResponse<T> handleDELETE(DataObjectRequest<T> request) { if(getRequestValidator() != null) getRequestValidator().validateDELETE(request); try { DefaultDataObjectResponse<T> response = new DefaultDataObjectResponse<>(); if(request.getId() != null) { T object = objectPersister.retrieve(request.getId()); if(object != null) { if(! visibilityFilterMap.get(VisibilityMethod.DELETE).isVisible(request, object)) return new DefaultDataObjectResponse<>( ErrorResponseFactory.unauthorized( String.format(AUTHORIZATION_EXCEPTION, object.getCustomerId()), request.getCID())); objectPersister.delete(request.getId()); response.add(object); } } return response; } catch(PersistenceException e) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.badRequest( new BadRequestException(String.format(UNABLE_TO_DELETE_EXCEPTION, request.getId()), e), request.getCID())); } } }
DataObjectRequestProcessor implements RequestProcessor<DataObjectResponse<T>, DataObjectRequest<T>> { @Override public DataObjectResponse<T> handleDELETE(DataObjectRequest<T> request) { if(getRequestValidator() != null) getRequestValidator().validateDELETE(request); try { DefaultDataObjectResponse<T> response = new DefaultDataObjectResponse<>(); if(request.getId() != null) { T object = objectPersister.retrieve(request.getId()); if(object != null) { if(! visibilityFilterMap.get(VisibilityMethod.DELETE).isVisible(request, object)) return new DefaultDataObjectResponse<>( ErrorResponseFactory.unauthorized( String.format(AUTHORIZATION_EXCEPTION, object.getCustomerId()), request.getCID())); objectPersister.delete(request.getId()); response.add(object); } } return response; } catch(PersistenceException e) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.badRequest( new BadRequestException(String.format(UNABLE_TO_DELETE_EXCEPTION, request.getId()), e), request.getCID())); } } DataObjectRequestProcessor(ObjectPersister<T> objectPersister, DataObjectValidator<T, DataObjectRequest<T>> validator);  DataObjectRequestProcessor(ObjectPersister<T> objectPersister); }
DataObjectRequestProcessor implements RequestProcessor<DataObjectResponse<T>, DataObjectRequest<T>> { @Override public DataObjectResponse<T> handleDELETE(DataObjectRequest<T> request) { if(getRequestValidator() != null) getRequestValidator().validateDELETE(request); try { DefaultDataObjectResponse<T> response = new DefaultDataObjectResponse<>(); if(request.getId() != null) { T object = objectPersister.retrieve(request.getId()); if(object != null) { if(! visibilityFilterMap.get(VisibilityMethod.DELETE).isVisible(request, object)) return new DefaultDataObjectResponse<>( ErrorResponseFactory.unauthorized( String.format(AUTHORIZATION_EXCEPTION, object.getCustomerId()), request.getCID())); objectPersister.delete(request.getId()); response.add(object); } } return response; } catch(PersistenceException e) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.badRequest( new BadRequestException(String.format(UNABLE_TO_DELETE_EXCEPTION, request.getId()), e), request.getCID())); } } DataObjectRequestProcessor(ObjectPersister<T> objectPersister, DataObjectValidator<T, DataObjectRequest<T>> validator);  DataObjectRequestProcessor(ObjectPersister<T> objectPersister); @Override DataObjectResponse<T> handleGET(DataObjectRequest<T> request); @Override DataObjectResponse<T> handlePOST(DataObjectRequest<T> request); @Override DataObjectResponse<T> handlePUT(DataObjectRequest<T> request); DataObjectResponse<T> handlePUT(DataObjectRequest<T> request, T previouslyRetrievedObject); @Override DataObjectResponse<T> handleDELETE(DataObjectRequest<T> request); DataObjectRequestProcessor<T> setVisibilityFilterMap(
        VisibilityFilterMap<T, DataObjectRequest<T>> map); DataObjectRequestProcessor<T> setVisibilityFilter(VisibilityMethod method,
        VisibilityFilter<T, DataObjectRequest<T>> filter); RequestValidator<DataObjectRequest<T>> getRequestValidator(); void setRequestValidator(RequestValidator<DataObjectRequest<T>> requestValidator); ObjectPersister<T> getObjectPersister(); }
DataObjectRequestProcessor implements RequestProcessor<DataObjectResponse<T>, DataObjectRequest<T>> { @Override public DataObjectResponse<T> handleDELETE(DataObjectRequest<T> request) { if(getRequestValidator() != null) getRequestValidator().validateDELETE(request); try { DefaultDataObjectResponse<T> response = new DefaultDataObjectResponse<>(); if(request.getId() != null) { T object = objectPersister.retrieve(request.getId()); if(object != null) { if(! visibilityFilterMap.get(VisibilityMethod.DELETE).isVisible(request, object)) return new DefaultDataObjectResponse<>( ErrorResponseFactory.unauthorized( String.format(AUTHORIZATION_EXCEPTION, object.getCustomerId()), request.getCID())); objectPersister.delete(request.getId()); response.add(object); } } return response; } catch(PersistenceException e) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.badRequest( new BadRequestException(String.format(UNABLE_TO_DELETE_EXCEPTION, request.getId()), e), request.getCID())); } } DataObjectRequestProcessor(ObjectPersister<T> objectPersister, DataObjectValidator<T, DataObjectRequest<T>> validator);  DataObjectRequestProcessor(ObjectPersister<T> objectPersister); @Override DataObjectResponse<T> handleGET(DataObjectRequest<T> request); @Override DataObjectResponse<T> handlePOST(DataObjectRequest<T> request); @Override DataObjectResponse<T> handlePUT(DataObjectRequest<T> request); DataObjectResponse<T> handlePUT(DataObjectRequest<T> request, T previouslyRetrievedObject); @Override DataObjectResponse<T> handleDELETE(DataObjectRequest<T> request); DataObjectRequestProcessor<T> setVisibilityFilterMap(
        VisibilityFilterMap<T, DataObjectRequest<T>> map); DataObjectRequestProcessor<T> setVisibilityFilter(VisibilityMethod method,
        VisibilityFilter<T, DataObjectRequest<T>> filter); RequestValidator<DataObjectRequest<T>> getRequestValidator(); void setRequestValidator(RequestValidator<DataObjectRequest<T>> requestValidator); ObjectPersister<T> getObjectPersister(); static final String OBJECT_NOT_FOUND_EXCEPTION; static final String AUTHORIZATION_EXCEPTION; static final String UNABLE_TO_CREATE_EXCEPTION; static final String UNABLE_TO_UPDATE_EXCEPTION; static final String UNABLE_TO_DELETE_EXCEPTION; }