JCICSX examples

Examples using JCICSX API classes, as well as their JCICS equivalents, are provided to give a basic understanding of how JCICSX can be used in typical use cases.

For more samples to play with, go to JCICSX samples in GitHub.

Setting up channels and containers

Example 1
The example shows how to set up a channel named XYZ with two containers:
  • A CHAR container called CONT1 with the text scenarios in it.
  • A BIT container called CONT2 with the content of the bytes byte array.

The JCICSX snippet shows the use of opinionated container types: the Java code is aware of the difference between BIT and CHAR in containers, and different methods are available for each type.

JCICSX
CICSContext task = CICSContext.getCICSContext();
Channel channel = task.getChannel("XYZ");
channel.getCHARContainer("CONT1").put("scenarios");
channel.getBITContainer("CONT2").put(bytes);
JCICS
Task task = Task.getTask();
Channel channel = task.getChannel("XYZ");
channel.createContainer("CONT1").putString("scenarios");
channel.createContainer("CONT2").put(bytes);

Linking to a program

Example 2
This example shows how to link to program ABC without passing any input.
JCICSX
CICSContext task = CICSContext.getCICSContext();
task.createProgramLinker("ABC").link();
JCICS
Task task = Task.getTask();
Program abcProgram = new Program();
abcProgram.setName("ABC");
abcProgram.link();
Example 3
This example shows how to link to program ABC with a channel named XYZ, passing a CHAR container named CONT-IN with the text scenarios in it, then get the content of a CHAR container called CONT-OUT and return it as a string.

The JCICSX snippet shows that JCICSX has convenient ways of calling common models: adding containers, linking, and getting response data.

JCICSX
CICSContext task = CICSContext.getCICSContext();
return task
    .createProgramLinkerWithChannel("ABC", task.getChannel("XYZ"))
    .setStringInput("CONT-IN", "scenarios")
    .link()
    .getOutputCHARContainer("CONT-OUT")
    .get();
JCICS
Task task = Task.getTask();
Channel channel = task.createChannel("XYZ");
channel.createContainer("CONT-IN").putString("scenarios");

Program abcProgram = new Program();
abcProgram.setName("ABC");
abcProgram.link();

return channel.getContainer("CONT-OUT").getString();

Mocking

Example 4
The JCICSX API can be easily mockable. There are many mocking frameworks you can use; this JCICSX example shows how to use Mockito to return some mocked contents of a container. Mocking out the CICS calls enables you to independently unit test the logic of your application.
CICSContext task = Mockito.mock(CICSContext.class);
Channel channel = Mockito.mock(Channel.class);
CHARContainer container = Mockito.mock(CHARContainer.class);
Mockito.when(task.getChannel("ABC")).thenReturn(channel);
Mockito.when(channel.getCHARContainer("container")).thenReturn(container);
Mockito.when(container.get()).thenReturn("the contents of my container");