@Test
public void testSignAgentCrt() throws Exception {

  Injector injector = getInjector();
  File directory = folder.newFolder();
  String hostname = "host1.example.com";
  Map<String, String> configurationMap = new HashMap<String, String>();
  configurationMap.put(Configuration.SRVR_KSTR_DIR.getKey(), directory.getAbsolutePath());
  configurationMap.put(Configuration.SRVR_CRT_PASS.getKey(), "server_cert_pass");
  configurationMap.put(Configuration.SRVR_CRT_NAME.getKey(), "server_cert_name");
  configurationMap.put(Configuration.SRVR_KEY_NAME.getKey(), "server_key_name");
  configurationMap.put(Configuration.PASSPHRASE.getKey(), "passphrase");
  Configuration configuration = injector.getInstance(Configuration.class);
  expect(configuration.validateAgentHostnames()).andReturn(true).once();
  expect(configuration.getConfigsMap()).andReturn(configurationMap).anyTimes();
  Method runCommand = CertificateManager.class.getDeclaredMethod("runCommand", String.class);
  final File agentCrtFile = new File(directory, String.format("%s.crt", hostname));
  String expectedCommand = String.format("openssl ca -config %s/ca.config -in %s/%s.csr -out %s -batch -passin pass:%s -keyfile %s/%s -cert %s/%s",
      directory.getAbsolutePath(),
      directory.getAbsolutePath(),
      hostname,
      agentCrtFile.getAbsolutePath(),
      configurationMap.get(Configuration.SRVR_CRT_PASS.getKey()),
      directory.getAbsolutePath(),
      configurationMap.get(Configuration.SRVR_KEY_NAME.getKey()),
      directory.getAbsolutePath(),
      configurationMap.get(Configuration.SRVR_CRT_NAME.getKey()));
  CertificateManager certificateManager = createMockBuilder(CertificateManager.class)
      .addMockedMethod(runCommand)
      .createMock();
  expect(certificateManager.runCommand(expectedCommand))
      .andAnswer(new IAnswer<Integer>() {
        @Override
        public Integer answer() throws Throwable {
          return (agentCrtFile.createNewFile()) ? 0 : 1;
        }
      })
      .once();
  injector.injectMembers(certificateManager);
  replayAll();
  SignCertResponse response = certificateManager.signAgentCrt(hostname, "crtContent", "passphrase");
  verifyAll();
  Assert.assertEquals(SignCertResponse.OK_STATUS, response.getResult());
}