FileStorageConnector implements StorageConnector { @Override public void write(Exportable artifact, UnitOfWork transaction, Properties parameters) throws Exception { ArgCheck.isNotNull(parameters); String filePath = getFilePath(parameters); ArgCheck.isNotEmpty(filePath); ArgCheck.isNotNull(artifact, "artifact"); ArgCheck.isNotNull(transaction, "transaction"); File destFile = new File(getPath(), filePath); byte[] contents = artifact.export(transaction, parameters); FileUtils.write(contents, destFile); setDownloadable(destFile.getAbsolutePath()); } FileStorageConnector(Properties parameters); @Override StorageConnectorId getId(); @Override Set<Descriptor> getDescriptors(); String getPath(); String getFilePath(Properties parameters); @Override InputStream read(Properties parameters); @Override void write(Exportable artifact, UnitOfWork transaction, Properties parameters); @Override boolean refresh(); @Override StorageTree<String> browse(); @Override void dispose();  }
@Test public void testRequiredPathParameterWrite() { try { Properties parameters = new Properties(); FileStorageConnector connector = new FileStorageConnector(parameters); connector.write(null, null, parameters); fail("Should not allow null path parameter"); } catch (Exception ex) { } }
@Test public void testRequiredFileDestParameter() { try { Properties parameters = new Properties(); parameters.setProperty(StorageConnector.FILES_HOME_PATH_PROPERTY, myFileDir.getAbsolutePath()); connector = new FileStorageConnector(parameters); UnitOfWork transaction = mock(UnitOfWork.class); when(transaction.getState()).thenReturn(State.NOT_STARTED); parameters = new Properties(); Exportable artifact = mock(Exportable.class); connector.write(artifact, transaction, parameters); fail("Should not allow null dest parameter"); } catch (Exception ex) { } }