<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:citrus="http://www.citrusframework.org/schema/config"
              xmlns:citrus-http="http://www.citrusframework.org/schema/http/config"
              xmlns:spring="http://www.springframework.org/schema/beans"
              xmlns:si="http://www.springframework.org/schema/integration"
              xmlns:file="http://www.springframework.org/schema/integration/file"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                  http://www.citrusframework.org/schema/config http://www.citrusframework.org/schema/config/citrus-config.xsd
                  http://www.citrusframework.org/schema/http/config
                  http://www.citrusframework.org/schema/http/config/citrus-http-config.xsd
                  http://www.springframework.org/schema/integration
                  http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
                  http://www.springframework.org/schema/integration/file
                  http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd">

    <!-- Citrus beans, necessary for Citrus to perform checks etc. -->
    <bean id="citrusJMSConnectionFactory"
         class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="vm://localhost:61616" />
        <property name="userName" value="user"/>
        <property name="password" value="password"/>
    </bean>

    <bean id="namespaceContextBuilder" class="com.consol.citrus.xml.namespace.NamespaceContextBuilder">
        <property name="namespaceMappings">
            <props>
                <prop key="ns1">http://www.redstream.nl/invoice</prop>
            </props>
        </property>
    </bean>

    <bean name="redstreamIntegrationTests"
         class="com.consol.citrus.TestSuite">
        <property name="tasksBefore">
            <list>
                <bean class="com.consol.citrus.actions.ExecuteSQLAction">
                    <property name="dataSource" ref="rsDataSource"/>
                    <property name="statements">
                        <list>
                            <value>DELETE FROM RS_LOGS</value>
                        </list>
                    </property>
                </bean>
            </list>
        </property>
    </bean>

    <!-- manadatory if XML files are used in a test -->
    <bean id="xmlMessageValidator" class="com.consol.citrus.validation.xml.DomXmlMessageValidator"/>

    <bean id="schemaRepository"
           class="com.consol.citrus.xml.XsdSchemaRepository">
        <property name="schemas">
            <list>
                <bean class="org.springframework.xml.xsd.SimpleXsdSchema">
                    <property name="xsd"
                               value="classpath:schemas/rs_invoice_0.3.xsd"/>
                </bean>
            </list>
        </property>
    </bean>

    <!--
        *******************
        * RS adapter    *
        *******************
    -->
    <bean id="rsDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="url" value="jdbc:oracle:thin:@test-vm:1521:XE"/>
        <property name="username" value="user"/>
        <property name="password" value="password"/>
        <property name="driverClassName" value="oracle.jdbc.xa.client.OracleXADataSource"/>
        <property name="removeAbandoned" value="true"/>
    </bean>

    <!--
        *******************
        * INVOICE Adapter *
        *******************
    -->
    <citrus:message-channel-sender id="invoiceFileSender" channel="fileOutboundChannel"/>

    <file:outbound-channel-adapter id="invoice-files-out" channel="fileOutboundChannel"
        directory="file://Volumes/staging/invoice" filename-generator="test-filename-generator" />

    <bean id="test-filename-generator" class="nl.redstream.citrus.TestFileNameGenerator" />

    <si:channel id="fileOutboundChannel" />
   

    <!--
         ********************
         * ORDER Adapter   *
         ********************
    -->
    <!-- receive Invoice HTTP request -->
    <citrus-http:server id="orderHttpServer"
               port="8060"
               uri="/services/post-invoice"
               deamon="false"
               message-handler="jmsForwardingMessageHandler"
               auto-start="true"/>


    <!-- Forward all incoming requests to this message handler -->
    <bean id="jmsForwardingMessageHandler"
         class="com.consol.citrus.adapter.handler.JmsConnectingMessageHandler">
        <property name="destinationName" value="Citrus.order-response"/>
        <property name="connectionFactory" ref="citrusJMSConnectionFactory" />
        <property name="replyTimeout" value="6000"/>
    </bean>

    <!-- Process all received requests -->
    <citrus:jms-sync-message-receiver id="orderRequestReceiver"
                            destination-name="Citrus.order-response"
                            connection-factory="citrusJMSConnectionFactory" />
    <citrus:jms-reply-message-sender id="orderResponseSender"
                            reply-destination-holder="orderRequestReceiver"
                            connection-factory="citrusJMSConnectionFactory" />

</beans>
