MessageScope extends AbstractMessageScope implements Scope { @Override public FixNode resolve(PathStep pathStep) { final String name = pathStep.getName(); final List<Object> members = getRepository().getMessageMembers(messageType); for (final Object member : members) { if (member instanceof FieldRefType) { final FieldRefType fieldRefType = (FieldRefType) member; final String fieldName = getRepository().getFieldName(fieldRefType.getId().intValue(), fieldRefType.getScenario()); if (name.equals(fieldName)) { return resolveField(fieldRefType); } } else if (member instanceof GroupRefType) { final GroupRefType groupRefType = (GroupRefType) member; final GroupType group = getRepository().getGroup(groupRefType); if (name.equals(group.getName())) { return resolveGroup(pathStep, groupRefType); } } } return null; } MessageScope(Message message, MessageType messageType, RepositoryAccessor repository,
      SymbolResolver symbolResolver, Evaluator evaluator); @Override FixValue<?> assign(PathStep pathStep, FixValue<?> value); @Override void close(); @Override String getName(); @Override Scope nest(PathStep arg0, Scope arg1); @Override FixNode remove(PathStep arg0); @Override FixNode resolve(PathStep pathStep); @Override void setParent(Scope parent);  }
@Test public void testResolveField() { String mdReqId = "REQ1234"; md.set(new MDReqID(mdReqId)); PathStep pathStep = new PathStep("MDReqID"); FixValue<?> node = (FixValue<?>) messageScope.resolve(pathStep ); assertEquals(mdReqId, node.getValue().toString()); }
@Test public void testFieldNotFound() { PathStep pathStep = new PathStep("MDReqID"); FixValue<?> node = (FixValue<?>) messageScope.resolve(pathStep ); assertNull(node.getValue()); }
@Test public void testResolveGroupIndex() { MarketDataIncrementalRefresh.NoMDEntries group = new MarketDataIncrementalRefresh.NoMDEntries(); char mdEntryType = '0'; group.set(new MDEntryType(mdEntryType)); group.set(new MDEntryPx(12.32)); group.set(new MDEntrySize(100)); group.set(new OrderID("ORDERID")); md.addGroup(group); PathStep pathStep = new PathStep("MDIncGrp"); pathStep.setIndex(1); Scope node = (Scope) messageScope.resolve(pathStep ); PathStep pathStep2 = new PathStep("MDEntryType"); FixValue<?> node2 = (FixValue<?>) node.resolve(pathStep2); assertEquals(mdEntryType, node2.getValue()); }
@Test public void testGroupNotFound() { MarketDataIncrementalRefresh.NoMDEntries group = new MarketDataIncrementalRefresh.NoMDEntries(); char mdEntryType = '0'; group.set(new MDEntryType(mdEntryType)); group.set(new MDEntryPx(12.32)); group.set(new MDEntrySize(100)); group.set(new OrderID("ORDERID")); md.addGroup(group); PathStep pathStep = new PathStep("MDIncGrp"); pathStep.setIndex(2); Scope node = (Scope) messageScope.resolve(pathStep ); assertNull(node); }
@Test public void testResolveGroupPredicate() { MarketDataIncrementalRefresh.NoMDEntries group = new MarketDataIncrementalRefresh.NoMDEntries(); group.set(new MDEntryType(MDEntryType.Bid)); group.set(new MDEntryPx(12.32)); group.set(new MDEntrySize(100)); md.addGroup(group); group.set(new MDEntryType(MDEntryType.Bid)); group.set(new MDEntryPx(12.31)); group.set(new MDEntrySize(200)); md.addGroup(group); PathStep pathStep = new PathStep("MDIncGrp"); pathStep.setPredicate("MDEntryPx==12.31"); Scope node = (Scope) messageScope.resolve(pathStep ); assertNotNull(node); PathStep pathStep2 = new PathStep("MDEntryPx"); FixValue<?> node2 = (FixValue<?>) node.resolve(pathStep2); assertNotNull(node2); assertEquals(new BigDecimal("12.31"), node2.getValue()); }