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());
}
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)));
}
Aggregations