This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#22 Adding deviceId to REC content in MQTT
- Loading branch information
Showing
5 changed files
with
106 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package no.entra.bacnet.agent.mqtt; | ||
|
||
import no.entra.bacnet.agent.devices.DeviceId; | ||
import no.entra.bacnet.rec.RealEstateCore; | ||
|
||
import java.net.InetAddress; | ||
import java.util.Optional; | ||
|
||
public interface MqttClient { | ||
|
||
void publishRealEstateCore(RealEstateCore message, Optional<InetAddress> sourceAddress); | ||
void publishRealEstateCore(RealEstateCore message, DeviceId recDeviceId, Optional<InetAddress> sourceAddress); | ||
void publishUnknownHexString(String hexString); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/test/java/no/entra/bacnet/agent/mqtt/AzureIoTMqttClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package no.entra.bacnet.agent.mqtt; | ||
|
||
import com.microsoft.azure.sdk.iot.device.Message; | ||
import no.entra.bacnet.agent.devices.DeviceId; | ||
import no.entra.bacnet.rec.ConfigurationRequest; | ||
import no.entra.bacnet.rec.helpers.DateTimeHelper; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.skyscreamer.jsonassert.JSONAssert; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class AzureIoTMqttClientTest { | ||
|
||
private LocalDateTime observationTime; | ||
private AzureIoTMqttClient mqttClient; | ||
private String expectedJson = "{\n" + | ||
" \"deviceId\": \"id1234\",\n" + | ||
" \"configurations\": [{\n" + | ||
" \"sender\": \"sendt from\",\n" + | ||
" \"recipient\": \"recip\",\n" + | ||
" \"observationTime\": \"2019-12-09T20:57:17.776468\",\n" + | ||
" \"id\": \"123\",\n" + | ||
" \"type\": \"IHave\",\n" + | ||
" \"properties\": {\n" + | ||
" \"ObjectName\": \"TFM434\"\n" + | ||
" }\n" + | ||
" }]\n" + | ||
"}"; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
String localDateTime = "2019-12-09T20:57:17.776468"; | ||
observationTime = DateTimeHelper.fromIsoString(localDateTime); | ||
mqttClient = new AzureIoTMqttClient(); | ||
} | ||
|
||
@Test | ||
public void buildMqttMessage() { | ||
ConfigurationRequest recMessage = new ConfigurationRequest(); | ||
recMessage.setObservationTime(observationTime); | ||
recMessage.setId("123"); | ||
recMessage.setRecipient("recip"); | ||
recMessage.setSender("sendt from"); | ||
recMessage.setType("IHave"); | ||
recMessage.addProperty("ObjectName", "TFM434"); | ||
DeviceId recDeviceId = new DeviceId("id1234"); | ||
recDeviceId.setTfmTag("TFM767"); | ||
Message mqttMessage = mqttClient.buildMqttMessage(recMessage, recDeviceId, Optional.empty()); | ||
assertNotNull(mqttMessage); | ||
byte[] bodyBytes = mqttMessage.getBytes(); | ||
String bodyJson = new String(bodyBytes); | ||
assertNotNull(bodyJson); | ||
JSONAssert.assertEquals(expectedJson, bodyJson, true); | ||
} | ||
} |