You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Imran Raza Khan <im...@gmail.com> on 2019/07/16 17:15:24 UTC

MQTT and Protobuf Route Test issue in Apache Camel 2.24.1

i have develop a route like below with test

    public class ShutdownPC extends RouteBuilder
    {
        @Override
        public void configure() throws Exception
        {
            from("mqtt:UpsStatus?host=tcp://1.1.1.1:1883
&userName=x&password=x&subscribeTopicNames=ups_status")
            .unmarshal()
            .protobuf("com.my$UpsStatus")
            .choice()
                .when().simple("${body.getLowBattery()} == true")
                    .log("Shutdown PC")
                    .to("exec:shutdown?args=-h now")
                .otherwise()
                    .log("Dont Shutdown PC")
            .end();
        }
    }
This work fine but i write test for it which is failing and always connect
to real broker rather then local broker which i mentioned for testing and
how i can improve this test

    public class ShutdownPCTest extends CamelTestSupport {
        @Override
        public void setUp() throws Exception {
            super.setUp();
            this.context.addRoutes(new ShutdownPC());
        }

        @Test
        public void testShutdownPC() throws Exception {
            UPSStatus upsStatus =
UPSStatus.newBuilder().setLowBattery(true).build();

            MQTT mqtt = new MQTT();
            mqtt.setHost("tcp://127.0.0.1:1883");
            BlockingConnection publisherConnection =
mqtt.blockingConnection();
            publisherConnection.connect();
            publisherConnection.publish("ups_status",
upsStatus.toByteArray(), QoS.AT_LEAST_ONCE, false);
        }

        @After
        public void tearDown() throws Exception {
            super.tearDown();
        }
    }