Пример #1
0
  @Test
  public void hiddenTargetHandlingAtRoot() throws Exception {
    // test subject
    final DefaultFSPeer subject = new DefaultFSPeer();

    // repo base
    File repoBase = new File("target/repoId");

    // the file we want to store
    File target = new File(repoBase, "archetype-catalog.xml");
    target.getParentFile().mkdirs();

    final StorageFileItem file = Mockito.mock(StorageFileItem.class);
    Mockito.when(file.getPath()).thenReturn("/archetype-catalog.xml");
    Mockito.when(file.getParentPath()).thenReturn("/");

    // getting hidden target for target
    File hiddenTarget = subject.getHiddenTarget(null, repoBase, target, file);
    assertThat(hiddenTarget, notNullValue());
    assertThat(hiddenTarget, isFile());
    // startsWith, as garbage is appended to it's end
    assertThat(hiddenTarget.getName(), startsWith("archetype-catalog.xml"));
    // contains, as OS path from root is prefixing this, and garbage at the end suffixing it
    assertThat(
        hiddenTarget.getPath(),
        containsString(
            "target/repoId/.nexus/tmp/archetype-catalog.xml".replace("/", File.separator)));

    // writing to hidden target is handled elsewhere, so we simulate content being written out
    final String PAYLOAD = "dummy payload";
    FileUtils.write(hiddenTarget, PAYLOAD);

    // handle the rename
    subject.handleRenameOperation(hiddenTarget, target);

    // hidden should cease to exist
    assertThat(hiddenTarget, not(exists()));
    // target should exists
    assertThat(target, exists());
    // name should be not garbaged anymore
    assertThat(target.getName(), equalTo("archetype-catalog.xml"));
    // path prefixed by OS from root, no garbage at tail
    assertThat(
        target.getPath(),
        endsWith("target/repoId/archetype-catalog.xml".replace("/", File.separator)));
    // content is fine too
    assertThat(FileUtils.readFileToString(target), equalTo(PAYLOAD));
  }