Search in sources :

Example 6 with EntryChangeDecorator

use of org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator 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)

Example 7 with EntryChangeDecorator

use of org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator in project directory-ldap-api by apache.

the class EntryChangeControlTest method testDecodeEntryChangeControlSuccess.

/**
 * Test the decoding of a EntryChangeControl
 */
@Test
public void testDecodeEntryChangeControlSuccess() 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 });
    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(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 8 with EntryChangeDecorator

use of org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator in project directory-ldap-api by apache.

the class EntryChangeControlTest method testDecodeEntryChangeControlWithADDAndPreviousDNBad.

/**
 * Test the decoding of a EntryChangeControl with a add so we should not
 * have a PreviousDN
 */
@Test(expected = DecoderException.class)
public void testDecodeEntryChangeControlWithADDAndPreviousDNBad() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x0D);
    bb.put(new byte[] { // EntryChangeNotification ::= SEQUENCE {
    0x30, // EntryChangeNotification ::= SEQUENCE {
    0x0B, 0x0A, 0x01, // changeType ENUMERATED {
    0x01, // }
    0x04, 0x03, 'a', '=', // previousDN LDAPDN OPTIONAL, --
    'b', // modifyDN ops. only
    0x02, 0x01, // changeNumber INTEGER OPTIONAL -- if supported
    0x10 // }
    });
    bb.flip();
    EntryChangeDecorator decorator = new EntryChangeDecorator(codec);
    decorator.decode(bb.array());
}
Also used : EntryChangeDecorator(org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 9 with EntryChangeDecorator

use of org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator in project directory-ldap-api by apache.

the class EntryChangeControlTest method testDecodeEntryChangeControlWithWrongChangeNumber.

/**
 * Test the decoding of a EntryChangeControl with a wrong changeNumber
 */
@Test(expected = DecoderException.class)
public void testDecodeEntryChangeControlWithWrongChangeNumber() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x1C);
    bb.put(new byte[] { // EntryChangeNotification ::= SEQUENCE {
    0x30, // EntryChangeNotification ::= SEQUENCE {
    0x1A, 0x0A, 0x01, // changeType ENUMERATED {
    0x08, // }
    0x04, 0x03, 'a', '=', // previousDN LDAPDN OPTIONAL, -- modifyDN ops. only
    'b', 0x02, // changeNumber INTEGER OPTIONAL -- if supported
    0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
    bb.flip();
    EntryChangeDecorator decorator = new EntryChangeDecorator(codec);
    decorator.decode(bb.array());
}
Also used : EntryChangeDecorator(org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

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