@Test public void testCopy() throws Exception { Asset asset = new Asset(config); asset.copy(); File cssFile = new File(folder.toString() + File.separatorChar + "css" + File.separatorChar + "bootstrap.min.css"); Assertions.assertTrue(cssFile.exists(), () -> "File " + cssFile.getAbsolutePath() + " does not exist"); File imgFile = new File(folder.toString() + File.separatorChar + "img" + File.separatorChar + "glyphicons-halflings.png"); Assertions.assertTrue(imgFile.exists(), () -> "File " + imgFile.getAbsolutePath() + " does not exist"); File jsFile = new File(folder.toString() + File.separatorChar + "js" + File.separatorChar + "bootstrap.min.js"); Assertions.assertTrue(jsFile.exists(), () -> "File " + jsFile.getAbsolutePath() + " does not exist"); Assertions.assertTrue(asset.getErrors().isEmpty(), "Errors during asset copying"); }
@Test public void testJBakeIgnoredFolder() { URL assetsUrl = this.getClass().getResource("/fixture/assets"); File assets = new File(assetsUrl.getFile()); Asset asset = new Asset(config); asset.copy(assets); File cssFile = new File(folder.toString() + File.separatorChar + "css" + File.separatorChar + "bootstrap.min.css"); Assertions.assertTrue(cssFile.exists(), () -> "File " + cssFile.getAbsolutePath() + " does not exist"); File imgFile = new File(folder.toString() + File.separatorChar + "img" + File.separatorChar + "glyphicons-halflings.png"); Assertions.assertTrue(imgFile.exists(), () -> "File " + imgFile.getAbsolutePath() + " does not exist"); File jsFile = new File(folder.toString() + File.separatorChar + "js" + File.separatorChar + "bootstrap.min.js"); Assertions.assertTrue(jsFile.exists(), () -> "File " + jsFile.getAbsolutePath() + " does not exist"); File ignorableFolder = new File(folder.toString() + File.separatorChar + "ignorablefolder"); Assertions.assertFalse(ignorableFolder.exists(), () -> "Folder " + ignorableFolder.getAbsolutePath() + " must not exist"); Assertions.assertTrue(asset.getErrors().isEmpty(), "Errors during asset copying"); }
@Test public void testCopyIgnore() throws Exception { File assetFolder = new File(folder.toFile(), "ignoredAssets"); assetFolder.mkdirs(); FileUtils.copyDirectory(new File(this.getClass().getResource("/fixture/ignorables").getFile()), assetFolder); config.setAssetFolder(assetFolder); config.setAssetIgnoreHidden(true); TestUtils.hideAssets(assetFolder); Asset asset = new Asset(config); asset.copy(assetFolder); File testFile = new File(folder.toFile(), "test.txt"); Assertions.assertTrue(testFile.exists(), () -> "File " + testFile.getAbsolutePath() + " does not exist"); File testIgnoreFile = new File(folder.toFile(), ".test.txt"); Assertions.assertFalse(testIgnoreFile.exists(), () -> "File " + testIgnoreFile.getAbsolutePath() + " does exist"); Assertions.assertTrue(asset.getErrors().isEmpty(), "Errors during asset copying"); }
@Test public void testCopyAssetsFromContent() { URL contentUrl = this.getClass().getResource("/fixture/content"); File contents = new File(contentUrl.getFile()); Asset asset = new Asset(config); asset.copyAssetsFromContent(contents); int totalFiles = countFiles(folder.toFile()); int expected = 3; Assertions.assertTrue(totalFiles == expected, () -> String.format("Number of files copied must be %d but are %d", expected, totalFiles)); File pngFile = new File(folder.toString() + File.separatorChar + "blog" + File.separatorChar + "2012/images/custom-image.png"); Assertions.assertTrue(pngFile.exists(), () -> "File " + pngFile.getAbsolutePath() + " does not exist"); File jpgFile = new File(folder.toString() + File.separatorChar + "blog" + File.separatorChar + "2013/images/custom-image.jpg"); Assertions.assertTrue(jpgFile.exists(), () -> "File " + jpgFile.getAbsolutePath() + " does not exist"); File jsonFile = new File(folder.toString() + File.separatorChar + "blog" + File.separatorChar + "2012/sample.json"); Assertions.assertTrue(jsonFile.exists(), () -> "File " + jsonFile.getAbsolutePath() + " does not exist"); Assertions.assertTrue(asset.getErrors().isEmpty(), "Errors during asset copying"); }
asset.copyAssetsFromContent(config.getContentFolder()); errors.addAll(asset.getErrors());
@Test public void testCopyCustomFolder() throws Exception { config.setAssetFolder(new File(config.getSourceFolder(), "/media")); Asset asset = new Asset(config); asset.copy(); File favFile = new File(folder.toString() + File.separatorChar + "favicon.ico"); Assertions.assertTrue(favFile.exists(), () -> "File " + favFile.getAbsolutePath() + " does not exist"); Assertions.assertTrue(asset.getErrors().isEmpty(), "Errors during asset copying"); }
/** * Primary intention is to extend test cases to increase coverage. * * @throws Exception */ @Test public void testWriteProtected() throws Exception { File assets = new File(config.getSourceFolder(), "assets"); File css = new File(folder.toFile(),"css"); css.mkdir(); final File cssFile = new File(css, "bootstrap.min.css"); FileUtils.touch(cssFile); cssFile.setReadOnly(); config.setAssetFolder(assets); config.setDestinationFolder(folder.toFile()); Asset asset = new Asset(config); asset.copy(); cssFile.setWritable(true); Assertions.assertFalse(asset.getErrors().isEmpty(), "At least one error during copy expected"); }
asset.copyAssetsFromContent(config.getContentFolder()); errors.addAll(asset.getErrors());