/** Test that an empty dir will be removed during cleaning. */ @Test public void testCleanNotEmptyGrandParentDir() throws Exception { String expResult = "0c40ffacd15b0f66d5081a93407d3ff5e3c65a71"; Path grandparent = rootDir.toPath().resolve("0c"); Path parent = grandparent.resolve("40ffacd15b0f66d5081a93407d3ff5e3c65a71"); Path other = grandparent.resolve("40ffacd15b0f66d5081a93407d3ff5e3c65a81"); Files.createDirectories(other); Path expectedContent = parent.resolve("content"); assertFalse(expectedContent + " shouldn't exist", Files.exists(expectedContent)); assertFalse(parent + " shouldn't exist", Files.exists(parent)); byte[] result; try (InputStream stream = getResourceAsStream("overlay.xhtml")) { assertThat(repository.hasContent(HashUtil.hexStringToByteArray(expResult)), is(false)); result = repository.addContent(stream); } assertThat(result, is(notNullValue())); assertThat(HashUtil.bytesToHexString(result), is(expResult)); assertThat(repository.hasContent(HashUtil.hexStringToByteArray(expResult)), is(true)); assertTrue(expectedContent + " should have been created", Files.exists(expectedContent)); assertTrue(parent + " should have been created", Files.exists(parent)); repository.removeContent(new ContentReference("overlay.xhtml", expResult)); assertFalse(repository.hasContent(HashUtil.hexStringToByteArray(expResult))); assertFalse(expectedContent + " should have been deleted", Files.exists(expectedContent)); assertFalse(parent.toAbsolutePath() + " should have been deleted", Files.exists(parent)); assertTrue(other + " should not have been deleted", Files.exists(other)); assertTrue(grandparent + " should not have been deleted", Files.exists(grandparent)); Path content = repository.getContent(result).getPhysicalFile().toPath(); assertFalse(Files.exists(content)); }
/** Test of hasContent method, of class ContentRepository. */ @Test public void testHasContent() throws Exception { String expResult = "0c40ffacd15b0f66d5081a93407d3ff5e3c65a71"; try (InputStream stream = getResourceAsStream("overlay.xhtml")) { assertThat(repository.hasContent(HashUtil.hexStringToByteArray(expResult)), is(false)); byte[] result = repository.addContent(stream); assertThat(result, is(notNullValue())); assertThat(HashUtil.bytesToHexString(result), is(expResult)); assertThat(repository.hasContent(HashUtil.hexStringToByteArray(expResult)), is(true)); } }