<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xmlns:int="http://www.springframework.org/schema/integration"
	   xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
	   xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
		http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/integration/mongodb https://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd">

	<int:channel id="in"/>

	<int:channel id="out">
		<int:queue capacity="5"/>
	</int:channel>

	<int-mongodb:outbound-gateway id="gatewaySingleQuery"
								  mongodb-factory="mongoDbFactory"
								  mongo-converter="mongoConverter"
								  query="{name: 'Xavi'}"
								  collection-name="data"
								  expect-single-result="true"
								  request-channel="in"
								  reply-channel="out"
								  entity-class="org.springframework.integration.mongodb.MongoDbContainerTest$Person"/>

	<int-mongodb:outbound-gateway id="gatewayWithTemplate"
								  mongo-template="mongoDbTemplate"
								  query="{name: 'Xavi'}"
								  collection-name="data"
								  expect-single-result="true"
								  request-channel="in"
								  reply-channel="out"
								  entity-class="org.springframework.integration.mongodb.MongoDbContainerTest$Person"/>

	<int-mongodb:outbound-gateway id="gatewaySingleQueryExpression"
								  mongodb-factory="mongoDbFactory"
								  mongo-converter="mongoConverter"
								  query-expression="headers.query"
								  collection-name-expression="headers.collectionName"
								  expect-single-result="true"
								  request-channel="in"
								  reply-channel="out"
								  entity-class="org.springframework.integration.mongodb.MongoDbContainerTest$Person"/>

	<int-mongodb:outbound-gateway id="gatewayQueryExpression"
								  mongodb-factory="mongoDbFactory"
								  mongo-converter="mongoConverter"
								  query-expression="headers.query"
								  collection-name-expression="headers.collectionName"
								  expect-single-result="false"
								  request-channel="in"
								  reply-channel="out"
								  entity-class="org.springframework.integration.mongodb.MongoDbContainerTest$Person"/>

	<int-mongodb:outbound-gateway id="gatewayQueryExpressionLimit"
								  mongodb-factory="mongoDbFactory"
								  mongo-converter="mongoConverter"
								  query-expression="new BasicQuery('{''address.state'' : ''PA''}').limit(2)"
								  collection-name-expression="headers.collectionName"
								  expect-single-result="false"
								  request-channel="in"
								  reply-channel="out"
								  entity-class="org.springframework.integration.mongodb.MongoDbContainerTest$Person"/>

	<int-mongodb:outbound-gateway id="gatewayCollectionCallback"
								  mongodb-factory="mongoDbFactory"
								  mongo-converter="mongoConverter"
								  collection-callback="countCollectionCallback"
								  collection-name-expression="headers.collectionName"
								  request-channel="in"
								  reply-channel="out"
								  entity-class="org.springframework.integration.mongodb.MongoDbContainerTest$Person"/>


	<bean id="mongoDbFactory" class="org.springframework.integration.mongodb.MongoDbContainerTest"
		  factory-method="createMongoDbFactory"/>

	<bean id="mongoDbTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
		<constructor-arg ref="mongoDbFactory"/>
	</bean>

	<bean id="mongoConverter"
		  class="org.springframework.integration.mongodb.MongoDbContainerTest.TestMongoConverter">
		<constructor-arg ref="mongoDbFactory"/>
		<constructor-arg>
			<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
		</constructor-arg>
	</bean>

	<bean id="countCollectionCallback"
		  class="org.springframework.integration.mongodb.MongoDbContainerTest$TestCollectionCallback"/>

</beans>
