/** 
 * 
 * Copyright 2004 Protique Ltd
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 * 
 **/
package org.activemq.ws.notification.impl;

import org.activemq.ws.notification.impl.invoke.ActiveSOAPNotificationConsumer;
import org.activemq.ws.xmlbeans.addressing.v2003_03.EndpointReferenceType;
import org.activemq.ws.xmlbeans.notification.base.NotifyDocument;
import org.codehaus.activesoap.SoapService;
import org.codehaus.activesoap.handler.xmlbeans.XMLBeansRegistry;
import org.codehaus.activesoap.transport.LocalTransportClient;

/**
 * @version $Revision: 1.1 $
 */
public class ActiveSOAPNotificationBrokerTest extends TestSupport {

    public void testSubscribeWithSOAPEndpoint() throws Exception {
        StubNotificationConsumer service = new StubNotificationConsumer();

        XMLBeansRegistry registry = new XMLBeansRegistry();
        registry.registerService(service);

        final SoapService serverSide = new SoapService(registry);
        serverSide.setRepairingNamespace(true);

        ActiveMQNotificationBroker broker = new ActiveMQNotificationBroker() {
            protected org.activemq.ws.notification.NotificationConsumer createNotificationConsumer(EndpointReferenceType consumerReference) {
                return ActiveSOAPNotificationConsumer.newSoapInstance(new LocalTransportClient(serverSide));
            }
        };

        addSubscription(broker);
        sendNotification(broker);

        NotifyDocument subNotifyDoc = (NotifyDocument) service.getResult().poll(2000);
        System.out.println("Got Notify: "+subNotifyDoc);
        
        assertValidMessage(subNotifyDoc);
    }



}
