org.apache.servicemix.audit.async.TestSupport.java Source code

Java tutorial

Introduction

Here is the source code for org.apache.servicemix.audit.async.TestSupport.java

Source

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.servicemix.audit.async;

import javax.xml.namespace.QName;

import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.xbean.BrokerFactoryBean;
import org.apache.servicemix.client.DefaultServiceMixClient;
import org.apache.servicemix.client.ServiceMixClient;
import org.apache.servicemix.jbi.container.ActivationSpec;
import org.apache.servicemix.jbi.container.JBIContainer;
import org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow;
import org.junit.After;
import org.junit.Before;
import org.springframework.core.io.ClassPathResource;

public abstract class TestSupport {

    protected JBIContainer container;
    protected ServiceMixClient client;

    protected BrokerService broker;

    @Before
    public void setUp() throws Exception {
        System.out.println("Setting up");
        createJmsBroker();

        container = new JBIContainer();
        container.setFlow(new SedaFlow());
        container.init();
        container.start();

        client = new DefaultServiceMixClient(container);
    }

    @After
    public void tearDown() throws Exception {
        System.out.println("Tearing down");
        if (container != null) {
            container.stop();
            container.shutDown();
        }
        if (broker != null) {
            broker.stop();
        }
    }

    protected ActivationSpec createActivationSpec(String name, Object component) {
        ActivationSpec spec = new ActivationSpec(component);
        spec.setComponentName(name);
        spec.setService(new QName("urn:test", name));
        spec.setEndpoint(name);
        return spec;
    }

    protected void createJmsBroker() throws Exception {
        BrokerFactoryBean bfb = new BrokerFactoryBean(
                new ClassPathResource("org/apache/servicemix/audit/async/activemq.xml"));
        bfb.afterPropertiesSet();
        broker = bfb.getBroker();
        broker.start();
    }

}