-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: John Eberhard <[email protected]>
- Loading branch information
Showing
2 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// JTOpen (IBM Toolbox for Java - OSS version) | ||
// | ||
// Filename: AS400NewInstance.java | ||
// | ||
// The source code contained herein is licensed under the IBM Public License | ||
// Version 1.0, which has been approved by the Open Source Initiative. | ||
// Copyright (C) 1997-2023 International Business Machines Corporation and | ||
// others. All rights reserved. | ||
// | ||
/////////////////////////////////////////////////////////////////////////////// | ||
package test.AS400; | ||
|
||
import java.io.*; | ||
import java.sql.Connection; | ||
|
||
import com.ibm.as400.access.*; | ||
import com.ibm.as400.util.AboutToolbox; | ||
|
||
import test.DisableSSL; | ||
import test.JDReflectionUtil; | ||
import test.PasswordVault; | ||
import test.Testcase; | ||
|
||
import java.util.Hashtable; | ||
import java.util.Vector; | ||
|
||
/** | ||
* Testcase AS400NewInstance | ||
* | ||
* Tests the following static methods of the AS400 class. | ||
* | ||
* public static AS400 newInstance(boolean useSSL, String systemName) | ||
* public static AS400 newInstance(boolean useSSL, String systemName, String userId, char[] password, char[] additionalAuthenticationFactor) | ||
* public static AS400 newInstance(boolean useSSL, String systemName, String userId, char[] password, String proxyServer) | ||
* public static AS400 newInstance(boolean useSSL, String systemName, ProfileTokenCredential profileToken) | ||
* public static AS400 newInstance(boolean useSSL, AS400 system) | ||
**/ | ||
public class AS400NewInstance extends Testcase { | ||
|
||
StringBuffer sb = new StringBuffer(); | ||
private Connection connection_; | ||
/** | ||
* Constructor. This is called from the AS400Test constructor. | ||
**/ | ||
public AS400NewInstance(AS400 systemObject, Hashtable<String, Vector<String>> namesAndVars, int runMode, | ||
FileOutputStream fileOutputStream, String testLib, String password, AS400 pwrSys) { | ||
super(systemObject, "AS400NewInstance", namesAndVars, runMode, fileOutputStream, password); | ||
pwrSys_ = pwrSys; | ||
|
||
} | ||
|
||
protected void setup() throws Exception { | ||
super.setup(); | ||
connection_ = new AS400JDBCDriver().connect(systemObject_); | ||
} | ||
protected void cleanup() throws Exception { | ||
connection_.close(); | ||
super.cleanup(); | ||
} | ||
/** | ||
* | ||
**/ | ||
public void Var001() { | ||
boolean succeeded = true; | ||
|
||
try { | ||
sb.setLength(0); | ||
sb.append(AboutToolbox.getVersionDescription()+"\n"); | ||
sb.append("Calling newInstance to "+systemName_+"\n"); | ||
AS400 testAs400 = (AS400) JDReflectionUtil.callStaticMethod_O("com.ibm.as400.access.AS400", "newInstance", true, systemName_); | ||
testAs400.setUserId(userId_); | ||
char[] password = PasswordVault.decryptPassword(encryptedPassword_); | ||
testAs400.setPassword(password); | ||
PasswordVault.clearPassword(password); | ||
testAs400.connectService(AS400.SIGNON); | ||
Job[] jobs = testAs400.getJobs(AS400.SIGNON); | ||
String serverJobName = jobs[1].getNumber()+"/"+jobs[1].getUser()+"/"+jobs[1].getName(); | ||
sb.append("connected to "+serverJobName); | ||
assertCondition(succeeded, sb); | ||
} catch (Exception e) { | ||
failed(e, "Unexpected Exception: "+sb.toString()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// JTOpen (IBM Toolbox for Java - OSS version) | ||
// | ||
// Filename: AS400Test.java | ||
// | ||
// The source code contained herein is licensed under the IBM Public License | ||
// Version 1.0, which has been approved by the Open Source Initiative. | ||
// Copyright (C) 1997-2023 International Business Machines Corporation and | ||
// others. All rights reserved. | ||
// | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
package test; | ||
|
||
import com.ibm.as400.access.AS400; | ||
import com.ibm.as400.access.CommandCall; | ||
|
||
import test.AS400.AS400NewInstance; | ||
|
||
import java.util.Enumeration; | ||
|
||
/** | ||
Test driver for the AS400 component. | ||
The following testcases can be run: | ||
<ul compact> | ||
<li>AS400NewInstance</li> | ||
<br> | ||
This test exercises the newInstance methods of the AS400 class. The following methods are verified: | ||
<ul> | ||
<li>public static AS400 newInstance(boolean useSSL, String systemName) | ||
<li>public static AS400 newInstance(boolean useSSL, String systemName, String userId, char[] password, char[] additionalAuthenticationFactor) | ||
<li>public static AS400 newInstance(boolean useSSL, String systemName, String userId, char[] password, String proxyServer) | ||
<li>public static AS400 newInstance(boolean useSSL, String systemName, ProfileTokenCredential profileToken) | ||
<li>public static AS400 newInstance(boolean useSSL, AS400 system) | ||
</ul> | ||
<li>TBD | ||
</ul> | ||
**/ | ||
public class AS400Test extends TestDriver | ||
{ | ||
static AS400 PwrSys = null; | ||
|
||
public static String COLLECTION = "JDDDMTST"; | ||
|
||
/** | ||
Main for running standalone application tests. | ||
**/ | ||
public static void main(String args[]) | ||
{ | ||
try { | ||
AS400Test as400Test = new AS400Test(args); | ||
as400Test.init(); | ||
as400Test.start(); | ||
as400Test.stop(); | ||
as400Test.destroy(); | ||
} | ||
catch (Exception e) | ||
{ | ||
System.out.println("Program terminated abnormally."); | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
/** | ||
This ctor used for applets. | ||
@exception Exception Initialization errors may cause an exception. | ||
**/ | ||
public AS400Test() | ||
throws Exception | ||
{ | ||
super(); | ||
} | ||
|
||
/** | ||
This ctor used for applications. | ||
@param args the array of command line arguments | ||
@exception Exception Incorrect arguments will cause an exception | ||
**/ | ||
public AS400Test(String[] args) | ||
throws Exception | ||
{ | ||
super(args); | ||
} | ||
|
||
|
||
/** | ||
* Performs setup for the testcase | ||
*/ | ||
public void setup() { | ||
if (testLib_ != null) { | ||
COLLECTION = testLib_; | ||
} | ||
} | ||
|
||
|
||
/** | ||
Creates Testcase objects for all the testcases in this component. | ||
**/ | ||
public void createTestcases() | ||
{ | ||
|
||
|
||
// Instantiate all testcases to be run. | ||
boolean allTestcases = (namesAndVars_.size() == 0); | ||
// Determine what library to create files, etc. in | ||
if (testLib_ == null) | ||
{ | ||
testLib_ = "JTOAS4000"; | ||
} | ||
|
||
|
||
// do some setup | ||
|
||
if (!(pwrSys_.getUserId()).equals("")) | ||
{ | ||
/* For now, use the old methods to get a connection */ | ||
char[] decryptedPassword = PasswordVault.decryptPassword(pwrSysEncryptedPassword_); | ||
PwrSys = new AS400( systemObject_.getSystemName(), pwrSysUserID_, decryptedPassword); | ||
PasswordVault.clearPassword(decryptedPassword); | ||
|
||
try { | ||
|
||
PwrSys.setGuiAvailable(false); | ||
if (allTestcases) | ||
{ | ||
CommandCall cmd = new CommandCall(PwrSys); | ||
String deleteResult = deleteLibrary(cmd, testLib_); | ||
if (deleteResult != null && | ||
!deleteResult.equals("CPF2110")) | ||
{ | ||
System.out.println( "Setup could not delete library " + testLib_ + ": " | ||
+ cmd.getMessageList()[0].getID() + " " | ||
+ cmd.getMessageList()[0].getText() ); | ||
if (deleteResult.equals("CPF3202")) | ||
{ | ||
System.out.println( "To delete "+testLib_+", signon to the system and use the WRKOBJLCK command to end the jobs holding the locks." ); | ||
} | ||
} | ||
deleteResult = deleteLibrary(cmd, "\"" + testLib_ +"\""); | ||
if (deleteResult != null && | ||
!deleteResult.equals("CPF2110")) | ||
{ | ||
System.out.println( "Setup could not delete library " + testLib_ + ": " | ||
+ cmd.getMessageList()[0].getID() + " " | ||
+ cmd.getMessageList()[0].getText() ); | ||
if (deleteResult.equals("CPF3202")) | ||
{ | ||
System.out.println( "To delete "+testLib_+", signon to the system and use the WRKOBJLCK command to end the jobs holding the locks." ); | ||
} | ||
} | ||
if (!cmd.run("CRTLIB "+testLib_)) | ||
{ | ||
System.out.println("Setup could not create library "+testLib_+": "+ | ||
cmd.getMessageList()[0].toString()); | ||
} | ||
|
||
if (!cmdRun("GRTOBJAUT OBJ("+testLib_+") OBJTYPE(*LIB) USER("+userId_+") AUT(*ALL)")) { | ||
out_.println("CRTOBJAUT failed"); | ||
} | ||
|
||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
System.out.println( "Setup failed " + e ); | ||
e.printStackTrace(); | ||
} | ||
} | ||
else | ||
{ | ||
System.out.println("Warning: -pwrSys option not specified. Some " + | ||
"variations may fail due to leftover objects."); | ||
} | ||
|
||
|
||
|
||
if (allTestcases || namesAndVars_.containsKey("AS400NewInstance")) | ||
{ | ||
AS400NewInstance tc = | ||
new AS400NewInstance(systemObject_, | ||
namesAndVars_, runMode_, | ||
fileOutputStream_, testLib_, password_, PwrSys); | ||
testcases_.addElement(tc); | ||
namesAndVars_.remove("AS400NewInstance"); | ||
} | ||
|
||
|
||
|
||
// Put out error message for each invalid testcase name. | ||
for (Enumeration<String> e = namesAndVars_.keys(); e.hasMoreElements();) | ||
{ | ||
System.out.println("Testcase " + e.nextElement() + " not found."); | ||
} | ||
} // createTestcases | ||
} | ||
|