@Test public void testDoAddCustomMediaFiles() throws IOException, OrnidroidException { final OrnidroidIOServiceImpl serviceImpl = (OrnidroidIOServiceImpl) this.ornidroidIOService; final File srcDir = buildOrnidroidHomeTest(TEST_DIRECTORY + "/srcDir"); final File destDir = new File(TEST_DIRECTORY + "/destDir"); destDir.mkdirs(); Assert.assertEquals("directory should be empty before the test", 0, destDir.list().length); File selectedFile = new File(srcDir.getAbsolutePath() + "/images/" + "file1.jpg"); File destFile = new File(destDir.getAbsolutePath() + "/custom_file1.jpg"); File propertiesFile = new File(TEST_DIRECTORY + "/destDir/custom_file1.jpg.properties"); serviceImpl.doAddCustomMediaFiles(OrnidroidFileType.PICTURE, selectedFile, destFile, propertiesFile, "comment"); Assert.assertEquals("directory should have 2 files after the test", 2, destDir.list().length); final OrnidroidFileFactoryImpl factory = OrnidroidFileFactoryImpl .getFactory(); OrnidroidFile ornidroidFile = factory.createOrnidroidFile( destFile.getAbsolutePath(), OrnidroidFileType.PICTURE, SupportedLanguage.ENGLISH.getCode()); Assert.assertEquals("comment", ornidroidFile .getProperty(PictureOrnidroidFile.IMAGE_DESCRIPTION_PROPERTY)); selectedFile = new File(srcDir.getAbsolutePath() + "/audio/" + "file1.mp3"); destFile = new File(destDir.getAbsolutePath() + "/custom_file1.mp3"); propertiesFile = new File(TEST_DIRECTORY + "/destDir/custom_file1.mp3.properties"); serviceImpl.doAddCustomMediaFiles(OrnidroidFileType.AUDIO, selectedFile, destFile, propertiesFile, "comment"); Assert.assertEquals("directory should have 4 files after the test", 4, destDir.list().length); ornidroidFile = factory.createOrnidroidFile(destFile.getAbsolutePath(), OrnidroidFileType.AUDIO, SupportedLanguage.ENGLISH.getCode()); Assert.assertEquals("comment", ornidroidFile .getProperty(AudioOrnidroidFile.AUDIO_TITLE_PROPERTY)); selectedFile = new File(srcDir.getAbsolutePath() + "/images/" + "unknown_file1.jpg"); try { serviceImpl.doAddCustomMediaFiles(OrnidroidFileType.PICTURE, selectedFile, destFile, propertiesFile, "comment"); Assert.fail("an exception should have occurred"); } catch (final OrnidroidException e) { Assert.assertTrue(e.getErrorType().equals( OrnidroidError.ADD_CUSTOM_MEDIA_ERROR)); } selectedFile = new File(srcDir.getAbsolutePath() + "/images/" + "file1.jpg"); destFile = new File(destDir.getAbsolutePath() + "/unknownDir/custom_file1.jpg"); try { serviceImpl.doAddCustomMediaFiles(OrnidroidFileType.PICTURE, selectedFile, destFile, propertiesFile, "comment"); Assert.fail("an exception should have occurred"); } catch (final OrnidroidException e) { Assert.assertTrue(e.getErrorType().equals( OrnidroidError.ADD_CUSTOM_MEDIA_ERROR)); } }
protected void doAddCustomMediaFiles(final OrnidroidFileType fileType, final File selectedFile, final File destFile, final File propertiesFile, final String comment) throws OrnidroidException { try { FileHelper.doCopyFile(selectedFile, destFile); FileHelper.writeStringToFile(propertiesFile, getCustomPropertiesString(fileType, comment), null, false); } catch (final IOException e) { try { FileHelper.forceDelete(destFile); FileHelper.forceDelete(propertiesFile); } catch (final IOException e1) { } if (!BasicConstants.isJunitContext()) { Log.e(BasicConstants.LOG_TAG, e.getMessage(), e); } throw new OrnidroidException(OrnidroidError.ADD_CUSTOM_MEDIA_ERROR, e); } }
OrnidroidIOServiceImpl implements IOrnidroidIOService { protected void doAddCustomMediaFiles(final OrnidroidFileType fileType, final File selectedFile, final File destFile, final File propertiesFile, final String comment) throws OrnidroidException { try { FileHelper.doCopyFile(selectedFile, destFile); FileHelper.writeStringToFile(propertiesFile, getCustomPropertiesString(fileType, comment), null, false); } catch (final IOException e) { try { FileHelper.forceDelete(destFile); FileHelper.forceDelete(propertiesFile); } catch (final IOException e1) { } if (!BasicConstants.isJunitContext()) { Log.e(BasicConstants.LOG_TAG, e.getMessage(), e); } throw new OrnidroidException(OrnidroidError.ADD_CUSTOM_MEDIA_ERROR, e); } } }
OrnidroidIOServiceImpl implements IOrnidroidIOService { protected void doAddCustomMediaFiles(final OrnidroidFileType fileType, final File selectedFile, final File destFile, final File propertiesFile, final String comment) throws OrnidroidException { try { FileHelper.doCopyFile(selectedFile, destFile); FileHelper.writeStringToFile(propertiesFile, getCustomPropertiesString(fileType, comment), null, false); } catch (final IOException e) { try { FileHelper.forceDelete(destFile); FileHelper.forceDelete(propertiesFile); } catch (final IOException e1) { } if (!BasicConstants.isJunitContext()) { Log.e(BasicConstants.LOG_TAG, e.getMessage(), e); } throw new OrnidroidException(OrnidroidError.ADD_CUSTOM_MEDIA_ERROR, e); } } OrnidroidIOServiceImpl(); }
OrnidroidIOServiceImpl implements IOrnidroidIOService { protected void doAddCustomMediaFiles(final OrnidroidFileType fileType, final File selectedFile, final File destFile, final File propertiesFile, final String comment) throws OrnidroidException { try { FileHelper.doCopyFile(selectedFile, destFile); FileHelper.writeStringToFile(propertiesFile, getCustomPropertiesString(fileType, comment), null, false); } catch (final IOException e) { try { FileHelper.forceDelete(destFile); FileHelper.forceDelete(propertiesFile); } catch (final IOException e1) { } if (!BasicConstants.isJunitContext()) { Log.e(BasicConstants.LOG_TAG, e.getMessage(), e); } throw new OrnidroidException(OrnidroidError.ADD_CUSTOM_MEDIA_ERROR, e); } } OrnidroidIOServiceImpl(); void addCustomMediaFile(final String birdDirectory,
			final OrnidroidFileType fileType, final String selectedFileName,
			final File selectedFile, final String comment); void checkAndCreateDirectory(final File fileDirectory); void checkOrnidroidHome(final String ornidroidHome); void downloadMediaFiles(final String mediaHomeDirectory,
			final Bird bird, final OrnidroidFileType fileType); List<String> filesToUpdate(final String mediaHomeDirectory,
			final Bird bird, final OrnidroidFileType fileType); void loadMediaFiles(final String fileDirectory, final Bird bird,
			final OrnidroidFileType fileType); void removeCustomMediaFile(final OrnidroidFile ornidroidFile); @Override void resetExistingDirectory(File directoryToReset); void downloadZipPackage(String zipname, String mediaHomeDirectory); boolean isEnoughFreeSpace(OrnidroidFileType fileType); ZipPackage getZipname(OrnidroidFileType fileType); int getZipDownloadProgressPercent(OrnidroidFileType fileType,
			int folderSizeBeforeDownload); int getInstallProgressPercent(OrnidroidFileType fileType); }
