Search in sources :

Example 21 with CompareRequest

use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.

the class CompareRequestTest method testRequestWith1ControlBase64Value.

/**
 * 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()));
}
Also used : DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) Control(org.apache.directory.api.ldap.model.message.Control) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 22 with CompareRequest

use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.

the class CompareRequestTest method testRequestWith1CompleteAssertionBase64Value.

/**
 * Test parsing of a request with a complete assertion with base64 value
 */
@Test
public void testRequestWith1CompleteAssertionBase64Value() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(CompareRequestTest.class.getResource("request_with_1_complete_assertion_base64_value.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    CompareRequest compareRequest = (CompareRequest) parser.getBatchRequest().getCurrentRequest();
    assertTrue(compareRequest.getName().equals("cn=Bob Rush,ou=Dev,dc=Example,dc=COM"));
    assertEquals("sn", compareRequest.getAttributeId());
    assertEquals("DSMLv2.0 rocks!!", compareRequest.getAssertionValue().getValue());
}
Also used : CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 23 with CompareRequest

use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.

the class CompareRequestTest method testRequestWith1ControlEmptyValue.

/**
 * 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());
}
Also used : CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) Control(org.apache.directory.api.ldap.model.message.Control) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 24 with CompareRequest

use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.

the class CompareRequestTest method testRequestWithRequestId.

/**
 * Test parsing of a request with the (optional) requestID attribute
 */
@Test
public void testRequestWithRequestId() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(CompareRequestTest.class.getResource("request_with_requestID_attribute.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    CompareRequest compareRequest = (CompareRequest) parser.getBatchRequest().getCurrentRequest();
    assertEquals(456, compareRequest.getMessageId());
}
Also used : CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 25 with CompareRequest

use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.

the class CompareRequestDsml method toDsml.

/**
 * {@inheritDoc}
 */
@Override
public Element toDsml(Element root) {
    Element element = super.toDsml(root);
    CompareRequest request = getDecorated();
    // Dn
    if (request.getName() != null) {
        element.addAttribute("dn", request.getName().getName());
    }
    // Assertion
    Element assertionElement = element.addElement("assertion");
    if (request.getAttributeId() != null) {
        assertionElement.addAttribute("name", request.getAttributeId());
    }
    if (request.getAssertionValue() != null) {
        assertionElement.addElement("value").setText(request.getAssertionValue().getValue());
    }
    return element;
}
Also used : CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) Element(org.dom4j.Element)

Aggregations

CompareRequest (org.apache.directory.api.ldap.model.message.CompareRequest)26 Test (org.junit.Test)15 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)12 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)12 Control (org.apache.directory.api.ldap.model.message.Control)7 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)5 CompareRequestDecorator (org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator)5 CompareRequestImpl (org.apache.directory.api.ldap.model.message.CompareRequestImpl)5 CompareResponse (org.apache.directory.api.ldap.model.message.CompareResponse)5 DecoderException (org.apache.directory.api.asn1.DecoderException)4 ByteBuffer (java.nio.ByteBuffer)3 EncoderException (org.apache.directory.api.asn1.EncoderException)3 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)3 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)3 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)3 Dn (org.apache.directory.api.ldap.model.name.Dn)3 BatchRequestDsml (org.apache.directory.api.dsmlv2.request.BatchRequestDsml)2 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)2 AbandonRequest (org.apache.directory.api.ldap.model.message.AbandonRequest)2