Java Code Examples for org.apache.directory.api.ldap.model.message.ModifyResponse#getControls()
The following examples show how to use
org.apache.directory.api.ldap.model.message.ModifyResponse#getControls() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a response with a (optional) Control element */ @Test public void testResponseWith1Control() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( ModifyResponseTest.class.getResource( "response_with_1_control.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); Map<String, Control> controls = modifyResponse.getControls(); assertEquals( 1, modifyResponse.getControls().size() ); Control control = controls.get( "1.2.840.113556.1.4.643" ); assertNotNull( control ); assertTrue( control.isCritical() ); assertEquals( "1.2.840.113556.1.4.643", control.getOid() ); assertEquals( "Some text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) ); }
Example 2
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a response with a (optional) Control element with empty value */ @Test public void testResponseWith1ControlEmptyValue() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( ModifyResponseTest.class.getResource( "response_with_1_control_empty_value.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); Map<String, Control> controls = modifyResponse.getControls(); assertEquals( 1, modifyResponse.getControls().size() ); Control control = controls.get( "1.2.840.113556.1.4.643" ); assertNotNull( control ); assertTrue( control.isCritical() ); assertEquals( "1.2.840.113556.1.4.643", control.getOid() ); assertFalse( ( ( DsmlControl<?> ) control ).hasValue() ); }
Example 3
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a response with 2 (optional) Control elements */ @Test public void testResponseWith2Controls() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( ModifyResponseTest.class.getResource( "response_with_2_controls.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); Map<String, Control> controls = modifyResponse.getControls(); assertEquals( 2, modifyResponse.getControls().size() ); Control control = controls.get( "1.2.840.113556.1.4.789" ); assertNotNull( control ); assertFalse( control.isCritical() ); assertEquals( "1.2.840.113556.1.4.789", control.getOid() ); assertEquals( "Some other text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) ); }
Example 4
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a response with 3 (optional) Control elements without value */ @Test public void testResponseWith3ControlsWithoutValue() { Dsmlv2ResponseParser parser = null; try { parser = new Dsmlv2ResponseParser( getCodec() ); parser.setInput( ModifyResponseTest.class.getResource( "response_with_3_controls_without_value.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyResponse modifyResponse = ( ModifyResponse ) parser.getBatchResponse().getCurrentResponse(); Map<String, Control> controls = modifyResponse.getControls(); assertEquals( 3, modifyResponse.getControls().size() ); Control control = controls.get( "1.2.840.113556.1.4.456" ); assertNotNull( control ); assertTrue( control.isCritical() ); assertEquals( "1.2.840.113556.1.4.456", control.getOid() ); assertFalse( ( ( DsmlControl<?> ) control ).hasValue() ); }
Example 5
Source File: ModifyResponseTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Test the decoding of a ModifyResponse with controls */ @Test public void testDecodeModifyResponseSuccessWithControls() throws DecoderException, EncoderException { ByteBuffer stream = ByteBuffer.allocate( 0x32 ); stream.put( new byte[] { 0x30, 0x30, // LDAPMessage ::=SEQUENCE { 0x02, 0x01, 0x01, // messageID MessageID 0x67, 0x07, // CHOICE { ..., modifyResponse ModifyResponse, ... // ModifyResponse ::= [APPLICATION 7] LDAPResult 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE { // resultCode ENUMERATED { // success (0), ... // }, 0x04, 0x00, // matchedDN LDAPDN, 0x04, 0x00, // errorMessage LDAPString, // referral [3] Referral OPTIONAL } // } ( byte ) 0xA0, 0x22, // A control 0x30, 0x20, 0x04, 0x17, // EntryChange response control '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '7', 0x04, 0x05, // Control value 0x30, 0x03, // EntryChangeNotification ::= SEQUENCE { 0x0A, 0x01, 0x01 // changeType ENUMERATED { // add (1), } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyResponse> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyResponse PDU Asn1Decoder.decode( stream, ldapMessageContainer ); // Check the decoded ModifyResponse PDU ModifyResponse modifyResponse = ldapMessageContainer.getMessage(); assertEquals( 1, modifyResponse.getMessageId() ); assertEquals( ResultCodeEnum.SUCCESS, modifyResponse.getLdapResult().getResultCode() ); assertEquals( "", modifyResponse.getLdapResult().getMatchedDn().getName() ); assertEquals( "", modifyResponse.getLdapResult().getDiagnosticMessage() ); // Check the Control Map<String, Control> controls = modifyResponse.getControls(); assertEquals( 1, controls.size() ); Control control = controls.get( "2.16.840.1.113730.3.4.7" ); assertTrue( control instanceof EntryChange); assertEquals( "2.16.840.1.113730.3.4.7", control.getOid() ); // Check encode reverse Asn1Buffer buffer = new Asn1Buffer(); LdapEncoder.encodeMessage( buffer, codec, modifyResponse ); assertArrayEquals( stream.array(), buffer.getBytes().array() ); }