1

I'm trying to develop a Java Class that will be used on a RPG program on iSeries. This Class will manage files with IFSFile. The problem is that I don't know how can I test this (if possible) on my PC.

My code would be something like:

import java.io.BufferedReader;
import java.io.IOException;

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400SecurityException;
import com.ibm.as400.access.IFSFile;
import com.ibm.as400.access.IFSFileReader;
(...)

        AS400 system = new AS400("AS400SystemName");
        IFSFile file = new IFSFile(system, "/File1");
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new IFSFileReader(file));
        } catch (AS400SecurityException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // Read one line of the file
        String line1 = null;
        try {
            line1 = reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // Print line
        System.out.println(line1);

        // Close reader
        try {
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }</pre>

I don't know well iSeries and I have some doubts:

  1. If I try to run this code on my PC it asks me to a user/password, when the class will be used on iSeries, it will ask also, or it will take the user that is running the application?

  2. Is there any way in which I can test this part on my PC, in order to know if it will work on production? My idea is first use a mock for Unit testing, but later I would like to have some functional tests that don't use the mock, maybe some kind of emulator or similar...

Thanks in advance.

2 Answers2

2

I would suggest you define the hostname, user id, & password parameters to the AS400 object as fields (or constants) and assign them based on how it's being run.

When you're debugging

String host = "AS400SystemName";
String user = "youruserid";
String pass = "yourpassword";

AS400 system = new AS400(host, user, pass);

When you're running the class on the IBM i host, define the variables like this:

String host = "localhost";
String user = "*CURRENT";
String pass = "*CURRENT";

You might also want to set the GUI available attribute on the AS400 object to false using setGUIAvailable. This way, if a bad user id or password is passed, an exception will be thrown instead of a GUI login window popping up.

In general, functionality that works on a PC will work the same on the host.

David G
  • 3,940
  • 1
  • 22
  • 30
  • Thanks a lot, David. But, I have no access to the AS400 from the machine I use to develop. So I can't figure if there is some method to test it. – user2539663 Jul 01 '13 at 17:24
  • You might want to consider looking at the [IFSJavaFile](http://javadoc.midrange.com/jtopen/com/ibm/as400/access/IFSJavaFile.html) object ... this will let you use File operations on IFS based objects. You could _test_ using normal files. Personally, I wouldn't recommend moving anything like this into production until you've tested on a real IBM i. – David G Jul 01 '13 at 18:24
  • Thanks. My Idea is to use IFSJavaFile, the problem is how to test without iSeries. Anyway, the example you sent helps me because more than a mock, but if someone has any better way to test it (without an iSeries), it would be appreciate. – user2539663 Jul 01 '13 at 18:54
0
  • In answer to question 1, the user id and password issue, be sure to use the JT400Native.jar instead of JT400.jar in your classpath on the iSeries side. When using JT400Native.jar, it should take the user id and password of the currently running job when using the com.ibm.as400.access classes.

  • In answer to question 2, you cannot test your program without an iSeries to talk to. Optionally, you can read from a normal file input stream or write to a normal file output stream instead of the IFSFile. This will, at least, let you test the business logic of your code. But when it's time to test the com.ibm.as400.access classes, you just can't do it without access to a real iSeries. An emulator would be nice, but the architecture is just so different, I don't know of anyone who made one.

Tracy Probst
  • 1,839
  • 12
  • 13
  • Thanks a lot, for sure an emulator would be great :) – user2539663 Jul 03 '13 at 15:18
  • 1
    JT400Native.jar doesn't specifically allow for using the current users credentials when running java code. It just provides native optimizations that aren't present in the pure java JT400.jar. When using JT400.jar, simply creating a no parameter `AS400` object will use the current users credentials. Optionally, you can construct the AS400 object using `new AS400("localhost", "*CURRENT", "*CURRENT");` to use the current user information. Personally, I always use the pure java JT400 to avoid any differences between it and JT400Native.jar. – David G Aug 09 '13 at 17:41