@Config(manifest = Config.NONE, reportSdk = 15) @Test(expected = UnsupportedOperationException.class) public void testConnectSdkNotSufficient() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(null); TestClientStatusCallback csb = new TestClientStatusCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); assertEquals(0, mockClient.connectCalls); }
@Test(expected = IllegalArgumentException.class) public void testConnectWebSocketNullCredentialsProvider() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); testClient.connect((AWSCredentialsProvider)null, csb); }
@Test(expected = IllegalArgumentException.class) public void testPublishDataWithCallbackEmptyTopic() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); TestMessageDeliveryCallback mdcb = new TestMessageDeliveryCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); testClient.publishData("test1".getBytes(StringUtils.UTF8), "", AWSIotMqttQos.QOS0, mdcb, "TEST_TOKEN"); }
@Test(expected = IllegalArgumentException.class) public void testPublishDataWithCallbackNullTopic() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); TestMessageDeliveryCallback mdcb = new TestMessageDeliveryCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); testClient.publishData("test1".getBytes(StringUtils.UTF8), null, AWSIotMqttQos.QOS0, mdcb, "TEST_TOKEN"); }
@Test(expected = IllegalArgumentException.class) public void testPublishDataWithCallbackNullQos() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); TestMessageDeliveryCallback mdcb = new TestMessageDeliveryCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); testClient.publishData("test1".getBytes(StringUtils.UTF8), "unit/test/topic", null, mdcb, "TEST_TOKEN"); }
@Test(expected = IllegalArgumentException.class) public void testConnectNullKeyStore() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); testClient.connect((KeyStore) null, csb); assertEquals(0, mockClient.connectCalls); }
@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 testPublishStringWithCallbackNullTopic() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); TestMessageDeliveryCallback mdcb = new TestMessageDeliveryCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); testClient.publishString("test1", null, AWSIotMqttQos.QOS0, mdcb, "TEST_TOKEN"); }
@Test(expected = IllegalArgumentException.class) public void testPublishDataWithCallbackNullData() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); TestMessageDeliveryCallback mdcb = new TestMessageDeliveryCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); testClient.publishData(null, "unit/test/topic", AWSIotMqttQos.QOS0, mdcb, "TEST_TOKEN"); }
@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 = 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 testPublishStringWithCallbackNullQos() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); TestMessageDeliveryCallback mdcb = new TestMessageDeliveryCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); testClient.publishString("test1", "unit/test/topic", null, mdcb, "TEST_TOKEN"); }
@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 testPublishStringWithCallbackNullString() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); TestMessageDeliveryCallback mdcb = new TestMessageDeliveryCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); testClient.publishString(null, "unit/test/topic", AWSIotMqttQos.QOS0, mdcb, "TEST_TOKEN"); }
@Test(expected = IllegalArgumentException.class) public void testPublishStringWithCallbackEmptyTopic() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); TestMessageDeliveryCallback mdcb = new TestMessageDeliveryCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); testClient.publishString("test1", "", AWSIotMqttQos.QOS0, mdcb, "TEST_TOKEN"); }
@Test public void testIsReadyToPublishTrue() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); mockClient.mockConnectSuccess(); assertTrue(testClient.isReadyToPublish()); }
@Test public void testConnectFailureConnectedException() throws Exception { MockMqttClient mockClient = new MockMqttClient(); mockClient.throwsExceptionOnConnect = true; mockClient.connectException = new MqttException(MqttException.REASON_CODE_CLIENT_CONNECTED); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); KeyStore testKeystore = AWSIotKeystoreHelper .getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); assertEquals(MqttManagerConnectionState.Connected, testClient.getConnectionState()); }
@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 testPublishStringEmptyTopic() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); testClient.publishString("test1", "", AWSIotMqttQos.QOS0); assertEquals(1, mockClient.connectCalls); assertEquals(0, mockClient.publishCalls); }
@Test public void testConnectFailureConnectingException() throws Exception { MockMqttClient mockClient = new MockMqttClient(); mockClient.throwsExceptionOnConnect = true; mockClient.connectException = new MqttException(MqttException.REASON_CODE_CONNECT_IN_PROGRESS); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); KeyStore testKeystore = AWSIotKeystoreHelper .getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); assertEquals(MqttManagerConnectionState.Connecting, testClient.getConnectionState()); }