Added first try to use Fuse source MQTT client in test units

This commit is contained in:
selva.andre
2012-08-30 18:46:54 +02:00
parent ecaf50a1a8
commit 2b77aa1b54
2 changed files with 49 additions and 9 deletions
+23 -4
View File
@@ -58,6 +58,14 @@
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.fusesource.mqtt-client</groupId>
<artifactId>mqtt-client</artifactId>
<!-- <version>1.4-SNAPSHOT</version>-->
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@@ -101,10 +109,21 @@
</plugins>
</build>
<!-- <repositories>
<repository>
<repositories>
<!-- <repository>
<id>Fusesource Releases</id>
<url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
</repository>
</repositories>-->
</repository>-->
<!-- <repository>
<id>fusesource.snapshots</id>
<name>FuseSource Snapshot Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>-->
</repositories>
</project>
@@ -6,6 +6,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.dna.mqtt.moquette.client.Client;
import org.dna.mqtt.moquette.client.IPublishCallback;
import org.fusesource.mqtt.client.*;
import org.junit.After;
import static org.junit.Assert.*;
import org.junit.Before;
@@ -40,6 +41,26 @@ public class ServerIntegrationTest {
}
}
@Ignore
public void testSubscribe_FSClient() throws Exception {
// startServer();
MQTT mqtt = new MQTT();
// mqtt.setHost("localhost", Server.PORT);
mqtt.setHost("test.mosquitto.org", Server.PORT);
mqtt.setClientId("TestClient");
FutureConnection connection = mqtt.futureConnection();
connection.connect().await();
Topic[] topics = {new Topic("/topic", QoS.AT_MOST_ONCE)};
Future<byte[]> futSub = connection.subscribe(topics);
connection.publish("/topic", "Test my payload".getBytes(), QoS.AT_MOST_ONCE, false).await();
byte[] qoses = futSub.await();
assertEquals(1, qoses.length);
connection.disconnect().await();
}
@Test
public void testSubscribe() throws IOException, InterruptedException {
@@ -47,20 +68,20 @@ public class ServerIntegrationTest {
Client client = new Client("localhost", Server.PORT);
// Client client = new Client("test.mosquitto.org", 1883);
client.connect();
client.subscribe("/topic", new IPublishCallback() {
public void published(String topic, byte[] message) {
received = true;
}
});
client.publish("/topic", "Test my payload".getBytes());
client.close();
client.shutdown();
assertTrue(received);
}