/*
 * 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.camel.component.vm;

import org.apache.camel.CamelContext;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.support.service.ServiceHelper;
import org.junit.After;
import org.junit.Before;

public abstract class AbstractVmTestSupport extends ContextTestSupport {

    protected CamelContext context2;
    protected ProducerTemplate template2;

    @Override
    @Before
    public void setUp() throws Exception {
        super.setUp();
        context2 = new DefaultCamelContext();
        template2 = context2.createProducerTemplate();

        ServiceHelper.startService(template2, context2);

        // add routes after CamelContext has been started
        RouteBuilder routeBuilder = createRouteBuilderForSecondContext();
        if (routeBuilder != null) {
            context2.addRoutes(routeBuilder);
        }
    }

    @Override
    @After
    public void tearDown() throws Exception {
        ServiceHelper.stopService(context2, template2);
        VmComponent.ENDPOINTS.clear();
        VmComponent.QUEUES.clear();
        super.tearDown();
    }

    protected RouteBuilder createRouteBuilderForSecondContext() throws Exception {
        return null;
    }
}

@@ -960,16 +960,49 @@
 mplate;%0A
+import org.apache.camel.Service;%0A
 import o
@@ -1035,24 +1035,24 @@
 uteBuilder;%0A
-
 import org.a
@@ -1550,30 +1550,16 @@
         
-ServiceHelper.
 startSer
@@ -1562,16 +1562,17 @@
 tService
+s
 (templat
@@ -1901,22 +1901,8 @@
     
-ServiceHelper.
 stop
@@ -1908,16 +1908,17 @@
 pService
+s
 (context
@@ -2144,16 +2144,608 @@
 n null;%0A
-
     %7D%0A
+%0A    protected void startServices(Object... services) %7B%0A        for (Object o : services) %7B%0A            if (o instanceof Service) %7B%0A                ((Service) o).start();%0A            %7D else if (o instanceof CamelContext) %7B%0A                ((CamelContext) o).start();%0A            %7D%0A        %7D%0A    %7D%0A%0A    protected void stopServices(Object... services) %7B%0A        for (Object o : services) %7B%0A            if (o instanceof Service) %7B%0A                ((Service) o).stop();%0A            %7D else if (o instanceof CamelContext) %7B%0A                ((CamelContext) o).stop();%0A            %7D%0A        %7D%0A    %7D%0A%0A
 %7D%0A

Fix VM component tests