/** * Publish data to an MQTT topic. * * @param data The message payload to be sent as a byte array. * @param topic The topic on which to publish. * @param qos The quality of service requested for this message. */ public void publishData(byte[] data, String topic, AWSIotMqttQos qos) { publishData(data, topic, qos, null, null); }
/** * Get the PEM type. * * @return type */ public PEMObjectType getPEMObjectType() { return PEMObjectType.fromBeginMarker(beginMarker); } }
/** * Wrapper method to notify user if they have specified a callback. * Maps internal state to user connection statuses. */ void userConnectionCallback() { userConnectionCallback(null); }
@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 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 = 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 = AmazonClientException.class) public void testPublishStringQos0Failure() throws Exception { MockMqttClient mockClient = new MockMqttClient(); mockClient.throwsExceptionOnPublish = true; 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(); testClient.publishString("test1", "unit/test/topic", AWSIotMqttQos.QOS0); }
@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(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); }
@Before public void setUp() { testObject = new MyTestObject(1, "test", 2.0); qMessage = new AWSIotMqttQueueMessage("test-topic", "test-message".getBytes(StringUtils.UTF8), AWSIotMqttQos.QOS0, new PublishMessageUserData(mdcb, testObject)); }
/** * For constructed field, return a parser for its content. * * @return A parser for the construct. * @throws IOException if DER cannot be parsed. */ public DerParser getParser() throws IOException { if (!isConstructed()) { throw new IOException("Invalid DER: can't parse primitive entity"); //$NON-NLS-1$ } return new DerParser(value); }
@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(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 = 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 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 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 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 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 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 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); }