コード例 #1
0
 /** Test of explodeContent method, of class ContentRepository. */
 @Test
 public void testExplodeContent() throws Exception {
   byte[] archive = createArchive(Collections.singletonList("overlay.xhtml"));
   try (ByteArrayInputStream stream = new ByteArrayInputStream(archive)) {
     byte[] hash = repository.explodeContent(repository.addContent(stream));
     String expResult = "b1f18e286615dda0643633ec31f1a17d90e48875";
     // hash is different from the simple overlay.xhtml as we add the content folder name in the
     // computation
     assertThat(hash, is(notNullValue()));
     Path content = repository.getContent(hash).getPhysicalFile().toPath();
     String contentHtml = readFileContent(content.resolve("overlay.xhtml"));
     String expectedContentHtml = readFileContent(getResourceAsStream("overlay.xhtml"));
     assertThat(contentHtml, is(expectedContentHtml));
     assertThat(HashUtil.bytesToHexString(hash), is(expResult));
   }
 }
コード例 #2
0
 /** Test of explodeContent method, of class ContentRepository. */
 @Test
 public void testExplodeSubContent() throws Exception {
   byte[] archive =
       createMultiLevelArchive(Collections.singletonList("overlay.xhtml"), "test/archive.zip");
   try (ByteArrayInputStream stream = new ByteArrayInputStream(archive)) {
     byte[] originalHash = repository.addContent(stream);
     assertThat(originalHash, is(notNullValue()));
     assertThat(
         HashUtil.bytesToHexString(originalHash), is("f11be1883895957b06f7e46d784cad60dd015d71"));
     try {
       repository.explodeSubContent(originalHash, "test/archive.zip");
       fail("Shouldn't be able to explode sub content of unexploded content");
     } catch (ExplodedContentException ex) {
     }
     byte[] hash = repository.explodeContent(originalHash);
     // hash is different from the simple overlay.xhtml as we add the content folder name in the
     // computation
     assertThat(hash, is(notNullValue()));
     assertThat(HashUtil.bytesToHexString(hash), is("5ab326c763fadad903d0e9bbfecbb42e69a1b8b4"));
     Path content = repository.getContent(hash).getPhysicalFile().toPath();
     String contentHtml = readFileContent(content.resolve("overlay.xhtml"));
     String expectedContentHtml = readFileContent(getResourceAsStream("overlay.xhtml"));
     assertThat(contentHtml, is(expectedContentHtml));
     Path archiveFile = content.resolve("test").resolve("archive.zip");
     assertTrue(Files.exists(archiveFile));
     assertTrue(PathUtil.isArchive(archiveFile));
     byte[] fullyExplodedHash = repository.explodeSubContent(hash, "test/archive.zip");
     assertThat(fullyExplodedHash, is(notNullValue()));
     assertThat(
         HashUtil.bytesToHexString(fullyExplodedHash),
         is("231f4d042711f017d7f8c45aa4affcccbd4d67f4"));
     content =
         repository
             .getContent(repository.explodeSubContent(hash, "test/archive.zip"))
             .getPhysicalFile()
             .toPath();
     Path directory = content.resolve("test").resolve("archive.zip");
     assertTrue("Should not be a zip file", Files.isDirectory(directory));
     assertThat(contentHtml, is(expectedContentHtml));
   }
 }
