Package com.opengamma.engine.target

Examples of com.opengamma.engine.target.MockComputationTargetResolver


    EHCacheUtils.clear(_cacheManager);
  }

  //-------------------------------------------------------------------------
  public void testBasicMethods() {
    final MockComputationTargetResolver resolver = MockComputationTargetResolver.resolved();
    final Portfolio underlying = resolver.getPositionSource().getPortfolio(UniqueId.of("Portfolio", "0"), VersionCorrection.LATEST);
    final Portfolio portfolio = new LazyResolvedPortfolio(new LazyResolveContext(resolver.getSecuritySource(), null).atVersionCorrection(VersionCorrection.LATEST), underlying);
    assertEquals(portfolio.getAttributes(), underlying.getAttributes());
    portfolio.setAttributes(ImmutableMap.of("K1", "V1", "K2", "V2"));
    assertEquals(portfolio.getAttributes(), underlying.getAttributes());
    portfolio.addAttribute("K3", "V3");
    assertEquals(portfolio.getAttributes().size(), 3);
View Full Code Here


    assertEquals(portfolio.getUniqueId(), underlying.getUniqueId());
    assertEquals(portfolio.getRootNode().getUniqueId(), underlying.getRootNode().getUniqueId());
  }

  public void testSerialization_full() throws Exception {
    final MockComputationTargetResolver resolver = MockComputationTargetResolver.resolved();
    final Portfolio underlying = resolver.getPositionSource().getPortfolio(UniqueId.of("Portfolio", "0"), VersionCorrection.LATEST);
    Portfolio portfolio = new LazyResolvedPortfolio(new LazyResolveContext(resolver.getSecuritySource(), null).atVersionCorrection(VersionCorrection.LATEST), underlying);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ObjectOutputStream(baos).writeObject(portfolio);
    final Object resultObject = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
    assertTrue(resultObject instanceof SimplePortfolio);
    portfolio = (Portfolio) resultObject;
View Full Code Here

    assertEquals(portfolio.getRootNode().getUniqueId(), underlying.getRootNode().getUniqueId());
    assertEquals(portfolio.getRootNode().getChildNodes().size(), underlying.getRootNode().getChildNodes().size());
  }

  public void testSerialization_targetResolver() throws Exception {
    final MockComputationTargetResolver resolver = MockComputationTargetResolver.resolved();
    final Portfolio underlying = resolver.getPositionSource().getPortfolio(UniqueId.of("Portfolio", "0"), VersionCorrection.LATEST);
    Portfolio portfolio = new LazyResolvedPortfolio(
        new LazyResolveContext(resolver.getSecuritySource(), new DefaultCachingComputationTargetResolver(resolver, _cacheManager)).atVersionCorrection(VersionCorrection.LATEST),
        underlying);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ObjectOutputStream(baos).writeObject(portfolio);
    final Object resultObject = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
    assertTrue(resultObject instanceof TargetResolverPortfolio);
View Full Code Here

*/
@Test
public class LazyComputationTargetResolverTest {

  public void testPortfolioNode() {
    final MockComputationTargetResolver mock = MockComputationTargetResolver.unresolved();
    final ComputationTargetResolver resolver = new LazyComputationTargetResolver(mock);
    final ComputationTarget target = resolver.resolve(new ComputationTargetSpecification(ComputationTargetType.PORTFOLIO_NODE, UniqueId.of("Node", "0")), VersionCorrection.LATEST);
    final PortfolioNode node = target.getPortfolioNode();
    assertEquals(node.getUniqueId(), UniqueId.of("Node", "0"));
    assertEquals(mock.getResolveCalls(), 0);
    assertEquals(node.getName(), "Node 0");
    assertEquals(mock.getResolveCalls(), 1);
    final List<PortfolioNode> childNodes = node.getChildNodes();
    assertEquals(childNodes.size(), 2);
    assertEquals(mock.getResolveCalls(), 1);
    assertEquals(childNodes.get(0).getUniqueId(), UniqueId.of("Node", "1"));
    assertEquals(childNodes.get(1).getUniqueId(), UniqueId.of("Node", "4"));
    assertEquals(mock.getResolveCalls(), 1);
    assertEquals(childNodes.get(0).getName(), "Node 1");
    assertEquals(childNodes.get(0).getChildNodes().size(), 2);
    assertEquals(childNodes.get(1).getName(), "Node 4");
    assertEquals(childNodes.get(1).getChildNodes().size(), 2);
    assertEquals(mock.getResolveCalls(), 3);
    final List<Position> positions = node.getPositions();
    assertEquals(positions.size(), 2);
    assertEquals(mock.getResolveCalls(), 3);
    assertEquals(positions.get(0).getUniqueId(), UniqueId.of("Position", "12"));
    assertEquals(positions.get(1).getUniqueId(), UniqueId.of("Position", "13"));
    assertEquals(mock.getResolveCalls(), 3);
    assertEquals(positions.get(0).getQuantity(), BigDecimal.ONE);
    assertEquals(positions.get(1).getQuantity(), BigDecimal.ONE);
    assertEquals(mock.getResolveCalls(), 5);
  }
View Full Code Here

    assertEquals(positions.get(1).getQuantity(), BigDecimal.ONE);
    assertEquals(mock.getResolveCalls(), 5);
  }

  public void testPosition() {
    final MockComputationTargetResolver mock = MockComputationTargetResolver.unresolved();
    final ComputationTargetResolver resolver = new LazyComputationTargetResolver(mock);
    final ComputationTarget target = resolver.resolve(new ComputationTargetSpecification(ComputationTargetType.POSITION, UniqueId.of("Position", "0")), VersionCorrection.LATEST);
    final Position position = target.getPosition();
    assertEquals(position.getUniqueId(), UniqueId.of("Position", "0"));
    assertEquals(mock.getResolveCalls(), 0);
    assertEquals(position.getAttributes(), Collections.emptyMap());
    assertEquals(position.getQuantity(), BigDecimal.ONE);
    assertEquals(mock.getResolveCalls(), 1);
    final Collection<Trade> trades = position.getTrades();
    assertEquals(trades.size(), 1);
    assertEquals(mock.getResolveCalls(), 1);
    final Trade trade = trades.iterator().next();
    assertEquals(trade.getUniqueId(), UniqueId.of("Trade", "0"));
    assertEquals(mock.getResolveCalls(), 1);
    assertEquals(trade.getQuantity(), BigDecimal.ONE);
    assertEquals(mock.getResolveCalls(), 2);
    final Security security = position.getSecurityLink().getTarget();
    assertEquals(security.getSecurityType(), "MOCK");
    assertEquals(mock.getResolveCalls(), 3);
  }
View Full Code Here

    EHCacheUtils.clear(_cacheManager);
  }

  //-------------------------------------------------------------------------
  public void testBasicMethods() {
    final MockComputationTargetResolver resolver = MockComputationTargetResolver.resolved();
    final Position underlying = resolver.getPositionSource().getPosition(UniqueId.of("Position", "0"));
    final Position position = new LazyResolvedPosition(new LazyResolveContext(resolver.getSecuritySource(), null).atVersionCorrection(VersionCorrection.LATEST), underlying);
    assertEquals(position.getAttributes(), underlying.getAttributes());
    assertEquals(position.getQuantity(), underlying.getQuantity());
    assertEquals(position.getTrades().size(), underlying.getTrades().size());
    assertEquals(position.getUniqueId(), underlying.getUniqueId());
  }
