Java Code Examples for org.apache.directory.api.ldap.model.message.ModifyRequest#getControls()
The following examples show how to use
org.apache.directory.api.ldap.model.message.ModifyRequest#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: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with a (optional) Control element */ @Test public void testRequestWith1Control() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( ModifyRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Map<String, Control> controls = modifyRequest.getControls(); assertEquals( 1, modifyRequest.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: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with a (optional) Control element with Base64 Value */ @Test public void testRequestWith1ControlBase64Value() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( ModifyRequestTest.class.getResource( "request_with_1_control_base64_value.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Map<String, Control> controls = modifyRequest.getControls(); assertEquals( 1, modifyRequest.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( "DSMLv2.0 rocks!!", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) ); }
Example 3
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with a (optional) Control element with empty value */ @Test public void testRequestWith1ControlEmptyValue() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( ModifyRequestTest.class.getResource( "request_with_1_control_empty_value.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Map<String, Control> controls = modifyRequest.getControls(); assertEquals( 1, modifyRequest.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 4
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with 2 (optional) Control elements */ @Test public void testRequestWith2Controls() { Dsmlv2Parser parser = null; try { parser = newParser(); parser .setInput( ModifyRequestTest.class.getResource( "request_with_2_controls.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Map<String, Control> controls = modifyRequest.getControls(); assertEquals( 2, modifyRequest.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 5
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with 3 (optional) Control elements without value */ @Test public void testRequestWith3ControlsWithoutValue() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( ModifyRequestTest.class.getResource( "request_with_3_controls_without_value.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } ModifyRequest modifyRequest = ( ModifyRequest ) parser.getBatchRequest().getCurrentRequest(); Map<String, Control> controls = modifyRequest.getControls(); assertEquals( 3, modifyRequest.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 6
Source File: ModifyRequestTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Test the decoding of a ModifyRequest with an add operation, and a * modification with a type and an empty vals wuth controls */ @Test public void testDecodeModifyRequestAddOperationModificationTypeEmptyValsWithControls() throws DecoderException, EncoderException { ByteBuffer stream = ByteBuffer.allocate( 0x54 ); stream.put( new byte[] { 0x30, 0x52, // LdapMessage 0x02, 0x01, 0x31, // messageID MessageID 0x66, 0x30, // ModifyRequest 0x04, 0x20, // entry LDAPDN, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x30, 0x0C, 0x30, 0x0A, 0x0A, 0x01, 0x00, 0x30, 0x05, 0x04, 0x01, 'l', 0x31, 0x00, ( byte ) 0xA0, 0x1B, // A control 0x30, 0x19, 0x04, 0x17, '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2' } ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<ModifyRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a ModifyRequest PDU Asn1Decoder.decode( stream, ldapMessageContainer ); // Check the decoded PDU ModifyRequest modifyRequest = ldapMessageContainer.getMessage(); assertEquals( 49, modifyRequest.getMessageId() ); assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getName().toString() ); Object[] modifications = modifyRequest.getModifications().toArray(); assertEquals( 1, modifications.length ); Modification modification = ( Modification ) modifications[0]; Attribute attributeValue = modification.getAttribute(); assertEquals( "l", Strings.toLowerCaseAscii( attributeValue.getUpId() ) ); assertEquals( 0, attributeValue.size() ); // Check the Control Map<String, Control> controls = modifyRequest.getControls(); assertEquals( 1, controls.size() ); Control control = modifyRequest.getControl( "2.16.840.1.113730.3.4.2" ); assertTrue( control instanceof ManageDsaIT ); assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() ); // Check encode reverse Asn1Buffer buffer = new Asn1Buffer(); LdapEncoder.encodeMessage( buffer, codec, modifyRequest ); assertArrayEquals( stream.array(), buffer.getBytes().array() ); }