/**
   * Test method for {@link
   * org.alfresco.deployment.transformers.EncryptionTransformer#addFilter(java.io.OutputStream,
   * org.alfresco.deployment.DeploymentTransportTransformer.Direction, java.lang.String)}. This test
   * compresses a message with one transformation. Then sends the results through another instance
   * to give us plain text again.
   */
  public void testAddFilter() {
    SampleEncryptionTransformer transformer = new SampleEncryptionTransformer();
    transformer.setPassword("Welcome To Hades");
    transformer.setCipherName("PBEWithMD5AndDES");

    String path = "wibble";

    ByteArrayOutputStream compressed = new ByteArrayOutputStream();

    // A sender should encrypt the stream
    OutputStream out = null;
    // out = (OutputStream)transformer.addFilter(compressed, Direction.SENDER, path);
    out = (OutputStream) transformer.addFilter(compressed, path, null, null);

    assertNotNull("null output stream returned", compressed);

    String clearText = "hello world";

    try {
      out.write(clearText.getBytes());
    } catch (IOException ie) {
      fail("unexpected exception thrown" + ie.toString());
    }

    try {
      out.flush();
      out.close();
    } catch (IOException ie) {
      fail("unexpected exception thrown, " + ie.toString());
    }

    assert (compressed.size() > 0);

    // Now set up another instance to decrypt the message
    InputStream decompress = null;

    ByteArrayInputStream compressedStream = new ByteArrayInputStream(compressed.toByteArray());

    ByteArrayOutputStream result = new ByteArrayOutputStream();

    decompress = (InputStream) transformer.addFilter(compressedStream, "wibble", null, null);

    try {
      byte[] readBuffer = new byte[1002];
      while (true) {
        int readLen = decompress.read(readBuffer);
        if (readLen > 0) {
          result.write(readBuffer, 0, readLen);
        } else {
          break;
        }
      }

    } catch (IOException ie) {
      fail("unexpected exception thrown, " + ie.toString());
    }

    // now uncompress should equal clearText
    assertTrue(result.toString().equalsIgnoreCase(clearText));
  }
  public void testSetProperties() {
    SampleEncryptionTransformer transformer = new SampleEncryptionTransformer();
    String password = "******";
    transformer.setPassword(password);

    String cipherName = "PBEWithMD5AndDESAndTripleDES";
    transformer.setPassword(password);

    int iterations = 99;
    transformer.setPassword(password);
    transformer.setCipherName(cipherName);
    transformer.setIterationCount(iterations);

    assertEquals(transformer.getPassword(), password);
    assertEquals(transformer.getCipherName(), cipherName);
    assertEquals(transformer.getIterationCount(), iterations);
  }