/**
   * Attempt to add nothing.
   *
   * @throws Exception
   */
  @Test
  public void testAddNothing() throws Exception {
    when(client.addFiles(fileSpecsToAdd, Boolean.FALSE, -1, null, Boolean.FALSE))
        .thenReturn(fileSpecsAdded);

    AddScmResult addResult = (AddScmResult) addCommand.execute(repository, scmFileSet, parameters);
    Assert.assertTrue("The result was not a success.", addResult.isSuccess());
  }
  /**
   * Attempts to add one file, but the operation fails and no exception is thrown by P4Java. The
   * result of the command should be a failure.
   *
   * @throws Exception
   */
  @Test
  public void testAddFail() throws Exception {
    File fileToAdd = new File("src/test/resources/testAdd/fileToAdd.txt");
    files.add(fileToAdd);

    when(client.addFiles(fileSpecsToAdd, Boolean.FALSE, -1, null, Boolean.FALSE))
        .thenReturn(fileSpecsAdded);

    AddScmResult addResult = (AddScmResult) addCommand.execute(repository, scmFileSet, parameters);
    Assert.assertTrue(
        "Should not be a success, attempt to add should have failed.", !addResult.isSuccess());
  }
Exemplo n.º 3
0
  protected MkdirScmResult executeMkdirCommand(
      ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean createInLocal)
      throws ScmException {
    LocalScmProviderRepository repo = (LocalScmProviderRepository) repository;
    List<ScmFile> createdDirs = new ArrayList<ScmFile>();

    // create/commit the directory directly in the repository
    if (!createInLocal) {
      File file = (File) fileSet.getFileList().get(0);
      File modulePath = new File(repo.getRoot(), repo.getModule());
      File dir = new File(modulePath, file.getName());

      if (dir.exists()) {
        return new MkdirScmResult(
            null, "Directory already exists!", "Directory already exists.", false);
      } else {
        if (getLogger().isInfoEnabled()) {
          getLogger().info("Creating directory in '" + modulePath.getAbsolutePath() + "'");
        }

        FileUtils.mkdir(dir.getAbsolutePath());
        createdDirs.add(new ScmFile(dir.getPath(), ScmFileStatus.ADDED));
      }
    } else {
      // add the directory, but not commit
      LocalAddCommand addCmd = new LocalAddCommand();
      addCmd.setLogger(getLogger());

      CommandParameters parameters = new CommandParameters();
      parameters.setString(CommandParameter.MESSAGE, message);
      parameters.setString(CommandParameter.BINARY, "false");

      String path = ((File) fileSet.getFileList().get(0)).getPath();
      if (repo.isFileAdded(path)) {
        return new MkdirScmResult(
            null, "Directory already exists!", "Directory already exists.", false);
      }

      AddScmResult result = (AddScmResult) addCmd.execute(repository, fileSet, parameters);
      createdDirs.addAll(result.getAddedFiles());
    }

    return new MkdirScmResult(null, createdDirs);
  }
  /**
   * Attempt to add one file, expect that one file is returned as added.
   *
   * @throws Exception
   */
  @Test
  public void testAddOne() throws Exception {
    File fileToAdd = new File("src/test/resources/testAdd/fileToAdd.txt");
    files.add(fileToAdd);

    IFileSpec fileSpec = mock(IFileSpec.class);
    when(fileSpec.getDepotPathString()).thenReturn("//depot/path/string/fileToAdd.txt");
    when(fileSpec.getAction()).thenReturn(FileAction.ADD);
    fileSpecsToAdd.add(fileSpec);
    fileSpecsAdded.add(fileSpec);

    ScmFile scmFile = new ScmFile(fileToAdd.getAbsolutePath(), ScmFileStatus.ADDED);
    scmFilesAdded.add(scmFile);

    when(client.addFiles(fileSpecsToAdd, Boolean.FALSE, -1, null, Boolean.FALSE))
        .thenReturn(fileSpecsAdded);

    AddScmResult addResult = (AddScmResult) addCommand.execute(repository, scmFileSet, parameters);
    Assert.assertTrue("The result was not a success.", addResult.isSuccess());
  }