/*
 *  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.karaf.itests.examples;

import org.apache.karaf.itests.KarafTestSupport;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerMethod;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

import static org.junit.Assert.assertEquals;

@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class CamelExampleTest extends KarafTestSupport {

    public void setup() throws Exception {
        addFeaturesRepository("mvn:org.apache.karaf.examples/karaf-camel-example-features/" + System.getProperty("karaf.version") + "/xml");
    }

    @Test
    public void testJavaDSL() throws Exception {
        setup();
        installAndAssertFeature("karaf-camel-example-java");
        verify();
    }

    @Test
    public void testBlueprintDSL() throws Exception {
        setup();
        installAndAssertFeature("karaf-camel-example-blueprint");
        verify();
    }

    public void verify() throws Exception {
        String output = executeCommand("camel:route-list");
        while (true) {
            if (!output.contains("Started")) {
                Thread.sleep(500);
                output = executeCommand("camel:route-list");
            } else {
                break;
            }
        }
        System.out.println(output);

        URL url = new URL("http://localhost:9090/example");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setDoOutput(true);
        connection.setDoInput(true);

        PrintWriter writer = new PrintWriter(new OutputStreamWriter(connection.getOutputStream()));
        writer.println("{ \"notification\": { \"type\": \"email\", \"to\": \"foo@bar.com\", \"message\": \"this is a test\" }}");
        writer.flush();
        writer.close();

        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String line;
        StringBuffer buffer = new StringBuffer();
        while ((line = reader.readLine()) != null) {
            buffer.append(line);
        }
        reader.close();

        output = buffer.toString();
        System.out.println(output);
        assertEquals("{ \"status\": \"email sent\", \"to\": \"foo@bar.com\", \"subject\": \"Notification\" }", output);

        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setDoOutput(true);
        connection.setDoInput(true);

        writer = new PrintWriter(new OutputStreamWriter(connection.getOutputStream()));
        writer.println("{ \"notification\": { \"type\": \"http\", \"service\": \"http://foo\" }}");
        writer.flush();
        writer.close();

        reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        buffer = new StringBuffer();
        while ((line = reader.readLine()) != null) {
            buffer.append(line);
        }
        reader.close();

        output = buffer.toString();
        System.out.println(output);
        assertEquals("{ \"status\": \"http requested\", \"service\": \"http://foo\" }", output);
    }

}

@@ -1994,32 +1994,8 @@
 ile 
-(true) %7B%0A            if 
 (!ou
@@ -2034,20 +2034,16 @@
         
-    
 Thread.s
@@ -2061,28 +2061,24 @@
             
- 
-   
 output = exe
@@ -2114,66 +2114,8 @@
 %22);%0A
-            %7D else %7B%0A                break;%0A            %7D%0A
     

Change waiting loop in CamelExampleTest