Java Code Examples for org.apache.directory.api.ldap.model.message.CompareRequest#getControls()
The following examples show how to use
org.apache.directory.api.ldap.model.message.CompareRequest#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: CompareRequestTest.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( CompareRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest(); Map<String, Control> controls = compareRequest.getControls(); assertEquals( 1, compareRequest.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: CompareRequestTest.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( CompareRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest(); Map<String, Control> controls = compareRequest.getControls(); assertEquals( 1, compareRequest.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 3
Source File: CompareRequestTest.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( CompareRequestTest.class.getResource( "request_with_1_control_empty_value.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest(); Map<String, Control> controls = compareRequest.getControls(); assertEquals( 1, compareRequest.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: CompareRequestTest.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( CompareRequestTest.class.getResource( "request_with_2_controls.xml" ).openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest(); Map<String, Control> controls = compareRequest.getControls(); assertEquals( 2, compareRequest.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: CompareRequestTest.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( CompareRequestTest.class.getResource( "request_with_3_controls_without_value.xml" ) .openStream(), "UTF-8" ); parser.parse(); } catch ( Exception e ) { fail( e.getMessage() ); } CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest(); Map<String, Control> controls = compareRequest.getControls(); assertEquals( 3, compareRequest.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: CompareRequestTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Test the decoding of an compare request with controls */ @Test public void testDecodeCompareRequestWithControls() throws DecoderException, EncoderException { ByteBuffer stream = ByteBuffer.allocate( 0x55 ); stream.put( new byte[] { 0x30, 0x53, // LDAPMessage ::= SEQUENCE { 0x02, 0x01, 0x01, // messageID MessageID // CHOICE { ..., compareRequest CompareRequest, ... 0x6E, 0x31, // CompareRequest ::= [APPLICATION 14] SEQUENCE { 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', // ava AttributeValueAssertion } 0x30, 0x0D, // AttributeValueAssertion ::= SEQUENCE { 0x04, 0x04, // attributeDesc AttributeDescription, 't', 'e', 's', 't', 0x04, 0x05, // assertionValue AssertionValue } 'v', 'a', 'l', 'u', 'e', ( 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<CompareRequest> container = new LdapMessageContainer<>( codec ); // Decode the CompareRequest PDU Asn1Decoder.decode( stream, container ); // Check the decoded CompareRequest PDU CompareRequest compareRequest = container.getMessage(); assertEquals( 1, compareRequest.getMessageId() ); assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getName().toString() ); assertEquals( "test", compareRequest.getAttributeId() ); assertEquals( "value", compareRequest.getAssertionValue().toString() ); // Check the Control Map<String, Control> controls = compareRequest.getControls(); assertEquals( 1, controls.size() ); Control control = controls.get( "2.16.840.1.113730.3.4.2" ); assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() ); assertTrue( control instanceof ManageDsaIT ); // Check the encoding Asn1Buffer buffer = new Asn1Buffer(); LdapEncoder.encodeMessage( buffer, codec, compareRequest ); assertArrayEquals( stream.array(), buffer.getBytes().array() ); }