Search in sources :

Example 1 with MqttBrokerConnectionEx

use of org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnectionEx in project smarthome by eclipse.

the class MqttServiceTests method brokerConnectionListenerTests.

// Tests addBrokersListener/removeBrokersListener
@Test
public void brokerConnectionListenerTests() throws ConfigurationException {
    MqttService service = new MqttServiceImpl();
    assertFalse(service.hasBrokerObservers());
    MqttServiceObserver observer = mock(MqttServiceObserver.class);
    service.addBrokersListener(observer);
    assertTrue(service.hasBrokerObservers());
    MqttBrokerConnectionEx connection = new MqttBrokerConnectionEx("tcp://123.123.123.123", null, false, "brokerConnectionListenerTests");
    assertTrue(service.addBrokerConnection("name", connection));
    ArgumentCaptor<MqttBrokerConnection> argumentCaptorConn = ArgumentCaptor.forClass(MqttBrokerConnection.class);
    ArgumentCaptor<String> argumentCaptorConnName = ArgumentCaptor.forClass(String.class);
    verify(observer).brokerAdded(argumentCaptorConnName.capture(), argumentCaptorConn.capture());
    assertThat(argumentCaptorConnName.getValue(), equalTo("name"));
    assertThat(argumentCaptorConn.getValue(), equalTo(connection));
    service.removeBrokerConnection("name");
    verify(observer).brokerRemoved(argumentCaptorConnName.capture(), argumentCaptorConn.capture());
    assertThat(argumentCaptorConnName.getValue(), equalTo("name"));
    assertThat(argumentCaptorConn.getValue(), equalTo(connection));
    service.removeBrokersListener(observer);
    assertFalse(service.hasBrokerObservers());
}
Also used : MqttBrokerConnection(org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection) MqttService(org.eclipse.smarthome.io.transport.mqtt.MqttService) MqttServiceObserver(org.eclipse.smarthome.io.transport.mqtt.MqttServiceObserver) MqttBrokerConnectionEx(org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnectionEx) Test(org.junit.Test)

Example 2 with MqttBrokerConnectionEx

use of org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnectionEx in project smarthome by eclipse.

the class MqttServiceTests method brokerConnectionAddRemoveEnumerateTests.

@Test
public void brokerConnectionAddRemoveEnumerateTests() {
    MqttService service = new MqttServiceImpl();
    MqttBrokerConnectionEx connection = new MqttBrokerConnectionEx("tcp://123.123.123.123", null, false, "brokerConnectionAddRemoveEnumerateTests");
    // Add
    assertThat(service.getAllBrokerConnections().size(), is(equalTo(0)));
    assertTrue(service.addBrokerConnection("name", connection));
    assertFalse(service.addBrokerConnection("name", connection));
    // Get/Enumerate
    assertNotNull(service.getBrokerConnection("name"));
    assertThat(service.getAllBrokerConnections().size(), is(equalTo(1)));
    // Remove
    service.removeBrokerConnection("name");
    assertThat(service.getAllBrokerConnections().size(), is(equalTo(0)));
}
Also used : MqttService(org.eclipse.smarthome.io.transport.mqtt.MqttService) MqttBrokerConnectionEx(org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnectionEx) Test(org.junit.Test)

Aggregations

MqttBrokerConnectionEx (org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnectionEx)2 MqttService (org.eclipse.smarthome.io.transport.mqtt.MqttService)2 Test (org.junit.Test)2 MqttBrokerConnection (org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection)1 MqttServiceObserver (org.eclipse.smarthome.io.transport.mqtt.MqttServiceObserver)1