SimulationScript extends Script { public void parameters(Closure<?> body) { ParametersDelegate parametersDelegate = new ParametersDelegate(); body.setDelegate(parametersDelegate); body.setResolveStrategy(Closure.DELEGATE_FIRST); body.call(); Binding binding = getBinding(); Map<String, Class<?>> parameters = parametersDelegate.getParameters(); for (Map.Entry<String, Class<?>> entry : parameters.entrySet()) { String varName = entry.getKey(); Class<?> varType = entry.getValue(); if (!binding.hasVariable(varName)) { throw new DataNotFoundException("Parameter named " + varName + " not found"); } Object varValue = binding.getVariable(varName); if (!varType.isInstance(varValue)) { throw new IllegalArgumentException("Parameter " + varName + " has type " + varValue.getClass().getName() + ", " + "required type is " + varType.getName()); } } } SimulationScript();  SimulationScript(Binding binding); void parameters(Closure<?> body); Simulation simulation(String name, Closure<?> body); Scenario scenario(String name, Closure<?> body); void curve(Closure<?> body); void curveData(Closure<?> body); void marketData(Closure<?> body); void surface(Closure<?> body); void spotRate(Closure<?> body);  }
@Test public void parameters() { Map<String, Object> params = ImmutableMap.<String, Object>of("foo", "FOO", "bar", 123d); Scenario scenario = SimulationUtils.createScenarioFromDsl("src/test/groovy/ParametersTest.groovy", params); assertNotNull(scenario); ScenarioDefinition scenarioDefinition = scenario.createDefinition(); Map<DistinctMarketDataSelector, FunctionParameters> definitionMap = scenarioDefinition.getDefinitionMap(); PointSelector selector = new PointSelector(null, Sets.newHashSet(ExternalId.of("SCHEME", "FOO")), null, null, null, null, null); assertTrue(definitionMap.containsKey(selector)); SimpleFunctionParameters functionParameters = (SimpleFunctionParameters) definitionMap.get(selector); CompositeStructureManipulator<?> composite = functionParameters.getValue(StructureManipulationFunction.EXPECTED_PARAMETER_NAME); StructureManipulator<?> manipulator = composite.getManipulators().get(0); assertEquals(new MarketDataScaling(123), manipulator); }