コード例 #3
0
 @Test
 public void testListContents() throws Exception {
   byte[] archive = createArchive(Collections.singletonList("overlay.xhtml"));
   try (ByteArrayInputStream stream = new ByteArrayInputStream(archive)) {
     byte[] hash = repository.explodeContent(repository.addContent(stream));
     String expResult = "b1f18e286615dda0643633ec31f1a17d90e48875";
     // hash is different from the simple overlay.xhtml as we add the content folder name in the
     // computation
     assertThat(hash, is(notNullValue()));
     Path content = repository.getContent(hash).getPhysicalFile().toPath();
     String contentHtml = readFileContent(content.resolve("overlay.xhtml"));
     String expectedContentHtml = readFileContent(getResourceAsStream("overlay.xhtml"));
     assertThat(contentHtml, is(expectedContentHtml));
     assertThat(HashUtil.bytesToHexString(hash), is(expResult));
     String updatedExpectedResult = "161a2c95b16d5ffede0721c2cec984ca51009082";
     hash =
         repository.addContentToExploded(
             hash,
             Collections.singletonList(
                 new ExplodedContent(
                     "test.jsp",
                     new ByteArrayInputStream("this is a test".getBytes(StandardCharsets.UTF_8)))),
             true);
     assertThat(hash, is(notNullValue()));
     assertThat(HashUtil.bytesToHexString(hash), is(updatedExpectedResult));
     List<String> contents =
         repository
             .listContent(hash, "", ContentFilter.Factory.createContentFilter(-1, false))
             .stream()
             .map(ContentRepositoryElement::getPath)
             .collect(Collectors.toList());
     assertThat(contents.size(), is(2));
     assertThat(contents, CoreMatchers.hasItems("test.jsp", "overlay.xhtml"));
     hash =
         repository.addContentToExploded(
             hash,
             Collections.singletonList(new ExplodedContent("test/empty-file.txt", emptyStream())),
             true);
     hash =
         repository.addContentToExploded(
             hash, Collections.singletonList(new ExplodedContent("empty-dir", null)), true);
     contents =
         repository
             .listContent(hash, "", ContentFilter.Factory.createContentFilter(-1, false))
             .stream()
             .map(ContentRepositoryElement::getPath)
             .collect(Collectors.toList());
     assertThat(contents, is(notNullValue()));
     assertThat(contents.size(), is(5));
     assertThat(
         contents,
         CoreMatchers.hasItems(
             "test.jsp", "overlay.xhtml", "test/empty-file.txt", "test/", "empty-dir/"));
     hash = repository.removeContentFromExploded(hash, Collections.singletonList("test.jsp"));
     contents =
         repository
             .listContent(hash, "", ContentFilter.Factory.createFileFilter(-1, false))
             .stream()
             .map(ContentRepositoryElement::getPath)
             .collect(Collectors.toList());
     assertThat(contents, is(notNullValue()));
     assertThat(contents.size(), is(2));
     assertThat(contents, CoreMatchers.hasItems("overlay.xhtml", "test/empty-file.txt"));
   }
 }
コード例 #4
0
 /** Test of explodeContent method, of class ContentRepository. */
 @Test
 public void testChangeExplodedContent() throws Exception {
   byte[] archive = createArchive(Collections.singletonList("overlay.xhtml"));
   try (ByteArrayInputStream stream = new ByteArrayInputStream(archive)) {
     byte[] hash = repository.explodeContent(repository.addContent(stream));
     String expResult = "b1f18e286615dda0643633ec31f1a17d90e48875";
     // hash is different from the simple overlay.xhtml as we add the content folder name in the
     // computation
     assertThat(hash, is(notNullValue()));
     Path content = repository.getContent(hash).getPhysicalFile().toPath();
     String contentHtml = readFileContent(content.resolve("overlay.xhtml"));
     String expectedContentHtml = readFileContent(getResourceAsStream("overlay.xhtml"));
     assertThat(contentHtml, is(expectedContentHtml));
     assertThat(HashUtil.bytesToHexString(hash), is(expResult));
     String updatedExpectedResult = "161a2c95b16d5ffede0721c2cec984ca51009082";
     hash =
         repository.addContentToExploded(
             hash,
             Collections.singletonList(
                 new ExplodedContent(
                     "test.jsp",
                     new ByteArrayInputStream("this is a test".getBytes(StandardCharsets.UTF_8)))),
             true);
     assertThat(hash, is(notNullValue()));
     assertThat(HashUtil.bytesToHexString(hash), is(updatedExpectedResult));
     try (InputStream addedContent = repository.readContent(hash, "test.jsp")) {
       assertThat(addedContent, is(notNullValue()));
       assertThat(readFileContent(addedContent), is("this is a test"));
     }
     content = repository.getContent(hash).getPhysicalFile().toPath();
     assertThat(content.toFile().list().length, is(2));
     hash = repository.removeContentFromExploded(hash, Collections.singletonList("test.jsp"));
     assertThat(hash, is(notNullValue()));
     assertThat(HashUtil.bytesToHexString(hash), is(expResult));
     updatedExpectedResult = "a44921155d75009d885db3357005b85b435cf59f";
     hash =
         repository.addContentToExploded(
             hash,
             Collections.singletonList(
                 new ExplodedContent(
                     "test.jsp",
                     new ByteArrayInputStream(
                         "this is an overwrite test".getBytes(StandardCharsets.UTF_8)))),
             true);
     assertThat(hash, is(notNullValue()));
     assertThat(HashUtil.bytesToHexString(hash), is(updatedExpectedResult));
     try (InputStream addedContent = repository.readContent(hash, "test.jsp")) {
       assertThat(addedContent, is(notNullValue()));
       assertThat(readFileContent(addedContent), is("this is an overwrite test"));
     }
     try {
       hash =
           repository.addContentToExploded(
               hash,
               Collections.singletonList(
                   new ExplodedContent(
                       "test.jsp",
                       new ByteArrayInputStream(
                           "this is a failure test".getBytes(StandardCharsets.UTF_8)))),
               false);
       fail("Overwritting shouldn't work");
     } catch (ExplodedContentException ex) {
     }
   }
 }