コード例 #1
0
  /**
   * Test for overwrite existing file with action = create.
   *
   * @throws CruiseControlException
   * @throws IOException
   */
  public final void testMsgActionCreate() throws CruiseControlException, IOException {
    final File outFile = filesToDelete.add(this);
    final WriterBuilder writerObj = new WriterBuilder();

    // Create file with inner text
    IO.write(outFile, "InnerText");

    // Set append true.
    writerObj.setFile(outFile.getAbsolutePath());
    writerObj.setAction("create");
    newMssg(writerObj).append("first text");

    // Validation step
    // Setting overwrite false set append also false
    assertFalse(writerObj.getAppend());

    try {
      writerObj.validate();
      fail();
    } catch (Exception e) {
      assertTrue(e.getMessage().equals("Trying to overwrite file without permition."));
    }

    // Build step. The file was not existing during the validation, but has been created
    // later on ...
    IO.delete(outFile);
    writerObj.validate();
    // Create file with inner text - again
    IO.write(outFile, "InnerText");

    // Trigger the build as well
    final Element out = writerObj.build(buildMap, buildProgress);
    assertNotNull(out.getAttribute("error"));
  }
コード例 #2
0
  /**
   * Test using of GZIP.
   *
   * @throws CruiseControlException
   * @throws IOException
   */
  @Ignore
  public final void testMsgAddGzip() throws CruiseControlException, IOException {
    final File outFile = filesToDelete.add(this);
    final File inpFile = filesToDelete.add(this);
    final WriterBuilder writerObj = new WriterBuilder();
    final DataBuffer buff = new DataBuffer();

    IO.delete(outFile);

    writerObj.setFile(outFile.getAbsolutePath());
    writerObj.setGzip(true);
    newMssg(writerObj).append(buff.add("first text"));
    newMssg(writerObj).append(buff.add("second text"));
    newFile(writerObj).setFile(buff.add("Third text, that is in file.", inpFile));
    newMssg(writerObj).append(buff.add("4th text"));

    writerObj.validate();
    writerObj.build(buildMap, buildProgress);

    final File gzipFile =
        new File(outFile.getAbsolutePath() + ".gzip"); // just add extension to the name
    assertTrue(gzipFile.exists());
    assertStreams(buff.getData(), new GZIPInputStream(new FileInputStream(gzipFile)));
  }