Java IFSFile on Iseries testing over PC

2019-08-02 14:56发布

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条回答
不美不萌又怎样
2楼-- · 2019-08-02 14:57

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.

查看更多
对你真心纯属浪费
3楼-- · 2019-08-02 15:04
  • 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.

查看更多
登录 后发表回答