OrnidroidIOServiceImpl implements IOrnidroidIOService { protected void doAddCustomMediaFiles(final OrnidroidFileType fileType, final File selectedFile, final File destFile, final File propertiesFile, final String comment) throws OrnidroidException { try { FileHelper.doCopyFile(selectedFile, destFile); FileHelper.writeStringToFile(propertiesFile, getCustomPropertiesString(fileType, comment), null, false); } catch (final IOException e) { try { FileHelper.forceDelete(destFile); FileHelper.forceDelete(propertiesFile); } catch (final IOException e1) { } if (!BasicConstants.isJunitContext()) { Log.e(BasicConstants.LOG_TAG, e.getMessage(), e); } throw new OrnidroidException(OrnidroidError.ADD_CUSTOM_MEDIA_ERROR, e); } } OrnidroidIOServiceImpl(); void addCustomMediaFile(final String birdDirectory,
			final OrnidroidFileType fileType, final String selectedFileName,
			final File selectedFile, final String comment); void checkAndCreateDirectory(final File fileDirectory); void checkOrnidroidHome(final String ornidroidHome); void downloadMediaFiles(final String mediaHomeDirectory,
			final Bird bird, final OrnidroidFileType fileType); List<String> filesToUpdate(final String mediaHomeDirectory,
			final Bird bird, final OrnidroidFileType fileType); void loadMediaFiles(final String fileDirectory, final Bird bird,
			final OrnidroidFileType fileType); void removeCustomMediaFile(final OrnidroidFile ornidroidFile); @Override void resetExistingDirectory(File directoryToReset); void downloadZipPackage(String zipname, String mediaHomeDirectory); boolean isEnoughFreeSpace(OrnidroidFileType fileType); ZipPackage getZipname(OrnidroidFileType fileType); int getZipDownloadProgressPercent(OrnidroidFileType fileType,
			int folderSizeBeforeDownload); int getInstallProgressPercent(OrnidroidFileType fileType);  }