use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.
the class StoreModifyRequestObjectName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
ModifyRequest modifyRequest = modifyRequestDecorator.getDecorated();
TLV tlv = container.getCurrentTLV();
Dn object = Dn.EMPTY_DN;
// Store the value.
if (tlv.getLength() == 0) {
(modifyRequestDecorator.getDecorated()).setName(object);
} else {
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
object = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
LOG.error("{} : {}", msg, ine.getMessage());
ModifyResponseImpl response = new ModifyResponseImpl(modifyRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
}
modifyRequest.setName(object);
}
if (IS_DEBUG) {
LOG.debug("Modification of Dn {}", modifyRequest.getName());
}
}
use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.
the class BatchRequestTest method testResponseWith1ModifyRequest.
/**
* Test parsing of a Request with 1 ModifyRequest
*/
@Test
public void testResponseWith1ModifyRequest() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(BatchRequestTest.class.getResource("request_with_1_ModifyRequest.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
BatchRequestDsml batchRequest = parser.getBatchRequest();
assertEquals(1, batchRequest.getRequests().size());
if (batchRequest.getCurrentRequest() instanceof ModifyRequest) {
assertTrue(true);
} else {
fail();
}
}
use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.
the class ModifyRequestTest method testRequestWithOperationAdd.
/**
* Test parsing of a request with operation attribute to Add value
* @throws NamingException
*/
@Test
public void testRequestWithOperationAdd() throws LdapException {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(ModifyRequestTest.class.getResource("request_with_operation_add.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());
}
use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.
the class ModifyRequestTest method testRequestWith1Modification.
/**
* Test parsing of a request with a Modification element
* @throws NamingException
*/
@Test
public void testRequestWith1Modification() throws LdapException {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(ModifyRequestTest.class.getResource("request_with_1_modification.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("CN=John Smith, DC=microsoft, 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 testRequestWithModificationWithoutValue.
/**
* Test parsing of a request with a Modification element without Value element
* @throws NamingException
*/
@Test
public void testRequestWithModificationWithoutValue() throws LdapException {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(ModifyRequestTest.class.getResource("request_with_modification_without_value.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(0, attribute.size());
}
Aggregations