View Full Code Here

    assertEquals(position.getTrades().size(), underlying.getTrades().size());
    assertEquals(position.getUniqueId(), underlying.getUniqueId());
  }

  public void testSerialization_full() throws Exception {
    final MockComputationTargetResolver resolver = MockComputationTargetResolver.resolved();
    final Position underlying = resolver.getPositionSource().getPosition(UniqueId.of("Position", "0"));
    Position position = new LazyResolvedPosition(new LazyResolveContext(resolver.getSecuritySource(), null).atVersionCorrection(VersionCorrection.LATEST), underlying);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ObjectOutputStream(baos).writeObject(position);
    final Object resultObject = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
    assertTrue(resultObject instanceof SimplePosition);
    position = (Position) resultObject;
View Full Code Here

    assertEquals(position.getTrades().size(), underlying.getTrades().size());
    assertEquals(position.getUniqueId(), underlying.getUniqueId());
  }

  public void testSerialization_targetResolver() throws Exception {
    final MockComputationTargetResolver resolver = MockComputationTargetResolver.resolved();
    final Position underlying = resolver.getPositionSource().getPosition(UniqueId.of("Position", "0"));
    Position position = new LazyResolvedPosition(new LazyResolveContext(resolver.getSecuritySource(), new DefaultCachingComputationTargetResolver(resolver,
        _cacheManager)).atVersionCorrection(VersionCorrection.LATEST), underlying);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ObjectOutputStream(baos).writeObject(position);
    final Object resultObject = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
    assertTrue(resultObject instanceof TargetResolverPosition);
View Full Code Here

    assertEquals(security.getSecurityType(), "MOCK");
    assertEquals(mock.getResolveCalls(), 3);
  }

  public void testTrade() {
    final MockComputationTargetResolver mock = MockComputationTargetResolver.unresolved();
    final ComputationTargetResolver resolver = new LazyComputationTargetResolver(mock);
    final ComputationTarget target = resolver.resolve(new ComputationTargetSpecification(ComputationTargetType.TRADE, UniqueId.of("Trade", "0")), VersionCorrection.LATEST);
    final Trade trade = target.getTrade();
    assertEquals(trade.getUniqueId(), UniqueId.of("Trade", "0"));
    assertEquals(mock.getResolveCalls(), 0);
    assertEquals(trade.getAttributes(), Collections.emptyMap());
    trade.setAttributes(ImmutableMap.of("K1", "V1"));
    assertEquals(trade.getAttributes(), ImmutableMap.of("K1", "V1"));
    trade.addAttribute("K2", "V2");
    assertEquals(trade.getAttributes(), ImmutableMap.of("K1", "V1", "K2", "V2"));
    assertEquals(trade.getCounterparty(), new SimpleCounterparty(ExternalId.of("Counterparty", "Mock")));
    assertEquals(trade.getPremium(), null);
    assertEquals(trade.getPremiumCurrency(), null);
    assertEquals(trade.getPremiumDate(), null);
    assertEquals(trade.getPremiumTime(), null);
    assertEquals(trade.getTradeDate(), MockComputationTargetResolver.TODAY);
    assertEquals(trade.getTradeTime(), null);
    assertEquals(trade.getQuantity(), BigDecimal.ONE);
    assertEquals(mock.getResolveCalls(), 1);
    final Security security = trade.getSecurityLink().getTarget();
    assertEquals(security.getSecurityType(), "MOCK");
    assertEquals(mock.getResolveCalls(), 2);
  }
View Full Code Here

    assertEquals(security.getSecurityType(), "MOCK");
    assertEquals(mock.getResolveCalls(), 2);
  }

  public void testSecurity() {
    final MockComputationTargetResolver mock = MockComputationTargetResolver.unresolved();
    final ComputationTargetResolver resolver = new LazyComputationTargetResolver(mock);
    final ComputationTarget target = resolver.resolve(new ComputationTargetSpecification(ComputationTargetType.SECURITY, UniqueId.of("Security", "0")), VersionCorrection.LATEST);
    final Security security = target.getSecurity();
    assertEquals(mock.getResolveCalls(), 1);
    assertEquals(security.getSecurityType(), "MOCK");
    assertEquals(mock.getResolveCalls(), 1);
  }
View Full Code Here

TOP

Related Classes of com.opengamma.engine.target.MockComputationTargetResolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.