/**
 * Licensed to the Rhiot under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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 io.rhiot.io.rhiot.component.gps.gpsd;

import io.rhiot.component.gps.gpsd.ClientGpsCoordinates;
import io.rhiot.component.gps.gpsd.GpsdConstants;
import io.rhiot.deployer.detector.Device;
import io.rhiot.deployer.detector.DeviceDetector;
import io.rhiot.deployer.detector.SimplePortScanningDeviceDetector;
import io.rhiot.utils.Networks;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.TimeUnit;

import static io.rhiot.deployer.detector.Device.DEVICE_RASPBERRY_PI_2;
import static org.junit.Assume.assumeTrue;

public class GpsdProducerIntegrationTest extends CamelTestSupport {

    private static final Logger LOG = LoggerFactory.getLogger(GpsdProducerIntegrationTest.class);
    static boolean isRpiAvailable;
    static DeviceDetector deviceDetector = new SimplePortScanningDeviceDetector();
    static String piAddress;
    static List<Device> devices;

    @BeforeClass
    public static void beforeClass() {

        devices = deviceDetector.detectDevices();
        piAddress = devices.size() == 1 ? devices.get(0).address().getHostAddress() : null;
        isRpiAvailable = devices.size() == 1 && devices.get(0).type().equals(DEVICE_RASPBERRY_PI_2) &&
                Networks.available(piAddress, GpsdConstants.DEFAULT_PORT);

        assumeTrue(isRpiAvailable);
    }

    @AfterClass
    public static void afterClass() {
        deviceDetector.close();
    }

    
    @Test
    public void testGpsdProducer() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:foo");
        mock.expectedMessageCount(1);

        ClientGpsCoordinates coordinates = template.requestBody("gpsd:gps?host=" + piAddress, "", ClientGpsCoordinates.class);

        //Should get only 1 message within 5 seconds
        assertMockEndpointsSatisfied(5, TimeUnit.SECONDS);
    }
    
    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() {
                from("timer:gps").to("gpsd://gpsSpeedTest?host=" + piAddress).to("mock:foo");
            }
        };
    }
}

@@ -821,65 +821,8 @@
 d;%0A%0A
-import io.rhiot.component.gps.gpsd.ClientGpsCoordinates;%0A
 impo
@@ -867,16 +867,16 @@
 stants;%0A
+
 import i
@@ -1297,65 +1297,8 @@
 est;
-%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aim
@@ -1545,106 +1545,8 @@
  %7B%0A%0A
-    private static final Logger LOG = LoggerFactory.getLogger(GpsdProducerIntegrationTest.class);%0A
     
@@ -2400,25 +2400,24 @@
 unt(1);%0A
-%0A
         
 ClientGp
@@ -2412,127 +2412,8 @@
     
-ClientGpsCoordinates coordinates = template.requestBody(%22gpsd:gps?host=%22 + piAddress, %22%22, ClientGpsCoordinates.class);%0A
 %0A   
@@ -2683,24 +2683,24 @@
 nfigure() %7B%0A
+
             
@@ -2739,17 +2739,8 @@
 /gps
-SpeedTest
 ?hos

Add producer to the camel-gpsd component (#227)