for (ValueRequirement requirement : inRequirements) {
assertEquals(requirement.getValueName(), MarketDataRequirementNames.MARKET_VALUE);
assertEquals(requirement.getTargetReference(), inRequirementTarget);
assertTrue(requirement.getConstraints().isSatisfiedBy(ValueProperties.none()));
}
Set<ComputedValue> outputs = _function.execute(_functionExecutionContext, new FunctionInputsImpl(resolver.atVersionCorrection(VersionCorrection.LATEST), new ComputedValue(new ValueSpecification(
MarketDataRequirementNames.MARKET_VALUE, ComputationTargetSpecification.of(UniqueId.of("ExternalId-LiveData", "USD_GBP")), properties), _rateUSD_GBP)), _matrixTarget,
Collections.singleton(outRequirement));
assertEquals(1, outputs.size());
ComputedValue output = outputs.iterator().next();
assertTrue(output.getValue() instanceof Double);
assertEquals(_rateUSD_GBP, (Double) output.getValue(), Double.MIN_NORMAL);
// Require value the "wrong" way up
// [PLAT-2290] Execute should be taking a ValueSpecification, getRequirements should be taking a ValueRequirement
outRequirement = new ValueRequirement(ValueRequirementNames.SPOT_RATE, _matrixTarget.toSpecification(), ValueProperties
.with(AbstractCurrencyMatrixSourcingFunction.SOURCE_CURRENCY_PROPERTY, "GBP").with(AbstractCurrencyMatrixSourcingFunction.TARGET_CURRENCY_PROPERTY, "USD")
.with(ValuePropertyNames.FUNCTION, "CMSF").get());
inRequirements = _function.getRequirements(_functionCompilationContext, _matrixTarget, outRequirement);
assertEquals(1, inRequirements.size());
for (ValueRequirement requirement : inRequirements) {
assertEquals(requirement.getValueName(), MarketDataRequirementNames.MARKET_VALUE);
assertEquals(requirement.getTargetReference(), inRequirementTarget);
assertTrue(requirement.getConstraints().isSatisfiedBy(ValueProperties.none()));
}
outputs = _function.execute(_functionExecutionContext,
new FunctionInputsImpl(resolver.atVersionCorrection(VersionCorrection.LATEST), new ComputedValue(new ValueSpecification(MarketDataRequirementNames.MARKET_VALUE,
ComputationTargetSpecification.of(UniqueId.of("ExternalId-LiveData", "USD_GBP")), properties), _rateUSD_GBP)), _matrixTarget, Collections.singleton(outRequirement));
assertEquals(1, outputs.size());
output = outputs.iterator().next();
assertTrue(output.getValue() instanceof Double);
assertEquals(1.0 / _rateUSD_GBP, (Double) output.getValue(), Double.MIN_NORMAL);
// Require no additional live data
// [PLAT-2290] Execute should be taking a ValueSpecification, getRequirements should be taking a ValueRequirement
outRequirement = new ValueRequirement(ValueRequirementNames.SPOT_RATE, _matrixTarget.toSpecification(), ValueProperties
.with(AbstractCurrencyMatrixSourcingFunction.SOURCE_CURRENCY_PROPERTY, "GBP").with(AbstractCurrencyMatrixSourcingFunction.TARGET_CURRENCY_PROPERTY, "EUR")
.with(ValuePropertyNames.FUNCTION, "CMSF").get());
inRequirements = _function.getRequirements(_functionCompilationContext, _matrixTarget, outRequirement);
assertEquals(0, inRequirements.size());
outputs = _function.execute(_functionExecutionContext, new EmptyFunctionInputs(), _matrixTarget, Collections.singleton(outRequirement));
assertEquals(1, outputs.size());
output = outputs.iterator().next();
assertTrue(output.getValue() instanceof Double);
assertEquals(1.0 / _rateEUR_GBP, (Double) output.getValue(), Double.MIN_NORMAL);
// Require intermediate value
// [PLAT-2290] Execute should be taking a ValueSpecification, getRequirements should be taking a ValueRequirement
outRequirement = new ValueRequirement(ValueRequirementNames.SPOT_RATE, _matrixTarget.toSpecification(), ValueProperties
.with(AbstractCurrencyMatrixSourcingFunction.SOURCE_CURRENCY_PROPERTY, "EUR").with(AbstractCurrencyMatrixSourcingFunction.TARGET_CURRENCY_PROPERTY, "USD")
.with(ValuePropertyNames.FUNCTION, "CMSF").get());
inRequirements = _function.getRequirements(_functionCompilationContext, _matrixTarget, outRequirement);
assertEquals(1, inRequirements.size());
for (ValueRequirement requirement : inRequirements) {
assertEquals(requirement.getValueName(), MarketDataRequirementNames.MARKET_VALUE);
assertEquals(requirement.getTargetReference(), inRequirementTarget);
assertTrue(requirement.getConstraints().isSatisfiedBy(ValueProperties.none()));
}
outputs = _function.execute(_functionExecutionContext,
new FunctionInputsImpl(resolver.atVersionCorrection(VersionCorrection.LATEST), new ComputedValue(new ValueSpecification(MarketDataRequirementNames.MARKET_VALUE,
ComputationTargetSpecification.of(UniqueId.of("ExternalId-LiveData", "USD_GBP")), properties), _rateUSD_GBP)), _matrixTarget, Collections.singleton(outRequirement));
assertEquals(1, outputs.size());
output = outputs.iterator().next();
assertTrue(output.getValue() instanceof Double);
assertEquals(_rateEUR_GBP / _rateUSD_GBP, (Double) output.getValue(), Double.MIN_NORMAL);