BlockingMessageSchedulerAction implements ISchedulerAction { @Override public void init(final ISchedulerEntry entry, final IObject args) throws SchedulerActionInitializationException { try { Object message = args.getValue(messageFN); Object chainId = args.getValue(chainFN); if (message == null || !(message instanceof IObject)) { throw new SchedulerActionInitializationException("\"message\" field of arguments should contain a message object", null); } if (null == chainId) { throw new SchedulerActionInitializationException("\"chain\" field of arguments should contain name of the chain", null); } String entryIdFieldFN = (String) args.getValue(setEntryIdFN); if (entryIdFieldFN != null && !entryIdFieldFN.isEmpty()) { ((IObject) message).setValue(IOC.resolve(Keys.getOrAdd(IFieldName.class.getCanonicalName()), entryIdFieldFN), entry.getId()); } entry.getState().setValue(messageFN, message); entry.getState().setValue(chainFN, chainId); Object preShutdownExecConfig = args.getValue(preShutdownExecFN); entry.getState().setValue(preShutdownExecFN, (preShutdownExecConfig == null || preShutdownExecConfig == Boolean.FALSE) ? Boolean.FALSE : Boolean.TRUE); Number stackDepth = (Number) args.getValue(stackDepthFN); if (null == stackDepth) { stackDepth = IOC.resolve(Keys.getOrAdd("default_stack_depth")); } entry.getState().setValue(stackDepthFN, stackDepth); } catch (ReadValueException | ChangeValueException | InvalidArgumentException | ResolutionException e) { throw new SchedulerActionInitializationException("Error occurred copying message from arguments to entry state.", e); } } BlockingMessageSchedulerAction(); @Override void init(final ISchedulerEntry entry, final IObject args); @Override void execute(final ISchedulerEntry entry);  }
@Test public void Should_initializeEntryState() throws Exception { IObject args = IOC.resolve(Keys.getOrAdd(IObject.class.getCanonicalName()), ("{" + "'message': {'a':'asd'}," + "'setEntryId': 'idFld'," + "'preShutdownExec': true," + "'chain': 'some_chain'," + "'stackDepth': 13" + "}").replace('\'','"')); action.init(schedulerEntryMock, args); assertEquals("asd", ((IObject)entryState.getValue(fn("message"))).getValue(fn("a"))); assertEquals(schedulerEntryMock.getId(), ((IObject)entryState.getValue(fn("message"))).getValue(fn("idFld"))); assertEquals(Boolean.TRUE, entryState.getValue(fn("preShutdownExec"))); assertEquals("some_chain", entryState.getValue(fn("chain"))); assertEquals(13, entryState.getValue(fn("stackDepth"))); }
@Test(expected = SchedulerActionInitializationException.class) public void Should_throwWhenNoMessageGiven() throws Exception { IObject args = IOC.resolve(Keys.getOrAdd(IObject.class.getCanonicalName()), ("{" + "'setEntryId': 'idFld'," + "'preShutdownExec': true," + "'chain': 'some_chain'," + "'stackDepth': 13" + "}").replace('\'','"')); action.init(schedulerEntryMock, args); }
@Test(expected = SchedulerActionInitializationException.class) public void Should_throwWhenNoChainGiven() throws Exception { IObject args = IOC.resolve(Keys.getOrAdd(IObject.class.getCanonicalName()), ("{" + "'message': {'a':'asd'}," + "'setEntryId': 'idFld'," + "'preShutdownExec': true," + "'stackDepth': 13" + "}").replace('\'','"')); action.init(schedulerEntryMock, args); }
@Test(expected = SchedulerActionInitializationException.class) public void Should_throwWhenErrorOccursResolvingDependency() throws Exception { IOC.remove(Keys.getOrAdd("default_stack_depth")); IObject args = IOC.resolve(Keys.getOrAdd(IObject.class.getCanonicalName()), ("{" + "'message': {'a':'asd'}," + "'setEntryId': 'idFld'," + "'preShutdownExec': true," + "'chain': 'some_chain'" + "}").replace('\'','"')); action.init(schedulerEntryMock, args); }
@Test public void Should_useDefaultWhenNoStackDepthGiven() throws Exception { IObject args = IOC.resolve(Keys.getOrAdd(IObject.class.getCanonicalName()), ("{" + "'message': {'a':'asd'}," + "'setEntryId': 'idFld'," + "'preShutdownExec': true," + "'chain': 'some_chain'" + "}").replace('\'','"')); action.init(schedulerEntryMock, args); assertEquals(321, entryState.getValue(fn("stackDepth"))); }