Search in sources :

Example 11 with Catalog

use of org.apache.commons.chain.Catalog in project kernel by exoplatform.

the class CommandServiceTest method testInitWithFile.

public void testInitWithFile() throws Exception {
    CommandService cservice = (CommandService) container.getComponentInstanceOfType(CommandService.class);
    cservice.putCatalog(getClass().getResourceAsStream("/conf/test-commands3.xml"));
    assertTrue(cservice.getCatalogNames().hasNext());
    Catalog c1 = cservice.getCatalog("catalog1");
    assertNotNull(c1.getCommand("Command2"));
}
Also used : CommandService(org.exoplatform.services.command.impl.CommandService) Catalog(org.apache.commons.chain.Catalog)

Example 12 with Catalog

use of org.apache.commons.chain.Catalog in project kernel by exoplatform.

the class CommandServiceTest method testStringConf.

public void testStringConf() throws Exception {
    CommandService cservice = (CommandService) container.getComponentInstanceOfType(CommandService.class);
    Catalog c = cservice.getCatalog();
    assertNull(c.getCommand("StrCommand"));
    cservice.putCatalog(new ByteArrayInputStream(IS.getBytes()));
    Catalog c1 = cservice.getCatalog();
    assertNotNull(c1.getCommand("StrCommand"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CommandService(org.exoplatform.services.command.impl.CommandService) Catalog(org.apache.commons.chain.Catalog)

Example 13 with Catalog

use of org.apache.commons.chain.Catalog in project tutorials by eugenp.

the class AtmChainTest method givenInputsToContext_whenAppliedChain_thenExpectedContext.

@Test
public void givenInputsToContext_whenAppliedChain_thenExpectedContext() {
    Context context = new AtmRequestContext();
    context.put(TOTAL_AMOUNT_TO_BE_WITHDRAWN, 460);
    context.put(AMOUNT_LEFT_TO_BE_WITHDRAWN, 460);
    Catalog catalog = new AtmCatalog();
    Command atmWithdrawalChain = catalog.getCommand(ATM_WITHDRAWAL_CHAIN);
    try {
        atmWithdrawalChain.execute(context);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Assert.assertEquals(EXPECTED_TOTAL_AMOUNT_TO_BE_WITHDRAWN, (int) context.get(TOTAL_AMOUNT_TO_BE_WITHDRAWN));
    Assert.assertEquals(EXPECTED_AMOUNT_LEFT_TO_BE_WITHDRAWN, (int) context.get(AMOUNT_LEFT_TO_BE_WITHDRAWN));
    Assert.assertEquals(EXPECTED_NO_OF_HUNDREDS_DISPENSED, (int) context.get(NO_OF_HUNDREDS_DISPENSED));
    Assert.assertEquals(EXPECTED_NO_OF_FIFTIES_DISPENSED, (int) context.get(NO_OF_FIFTIES_DISPENSED));
    Assert.assertEquals(EXPECTED_NO_OF_TENS_DISPENSED, (int) context.get(NO_OF_TENS_DISPENSED));
}
Also used : Context(org.apache.commons.chain.Context) Command(org.apache.commons.chain.Command) Catalog(org.apache.commons.chain.Catalog) Test(org.junit.Test)

Example 14 with Catalog

use of org.apache.commons.chain.Catalog in project Java-Tutorial by gpcodervn.

the class ChainStart4 method main.

public static void main(String[] args) throws Exception {
    // Create context
    MyContext ctx = new MyContext();
    ctx.setProperty("property-value");
    ctx.put("custom-key", "custom-value");
    // Get the catalog
    Catalog catalog = new MyXMLCatalog().getCatalog();
    // Get the command
    System.out.println("Execute the specific command: CMD_1");
    Command command1 = catalog.getCommand(MyCommandNamed.CMD_1.name());
    command1.execute(ctx);
    System.out.println("\nExecute the specific chain: CHAIN_1");
    Command chain1 = catalog.getCommand(MyCommandNamed.CHAIN_1.name());
    chain1.execute(ctx);
}
Also used : MyContext(com.gpcoder.context.MyContext) Command(org.apache.commons.chain.Command) Catalog(org.apache.commons.chain.Catalog)

Aggregations

Catalog (org.apache.commons.chain.Catalog)14 Command (org.apache.commons.chain.Command)6 CommandService (org.exoplatform.services.command.impl.CommandService)3 MyContext (com.gpcoder.context.MyContext)2 CatalogFactory (org.apache.commons.chain.CatalogFactory)2 Context (org.apache.commons.chain.Context)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ConfigParser (org.apache.commons.chain.config.ConfigParser)1 ContextBase (org.apache.commons.chain.impl.ContextBase)1 Test (org.junit.Test)1