/**
   * 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 password. Then sends the results through another instance but
   * with a different password.
   */
  public void testWrongPassword() {
    SampleEncryptionTransformer transformer = new SampleEncryptionTransformer();
    transformer.setPassword("Alice");
    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();

    // Password Alice != Eve
    transformer.setPassword("Eve");
    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;
        }
      }
      fail("Decryption should have failed.");

    } catch (IOException ie) {
      // We expect to get here
    }
  }
  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);
  }