Last active
January 19, 2017 04:03
-
-
Save greghelton/3bb177ac30b560b013ffeed21da5f914 to your computer and use it in GitHub Desktop.
unit test RPG SRVPGM with JUnit
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
package com.frontier.dpiplant.geo; | |
import com.ibm.as400.access.*; | |
import static org.junit.Assert.*; | |
import java.util.Date; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
import org.junit.Test; | |
public class GetLatLngSrvPgmCall { | |
static final Logger LOGGER = LogManager.getLogger(GetLatLngSrvPgmCall.class.getName()); | |
@Test | |
public void verifySundownAddress() { | |
Date start = new Date(); | |
try { | |
String address = "3600 W Sundown Ln Amarillo, TX"; | |
AS400Text addressText = new AS400Text(400); | |
AS400 as400 = new AS400("machine", "user-id", "password"); | |
ServiceProgramCall pgm = new ServiceProgramCall(as400); | |
ProgramParameter[] parameters = new ProgramParameter[4]; | |
parameters[0] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENCE, | |
addressText.toBytes(address), 400); | |
parameters[1] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENCE, 15); | |
parameters[2] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENCE, 15); | |
parameters[3] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENCE, 5); | |
pgm.setProgram("/QSYS.LIB/GAH285.LIB/BL0100S01.SRVPGM", parameters); | |
pgm.setProcedureName("getLatLng"); | |
pgm.setReturnValueFormat(ServiceProgramCall.RETURN_INTEGER); | |
if (pgm.run()) { | |
int i = new AS400Bin4().toInt(pgm.getReturnValue()); | |
AS400Text text400 = new AS400Text(15); | |
String lat = text400.toObject(parameters[1].getOutputData()).toString(); | |
String lng = text400.toObject(parameters[2].getOutputData()).toString(); | |
text400 = new AS400Text(5); | |
String fip = text400.toObject( parameters[3].getOutputData()).toString(); | |
LOGGER.info("lat/lng/fip=" + lat + "/" + lng + "/" + fip + " for " + address); | |
assertTrue("+035.103601000 ".equals(lat)); | |
assertTrue("-101.875709000 ".equals(lng)); | |
assertTrue("48381".equals(fip)); | |
Date end = new Date(); | |
LOGGER.info("srv time=" + (end.getTime() - start.getTime())); | |
} else { | |
System.out.println("SRVPGM call failed - messages follow:"); | |
AS400Message[] messagelist = pgm.getMessageList(); | |
for (int i = 0; i < messagelist.length; ++i) { | |
System.out.println(messagelist[i]); | |
} | |
fail("SRVPGM call failed"); | |
} | |
} catch(Exception e) { | |
System.out.println("SRVPGM call blew up " + e.getMessage()); | |
fail("SRVPGM call blew up " + e.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment