CheckpointFailureActionSectionStrategy implements ISectionStrategy { @Override public void onLoadConfig(final IObject config) throws ConfigurationProcessingException { try { IObject section = (IObject) config.getValue(sectionName); Object actionKeyName = section.getValue(actionNameFieldName); if (null == actionKeyName) { actionKeyName = "default configurable checkpoint failure action"; } IAction<IObject> action = IOC.resolve(IOC.resolve(IOC.getKeyForKeyStorage(), actionKeyName), section); IOC.register(Keys.getOrAdd("checkpoint failure action"), new SingletonStrategy(action)); } catch (ReadValueException | InvalidArgumentException | ResolutionException | RegistrationException e) { throw new ConfigurationProcessingException("Error occurred processing checkpoint_failure_action section.", e); } } CheckpointFailureActionSectionStrategy(); @Override void onLoadConfig(final IObject config); @Override IFieldName getSectionName();  }
@Test public void Should_resolveAndRegisterCustomAction() throws Exception { IObject config = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), "{'checkpoint_failure_action':{'action':'that checkpoint failure action'}}".replace('\'','"')); when(actionStrategyMock.resolve( same(config.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "checkpoint_failure_action"))) )).thenReturn(actionMock); new CheckpointFailureActionSectionStrategy().onLoadConfig(config); assertSame(actionMock, IOC.resolve(Keys.getOrAdd("checkpoint failure action"))); }
@Test public void Should_resolveAndRegisterDefaultActionIfActionDependencyNameWasNotGiven() throws Exception { IObject config = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), "{'checkpoint_failure_action':{}}".replace('\'','"')); when(defaultActionStrategyMock.resolve( same(config.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "checkpoint_failure_action"))) )).thenReturn(actionMock); new CheckpointFailureActionSectionStrategy().onLoadConfig(config); assertSame(actionMock, IOC.resolve(Keys.getOrAdd("checkpoint failure action"))); }