options.setWill(mqttLWT.getTopic(), mqttLWT.getMessage().getBytes(), mqttLWT.getQos().asInt(), false);
@Test public void testTopic() throws Exception { AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament("test/lwt", "bye", AWSIotMqttQos.QOS0); assertEquals("test/lwt", lwt.getTopic()); }
@Test public void testQos() throws Exception { AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament("test/lwt", "bye", AWSIotMqttQos.QOS0); assertEquals(AWSIotMqttQos.QOS0, lwt.getQos()); }
@Test public void testMessage() throws Exception { AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament("test/lwt", "bye", AWSIotMqttQos.QOS0); assertEquals("bye", lwt.getMessage()); }
testClient.setOfflinePublishQueueBound(50); AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament("test/lwt", "bye", AWSIotMqttQos.QOS0); testClient.setMqttLastWillAndTestament(lwt); assertEquals(50L, (long)testClient.getOfflinePublishQueueBound()); assertEquals("test/lwt", testClient.getMqttLastWillAndTestament().getTopic()); assertEquals("bye", testClient.getMqttLastWillAndTestament().getMessage()); assertEquals(AWSIotMqttQos.QOS0, testClient.getMqttLastWillAndTestament().getQos());
@Test(expected=IllegalArgumentException.class) public void testCreateLwtWithNullTopic() throws Exception { AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament(null, "bye", AWSIotMqttQos.QOS0); } @Test(expected=IllegalArgumentException.class)
@Test(expected=IllegalArgumentException.class) public void testCreateLwtWithEmptyTopic() throws Exception { AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament("", "bye", AWSIotMqttQos.QOS0); } @Test(expected=IllegalArgumentException.class)
options.setWill(mqttLWT.getTopic(), mqttLWT.getMessage().getBytes(), mqttLWT.getQos().asInt(), false);
@Test(expected=IllegalArgumentException.class) public void testCreateLwtWithNullQos() throws Exception { AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament("test/lwt", "bye", null); } }
options.setWill(mqttLWT.getTopic(), mqttLWT.getMessage().getBytes(), mqttLWT.getQos().asInt(), false);
@Test(expected=IllegalArgumentException.class) public void testCreateLwtWithNullMessage() throws Exception { AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament("test/lwt", null, AWSIotMqttQos.QOS0); } @Test(expected=IllegalArgumentException.class)
options.setWill(mqttLWT.getTopic(), mqttLWT.getMessage().getBytes(), mqttLWT.getQos().asInt(), false);
@Test public void testConnectWithLwt() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament("test/lwt", "bye", AWSIotMqttQos.QOS0); testClient.setMqttLastWillAndTestament(lwt); TestClientStatusCallback csb = new TestClientStatusCallback(); KeyStore testKeystore = AWSIotKeystoreHelper .getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); mockClient.mockConnectSuccess(); assertEquals(1, mockClient.connectCalls); assertTrue(mockClient.mostRecentOptions.isCleanSession()); assertEquals(300, mockClient.mostRecentOptions.getKeepAliveInterval()); assertEquals("test/lwt", mockClient.mostRecentOptions.getWillDestination()); assertEquals("bye", new String(mockClient.mostRecentOptions.getWillMessage().getPayload())); assertEquals(AWSIotMqttQos.QOS0.asInt(), mockClient.mostRecentOptions.getWillMessage().getQos()); assertFalse(mockClient.mostRecentOptions.getWillMessage().isRetained()); assertEquals(2, csb.statuses.size()); assertEquals(AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus.Connecting, csb.statuses.get(0)); assertEquals(AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus.Connected, csb.statuses.get(1)); assertEquals(MqttManagerConnectionState.Connected, testClient.getConnectionState()); }
options.setWill(mqttLWT.getTopic(), mqttLWT.getMessage().getBytes(), mqttLWT.getQos().asInt(), false);
AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament("my/lwt/topic", "Android client lost connection", AWSIotMqttQos.QOS0); mqttManager.setMqttLastWillAndTestament(lwt);
options.setWill(mqttLWT.getTopic(), mqttLWT.getMessage().getBytes(), mqttLWT.getQos().asInt(), false);
testClient.setKeepAlive(15); AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament("test/lwt", "bye", AWSIotMqttQos.QOS0); testClient.setMqttLastWillAndTestament(lwt);