Search in sources :

Example 36 with Context

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

the class SelectDestinationTest method testNetwork_M.

@Test
public void testNetwork_M() {
    cfg.put("ignore-luhn", "false");
    p.setConfiguration(cfg);
    Context ctx = new Context();
    ctx.put(ContextConstants.REQUEST.toString(), createISOMsg("5111111111111118"));
    int action = p.prepare(1L, ctx);
    assertEquals("Action should be PREPARED|NO_JOIN|READONLY", PREPARED | NO_JOIN | READONLY, action);
    Result rc = ctx.getResult();
    assertFalse("No failures", rc.hasFailures());
    assertEquals("Invalid Destination", "M", ctx.getString(DESTINATION.toString()));
}
Also used : Context(org.jpos.transaction.Context) Result(org.jpos.rc.Result) Test(org.junit.Test)

Example 37 with Context

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

the class SelectDestinationTest method testInvalidLUHN.

@Test
public void testInvalidLUHN() {
    cfg.put("ignore-luhn", "false");
    p.setConfiguration(cfg);
    Context ctx = new Context();
    ctx.put(ContextConstants.REQUEST.toString(), createISOMsg("5111111111111111"));
    int action = p.prepare(1L, ctx);
    assertEquals("Action should be ABORTED|NO_JOIN|READONLY", ABORTED | NO_JOIN | READONLY, action);
    Result rc = ctx.getResult();
    assertTrue("Has failures", rc.hasFailures());
    assertTrue("Should raise invalid card error", rc.failure().getIrc() == CMF.INVALID_CARD_OR_CARDHOLDER_NUMBER);
}
Also used : Context(org.jpos.transaction.Context) Result(org.jpos.rc.Result) Test(org.junit.Test)

Example 38 with Context

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

the class SelectDestinationTest method testNetwork_Default.

@Test
public void testNetwork_Default() {
    cfg.put("ignore-luhn", "true");
    p.setConfiguration(cfg);
    Context ctx = new Context();
    ctx.put(ContextConstants.REQUEST.toString(), createISOMsg("0000000000000001"));
    int action = p.prepare(1L, ctx);
    assertEquals("Action should be PREPARED|NO_JOIN|READONLY", PREPARED | NO_JOIN | READONLY, action);
    Result rc = ctx.getResult();
    assertFalse("No failures", rc.hasFailures());
    assertEquals("Invalid Destination", "DEFAULT", ctx.getString(DESTINATION.toString()));
}
Also used : Context(org.jpos.transaction.Context) Result(org.jpos.rc.Result) Test(org.junit.Test)

Example 39 with Context

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

the class CheckFields method prepare.

public int prepare(long id, Serializable context) {
    Context ctx = (Context) context;
    Result rc = ctx.getResult();
    try {
        ISOMsg m = (ISOMsg) ctx.get(request);
        if (m == null) {
            ctx.getResult().fail(CMF.INVALID_TRANSACTION, Caller.info(), "'%s' not available in Context", request);
            return ABORTED | NO_JOIN | READONLY;
        }
        Set<String> validFields = new HashSet<>();
        assertFields(ctx, m, cfg.get("mandatory", ""), true, validFields, rc);
        assertFields(ctx, m, cfg.get("optional", ""), false, validFields, rc);
        assertNoExtraFields(m, validFields, rc);
    } catch (Throwable t) {
        rc.fail(CMF.SYSTEM_ERROR, Caller.info(), t.getMessage());
        ctx.log(t);
    }
    return (rc.hasFailures() ? ABORTED : PREPARED) | NO_JOIN | READONLY;
}
Also used : Context(org.jpos.transaction.Context) Result(org.jpos.rc.Result) HashSet(java.util.HashSet)

Example 40 with Context

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

the class QueryHost method responseReceived.

public void responseReceived(ISOMsg resp, Object handBack) {
    Context ctx = (Context) handBack;
    ctx.put(responseName, resp);
    ctx.resume();
}
Also used : Context(org.jpos.transaction.Context)

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