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"));
}
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"));
}
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));
}
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);
}
Aggregations