use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.
the class ModifyRequestTest 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(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());
}
use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.
the class ModifyRequestTest method testRequestWith2Modifications.
/**
* Test parsing of a request with 2 Modification elements
* @throws NamingException
*/
@Test
public void testRequestWith2Modifications() throws LdapException {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(ModifyRequestTest.class.getResource("request_with_2_modifications.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
Collection<Modification> modifications = modifyRequest.getModifications();
assertEquals(2, modifications.size());
Iterator<Modification> iter = modifications.iterator();
Modification modification = iter.next();
assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
Attribute attribute = modification.getAttribute();
assertEquals("directreport", attribute.getId());
assertEquals("CN=John Smith, DC=microsoft, DC=com", attribute.get().getValue());
modification = iter.next();
attribute = modification.getAttribute();
assertEquals("sn", attribute.getId());
assertEquals(ModificationOperation.REPLACE_ATTRIBUTE, modification.getOperation());
assertEquals("CN=Steve Jobs, DC=apple, DC=com", attribute.get().getValue());
}
use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.
the class ModifyRequestTest method testRequestWithOperationDelete.
/**
* Test parsing of a request with operation attribute to Delete value
* @throws NamingException
*/
@Test
public void testRequestWithOperationDelete() throws LdapException {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(ModifyRequestTest.class.getResource("request_with_operation_delete.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
Collection<Modification> modifications = modifyRequest.getModifications();
assertEquals(1, modifications.size());
Modification modification = modifications.iterator().next();
assertEquals(ModificationOperation.REMOVE_ATTRIBUTE, modification.getOperation());
}
use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.
the class ModifyRequestTest method testRequestWithOperationReplace.
/**
* Test parsing of a request with operation attribute to Replace value
* @throws NamingException
*/
@Test
public void testRequestWithOperationReplace() throws LdapException {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(ModifyRequestTest.class.getResource("request_with_operation_replace.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
Collection<Modification> modifications = modifyRequest.getModifications();
assertEquals(1, modifications.size());
Modification modification = modifications.iterator().next();
assertEquals(ModificationOperation.REPLACE_ATTRIBUTE, modification.getOperation());
}
use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.
the class ModifyRequestTest method testRequestWithModificationWith2Values.
/**
* Test parsing of a request with a Modification element
* @throws NamingException
*/
@Test
public void testRequestWithModificationWith2Values() throws LdapException {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(ModifyRequestTest.class.getResource("request_with_modification_with_2_values.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
Collection<Modification> modifications = modifyRequest.getModifications();
assertEquals(1, modifications.size());
Modification modification = modifications.iterator().next();
assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
Attribute attribute = modification.getAttribute();
assertEquals("directreport", attribute.getId());
assertEquals(2, attribute.size());
assertTrue(attribute.contains("CN=John Smith, DC=microsoft, DC=com"));
assertTrue(attribute.contains("CN=Steve Jobs, DC=apple, DC=com"));
}
Aggregations