ExecuteDMNCommand implements ExecutableCommand<DMNResult> { @Override public DMNResult execute(Context context) { RegistryContext registryContext = (RegistryContext) context; DMNModel activeModel = registryContext.lookup(DMNModel.class); DMNRuntime dmnRuntime = registryContext.lookup(DMNRuntime.class); DMNContext dmnContext = registryContext.lookup(DMNContext.class); if (activeModel == null) { throw new IllegalStateException("No DMN active model defined"); } if (dmnRuntime == null) { throw new IllegalStateException("No DMNRuntime available"); } if (dmnContext == null) { dmnContext = dmnRuntime.newContext(); } DMNResult dmnResult = dmnRuntime.evaluateAll(activeModel, dmnContext); registryContext.register(DMNResult.class, dmnResult); registryContext.register(DMNContext.class, dmnRuntime.newContext()); return dmnResult; }  @Override DMNResult execute(Context context);  }
@Test public void execute() { RegistryContext registryContext = new ContextImpl(); ExecuteDMNCommand executeDMNCommand = new ExecuteDMNCommand(); assertThatThrownBy(() -> executeDMNCommand.execute(registryContext)) .isInstanceOf(IllegalStateException.class) .hasMessage("No DMN active model defined"); registryContext.register(DMNModel.class, new DMNModelImpl(null)); assertThatThrownBy(() -> executeDMNCommand.execute(registryContext)) .isInstanceOf(IllegalStateException.class) .hasMessage("No DMNRuntime available"); DMNContext dmnContext = DMNFactory.newContext(); dmnContext.set("example", 10); registryContext.register(DMNRuntime.class, new DMNRuntimeImpl(new VoidDMNRuntimeKB())); registryContext.register(DMNContext.class, dmnContext); DMNResult result = executeDMNCommand.execute(registryContext); assertNotNull(result); DMNContext newDmnContext = registryContext.lookup(DMNContext.class); assertEquals(1, dmnContext.getAll().size()); assertEquals(0, newDmnContext.getAll().size()); }