@Test public void testMessageArrivedThree() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); testClient.subscribeToTopic("unit/test/+", AWSIotMqttQos.QOS0, mcb); testClient.subscribeToTopic("unit/#", AWSIotMqttQos.QOS0, mcb); assertEquals(3, mockClient.subscribeCalls); assertEquals(3, mockClient.mockSubscriptions.size()); MqttMessage msg = new MqttMessage(); msg.setPayload("test payload".getBytes(StringUtils.UTF8)); mockClient.mockCallback.messageArrived("unit/test/topic", msg); assertEquals(3, mcb.receivedMessages.size()); assertEquals("unit/test/topic" + "test payload", mcb.receivedMessages.get(0)); assertEquals("unit/test/topic" + "test payload", mcb.receivedMessages.get(1)); assertEquals("unit/test/topic" + "test payload", mcb.receivedMessages.get(2)); }
mqttManager.subscribeToTopic("sdk/test/integration/ws", AWSIotMqttQos.QOS0, new AWSIotMqttNewMessageCallback() { @Override public void onMessageArrived(String topic, byte[] data) {
mqttManager.subscribeToTopic("sdk/test/integration/ws/reconnect", AWSIotMqttQos.QOS0, new AWSIotMqttNewMessageCallback() { @Override public void onMessageArrived(String topic, byte[] data) {
@Test public void testMessageArrivedTwo() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); testClient.subscribeToTopic("unit/test/+", AWSIotMqttQos.QOS0, mcb); assertEquals(2, mockClient.subscribeCalls); assertEquals(2, mockClient.mockSubscriptions.size()); MqttMessage msg = new MqttMessage(); msg.setPayload("test payload".getBytes(StringUtils.UTF8)); mockClient.mockCallback.messageArrived("unit/test/topic", msg); assertEquals(2, mcb.receivedMessages.size()); assertEquals("unit/test/topic" + "test payload", mcb.receivedMessages.get(0)); assertEquals("unit/test/topic" + "test payload", mcb.receivedMessages.get(1)); }
@Test public void testSubscribeToTopic() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); assertEquals(1, mockClient.subscribeCalls); assertTrue(mockClient.mockSubscriptions.containsKey("unit/test/topic")); assertEquals((Integer) 0, mockClient.mockSubscriptions.get("unit/test/topic")); MqttMessage msg = new MqttMessage(); msg.setPayload("test payload".getBytes(StringUtils.UTF8)); mockClient.mockCallback.messageArrived("unit/test/topic", msg); assertEquals(1, mcb.receivedMessages.size()); assertEquals("unit/test/topic" + "test payload", mcb.receivedMessages.get(0)); }
@Test public void testMessageArrivedOne() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); MqttMessage msg = new MqttMessage(); msg.setPayload("test payload".getBytes(StringUtils.UTF8)); mockClient.mockCallback.messageArrived("unit/test/topic", msg); assertEquals(1, mcb.receivedMessages.size()); assertEquals("unit/test/topic" + "test payload", mcb.receivedMessages.get(0)); }
@Test public void testUnSubscribeTopic() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); assertEquals(1, mockClient.subscribeCalls); assertTrue(mockClient.mockSubscriptions.containsKey("unit/test/topic")); assertEquals((Integer) 0, mockClient.mockSubscriptions.get("unit/test/topic")); MqttMessage msg = new MqttMessage(); msg.setPayload("test payload".getBytes(StringUtils.UTF8)); mockClient.mockCallback.messageArrived("unit/test/topic", msg); assertEquals(1, mcb.receivedMessages.size()); // received first one assertEquals("unit/test/topic" + "test payload", mcb.receivedMessages.get(0)); testClient.unsubscribeTopic("unit/test/topic"); assertEquals(1, mockClient.unsubscribeCalls); assertFalse(mockClient.mockSubscriptions.containsKey("unit/test/topic")); msg.setPayload("test payload".getBytes(StringUtils.UTF8)); mockClient.mockCallback.messageArrived("unit/test/topic", msg); assertEquals(1, mcb.receivedMessages.size()); // didn't receive this one }
@Test public void testMessageArrivedTooShallow() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); MqttMessage msg = new MqttMessage(); msg.setPayload("test payload".getBytes(StringUtils.UTF8)); mockClient.mockCallback.messageArrived("unit/test", msg); assertEquals(0, mcb.receivedMessages.size()); }
@Test public void testMessageArrivedDifferent() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); MqttMessage msg = new MqttMessage(); msg.setPayload("test payload".getBytes(StringUtils.UTF8)); mockClient.mockCallback.messageArrived("unit/test/differenttopic", msg); assertEquals(0, mcb.receivedMessages.size()); }
@Test public void testMessageArrivedTooDeep() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); MqttMessage msg = new MqttMessage(); msg.setPayload("test payload".getBytes(StringUtils.UTF8)); mockClient.mockCallback.messageArrived("unit/test/topic/subtopic", msg); assertEquals(0, mcb.receivedMessages.size()); }
@Test(expected = AmazonClientException.class) public void testSubscribeToTopicException() throws Exception { MockMqttClient mockClient = new MockMqttClient(); mockClient.throwsExceptionOnSubscribe = true; AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); }
@Test(expected = IllegalArgumentException.class) public void testSubscribeToTopicEmptyTopic() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("", AWSIotMqttQos.QOS0, mcb); assertEquals(0, mockClient.subscribeCalls); }
@Test(expected = IllegalArgumentException.class) public void testSubscribeToTopicNullTopic() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic(null, AWSIotMqttQos.QOS0, mcb); assertEquals(0, mockClient.subscribeCalls); }
@Test(expected = IllegalArgumentException.class) public void testSubscribeToTopicNullQos() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", null, mcb); assertEquals(0, mockClient.subscribeCalls); }
@Test(expected = AmazonClientException.class) public void testUnSubscribeToTopicException() throws Exception { MockMqttClient mockClient = new MockMqttClient(); mockClient.throwsExceptionOnUnsubscribe = true; AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); testClient.unsubscribeTopic("unit/test/topic"); }
@Test(expected = IllegalArgumentException.class) public void testUnSubscribeToTopicEmptyTopic() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); testClient.unsubscribeTopic(""); assertEquals(0, mockClient.unsubscribeCalls); }
@Test public void testSubscribeToTopicNullMqttClient() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.setMqttClient(null); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); assertEquals(0, mockClient.subscribeCalls); }
@Test(expected = IllegalArgumentException.class) public void testUnSubscribeToTopicNullTopic() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); testClient.unsubscribeTopic(null); assertEquals(0, mockClient.unsubscribeCalls); }
@Test public void testUnSubscribeToTopicNullMqttClient() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, null); TestNewMessageCallback mcb = new TestNewMessageCallback(); testClient.subscribeToTopic("unit/test/topic", AWSIotMqttQos.QOS0, mcb); testClient.setMqttClient(null); testClient.unsubscribeTopic("unit/test/topic"); assertEquals(0, mockClient.unsubscribeCalls); }
mqttManager.subscribeToTopic("sdk/test/integration/cert/large", AWSIotMqttQos.QOS0, new AWSIotMqttNewMessageCallback() { @Override public void onMessageArrived(String topic, byte[] data) {