@Test public void testGetGroup_Nested() { CdrItem subfield2 = new CdrItem(CdrItem.CdrItemType.CDR_ARRAY); Cdr subChild1 = new Cdr("Test"); subChild1.set("subChild", "value2"); subChild1.set("subChild2", "value3"); subfield2.setCdrs(Collections.singletonList(subChild1)); CdrItem subfield = new CdrItem(CdrItem.CdrItemType.CDR_ARRAY); Cdr subChild2 = new Cdr("Test"); subChild2.set("subChild", "value3"); subfield.setCdrs(Collections.singletonList(subChild2)); CdrItem field = new CdrItem(CdrItem.CdrItemType.CDR_ARRAY); Cdr child1 = new Cdr("Test"); child1.set("child", "value1"); child1.setItem("child2", subfield); Cdr child2 = new Cdr("Test"); child2.set("child", "value2"); child2.setItem("child2", subfield2); field.setCdrs(Arrays.asList(child1, child2)); Cdr parent = new Cdr("Parent"); parent.setItem("Test", field); Cdr group = fixtures.getGroup(parent, "TestMessage", "Test/child2[subChild=value3]"); assertNotNull(group); }
Cdr getGroup(Cdr message, String messageName, String groupName) { if (groupName.contains("/")) { String[] groupSplit = groupName.split("/"); String firstGroup = groupSplit[0]; String[] remainingGroups = Arrays.copyOfRange(groupSplit, 1, groupSplit.length); return getNestedGroup(message, messageName, firstGroup, remainingGroups); } CdrItem item = message.getItem(groupName); if (item.getCdrs() == null || !item.getType().equals(CdrItem.CdrItemType.CDR_ARRAY)) { fail("Requested " + groupName + " doesn't appear to be a group"); } Optional<Cdr> group = item.getCdrs() .stream() .filter(cdr -> cdr.getType().equals(groupName)) .findFirst(); if (group.isPresent()) { return group.get(); } else { Cdr newGroup = new Cdr(groupName); item.addCdrToList(newGroup); return newGroup; } }
FixFixtures { Cdr getGroup(Cdr message, String messageName, String groupName) { if (groupName.contains("/")) { String[] groupSplit = groupName.split("/"); String firstGroup = groupSplit[0]; String[] remainingGroups = Arrays.copyOfRange(groupSplit, 1, groupSplit.length); return getNestedGroup(message, messageName, firstGroup, remainingGroups); } CdrItem item = message.getItem(groupName); if (item.getCdrs() == null || !item.getType().equals(CdrItem.CdrItemType.CDR_ARRAY)) { fail("Requested " + groupName + " doesn't appear to be a group"); } Optional<Cdr> group = item.getCdrs() .stream() .filter(cdr -> cdr.getType().equals(groupName)) .findFirst(); if (group.isPresent()) { return group.get(); } else { Cdr newGroup = new Cdr(groupName); item.addCdrToList(newGroup); return newGroup; } } }
FixFixtures { Cdr getGroup(Cdr message, String messageName, String groupName) { if (groupName.contains("/")) { String[] groupSplit = groupName.split("/"); String firstGroup = groupSplit[0]; String[] remainingGroups = Arrays.copyOfRange(groupSplit, 1, groupSplit.length); return getNestedGroup(message, messageName, firstGroup, remainingGroups); } CdrItem item = message.getItem(groupName); if (item.getCdrs() == null || !item.getType().equals(CdrItem.CdrItemType.CDR_ARRAY)) { fail("Requested " + groupName + " doesn't appear to be a group"); } Optional<Cdr> group = item.getCdrs() .stream() .filter(cdr -> cdr.getType().equals(groupName)) .findFirst(); if (group.isPresent()) { return group.get(); } else { Cdr newGroup = new Cdr(groupName); item.addCdrToList(newGroup); return newGroup; } } FixFixtures(EtiqetHandlers handlers); }
FixFixtures { Cdr getGroup(Cdr message, String messageName, String groupName) { if (groupName.contains("/")) { String[] groupSplit = groupName.split("/"); String firstGroup = groupSplit[0]; String[] remainingGroups = Arrays.copyOfRange(groupSplit, 1, groupSplit.length); return getNestedGroup(message, messageName, firstGroup, remainingGroups); } CdrItem item = message.getItem(groupName); if (item.getCdrs() == null || !item.getType().equals(CdrItem.CdrItemType.CDR_ARRAY)) { fail("Requested " + groupName + " doesn't appear to be a group"); } Optional<Cdr> group = item.getCdrs() .stream() .filter(cdr -> cdr.getType().equals(groupName)) .findFirst(); if (group.isPresent()) { return group.get(); } else { Cdr newGroup = new Cdr(groupName); item.addCdrToList(newGroup); return newGroup; } } FixFixtures(EtiqetHandlers handlers); @Then("create a repeating group \"([^\"]*)\" in message \"([^\"]*)\"") void createRepeatingGroup(String groupType, String messageName); @Then("create a repeating group \"([^\"]*)\" with \"([^\"]*)\" in message \"([^\"]*)\"") void createRepeatingGroupWithFields(String groupType, String params, String messageName); @Then("create a repeating group \"([^\"]*)\" in group \"([^\"]*)\" in message \"([^\"]*)\"") void createRepeatingGroupInGroup(String groupType, String existingGroup, String messageName); @Then("create a repeating group \"([^\"]*)\" with \"([^\"]*)\" in group \"([^\"]*)\" in message \"([^\"]*)\"") void createRepeatingGroupWithFieldsInGroup(String groupType, String params, String existingGroup, String messageName); @Then("add fields \"([^\"]*)\" to \"([^\"]*)\" group in message \"([^\"]*)\"") void addFieldsToRepeatingGroup(String params, String groupType, String messageName); }
FixFixtures { Cdr getGroup(Cdr message, String messageName, String groupName) { if (groupName.contains("/")) { String[] groupSplit = groupName.split("/"); String firstGroup = groupSplit[0]; String[] remainingGroups = Arrays.copyOfRange(groupSplit, 1, groupSplit.length); return getNestedGroup(message, messageName, firstGroup, remainingGroups); } CdrItem item = message.getItem(groupName); if (item.getCdrs() == null || !item.getType().equals(CdrItem.CdrItemType.CDR_ARRAY)) { fail("Requested " + groupName + " doesn't appear to be a group"); } Optional<Cdr> group = item.getCdrs() .stream() .filter(cdr -> cdr.getType().equals(groupName)) .findFirst(); if (group.isPresent()) { return group.get(); } else { Cdr newGroup = new Cdr(groupName); item.addCdrToList(newGroup); return newGroup; } } FixFixtures(EtiqetHandlers handlers); @Then("create a repeating group \"([^\"]*)\" in message \"([^\"]*)\"") void createRepeatingGroup(String groupType, String messageName); @Then("create a repeating group \"([^\"]*)\" with \"([^\"]*)\" in message \"([^\"]*)\"") void createRepeatingGroupWithFields(String groupType, String params, String messageName); @Then("create a repeating group \"([^\"]*)\" in group \"([^\"]*)\" in message \"([^\"]*)\"") void createRepeatingGroupInGroup(String groupType, String existingGroup, String messageName); @Then("create a repeating group \"([^\"]*)\" with \"([^\"]*)\" in group \"([^\"]*)\" in message \"([^\"]*)\"") void createRepeatingGroupWithFieldsInGroup(String groupType, String params, String existingGroup, String messageName); @Then("add fields \"([^\"]*)\" to \"([^\"]*)\" group in message \"([^\"]*)\"") void addFieldsToRepeatingGroup(String params, String groupType, String messageName);  }