@Test
  public void testSafeCreateCommandNotExisting() throws Exception {
    String alias = "javax.jdo.option.ConnectionPassword";
    String credential = "MyTopSecretPassword";
    String providerPath = getProviderPath("CreateCommandTest.jceks");
    String[] args;
    int exitCode;

    /*
     * Safely update a non-existing credential. Should create the credential.
     */
    credential = "AnotherTopSecretPassword";
    args = getSafeCreateArgs(alias, credential, providerPath);
    exitCode = executeCommand(args);
    Assert.assertEquals(exitCode, 0);
  }
Safely creates a credential. If it does not exist, it will be created.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/credentialapi/CredentialUtilTest.java