Code review comment: I am planning to do another round of cleanup to make things a bit more consistent , I will address this later during the code cleanup ;)

Code before review:
public void publishTelemetryLifecycleTest(HttpClient httpClient, DigitalTwinsServiceVersion serviceVersion) {
DigitalTwinsAsyncClient client = getAsyncClient(httpClient, serviceVersion);
String wifiModelId = UniqueIdHelper.getUniqueModelId(TestAssetDefaults.WIFI_MODEL_ID_PREFIX, client, randomIntegerStringGenerator);
String roomWithWifiModelId = UniqueIdHelper.getUniqueModelId(TestAssetDefaults.ROOM_WITH_WIFI_MODEL_ID_PREFIX, client, randomIntegerStringGenerator);
String roomWithWifiTwinId = UniqueIdHelper.getUniqueDigitalTwinId(TestAssetDefaults.ROOM_WITH_WIFI_TWIN_ID_PREFIX, client, randomIntegerStringGenerator);
try {
createModelsAndTwins(client, wifiModelId, roomWithWifiModelId, roomWithWifiTwinId);
PublishTelemetryRequestOptions telemetryRequestOptions = new PublishTelemetryRequestOptions().setMessageId(testResourceNamer.randomUuid());
StepVerifier.create(client.publishTelemetryWithResponse(
roomWithWifiTwinId,
"{\"Telemetry1\": 5}",
telemetryRequestOptions,
Context.NONE))
.assertNext(createResponse -> assertThat(createResponse.getStatusCode())
.as("Publish telemetry succeeds")
.isEqualTo(HttpURLConnection.HTTP_NO_CONTENT))
.verifyComplete();
PublishTelemetryRequestOptions componentTelemetryRequestOptions = new PublishTelemetryRequestOptions().setMessageId(testResourceNamer.randomUuid());
Dictionary<String, Integer> telemetryPayload = new Hashtable<>();
telemetryPayload.put("ComponentTelemetry1", 9);
String telemetryStringPayload = new ObjectMapper().writeValueAsString(telemetryPayload);
StepVerifier.create(client.publishComponentTelemetryWithResponse(
roomWithWifiTwinId,
TestAssetDefaults.WIFI_COMPONENT_NAME,
telemetryStringPayload,
componentTelemetryRequestOptions,
Context.NONE))
.assertNext(createResponse -> assertThat(createResponse.getStatusCode())
.as("Publish telemetry succeeds")
.isEqualTo(HttpURLConnection.HTTP_NO_CONTENT))
.verifyComplete();
}
catch (Exception ex) {
fail("Failure in executing a step in the test case", ex);
}
finally {
try {
if (roomWithWifiTwinId != null){
client.deleteDigitalTwin(roomWithWifiTwinId).block();
}
if (roomWithWifiModelId != null){
client.deleteModel(roomWithWifiModelId).block();
}
if(wifiModelId != null){
client.deleteModel(wifiModelId).block();
}
}
catch (Exception ex) {
fail("Test cleanup failed", ex);
}
}
}

Line under review: createModelsAndTwins(client, wifiModelId, roomWithWifiModelId, roomWithWifiTwinId);

Code after addressing the review:
public void publishTelemetryLifecycleTest(HttpClient httpClient, DigitalTwinsServiceVersion serviceVersion) {
DigitalTwinsAsyncClient client = getAsyncClient(httpClient, serviceVersion);
String wifiModelId = UniqueIdHelper.getUniqueModelId(TestAssetDefaults.WIFI_MODEL_ID_PREFIX, client, randomIntegerStringGenerator);
String roomWithWifiModelId = UniqueIdHelper.getUniqueModelId(TestAssetDefaults.ROOM_WITH_WIFI_MODEL_ID_PREFIX, client, randomIntegerStringGenerator);
String roomWithWifiTwinId = UniqueIdHelper.getUniqueDigitalTwinId(TestAssetDefaults.ROOM_WITH_WIFI_TWIN_ID_PREFIX, client, randomIntegerStringGenerator);
try {
createModelsAndTwins(client, wifiModelId, roomWithWifiModelId, roomWithWifiTwinId);
PublishTelemetryRequestOptions telemetryRequestOptions = new PublishTelemetryRequestOptions().setMessageId(testResourceNamer.randomUuid());
StepVerifier.create(client.publishTelemetryWithResponse(
roomWithWifiTwinId,
"{\"Telemetry1\": 5}",
telemetryRequestOptions,
Context.NONE))
.assertNext(createResponse -> assertThat(createResponse.getStatusCode())
.as("Publish telemetry succeeds")
.isEqualTo(HttpURLConnection.HTTP_NO_CONTENT))
.verifyComplete();
PublishTelemetryRequestOptions componentTelemetryRequestOptions = new PublishTelemetryRequestOptions().setMessageId(testResourceNamer.randomUuid());
Dictionary<String, Integer> telemetryPayload = new Hashtable<>();
telemetryPayload.put("ComponentTelemetry1", 9);
String telemetryStringPayload = new ObjectMapper().writeValueAsString(telemetryPayload);
StepVerifier.create(client.publishComponentTelemetryWithResponse(
roomWithWifiTwinId,
TestAssetDefaults.WIFI_COMPONENT_NAME,
telemetryStringPayload,
componentTelemetryRequestOptions,
Context.NONE))
.assertNext(createResponse -> assertThat(createResponse.getStatusCode())
.as("Publish telemetry succeeds")
.isEqualTo(HttpURLConnection.HTTP_NO_CONTENT))
.verifyComplete();
}
catch (Exception ex) {
fail("Failure in executing a step in the test case", ex);
}
finally {
try {
if (roomWithWifiTwinId != null){
client.deleteDigitalTwin(roomWithWifiTwinId).block();
}
if (roomWithWifiModelId != null){
client.deleteModel(roomWithWifiModelId).block();
}
if(wifiModelId != null){
client.deleteModel(wifiModelId).block();
}
}
catch (Exception ex) {
fail("Test cleanup failed", ex);
}
}
}