| | |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.opends.server.DirectoryServerTestCase; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | @Test(groups = { "precommit", "pluggablebackend" }, sequential=true) |
| | | @Test(groups = { "precommit", "pluggablebackend", "unit" }, sequential=true) |
| | | public class EntryIDSetTest extends DirectoryServerTestCase |
| | | { |
| | | private static final int UNDEFINED_INITIAL_SIZE = 10; |
| | | |
| | | private final static int UNDEFINED_INITIAL_SIZE = 10; |
| | | private final static ByteString KEY = ByteString.valueOf("test"); |
| | | |
| | | @Test(expectedExceptions = NullPointerException.class) |
| | |
| | | assertIdsEquals(set.iterator(new EntryID(13)), 4L, 6L, 8L, 10L, 12L); |
| | | } |
| | | |
| | | @Test |
| | | public void testDefinedByteString() |
| | | @Test(dataProvider = "codecs") |
| | | public void testCodecs(EntryIDSetCodec codec) |
| | | { |
| | | ByteString string = newDefinedSet(4, 6, 8, 10, 12).toByteString(); |
| | | assertThat(decodeEntryIDSet(string)).containsExactly(4, 6, 8, 10, 12); |
| | | ByteString string = codec.encode(newDefinedSet(4, 6, 8, 10, 12)); |
| | | assertIdsEquals(codec.decode(KEY, string), 4, 6, 8, 10, 12); |
| | | |
| | | string = newDefinedSet().toByteString(); |
| | | assertThat(decodeEntryIDSet(string)).isEmpty(); |
| | | string = codec.encode(newUndefinedSet()); |
| | | assertThat(codec.decode(KEY, string).isDefined()).isFalse(); |
| | | assertThat(codec.decode(KEY, string).size()).isEqualTo(Long.MAX_VALUE); |
| | | |
| | | string = codec.encode(newUndefinedSetWithSize(ByteString.valueOf("none"), 1234)); |
| | | assertThat(codec.decode(KEY, string).isDefined()).isFalse(); |
| | | assertThat(codec.decode(KEY, string).size()).isEqualTo(1234); |
| | | } |
| | | |
| | | @Test(enabled = false, dataProvider = "codec") |
| | | public void testCodecsEmptyDefinedSet(EntryIDSetCodec codec) |
| | | { |
| | | // FIXME: When decoded, an empty defined set becomes an undefined set |
| | | // see OPENDJ-1833 |
| | | ByteString string = codec.encode(newDefinedSet()); |
| | | assertThat(codec.decode(KEY, string).size()).isEqualTo(0); |
| | | |
| | | string = codec.encode(newDefinedSet()); |
| | | assertThat(codec.decode(KEY, string).size()).isEqualTo(0); |
| | | } |
| | | |
| | | @Test(expectedExceptions = NullPointerException.class) |
| | |
| | | } |
| | | |
| | | @Test |
| | | public void testUndefinedByteString() |
| | | { |
| | | assertThat(newUndefinedWithInitialSize().toByteString()).isEqualTo( |
| | | ByteString.valueOf(UNDEFINED_INITIAL_SIZE | Long.MIN_VALUE)); |
| | | } |
| | | |
| | | @Test |
| | | public void testNewEmptySet() |
| | | { |
| | | assertThat(newDefinedSet().isDefined()).isTrue(); |
| | |
| | | } |
| | | |
| | | @Test |
| | | public void testNewSetFromBytes() |
| | | { |
| | | assertThat(newSetFromBytes(KEY, ByteString.empty()).isDefined()).isFalse(); |
| | | assertThat(newSetFromBytes(KEY, ByteString.valueOf(42 | Long.MIN_VALUE)).isDefined()).isFalse(); |
| | | assertThat(newSetFromBytes(KEY, ByteString.valueOf(42 | Long.MIN_VALUE)).size()).isEqualTo(42); |
| | | |
| | | assertThat(newSetFromBytes(KEY, newDefinedSet(1, 2, 3).toByteString()).isDefined()).isTrue(); |
| | | assertThat(newSetFromBytes(KEY, newDefinedSet(1, 2, 3).toByteString()).size()).isEqualTo(3); |
| | | } |
| | | |
| | | @Test |
| | | public void testNewSetWIthIDs() |
| | | { |
| | | assertThat(newDefinedSet().isDefined()).isTrue(); |
| | |
| | | return newUndefinedSetWithSize(ByteString.valueOf("test"), UNDEFINED_INITIAL_SIZE); |
| | | } |
| | | |
| | | @DataProvider(name = "codecs") |
| | | public static Object[][] codecs() { |
| | | return new Object[][] { { CODEC_V1 }, { CODEC_V2 } }; |
| | | } |
| | | |
| | | } |