<?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"
	   xmlns:tx="http://www.springframework.org/schema/tx"
	   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
		http://www.springframework.org/schema/tx https://www.springframework.org/schema/tx/spring-tx.xsd">

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

	<int-mongodb:inbound-channel-adapter id="mongoInboundAdapter"
										 channel="replyChannel"
										 query="{'name' : 'Bob'}"
										 entity-class="java.lang.Object"
										 auto-startup="false">
		<int:poller fixed-delay="100"/>
	</int-mongodb:inbound-channel-adapter>

	<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterNamedFactory"
										 mongodb-factory="mongoDbFactory"
										 channel="replyChannel"
										 query="{'name' : 'Bob'}"
										 auto-startup="false">
		<int:poller fixed-delay="5000"/>
	</int-mongodb:inbound-channel-adapter>

	<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithTemplate"
										 channel="replyChannel"
										 mongo-template="mongoDbTemplate"
										 query="{'name' : 'Bob'}"
										 expect-single-result="true"
										 entity-class="org.springframework.integration.mongodb.MongoDbContainerTest.Person"
										 auto-startup="false">
		<int:poller fixed-delay="5000"/>
	</int-mongodb:inbound-channel-adapter>

	<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithNamedCollection"
										 channel="replyChannel"
										 collection-name="foo"
										 mongo-template="mongoDbTemplate"
										 query="{'name' : 'Bob'}"
										 entity-class="java.lang.Object"
										 auto-startup="false">
		<int:poller fixed-delay="5000"/>
	</int-mongodb:inbound-channel-adapter>
	<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithStringQueryExpression"
										 channel="replyChannel"
										 collection-name="foo"
										 mongo-template="mongoDbTemplate"
										 query-expression="new String('{''name'' : ''Bob''}')"
										 entity-class="java.lang.Object"
										 auto-startup="false">
		<int:poller fixed-rate="5000"/>
	</int-mongodb:inbound-channel-adapter>

	<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithQueryExpression"
										 channel="replyChannel"
										 collection-name="foo"
										 mongo-template="mongoDbTemplate"
										 query-expression="new BasicQuery('{''name'' : ''Bob''}').limit(1)"
										 entity-class="java.lang.Object"
										 auto-startup="false">
		<int:poller fixed-rate="5000"/>
	</int-mongodb:inbound-channel-adapter>

	<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithNamedCollectionExpression"
										 channel="replyChannel"
										 collection-name-expression="'foo'"
										 mongo-template="mongoDbTemplate"
										 query="{'name' : 'Bob'}"
										 entity-class="java.lang.Object"
										 auto-startup="false">
		<int:poller fixed-delay="5000"/>
	</int-mongodb:inbound-channel-adapter>

	<int-mongodb:inbound-channel-adapter id="inboundAdapterWithOnSuccessDisposition"
										 channel="replyChannel"
										 query="{'name' : 'Bob'}"
										 auto-startup="false">

		<int:poller fixed-delay="200" max-messages-per-poll="1">
			<int:advice-chain synchronization-factory="syncFactory">
				<bean
						class="org.springframework.integration.mongodb.config.MongoDbInboundChannelAdapterIntegrationTests.TestMessageSourceAdvice"/>
				<tx:advice>
					<tx:attributes>
						<tx:method name="*"/>
					</tx:attributes>
				</tx:advice>
			</int:advice-chain>
		</int:poller>
	</int-mongodb:inbound-channel-adapter>

	<int:transaction-synchronization-factory id="syncFactory">
		<int:before-commit expression="@documentCleaner.remove(#mongoTemplate, payload, headers.mongo_collectionName)"/>
		<int:after-commit channel="afterCommitChannel"/>
	</int:transaction-synchronization-factory>

	<int:channel id="afterCommitChannel">
		<int:queue/>
	</int:channel>

	<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithConverter"
										 channel="replyChannel"
										 query="{'name' : 'Bob'}"
										 entity-class="java.lang.Object"
										 mongo-converter="mongoConverter"
										 auto-startup="false">
		<int:poller fixed-delay="100"/>
	</int-mongodb:inbound-channel-adapter>

	<bean id="documentCleaner"
		  class="org.springframework.integration.mongodb.config.MongoDbInboundChannelAdapterIntegrationTests.DocumentCleaner"/>

	<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>

	<int:channel id="replyChannel">
		<int:queue/>
	</int:channel>

	<bean id="transactionManager" class="org.springframework.integration.transaction.PseudoTransactionManager"/>

</beans>
