@Override public Module createModule(final ModuleInfo info) { final Module existing = getRegisteredModuleInstance(info); if (existing != null) return existing; try { final Module module = info.createModule(); getContext().inject(module); Priority.inject(module, info.getPriority()); return module; } catch (final ModuleException exc) { log.error("Cannot create module: " + info.getDelegateClassName(), exc); } return null; }
@Override public Module createModule(final ModuleInfo info) { final Module existing = getRegisteredModuleInstance(info); if (existing != null) return existing; try { final Module module = info.createModule(); getContext().inject(module); Priority.inject(module, info.getPriority()); return module; } catch (final ModuleException exc) { log.error("Cannot create module: " + info.getDelegateClassName(), exc); } return null; }
/** Tests {@link ModuleService#run(Module, boolean, Map)}. */ @Test public void testRunModuleMap() throws ModuleException, InterruptedException, ExecutionException { final ModuleInfo info = new FooModuleInfo(); final Module module = info.createModule(); final Module m = moduleService.run(module, false, createInputMap()).get(); assertSame(module, m); assertEquals(expectedResult(), m.getOutput("result")); }
/** Tests {@link ModuleService#run(Module, boolean, Object...)}. */ @Test public void testRunModuleArray() throws ModuleException, InterruptedException, ExecutionException { final ModuleInfo info = new FooModuleInfo(); final Module module = info.createModule(); final Module m = moduleService.run(module, false, createInputArray()).get(); assertSame(module, m); assertEquals(expectedResult(), m.getOutput("result")); }
/** * Tests that {@link ModuleService#run(ModuleInfo, boolean, Object...)} and * {@link ModuleService#run(Module, boolean, Object...)} intelligently handle * a single-element {@link Object} array consisting of a {@code Map<String, * Object>}. * <p> * This situation can happen e.g. due to Jython choosing the wrong overloaded * {@code run} method. We correct for the issue on our side, for convenience. * </p> */ @Test public void testRunMapHack() throws ModuleException, InterruptedException, ExecutionException { final ModuleInfo info = new FooModuleInfo(); final Object[] inputs = new Object[] { createInputMap() }; final Module m = moduleService.run(info, false, inputs).get(); assertEquals(expectedResult(), m.getOutput("result")); final Module module = info.createModule(); final Module m2 = moduleService.run(module, false, inputs).get(); assertEquals(expectedResult(), m2.getOutput("result")); }
@Test public void testGetSingleInput() throws ModuleException { final ModuleInfo info = new FooModuleInfo(); final Module module = info.createModule(); // verify single string input is detected final ModuleItem<String> singleString = moduleService.getSingleInput(module, String.class); assertSame(info.getInput("string"), singleString); // check that non-autofilled inputs are not detected final ModuleItem<Float> singleFloat = moduleService.getSingleInput(module, Float.class); assertNull(singleFloat); // verify that multiple inputs of the same type are not detected final ModuleItem<Integer> singleInteger = moduleService.getSingleInput(module, Integer.class); assertNull(singleInteger); // verify that single input is detected if there are // non-autofilled inputs of the same kind too final ModuleItem<Double> singleDouble = moduleService.getSingleInput(module, Double.class); assertSame(info.getInput("double2"), singleDouble); }