NIFI-1822 Added unit test skeleton for pooled script processor execution.

This commit is contained in:
Andy LoPresto 2016-05-10 16:08:02 -07:00
parent 23e4f685c3
commit fd9120c28b
No known key found for this signature in database
GPG Key ID: 3C6EF65B2F7DEF69
1 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,71 @@
package org.apache.nifi.processors.script
import org.apache.nifi.security.util.EncryptionMethod
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.python.bouncycastle.util.encoders.Hex
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import javax.crypto.Cipher
@RunWith(JUnit4.class)
class ExecuteScriptGroovyTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(ExecuteScriptGroovyTest.class)
@BeforeClass
public static void setUpOnce() throws Exception {
logger.metaClass.methodMissing = { String name, args ->
logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
}
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testShouldExecuteScript() throws Exception {
// Arrange
final String PASSWORD = "shortPassword";
final byte[] SALT = cipherProvider.generateSalt()
final String plaintext = "This is a plaintext message.";
// Act
for (EncryptionMethod em : strongKDFEncryptionMethods) {
logger.info("Using algorithm: ${em.getAlgorithm()}");
// Initialize a cipher for encryption
Cipher cipher = cipherProvider.getCipher(em, PASSWORD, SALT, DEFAULT_KEY_LENGTH, true);
byte[] iv = cipher.getIV();
logger.info("IV: ${Hex.encodeHexString(iv)}")
byte[] cipherBytes = cipher.doFinal(plaintext.getBytes("UTF-8"));
logger.info("Cipher text: ${Hex.encodeHexString(cipherBytes)} ${cipherBytes.length}");
cipher = cipherProvider.getCipher(em, PASSWORD, SALT, iv, DEFAULT_KEY_LENGTH, false);
byte[] recoveredBytes = cipher.doFinal(cipherBytes);
String recovered = new String(recoveredBytes, "UTF-8");
logger.info("Recovered: ${recovered}")
// Assert
assert plaintext.equals(recovered);
}
}
//testShouldExecuteScriptWithPool
//testShouldHandleFailingScript
//testShouldHandleNoAvailableEngine
//testPooledExecutionShouldBeFaster
}