Search in sources :

Example 21 with Context

use of org.jpos.transaction.Context in project jPOS by jpos.

the class ContextMaker method run.

public void run() {
    Thread.currentThread().setName(getName());
    while (running()) {
        Object o = sp.in(in, timeout);
        if (o != null) {
            Context ctx = new Context();
            ctx.put(contextName, o);
            if (contextValues != null) {
                for (Element e : contextValues) {
                    ctx.put(e.getName(), e.getValue());
                }
            }
            sp.out(out, ctx);
        }
    }
}
Also used : Context(org.jpos.transaction.Context) Element(org.jdom2.Element)

Example 22 with Context

use of org.jpos.transaction.Context in project jPOS by jpos.

the class CheckFieldsTest method testAmounts.

@Test
public void testAmounts() throws ISOException {
    Context ctx = new Context();
    ISOMsg m = new ISOMsg();
    ISOAmount local = new ISOAmount(4, 858, new BigDecimal("290.00"));
    ISOAmount settlement = new ISOAmount(5, 840, new BigDecimal("10.00"));
    m.set(local);
    m.set(settlement);
    ctx.put(ContextConstants.REQUEST.toString(), m);
    cfg.put("mandatory", "AMOUNT");
    int action = cf.prepare(1L, ctx);
    assertEquals(PREPARED | NO_JOIN | READONLY, action);
    Result rc = ctx.getResult();
    assertFalse(rc.hasInfo());
    assertFalse(rc.hasWarnings());
    assertFalse(rc.hasFailures());
    assertEquals(local, ctx.get(ContextConstants.LOCAL_AMOUNT.toString()));
    assertEquals(settlement, ctx.get(ContextConstants.AMOUNT.toString()));
}
Also used : Context(org.jpos.transaction.Context) ISOMsg(org.jpos.iso.ISOMsg) ISOAmount(org.jpos.iso.ISOAmount) BigDecimal(java.math.BigDecimal) Result(org.jpos.rc.Result) Test(org.junit.Test)

Example 23 with Context

use of org.jpos.transaction.Context in project jPOS by jpos.

the class CheckFieldsTest method testInvalidMidAndTid.

@Test
public void testInvalidMidAndTid() {
    Context ctx = new Context();
    ISOMsg m = new ISOMsg();
    m.set(41, "*1");
    m.set(42, "*2");
    ctx.put(ContextConstants.REQUEST.toString(), m);
    cfg.put("mandatory", "MID, TID");
    int action = cf.prepare(1L, ctx);
    assertEquals(ABORTED | NO_JOIN | READONLY, action);
    Result rc = ctx.getResult();
    assertEquals(CMF.INVALID_FIELD, rc.failure().getIrc());
    assertFalse(rc.hasInfo());
    assertFalse(rc.hasWarnings());
    assertTrue(rc.hasFailures());
    assertEquals(2, rc.failureList().size());
}
Also used : Context(org.jpos.transaction.Context) ISOMsg(org.jpos.iso.ISOMsg) Result(org.jpos.rc.Result) Test(org.junit.Test)

Example 24 with Context

use of org.jpos.transaction.Context in project jPOS by jpos.

the class CheckFieldsTest method testOriginalDataElements.

@Test
public void testOriginalDataElements() throws ISOException {
    Context ctx = new Context();
    ISOMsg m = new ISOMsg();
    Date now = new Date();
    m.set(56, "0200000000000001" + ISODate.formatDate(now, "yyyyMMddHHmmss"));
    ctx.put(ContextConstants.REQUEST.toString(), m);
    cfg.put("mandatory", "ORIGINAL_DATA_ELEMENTS");
    int action = cf.prepare(1L, ctx);
    assertEquals(PREPARED | NO_JOIN | READONLY, action);
    Result rc = ctx.getResult();
    assertFalse(rc.hasInfo());
    assertFalse(rc.hasWarnings());
    assertFalse(rc.hasFailures());
    assertEquals("0200", ctx.get(ContextConstants.ORIGINAL_MTI.toString()));
    assertEquals("000000000001", ctx.get(ContextConstants.ORIGINAL_STAN.toString()));
    assertEquals(now.getTime() / 1000, ((Date) ctx.get(ContextConstants.ORIGINAL_TIMESTAMP.toString())).getTime() / 1000);
}
Also used : Context(org.jpos.transaction.Context) ISOMsg(org.jpos.iso.ISOMsg) Date(java.util.Date) ISODate(org.jpos.iso.ISODate) Result(org.jpos.rc.Result) Test(org.junit.Test)

Example 25 with Context

use of org.jpos.transaction.Context in project jPOS by jpos.

the class CheckFieldsTest method testValidCard.

@Test
public void testValidCard() {
    Context ctx = new Context();
    ISOMsg m = new ISOMsg();
    m.set(2, "4111111111111111");
    m.set(14, "2912");
    m.set(35, "4111111111111111=2912");
    m.set(45, "B4111111111111111^TEST CARDHOLDER^29120000000000000000");
    ctx.put(ContextConstants.REQUEST.toString(), m);
    cfg.put("mandatory", "CARD");
    int action = cf.prepare(1L, ctx);
    assertEquals(PREPARED | NO_JOIN | READONLY, action);
}
Also used : Context(org.jpos.transaction.Context) ISOMsg(org.jpos.iso.ISOMsg) Test(org.junit.Test)

Aggregations

Context (org.jpos.transaction.Context)45 Test (org.junit.Test)29 Result (org.jpos.rc.Result)26 ISOMsg (org.jpos.iso.ISOMsg)20 Date (java.util.Date)5 ISODate (org.jpos.iso.ISODate)3 SpaceSource (org.jpos.space.SpaceSource)2 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Element (org.jdom2.Element)1 Configurable (org.jpos.core.Configurable)1 Configuration (org.jpos.core.Configuration)1 ConfigurationException (org.jpos.core.ConfigurationException)1 ISOAmount (org.jpos.iso.ISOAmount)1 ISOSource (org.jpos.iso.ISOSource)1 LocalSpace (org.jpos.space.LocalSpace)1 Space (org.jpos.space.Space)1 SpaceFactory (org.jpos.space.SpaceFactory)1