EnvironmentHandler implements IEnvironmentHandler { public void handle(final IObject environment, final IReceiverChain receiverChain, final IAction<Throwable> callback) throws EnvironmentHandleException { try { IMessageProcessingSequence processingSequence = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.message_processing_interfaces.message_processing.IMessageProcessingSequence"), stackDepth, receiverChain); IMessageProcessor messageProcessor = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.message_processing_interfaces.message_processing.IMessageProcessor"), taskQueue, processingSequence); IObject message = (IObject) environment.getValue(this.messageFieldName); IObject context = (IObject) environment.getValue(this.contextFieldName); context.setValue(this.fromExternalFieldName, true); messageProcessor.process(message, context); } catch (ResolutionException | InvalidArgumentException | ReadValueException | ChangeValueException | MessageProcessorProcessException e) { throw new EnvironmentHandleException(e); } } EnvironmentHandler(final IQueue<ITask> taskQueue, final int stackDepth); void handle(final IObject environment, final IReceiverChain receiverChain, final IAction<Throwable> callback);  }
@Test public void whenEnvironmentHandlerReceiveEnvironment_ItShouldProcessMessageProcessor() throws Exception { messageProcessor = mock(IMessageProcessor.class); IKey keyIMessageProcessor = Keys.getOrAdd("info.smart_tools.smartactors.message_processing_interfaces.message_processing.IMessageProcessor"); IOC.register( keyIMessageProcessor, new SingletonStrategy(messageProcessor) ); IObject iObject = IOC.resolve(Keys.getOrAdd("IObjectByString"), "{}"); IKey keyIObject = Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"); IOC.register( keyIObject, new SingletonStrategy(iObject) ); IObject environment = IOC.resolve(Keys.getOrAdd("IObjectByString"), "{\"message\": {\"hello\": \"world\"}, \"context\": {}}"); Map<Class<? extends Throwable>, IObject> exceptionalChainsAndEnv = new HashMap<>(); IMessageReceiver messageReceivers[] = new IMessageReceiver[1]; IObject iObjects[] = new IObject[1]; messageReceivers[0] = null; iObjects[0] = null; IReceiverChain chain = new ImmutableReceiverChain("name", mock(IObject.class), messageReceivers, iObjects, exceptionalChainsAndEnv); IQueue<ITask> queue = new BlockingQueue(null); IEnvironmentHandler handler = new EnvironmentHandler(queue, 1); handler.handle(environment, chain, null); try { verify(messageProcessor, times(1)).process( (IObject) environment.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "message")), (IObject) environment.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "context"))); } catch (ReadValueException e) { e.printStackTrace(); } Assert.assertTrue(((boolean) ((IObject)environment.getValue(new FieldName("context"))).getValue(new FieldName("fromExternal")))); }