Search in sources :

Example 1 with EntryChange

use of org.apache.directory.api.ldap.model.message.controls.EntryChange in project directory-ldap-api by apache.

the class EntryChangeControlTest method testEncodeEntryChangeControl.

/**
 * Test encoding of a EntryChangeControl.
 */
@Test
public void testEncodeEntryChangeControl() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0D);
    bb.put(new byte[] { // EntryChangeNotification ::= SEQUENCE {
    0x30, // EntryChangeNotification ::= SEQUENCE {
    0x0B, 0x0A, 0x01, // changeType ENUMERATED {
    0x08, // }
    0x04, 0x03, 'a', '=', // previousDN LDAPDN OPTIONAL, -- modifyDN ops. only
    'b', 0x02, 0x01, // changeNumber INTEGER OPTIONAL -- if supported
    0x10 });
    String expected = Strings.dumpBytes(bb.array());
    bb.flip();
    EntryChangeDecorator decorator = new EntryChangeDecorator(codec);
    EntryChange entryChange = (EntryChange) decorator.getDecorated();
    entryChange.setChangeType(ChangeType.MODDN);
    entryChange.setChangeNumber(16);
    entryChange.setPreviousDn(new Dn("a=b"));
    bb = decorator.encode(ByteBuffer.allocate(decorator.computeLength()));
    String decoded = Strings.dumpBytes(bb.array());
    assertEquals(expected, decoded);
}
Also used : EntryChangeDecorator(org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator) Dn(org.apache.directory.api.ldap.model.name.Dn) EntryChange(org.apache.directory.api.ldap.model.message.controls.EntryChange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 2 with EntryChange

use of org.apache.directory.api.ldap.model.message.controls.EntryChange in project directory-ldap-api by apache.

the class EntryChangeControlTest method testDecodeEntryChangeControlSuccessLongChangeNumber.

/**
 * Test the decoding of a EntryChangeControl
 */
@Test
public void testDecodeEntryChangeControlSuccessLongChangeNumber() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x13);
    bb.put(new byte[] { // EntryChangeNotification ::= SEQUENCE {
    0x30, // EntryChangeNotification ::= SEQUENCE {
    0x11, 0x0A, 0x01, // changeType ENUMERATED {
    0x08, // }
    0x04, 0x03, 'a', '=', // previousDN LDAPDN OPTIONAL, -- modifyDN ops. only
    'b', 0x02, // changeNumber INTEGER OPTIONAL } -- if supported
    0x07, 0x12, 0x34, 0x56, 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE });
    bb.flip();
    EntryChangeDecorator decorator = new EntryChangeDecorator(codec);
    EntryChange entryChange = (EntryChange) decorator.decode(bb.array());
    assertEquals(ChangeType.MODDN, entryChange.getChangeType());
    assertEquals("a=b", entryChange.getPreviousDn().toString());
    assertEquals(5124095576030430L, entryChange.getChangeNumber());
}
Also used : EntryChangeDecorator(org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator) EntryChange(org.apache.directory.api.ldap.model.message.controls.EntryChange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 3 with EntryChange

use of org.apache.directory.api.ldap.model.message.controls.EntryChange in project directory-ldap-api by apache.

the class EntryChangeControlTest method testDecodeEntryChangeControlWithADDAndChangeNumber.

/**
 * Test the decoding of a EntryChangeControl with a add and a change number
 */
@Test
public void testDecodeEntryChangeControlWithADDAndChangeNumber() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x08);
    bb.put(new byte[] { // EntryChangeNotification ::= SEQUENCE {
    0x30, // EntryChangeNotification ::= SEQUENCE {
    0x06, 0x0A, 0x01, // changeType ENUMERATED {
    0x01, // }
    0x02, 0x01, // changeNumber INTEGER OPTIONAL -- if supported
    0x10 // }
    });
    bb.flip();
    EntryChangeDecorator decorator = new EntryChangeDecorator(codec);
    EntryChange entryChange = (EntryChange) decorator.decode(bb.array());
    assertEquals(ChangeType.ADD, entryChange.getChangeType());
    assertNull(entryChange.getPreviousDn());
    assertEquals(16, entryChange.getChangeNumber());
}
Also used : EntryChangeDecorator(org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator) EntryChange(org.apache.directory.api.ldap.model.message.controls.EntryChange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 4 with EntryChange

use of org.apache.directory.api.ldap.model.message.controls.EntryChange in project directory-ldap-api by apache.

the class EntryChangeControlTest method testEncodeEntryChangeControlLong.

/**
 * Test encoding of a EntryChangeControl with a long changeNumber.
 */
@Test
public void testEncodeEntryChangeControlLong() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x13);
    bb.put(new byte[] { // EntryChangeNotification ::= SEQUENCE {
    0x30, // EntryChangeNotification ::= SEQUENCE {
    0x11, 0x0A, 0x01, // changeType ENUMERATED {
    0x08, // }
    0x04, 0x03, 'a', '=', // previousDN LDAPDN OPTIONAL, -- modifyDN ops. only
    'b', 0x02, // changeNumber INTEGER OPTIONAL -- if supported
    0x07, 0x12, 0x34, 0x56, 0x78, (byte) 0x9a, (byte) 0xbc, (byte) 0xde });
    String expected = Strings.dumpBytes(bb.array());
    bb.flip();
    EntryChangeDecorator decorator = new EntryChangeDecorator(codec);
    EntryChange entryChange = (EntryChange) decorator.getDecorated();
    entryChange.setChangeType(ChangeType.MODDN);
    entryChange.setChangeNumber(5124095576030430L);
    entryChange.setPreviousDn(new Dn("a=b"));
    bb = decorator.encode(ByteBuffer.allocate(decorator.computeLength()));
    String decoded = Strings.dumpBytes(bb.array());
    assertEquals(expected, decoded);
}
Also used : EntryChangeDecorator(org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator) Dn(org.apache.directory.api.ldap.model.name.Dn) EntryChange(org.apache.directory.api.ldap.model.message.controls.EntryChange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 5 with EntryChange

use of org.apache.directory.api.ldap.model.message.controls.EntryChange in project directory-ldap-api by apache.

the class EntryChangeControlTest method testDecodeEntryChangeControlWithADD.

/**
 * Test the decoding of a EntryChangeControl with a add and nothing else
 */
@Test
public void testDecodeEntryChangeControlWithADD() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x05);
    bb.put(new byte[] { // EntryChangeNotification ::= SEQUENCE {
    0x30, // EntryChangeNotification ::= SEQUENCE {
    0x03, 0x0A, 0x01, // changeType ENUMERATED {
    0x01 // ADD (1)
    // }
    // }
    });
    bb.flip();
    EntryChangeDecorator decorator = new EntryChangeDecorator(codec);
    EntryChange entryChange = (EntryChange) decorator.decode(bb.array());
    assertEquals(ChangeType.ADD, entryChange.getChangeType());
    assertNull(entryChange.getPreviousDn());
    assertEquals(EntryChangeDecorator.UNDEFINED_CHANGE_NUMBER, entryChange.getChangeNumber());
}
Also used : EntryChangeDecorator(org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator) EntryChange(org.apache.directory.api.ldap.model.message.controls.EntryChange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

ByteBuffer (java.nio.ByteBuffer)6 EntryChangeDecorator (org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator)6 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)6 EntryChange (org.apache.directory.api.ldap.model.message.controls.EntryChange)6 Test (org.junit.Test)6 Dn (org.apache.directory.api.ldap.model.name.Dn)2