use of org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator 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);
}
use of org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator 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());
}
use of org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator 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());
}
use of org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator 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);
}
use of org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator in project directory-ldap-api by apache.
the class EntryChangeControlTest method testDecodeEntryChangeControlWithWrongChangeType.
/**
* Test the decoding of a EntryChangeControl with a wrong changeType and
* nothing else
*/
@Test(expected = DecoderException.class)
public void testDecodeEntryChangeControlWithWrongChangeType() throws Exception {
ByteBuffer bb = ByteBuffer.allocate(0x05);
bb.put(new byte[] { // EntryChangeNotification ::= SEQUENCE {
0x30, // EntryChangeNotification ::= SEQUENCE {
0x03, 0x0A, 0x01, // changeType ENUMERATED {
0x03 // BAD Change Type
// }
// }
});
bb.flip();
EntryChangeDecorator decorator = new EntryChangeDecorator(codec);
decorator.decode(bb.array());
}
Aggregations