use of com.unboundid.ldap.protocol.CompareRequestProtocolOp in project ldapsdk by pingidentity.
the class InterceptedCompareOperationTestCase method testBasics.
/**
* Provides basic test coverage for an intercepted compare operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testBasics() throws Exception {
// Create an intercepted compare operation. We'll use a null connection,
// which shouldn't happen naturally but will be sufficient for this test.
final CompareRequestProtocolOp requestOp = new CompareRequestProtocolOp(new CompareRequest("dc=example,dc=com", "description", "foo"));
final InterceptedCompareOperation o = new InterceptedCompareOperation(null, 1, requestOp);
assertNotNull(o.toString());
// Test methods for a generic intercepted operation.
assertNull(o.getClientConnection());
assertEquals(o.getConnectionID(), -1L);
assertNull(o.getConnectedAddress());
assertEquals(o.getConnectedPort(), -1);
assertEquals(o.getMessageID(), 1);
assertNull(o.getProperty("propX"));
o.setProperty("propX", "valX");
assertNotNull(o.getProperty("propX"));
assertEquals(o.getProperty("propX"), "valX");
assertNotNull(o.toString());
o.setProperty("propX", null);
assertNull(o.getProperty("propX"));
// Test methods specific to an intercepted compare operation.
assertNotNull(o.getRequest());
assertEquals(o.getRequest().getAssertionValue(), "foo");
assertNotNull(o.toString());
final CompareRequest r = o.getRequest().duplicate();
r.setAssertionValue("bar");
o.setRequest(r);
assertNotNull(o.getRequest());
assertEquals(o.getRequest().getAssertionValue(), "bar");
assertNotNull(o.toString());
assertNull(o.getResult());
o.setResult(new LDAPResult(o.getMessageID(), ResultCode.SUCCESS));
assertNotNull(o.getResult());
assertNotNull(o.toString());
}
use of com.unboundid.ldap.protocol.CompareRequestProtocolOp in project ldapsdk by pingidentity.
the class CannedResponseRequestHandlerTestCase method testDefaultConstructor.
/**
* Tests the behavior of the request handler with the default configuration.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDefaultConstructor() throws Exception {
final CannedResponseRequestHandler handler = new CannedResponseRequestHandler().newInstance(null);
LDAPMessage m = handler.processAddRequest(1, new AddRequestProtocolOp("dc=example,dc=com", Arrays.asList(new Attribute("objectClass", "top", "domain"), new Attribute("dc", "example"))), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 1);
assertTrue(m.getProtocolOp() instanceof AddResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processBindRequest(2, new BindRequestProtocolOp("uid=admin,dc=example,dc=com", "password"), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 2);
assertTrue(m.getProtocolOp() instanceof BindResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processCompareRequest(3, new CompareRequestProtocolOp("dc=example,dc=com", "objectClass", new ASN1OctetString("top")), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 3);
assertTrue(m.getProtocolOp() instanceof CompareResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processDeleteRequest(4, new DeleteRequestProtocolOp("dc=example,dc=com"), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 4);
assertTrue(m.getProtocolOp() instanceof DeleteResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processExtendedRequest(5, new ExtendedRequestProtocolOp("1.2.3.4", null), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 5);
assertTrue(m.getProtocolOp() instanceof ExtendedResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processModifyRequest(6, new ModifyRequestProtocolOp("dc=example,dc=com", Arrays.asList(new Modification(ModificationType.REPLACE, "description", "foo"))), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 6);
assertTrue(m.getProtocolOp() instanceof ModifyResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processModifyDNRequest(6, new ModifyDNRequestProtocolOp("ou=People,dc=example,dc=com", "ou=Users", true, null), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 6);
assertTrue(m.getProtocolOp() instanceof ModifyDNResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processSearchRequest(7, new SearchRequestProtocolOp("dc=example,dc=com", SearchScope.SUB, DereferencePolicy.NEVER, 0, 0, false, Filter.createEqualityFilter("uid", "test"), Arrays.<String>asList()), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 7);
assertTrue(m.getProtocolOp() instanceof SearchResultDoneProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
}
use of com.unboundid.ldap.protocol.CompareRequestProtocolOp in project ldapsdk by pingidentity.
the class InMemoryDirectoryServer method compare.
/**
* {@inheritDoc}
* <BR><BR>
* This method may be used regardless of whether the server is listening for
* client connections, and regardless of whether compare operations are
* allowed in the server.
*/
@Override()
@NotNull()
public CompareResult compare(@NotNull final CompareRequest compareRequest) throws LDAPException {
final ArrayList<Control> requestControlList = new ArrayList<>(compareRequest.getControlList());
requestControlList.add(new Control(InMemoryRequestHandler.OID_INTERNAL_OPERATION_REQUEST_CONTROL, false));
final LDAPMessage responseMessage = inMemoryHandler.processCompareRequest(1, new CompareRequestProtocolOp(compareRequest.getDN(), compareRequest.getAttributeName(), compareRequest.getRawAssertionValue()), requestControlList);
final CompareResponseProtocolOp compareResponse = responseMessage.getCompareResponseProtocolOp();
final LDAPResult compareResult = new LDAPResult(responseMessage.getMessageID(), ResultCode.valueOf(compareResponse.getResultCode()), compareResponse.getDiagnosticMessage(), compareResponse.getMatchedDN(), compareResponse.getReferralURLs(), responseMessage.getControls());
switch(compareResponse.getResultCode()) {
case ResultCode.COMPARE_TRUE_INT_VALUE:
case ResultCode.COMPARE_FALSE_INT_VALUE:
return new CompareResult(compareResult);
default:
throw new LDAPException(compareResult);
}
}
use of com.unboundid.ldap.protocol.CompareRequestProtocolOp in project ldapsdk by pingidentity.
the class InMemoryOperationInterceptorRequestHandler method processCompareRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processCompareRequest(final int messageID, @NotNull final CompareRequestProtocolOp request, @NotNull final List<Control> controls) {
final InterceptedCompareOperation op = new InterceptedCompareOperation(connection, messageID, request, toArray(controls));
activeOperations.put(messageID, op);
try {
for (final InMemoryOperationInterceptor i : interceptors) {
try {
i.processCompareRequest(op);
} catch (final LDAPException le) {
Debug.debugException(le);
return new LDAPMessage(messageID, new CompareResponseProtocolOp(le.toLDAPResult()), le.getResponseControls());
} catch (final Exception e) {
Debug.debugException(e);
return new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_REQUEST_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null));
}
}
final LDAPMessage resultMessage = wrappedHandler.processCompareRequest(messageID, new CompareRequestProtocolOp((CompareRequest) op.getRequest()), op.getRequest().getControlList());
op.setResult(resultMessage.getCompareResponseProtocolOp().toLDAPResult(toArray(resultMessage.getControls())));
for (final InMemoryOperationInterceptor i : interceptors) {
try {
i.processCompareResult(op);
} catch (final Exception e) {
Debug.debugException(e);
return new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_RESULT_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null));
}
}
return new LDAPMessage(messageID, new CompareResponseProtocolOp(op.getResult()), op.getResult().getResponseControls());
} finally {
activeOperations.remove(messageID);
}
}
Aggregations