use of java.util.function.BiFunction in project riposte by Nike-Inc.
the class AsyncNettyHelperTest method biFunctionWithTracingAndMdc_separate_args_works_as_expected.
@Test
public void biFunctionWithTracingAndMdc_separate_args_works_as_expected() {
// given
Pair<Deque<Span>, Map<String, String>> setupInfo = generateTracingAndMdcInfo();
// when
BiFunction result = AsyncNettyHelper.biFunctionWithTracingAndMdc(biFunctionMock, setupInfo.getLeft(), setupInfo.getRight());
// then
verifyBiFunctionWithTracingAndMdcSupport(result, biFunctionMock, setupInfo.getLeft(), setupInfo.getRight());
}
use of java.util.function.BiFunction in project riposte by Nike-Inc.
the class AsyncNettyHelperTest method biFunctionWithTracingAndMdc_ctx_works_as_expected.
@Test
public void biFunctionWithTracingAndMdc_ctx_works_as_expected() {
// given
Pair<Deque<Span>, Map<String, String>> setupInfo = setupStateWithTracingAndMdcInfo();
// when
BiFunction result = AsyncNettyHelper.biFunctionWithTracingAndMdc(biFunctionMock, ctxMock);
// then
verifyBiFunctionWithTracingAndMdcSupport(result, biFunctionMock, setupInfo.getLeft(), setupInfo.getRight());
}
use of java.util.function.BiFunction in project camel by apache.
the class SpringLdapProducer method process.
/**
* Performs the LDAP operation defined in SpringLdapEndpoint that created
* this producer. The in-message in the exchange must be a map, containing
* the following entries:
*
* <pre>
* key: "dn" - base DN for the LDAP operation
* key: "filter" - necessary for the search operation only; LDAP filter for the search operation,
* see <a http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol>http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol</a>
* key: "attributes" - necessary for the bind operation only; an instance of javax.naming.directory.Attributes,
* containing the information necessary to create an LDAP node.
* key: "password" - necessary for the authentication operation only;
* key: "modificationItems" - necessary for the modify_attributes operation only;
* key: "function" - necessary for the function_driven operation only; provides a flexible hook into the {@link LdapTemplate} to call any method
* key: "request" - necessary for the function_driven operation only; passed into the "function" to enable the client to bind parameters that need to be passed into the {@link LdapTemplate}
* </pre>
*
* The keys are defined as final fields above.
*/
@Override
public void process(Exchange exchange) throws Exception {
@SuppressWarnings("unchecked") Map<String, Object> body = exchange.getIn().getBody(Map.class);
LdapOperation operation = endpoint.getOperation();
if (null == operation) {
throw new UnsupportedOperationException("LDAP operation must not be empty, but you provided an empty operation");
}
String dn = (String) body.get(DN);
if (operation != LdapOperation.FUNCTION_DRIVEN && (StringUtils.isBlank(dn))) {
throw new UnsupportedOperationException("DN must not be empty, but you provided an empty DN");
}
LdapOperations ldapTemplate = endpoint.getLdapTemplate();
switch(operation) {
case SEARCH:
String filter = (String) body.get(FILTER);
exchange.getIn().setBody(ldapTemplate.search(dn, filter, endpoint.scopeValue(), mapper));
break;
case BIND:
Attributes attributes = (Attributes) body.get(ATTRIBUTES);
ldapTemplate.bind(dn, null, attributes);
break;
case UNBIND:
ldapTemplate.unbind(dn);
break;
case AUTHENTICATE:
ldapTemplate.authenticate(LdapQueryBuilder.query().base(dn).filter((String) body.get(FILTER)), (String) body.get(PASSWORD));
break;
case MODIFY_ATTRIBUTES:
ModificationItem[] modificationItems = (ModificationItem[]) body.get(MODIFICATION_ITEMS);
ldapTemplate.modifyAttributes(dn, modificationItems);
break;
case FUNCTION_DRIVEN:
BiFunction<LdapOperations, Object, ?> ldapOperationFunction = (BiFunction<LdapOperations, Object, ?>) body.get(FUNCTION);
Object ldapOperationRequest = body.get(REQUEST);
exchange.getIn().setBody(ldapOperationFunction.apply(ldapTemplate, ldapOperationRequest));
break;
default:
throw new UnsupportedOperationException("Bug in the Spring-LDAP component. Despite of all assertions, you managed to call an unsupported operation '" + operation + "'");
}
}
use of java.util.function.BiFunction in project camel by apache.
the class SpringLdapProducerTest method testFunctionDriven.
@Test
public void testFunctionDriven() throws Exception {
String dn = "cn=dn";
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage();
Map<String, Object> body = new HashMap<String, Object>();
body.put(SpringLdapProducer.DN, dn);
body.put(SpringLdapProducer.REQUEST, dn);
body.put(SpringLdapProducer.FUNCTION, (BiFunction<LdapOperations, String, Void>) (l, q) -> {
l.lookup(q);
return null;
});
when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.FUNCTION_DRIVEN);
processBody(exchange, in, body);
verify(ldapTemplate).lookup(eq(dn));
}
use of java.util.function.BiFunction in project samza by apache.
the class TestStreamGraphImpl method testGetInputStream.
@Test
public void testGetInputStream() {
ApplicationRunner mockRunner = mock(ApplicationRunner.class);
Config mockConfig = mock(Config.class);
StreamSpec testStreamSpec = new StreamSpec("test-stream-1", "physical-stream-1", "test-system");
when(mockRunner.getStreamSpec("test-stream-1")).thenReturn(testStreamSpec);
StreamGraphImpl graph = new StreamGraphImpl(mockRunner, mockConfig);
BiFunction<String, MessageType, TestInputMessageEnvelope> xMsgBuilder = (k, v) -> new TestInputMessageEnvelope(k, v.getValue(), v.getEventTime(), "input-id-1");
MessageStream<TestMessageEnvelope> mInputStream = graph.getInputStream("test-stream-1", xMsgBuilder);
assertEquals(graph.getInputStreams().get(testStreamSpec), mInputStream);
assertTrue(mInputStream instanceof InputStreamInternalImpl);
assertEquals(((InputStreamInternalImpl) mInputStream).getMsgBuilder(), xMsgBuilder);
String key = "test-input-key";
MessageType msgBody = new MessageType("test-msg-value", 333333L);
TestMessageEnvelope xInputMsg = ((InputStreamInternalImpl<String, MessageType, TestMessageEnvelope>) mInputStream).getMsgBuilder().apply(key, msgBody);
assertEquals(xInputMsg.getKey(), key);
assertEquals(xInputMsg.getMessage().getValue(), msgBody.getValue());
assertEquals(xInputMsg.getMessage().getEventTime(), msgBody.getEventTime());
assertEquals(((TestInputMessageEnvelope) xInputMsg).getInputId(), "input-id-1");
}
Aggregations