public void testBasicElementMatcher() { String xml = "text <gadget></gadget> <something/> <gadget/> hello"; ApiView apiView = createApiViewFromXml(xml); DocumentHitIterator it = new DocumentHitIterator.ElementMatcher( apiView, ElementType.GADGET, Collections.<String, String>emptyMap(), -1); List<Integer> hits = Lists.newArrayList(); assertEquals(xml.indexOf("<gadget>") + 1, it.next().getStart()); assertEquals(10, it.next().getStart()); // Elements get counted as 1 assertNull(it.next()); }
} else if (query != null) { // range and index are both null. hitIterator = new DocumentHitIterator.ElementMatcher( view, query.getElementMatch(), query.getRestrictions(), query.getMaxRes()); } else {
public void testElementMatcherWithRestrictions() { String xml = "text <image attachment=\"nR_0YFT75\" style=\"full\">" + "<caption>good times</caption></image> hello"; ApiView apiView = createApiViewFromXml(xml); Map<String, String> restrictions = Maps.newHashMap(); assertEquals(1, countHits(new DocumentHitIterator.ElementMatcher( apiView, ElementType.ATTACHMENT, Collections.<String, String>emptyMap(), -1))); Restriction restriction = Attachment.restrictByAttachmentId("nR_0YFT75"); assertEquals(1, countHits(new DocumentHitIterator.ElementMatcher(apiView, ElementType.ATTACHMENT, ImmutableMap.of(restriction.getKey(), restriction.getValue()), -1))); restriction = Attachment.restrictByAttachmentId("nR_0YFT76"); assertEquals(0, countHits(new DocumentHitIterator.ElementMatcher(apiView, ElementType.ATTACHMENT, ImmutableMap.of(restriction.getKey(), restriction.getValue()), -1))); }
public void testElementMatcherWithRestrictions() { String xml = "text <image attachment=\"nR_0YFT75\" style=\"full\">" + "<caption>good times</caption></image> hello"; ApiView apiView = createApiViewFromXml(xml); Map<String, String> restrictions = Maps.newHashMap(); assertEquals(1, countHits(new DocumentHitIterator.ElementMatcher( apiView, ElementType.ATTACHMENT, Collections.<String, String>emptyMap(), -1))); Restriction restriction = Attachment.restrictByAttachmentId("nR_0YFT75"); assertEquals(1, countHits(new DocumentHitIterator.ElementMatcher(apiView, ElementType.ATTACHMENT, ImmutableMap.of(restriction.getKey(), restriction.getValue()), -1))); restriction = Attachment.restrictByAttachmentId("nR_0YFT76"); assertEquals(0, countHits(new DocumentHitIterator.ElementMatcher(apiView, ElementType.ATTACHMENT, ImmutableMap.of(restriction.getKey(), restriction.getValue()), -1))); }
public void testBasicElementMatcher() { String xml = "text <gadget></gadget> <something/> <gadget/> hello"; ApiView apiView = createApiViewFromXml(xml); DocumentHitIterator it = new DocumentHitIterator.ElementMatcher( apiView, ElementType.GADGET, Collections.<String, String>emptyMap(), -1); List<Integer> hits = Lists.newArrayList(); assertEquals(xml.indexOf("<gadget>") + 1, it.next().getStart()); assertEquals(10, it.next().getStart()); // Elements get counted as 1 assertNull(it.next()); }