@Test public void testParseInvalid() { assertThat(RangeOption.parse("Range=10-")).isNull(); assertThat(RangeOption.parse("Range=10-a")).isNull(); assertThat(RangeOption.parse("lang-en")).isNull(); assertThat(RangeOption.parse("member;Range=10-100")).isNull(); assertThat(RangeOption.parse(";Range=10-100")).isNull(); assertThat(RangeOption.parse("Range=10-100;")).isNull(); assertThat(RangeOption.parse("Range=10-100;lang-de")).isNull(); }
@Test public void testCompare() { RangeOption range1 = RangeOption.parse("Range=10-500"); RangeOption range2 = RangeOption.parse("Range=10-500"); assertThat(range1.compareTo(range2) == 0).isTrue(); assertThat(range2.compareTo(range1) == 0).isTrue(); range1 = RangeOption.parse("Range=0-*"); range2 = RangeOption.parse("Range=0-*"); assertThat(range1.compareTo(range2) == 0).isTrue(); assertThat(range2.compareTo(range1) == 0).isTrue(); range1 = RangeOption.parse("Range=0"); range2 = RangeOption.parse("Range=0"); assertThat(range1.compareTo(range2) == 0).isTrue(); assertThat(range2.compareTo(range1) == 0).isTrue(); range1 = RangeOption.parse("Range=0-101"); range2 = RangeOption.parse("Range=0-100"); assertThat(range1.compareTo(range2) > 0).isTrue(); assertThat(range2.compareTo(range1) < 0).isTrue(); range1 = RangeOption.parse("Range=0-*"); range2 = RangeOption.parse("Range=0-100"); assertThat(range1.compareTo(range2) > 0).isTrue(); assertThat(range2.compareTo(range1) < 0).isTrue(); }
@Override public final DefaultIncrementalAttributesMapper mapFromAttributes(Attributes attributes) throws NamingException { if (!hasMore()) { throw new IllegalStateException("No more attributes!"); } // Reset the affected attributes. rangedAttributesInNextIteration = new HashSet<String>(); NamingEnumeration<String> attributeNameEnum = attributes.getIDs(); while (attributeNameEnum.hasMore()) { String attributeName = attributeNameEnum.next(); String[] attributeNameSplit = attributeName.split(";"); IncrementalAttributeState state = getState(attributeNameSplit[0]); if (attributeNameSplit.length == 1) { // No range specification for this attribute state.processValues(attributes, attributeName); } else { for (String option : attributeNameSplit) { RangeOption responseRange = RangeOption.parse(option); if (responseRange != null) { state.processValues(attributes, attributeName); state.calculateNextRange(responseRange); if (state.hasMore()) { rangedAttributesInNextIteration.add(state.getRequestedAttributeName()); } } } } } return this; }
@Override public final DefaultIncrementalAttributesMapper mapFromAttributes(Attributes attributes) throws NamingException { if (!hasMore()) { throw new IllegalStateException("No more attributes!"); } // Reset the affected attributes. rangedAttributesInNextIteration = new HashSet<String>(); NamingEnumeration<String> attributeNameEnum = attributes.getIDs(); while (attributeNameEnum.hasMore()) { String attributeName = attributeNameEnum.next(); String[] attributeNameSplit = attributeName.split(";"); IncrementalAttributeState state = getState(attributeNameSplit[0]); if (attributeNameSplit.length == 1) { // No range specification for this attribute state.processValues(attributes, attributeName); } else { for (String option : attributeNameSplit) { RangeOption responseRange = RangeOption.parse(option); if (responseRange != null) { state.processValues(attributes, attributeName); state.calculateNextRange(responseRange); if (state.hasMore()) { rangedAttributesInNextIteration.add(state.getRequestedAttributeName()); } } } } } return this; }
@Override public final DefaultIncrementalAttributesMapper mapFromAttributes(Attributes attributes) throws NamingException { if (!hasMore()) { throw new IllegalStateException("No more attributes!"); } // Reset the affected attributes. rangedAttributesInNextIteration = new HashSet<String>(); NamingEnumeration<String> attributeNameEnum = attributes.getIDs(); while (attributeNameEnum.hasMore()) { String attributeName = attributeNameEnum.next(); String[] attributeNameSplit = attributeName.split(";"); IncrementalAttributeState state = getState(attributeNameSplit[0]); if (attributeNameSplit.length == 1) { // No range specification for this attribute state.processValues(attributes, attributeName); } else { for (String option : attributeNameSplit) { RangeOption responseRange = RangeOption.parse(option); if (responseRange != null) { state.processValues(attributes, attributeName); state.calculateNextRange(responseRange); if (state.hasMore()) { rangedAttributesInNextIteration.add(state.getRequestedAttributeName()); } } } } } return this; }
@Test public void testCompareInvalid() { RangeOption range1 = RangeOption.parse("Range=10-500"); RangeOption range2 = RangeOption.parse("Range=11-500"); try { assertThat(range1.compareTo(range2) == 0).isTrue(); fail("IllegalStateException expected"); } catch (IllegalStateException expected) { assertThat(true).isTrue(); } range1 = RangeOption.parse("Range=10"); range2 = RangeOption.parse("Range=10-500"); try { assertThat(range1.compareTo(range2) == 0).isTrue(); fail("IllegalStateException expected"); } catch (IllegalStateException expected) { assertThat(true).isTrue(); } range1 = RangeOption.parse("Range=10-500"); range2 = RangeOption.parse("Range=10"); try { assertThat(range1.compareTo(range2) == 0).isTrue(); fail("IllegalStateException expected"); } catch (IllegalStateException expected) { assertThat(true).isTrue(); } }
@Override public final DefaultIncrementalAttributesMapper mapFromAttributes(Attributes attributes) throws NamingException { if (!hasMore()) { throw new IllegalStateException("No more attributes!"); } // Reset the affected attributes. rangedAttributesInNextIteration = new HashSet<String>(); NamingEnumeration<String> attributeNameEnum = attributes.getIDs(); while (attributeNameEnum.hasMore()) { String attributeName = attributeNameEnum.next(); String[] attributeNameSplit = attributeName.split(";"); IncrementalAttributeState state = getState(attributeNameSplit[0]); if (attributeNameSplit.length == 1) { // No range specification for this attribute state.processValues(attributes, attributeName); } else { for (String option : attributeNameSplit) { RangeOption responseRange = RangeOption.parse(option); if (responseRange != null) { state.processValues(attributes, attributeName); state.calculateNextRange(responseRange); if (state.hasMore()) { rangedAttributesInNextIteration.add(state.getRequestedAttributeName()); } } } } } return this; }
@Test public void testParse() throws Exception { RangeOption range = RangeOption.parse("Range=0-100"); assertThat(range.getInitial()).isEqualTo(0); assertThat(range.getTerminal()).isEqualTo(100); range = RangeOption.parse("range=0-100"); assertThat(range.getInitial()).isEqualTo(0); assertThat(range.getTerminal()).isEqualTo(100); range = RangeOption.parse("RANGE=0-100"); assertThat(range.getInitial()).isEqualTo(0); assertThat(range.getTerminal()).isEqualTo(100); range = RangeOption.parse("Range=0-*"); assertThat(range.getInitial()).isEqualTo(0); assertThat(range.getTerminal()).isEqualTo(RangeOption.TERMINAL_END_OF_RANGE); range = RangeOption.parse("Range=10"); assertThat(range.getInitial()).isEqualTo(10); assertThat(range.getTerminal()).isEqualTo(RangeOption.TERMINAL_MISSING); }
@Test public void testNext() { RangeOption range = RangeOption.parse("Range=0-100"); range = range.nextRange(100); assertThat(range.getInitial()).isEqualTo(101); assertThat(range.getTerminal()).isEqualTo(200); range = range.nextRange(10); assertThat(range.getInitial()).isEqualTo(201); assertThat(range.getTerminal()).isEqualTo(210); range = range.nextRange(RangeOption.TERMINAL_END_OF_RANGE); assertThat(range.getInitial()).isEqualTo(211); assertThat(range.getTerminal()).isEqualTo(RangeOption.TERMINAL_END_OF_RANGE); } }