### Question:
CaseDocumentDatastore extends CommonDatastore<CaseDocumentItem, Document> implements DatastoreHasAdd<CaseDocumentItem>,
DatastoreHasGet<CaseDocumentItem>,
DatastoreHasUpdate<CaseDocumentItem>, DatastoreHasDelete { @Override public CaseDocumentItem update(final APIID id, final Map<String, String> attributes) { DocumentValue documentValue = null; try { final String urlPath; if (attributes.containsKey(CaseDocumentItem.ATTRIBUTE_UPLOAD_PATH) || attributes.containsKey(CaseDocumentItem.ATTRIBUTE_URL)) { if (attributes.containsKey(CaseDocumentItem.ATTRIBUTE_URL)) { urlPath = attributes.get(CaseDocumentItem.ATTRIBUTE_URL); documentValue = buildDocumentValueFromUrl(urlPath, -1); } else { urlPath = attributes.get(CaseDocumentItem.ATTRIBUTE_UPLOAD_PATH); documentValue = buildDocumentValueFromUploadPath(urlPath, -1, attributes.get(CaseDocumentItem.ATTRIBUTE_CONTENT_FILENAME)); } final Document document = processAPI.updateDocument(id.toLong(), documentValue); return convertEngineToConsoleItem(document); } else { throw new APIException("Error while attaching a new document. Request with bad param value."); } } catch (final UnauthorizedFolderException e) { throw new APIForbiddenException(e.getMessage()); } catch (final Exception e) { throw new APIException(e); } } CaseDocumentDatastore(final APISession engineSession, final WebBonitaConstantsUtils constantsValue, final ProcessAPI processAPI,
            final BonitaHomeFolderAccessor tenantFolder); @Override CaseDocumentItem get(final APIID id); @Override CaseDocumentItem add(final CaseDocumentItem item); @Override CaseDocumentItem update(final APIID id, final Map<String, String> attributes); ItemSearchResult<CaseDocumentItem> search(final int page, final int resultsByPage,
            final String search, final Map<String, String> filters, final String orders); @Override void delete(final List<APIID> ids);  }### Answer:
@Test(expected = APIException.class) public void it_should_not_update_document_and_throws_exception_for_missing_uploadPath() { final Map<String, String> attributes = new HashMap<>(); attributes.put(CaseDocumentItem.ATTRIBUTE_NAME, "Doc 1"); final APIID id = APIID.makeAPIID(1l); try { when(processAPI.getDocument(1l)).thenReturn(mockedDocument); } catch (final Exception e) { e.printStackTrace(); } documentDatastore.update(id, attributes); }
@Test(expected = APIForbiddenException.class) public void it_throws_an_exception_updating_a_document_with_unauthorized_path() throws IOException { final Map<String, String> attributes = new HashMap<>(); attributes.put(CaseDocumentItem.ATTRIBUTE_UPLOAD_PATH, "C:\\doc.jpg"); when(tenantFolder.getTempFile("C:\\doc.jpg", 1L)).thenThrow(new UnauthorizedFolderException("error")); documentDatastore.update(APIID.makeAPIID(1L), attributes); }
@Test(expected = APIException.class) public void it_throws_an_exception_when_cannot_write_file_on_update() throws IOException { final Map<String, String> attributes = new HashMap<>(); attributes.put(CaseDocumentItem.ATTRIBUTE_UPLOAD_PATH, "C:\\doc.jpg"); when(tenantFolder.getTempFile("C:\\doc.jpg", 1L)).thenThrow(new IOException("error")); try { documentDatastore.update(APIID.makeAPIID(1L), attributes); } catch (final APIForbiddenException e) { fail("Don't expect the APIException to be an APIForbiddenException"); } }