assertNotNull(compiledViewDefinition.getDependencyGraphExplorer("Config1"));
assertTargets(compiledViewDefinition, t1);
}
public void testPrimitivesAndSecuritiesNoPortfolioReference() {
final ViewDefinition viewDefinition = new ViewDefinition("Test", "jonathan");
final ViewCalculationConfiguration calcConfig = new ViewCalculationConfiguration(viewDefinition, "Config1");
viewDefinition.addViewCalculationConfiguration(calcConfig);
final ExternalId secIdentifier1 = ExternalId.of("SEC", "1");
final SimpleSecurity sec1 = new SimpleSecurity("My Sec");
sec1.addExternalId(secIdentifier1);
final InMemorySecuritySource securitySource = new InMemorySecuritySource();
securitySource.addSecurity(sec1);
final UniqueId t1 = UniqueId.of("TestScheme", "t1");
final InMemoryFunctionRepository functionRepo = new InMemoryFunctionRepository();
final MockFunction f1 = MockFunction.getMockFunction("f1", new ComputationTarget(ComputationTargetType.PRIMITIVE, t1), 42);
final MockFunction f2 = MockFunction.getMockFunction("f2", new ComputationTarget(ComputationTargetType.SECURITY, sec1), 60, f1);
functionRepo.addFunction(f1);
functionRepo.addFunction(f2);
final FunctionCompilationContext compilationContext = new FunctionCompilationContext();
compilationContext.setFunctionInitId(123);
final CompiledFunctionService cfs = new CompiledFunctionService(functionRepo, new CachingFunctionRepositoryCompiler(), compilationContext);
cfs.initialize();
final DefaultFunctionResolver functionResolver = new DefaultFunctionResolver(cfs);
final DefaultCachingComputationTargetResolver computationTargetResolver = new DefaultCachingComputationTargetResolver(new DefaultComputationTargetResolver(securitySource), _cacheManager);
compilationContext.setRawComputationTargetResolver(computationTargetResolver);
final ViewCompilationServices compilationServices = new ViewCompilationServices(new FixedMarketDataAvailabilityProvider(), functionResolver, compilationContext, new PoolExecutor(1, getClass()
.getSimpleName()),
new DependencyGraphBuilderFactory());
// We'll require r2 which can be satisfied by f2, which in turn requires the output of f1
// Additionally, the security should be resolved through the ComputationTargetResolver, which only has a security
// source.
calcConfig.addSpecificRequirement(f2.getResultSpec().toRequirementSpecification());
CompiledViewDefinitionWithGraphsImpl compiledViewDefinition = ViewDefinitionCompiler.compile(viewDefinition, compilationServices, Instant.now(), VersionCorrection.LATEST);
assertTrue(compiledViewDefinition.getMarketDataRequirements().isEmpty());
assertEquals(1, compiledViewDefinition.getDependencyGraphExplorers().size());
assertNotNull(compiledViewDefinition.getDependencyGraphExplorer("Config1"));
assertTargets(compiledViewDefinition, sec1.getUniqueId(), t1);
// Turning off primitive outputs should not affect the dep graph since the primitive is needed for the security
viewDefinition.getResultModelDefinition().setPrimitiveOutputMode(ResultOutputMode.NONE);
compiledViewDefinition = ViewDefinitionCompiler.compile(viewDefinition, compilationServices, Instant.now(), VersionCorrection.LATEST);
assertTargets(compiledViewDefinition, sec1.getUniqueId(), t1);
// Turning off security outputs, even if all primitive outputs are enabled, should allow the dep graph to be
// pruned completely, since the only *terminal* output is the security output.
viewDefinition.getResultModelDefinition().setPrimitiveOutputMode(ResultOutputMode.TERMINAL_OUTPUTS);
viewDefinition.getResultModelDefinition().setSecurityOutputMode(ResultOutputMode.NONE);
compiledViewDefinition = ViewDefinitionCompiler.compile(viewDefinition, compilationServices, Instant.now(), VersionCorrection.LATEST);
assertTargets(compiledViewDefinition);
}