public void testSingleValueExternalDependency() {
final ExternalId secIdentifier1 = ExternalId.of("SEC", "1");
final ExternalId secIdentifier2 = ExternalId.of("SEC", "2");
final SimplePosition pos = new SimplePosition(new BigDecimal(1), secIdentifier1);
final SimplePortfolioNode pn = new SimplePortfolioNode("node");
pn.addPosition(pos);
final SimplePortfolio p = new SimplePortfolio(UniqueId.of("FOO", "BAR"), "portfolio");
p.setRootNode(pn);
final MockPositionSource positionSource = new MockPositionSource();
positionSource.addPortfolio(p);
final SimpleSecurity sec1 = new SimpleSecurity("My Sec");
sec1.addExternalId(secIdentifier1);
final SimpleSecurity sec2 = new SimpleSecurity("Your Sec");
sec2.addExternalId(secIdentifier2);
final InMemorySecuritySource securitySource = new InMemorySecuritySource();
securitySource.addSecurity(sec1);
securitySource.addSecurity(sec2);
final MockFunction fn2 = MockFunction.getMockFunction("fn2", new ComputationTarget(ComputationTargetType.SECURITY, sec2), 14.2);
final MockFunction fn1 = MockFunction.getMockFunction("fn1", new ComputationTarget(ComputationTargetType.PORTFOLIO_NODE, pn), 14.2, fn2);
final InMemoryFunctionRepository functionRepo = new InMemoryFunctionRepository();
functionRepo.addFunction(fn1);
functionRepo.addFunction(fn2);
final FunctionCompilationContext functionCompilationContext = new FunctionCompilationContext();
functionCompilationContext.setFunctionInitId(123);
final CompiledFunctionService cfs = new CompiledFunctionService(functionRepo, new CachingFunctionRepositoryCompiler(), functionCompilationContext);
cfs.initialize();
final DefaultFunctionResolver functionResolver = new DefaultFunctionResolver(cfs);
final DefaultCachingComputationTargetResolver computationTargetResolver = new DefaultCachingComputationTargetResolver(new DefaultComputationTargetResolver(securitySource, positionSource),
_cacheManager);
functionCompilationContext.setRawComputationTargetResolver(computationTargetResolver);
final ViewCompilationServices vcs = new ViewCompilationServices(new FixedMarketDataAvailabilityProvider(), functionResolver, functionCompilationContext, new PoolExecutor(1, getClass()
.getSimpleName()),
new DependencyGraphBuilderFactory());
final ViewDefinition viewDefinition = new ViewDefinition("My View", UniqueId.of("FOO", "BAR"), "kirk");
viewDefinition.getResultModelDefinition().setPositionOutputMode(ResultOutputMode.NONE);
final ViewCalculationConfiguration calcConfig = new ViewCalculationConfiguration(viewDefinition, "Fibble");
calcConfig.addPortfolioRequirementName("My Sec", "OUTPUT");
viewDefinition.addViewCalculationConfiguration(calcConfig);
final CompiledViewDefinitionWithGraphsImpl compiledViewDefinition = ViewDefinitionCompiler.compile(viewDefinition, vcs, Instant.now(), VersionCorrection.LATEST);
assertTrue(compiledViewDefinition.getMarketDataRequirements().isEmpty());
assertEquals(1, compiledViewDefinition.getDependencyGraphExplorers().size());
final DependencyGraph dg = compiledViewDefinition.getDependencyGraphExplorer("Fibble").getWholeGraph();
assertNotNull(dg);
assertTrue(dg.getAllRequiredMarketData().isEmpty());
assertEquals(2, dg.getDependencyNodes().size());
// Expect the node and the security, since we've turned off position-level outputs and not actually provided a
// function that can produce them
assertTargets(compiledViewDefinition, sec2.getUniqueId(), pn.getUniqueId());
}