@Test public void testInvalidCommand() throws Exception { buildks buildksOBJ = new buildks(); String[] argsCreateCommand = {"creat", "TestCredential1", "-value", "PassworD123", "-provider", "jksp: int rc1 = buildksOBJ.createCredential(argsCreateCommand); assertEquals(-1, rc1); }
public int createCredential(String args[]){ int returnCode=-1; String command=null; String alias=null; String valueOption=null; String credential=null; String providerOption=null; String providerPath=null; String tempCredential=null; try{ if(args!=null && args.length==6) { command=args[0]; alias=args[1]; valueOption=args[2]; credential=args[3]; providerOption=args[4]; providerPath=args[5]; if(!isValidCreateCommand(command,alias,valueOption,credential,providerOption,providerPath)){ return returnCode; } deleteInvalidKeystore(providerPath); tempCredential=CredentialReader.getDecryptedString(providerPath, alias); }else{ return returnCode; } if(tempCredential==null){ returnCode=createKeyStore(args); }else{ try{ System.out.println("The alias " + alias + " already exists!! Will try to delete first."); boolean isSilentMode = true; String argsDelete[]=new String[4]; argsDelete[0]="delete"; argsDelete[1]=alias; argsDelete[2]=providerOption; argsDelete[3]=providerPath; returnCode=deleteCredential(argsDelete, isSilentMode); if(returnCode==0){ returnCode=createKeyStore(args); } }catch(Exception ex){ returnCode=-1; } } }catch(Exception ex){ ex.printStackTrace(); } return returnCode; }
buildks { public int createCredential(String args[]){ int returnCode=-1; String command=null; String alias=null; String valueOption=null; String credential=null; String providerOption=null; String providerPath=null; String tempCredential=null; try{ if(args!=null && args.length==6) { command=args[0]; alias=args[1]; valueOption=args[2]; credential=args[3]; providerOption=args[4]; providerPath=args[5]; if(!isValidCreateCommand(command,alias,valueOption,credential,providerOption,providerPath)){ return returnCode; } deleteInvalidKeystore(providerPath); tempCredential=CredentialReader.getDecryptedString(providerPath, alias); }else{ return returnCode; } if(tempCredential==null){ returnCode=createKeyStore(args); }else{ try{ System.out.println("The alias " + alias + " already exists!! Will try to delete first."); boolean isSilentMode = true; String argsDelete[]=new String[4]; argsDelete[0]="delete"; argsDelete[1]=alias; argsDelete[2]=providerOption; argsDelete[3]=providerPath; returnCode=deleteCredential(argsDelete, isSilentMode); if(returnCode==0){ returnCode=createKeyStore(args); } }catch(Exception ex){ returnCode=-1; } } }catch(Exception ex){ ex.printStackTrace(); } return returnCode; } }
buildks { public int createCredential(String args[]){ int returnCode=-1; String command=null; String alias=null; String valueOption=null; String credential=null; String providerOption=null; String providerPath=null; String tempCredential=null; try{ if(args!=null && args.length==6) { command=args[0]; alias=args[1]; valueOption=args[2]; credential=args[3]; providerOption=args[4]; providerPath=args[5]; if(!isValidCreateCommand(command,alias,valueOption,credential,providerOption,providerPath)){ return returnCode; } deleteInvalidKeystore(providerPath); tempCredential=CredentialReader.getDecryptedString(providerPath, alias); }else{ return returnCode; } if(tempCredential==null){ returnCode=createKeyStore(args); }else{ try{ System.out.println("The alias " + alias + " already exists!! Will try to delete first."); boolean isSilentMode = true; String argsDelete[]=new String[4]; argsDelete[0]="delete"; argsDelete[1]=alias; argsDelete[2]=providerOption; argsDelete[3]=providerPath; returnCode=deleteCredential(argsDelete, isSilentMode); if(returnCode==0){ returnCode=createKeyStore(args); } }catch(Exception ex){ returnCode=-1; } } }catch(Exception ex){ ex.printStackTrace(); } return returnCode; }  }
buildks { public int createCredential(String args[]){ int returnCode=-1; String command=null; String alias=null; String valueOption=null; String credential=null; String providerOption=null; String providerPath=null; String tempCredential=null; try{ if(args!=null && args.length==6) { command=args[0]; alias=args[1]; valueOption=args[2]; credential=args[3]; providerOption=args[4]; providerPath=args[5]; if(!isValidCreateCommand(command,alias,valueOption,credential,providerOption,providerPath)){ return returnCode; } deleteInvalidKeystore(providerPath); tempCredential=CredentialReader.getDecryptedString(providerPath, alias); }else{ return returnCode; } if(tempCredential==null){ returnCode=createKeyStore(args); }else{ try{ System.out.println("The alias " + alias + " already exists!! Will try to delete first."); boolean isSilentMode = true; String argsDelete[]=new String[4]; argsDelete[0]="delete"; argsDelete[1]=alias; argsDelete[2]=providerOption; argsDelete[3]=providerPath; returnCode=deleteCredential(argsDelete, isSilentMode); if(returnCode==0){ returnCode=createKeyStore(args); } }catch(Exception ex){ returnCode=-1; } } }catch(Exception ex){ ex.printStackTrace(); } return returnCode; }  static void main(String[] args); int createCredential(String args[]); int createKeyStore(String args[]); int createCredentialFromUserInput(); int listCredential(String args[]); int deleteCredential(String args[], boolean isSilentMode); static boolean isValidCreateCommand(String command,String alias,String valueOption,String credential,String providerOption,String providerPath); static boolean isValidListCommand(String command,String providerOption,String providerPath); static void displayCommand(String args[]); static void displaySyntax(String command); String getCredential(String args[]); static boolean isValidGetCommand(String command,String alias,String providerOption,String providerPath); void deleteInvalidKeystore(String providerPath); }
buildks { public int createCredential(String args[]){ int returnCode=-1; String command=null; String alias=null; String valueOption=null; String credential=null; String providerOption=null; String providerPath=null; String tempCredential=null; try{ if(args!=null && args.length==6) { command=args[0]; alias=args[1]; valueOption=args[2]; credential=args[3]; providerOption=args[4]; providerPath=args[5]; if(!isValidCreateCommand(command,alias,valueOption,credential,providerOption,providerPath)){ return returnCode; } deleteInvalidKeystore(providerPath); tempCredential=CredentialReader.getDecryptedString(providerPath, alias); }else{ return returnCode; } if(tempCredential==null){ returnCode=createKeyStore(args); }else{ try{ System.out.println("The alias " + alias + " already exists!! Will try to delete first."); boolean isSilentMode = true; String argsDelete[]=new String[4]; argsDelete[0]="delete"; argsDelete[1]=alias; argsDelete[2]=providerOption; argsDelete[3]=providerPath; returnCode=deleteCredential(argsDelete, isSilentMode); if(returnCode==0){ returnCode=createKeyStore(args); } }catch(Exception ex){ returnCode=-1; } } }catch(Exception ex){ ex.printStackTrace(); } return returnCode; }  static void main(String[] args); int createCredential(String args[]); int createKeyStore(String args[]); int createCredentialFromUserInput(); int listCredential(String args[]); int deleteCredential(String args[], boolean isSilentMode); static boolean isValidCreateCommand(String command,String alias,String valueOption,String credential,String providerOption,String providerPath); static boolean isValidListCommand(String command,String providerOption,String providerPath); static void displayCommand(String args[]); static void displaySyntax(String command); String getCredential(String args[]); static boolean isValidGetCommand(String command,String alias,String providerOption,String providerPath); void deleteInvalidKeystore(String providerPath);  }