From e213adcf30285c5bb2ef1cc704de6477f67e2e3f Mon Sep 17 00:00:00 2001 From: dshvaika Date: Tue, 30 Jun 2026 17:09:50 +0300 Subject: [PATCH] test(attributes): inline attribute-key constants, drop redundant locals --- ...AbstractCoapAttributesIntegrationTest.java | 22 +++++-------- ...AbstractMqttAttributesIntegrationTest.java | 32 +++++++------------ 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/application/src/test/java/org/thingsboard/server/transport/coap/attributes/AbstractCoapAttributesIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/coap/attributes/AbstractCoapAttributesIntegrationTest.java index f5b04049b2..a19718d601 100644 --- a/application/src/test/java/org/thingsboard/server/transport/coap/attributes/AbstractCoapAttributesIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/coap/attributes/AbstractCoapAttributesIntegrationTest.java @@ -175,10 +175,8 @@ public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoap client = new CoapTestClient(accessToken, FeatureType.ATTRIBUTES); SingleEntityFilter dtf = new SingleEntityFilter(); dtf.setSingleEntity(AliasEntityId.fromEntityId(savedDevice.getId())); - String clientKeysStr = CLIENT_ATTRIBUTE_KEYS; - String sharedKeysStr = SHARED_ATTRIBUTE_KEYS; - List clientKeysList = List.of(clientKeysStr.split(",")); - List sharedKeysList = List.of(sharedKeysStr.split(",")); + List clientKeysList = List.of(CLIENT_ATTRIBUTE_KEYS.split(",")); + List sharedKeysList = List.of(SHARED_ATTRIBUTE_KEYS.split(",")); List csKeys = getEntityKeys(clientKeysList, CLIENT_ATTRIBUTE); List shKeys = getEntityKeys(sharedKeysList, SHARED_ATTRIBUTE); List keys = new ArrayList<>(); @@ -196,7 +194,7 @@ public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoap String update = getWsClient().waitForUpdate(); assertThat(update).as("ws update received").isNotBlank(); - String featureTokenUrl = CoapTestClient.getFeatureTokenUrl(accessToken, FeatureType.ATTRIBUTES) + "?clientKeys=" + clientKeysStr + "&sharedKeys=" + sharedKeysStr; + String featureTokenUrl = CoapTestClient.getFeatureTokenUrl(accessToken, FeatureType.ATTRIBUTES) + "?clientKeys=" + CLIENT_ATTRIBUTE_KEYS + "&sharedKeys=" + SHARED_ATTRIBUTE_KEYS; client.setURI(featureTokenUrl); validateJsonResponse(client.getMethod()); } @@ -205,11 +203,9 @@ public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoap client = new CoapTestClient(accessToken, FeatureType.ATTRIBUTES); SingleEntityFilter dtf = new SingleEntityFilter(); dtf.setSingleEntity(AliasEntityId.fromEntityId(savedDevice.getId())); - String clientKeysStr = CLIENT_ATTRIBUTE_KEYS; - String sharedKeysStr = SHARED_ATTRIBUTE_KEYS; List keys = new ArrayList<>(); - keys.addAll(getEntityKeys(List.of(clientKeysStr.split(",")), CLIENT_ATTRIBUTE)); - keys.addAll(getEntityKeys(List.of(sharedKeysStr.split(",")), SHARED_ATTRIBUTE)); + keys.addAll(getEntityKeys(List.of(CLIENT_ATTRIBUTE_KEYS.split(",")), CLIENT_ATTRIBUTE)); + keys.addAll(getEntityKeys(List.of(SHARED_ATTRIBUTE_KEYS.split(",")), SHARED_ATTRIBUTE)); getWsClient().subscribeLatestUpdate(keys, dtf); getWsClient().registerWaitForUpdate(2); @@ -233,10 +229,8 @@ public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoap client = new CoapTestClient(accessToken, FeatureType.ATTRIBUTES); SingleEntityFilter dtf = new SingleEntityFilter(); dtf.setSingleEntity(AliasEntityId.fromEntityId(savedDevice.getId())); - String clientKeysStr = CLIENT_ATTRIBUTE_KEYS; - String sharedKeysStr = SHARED_ATTRIBUTE_KEYS; - List clientKeysList = List.of(clientKeysStr.split(",")); - List sharedKeysList = List.of(sharedKeysStr.split(",")); + List clientKeysList = List.of(CLIENT_ATTRIBUTE_KEYS.split(",")); + List sharedKeysList = List.of(SHARED_ATTRIBUTE_KEYS.split(",")); List csKeys = getEntityKeys(clientKeysList, CLIENT_ATTRIBUTE); List shKeys = getEntityKeys(sharedKeysList, SHARED_ATTRIBUTE); List keys = new ArrayList<>(); @@ -254,7 +248,7 @@ public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoap String update = getWsClient().waitForUpdate(); assertThat(update).as("ws update received").isNotBlank(); - String featureTokenUrl = CoapTestClient.getFeatureTokenUrl(accessToken, FeatureType.ATTRIBUTES) + "?clientKeys=" + clientKeysStr + "&sharedKeys=" + sharedKeysStr; + String featureTokenUrl = CoapTestClient.getFeatureTokenUrl(accessToken, FeatureType.ATTRIBUTES) + "?clientKeys=" + CLIENT_ATTRIBUTE_KEYS + "&sharedKeys=" + SHARED_ATTRIBUTE_KEYS; client.setURI(featureTokenUrl); validateProtoResponse(client.getMethod()); } diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/AbstractMqttAttributesIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/AbstractMqttAttributesIntegrationTest.java index 8d4cc6a6ae..4c2ffc8364 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/AbstractMqttAttributesIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/AbstractMqttAttributesIntegrationTest.java @@ -344,10 +344,8 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt client.connectAndWait(accessToken); SingleEntityFilter dtf = new SingleEntityFilter(); dtf.setSingleEntity(AliasEntityId.fromEntityId(savedDevice.getId())); - String clientKeysStr = CLIENT_ATTRIBUTE_KEYS; - String sharedKeysStr = SHARED_ATTRIBUTE_KEYS; - List clientKeysList = List.of(clientKeysStr.split(",")); - List sharedKeysList = List.of(sharedKeysStr.split(",")); + List clientKeysList = List.of(CLIENT_ATTRIBUTE_KEYS.split(",")); + List sharedKeysList = List.of(SHARED_ATTRIBUTE_KEYS.split(",")); List csKeys = getEntityKeys(clientKeysList, CLIENT_ATTRIBUTE); List shKeys = getEntityKeys(sharedKeysList, SHARED_ATTRIBUTE); List keys = new ArrayList<>(); @@ -365,7 +363,7 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt assertThat(update).as("ws update received").isNotBlank(); MqttTestCallback callback = new MqttTestSubscribeOnTopicCallback(attrSubTopic.replace("+", "1")); client.setCallback(callback); - String payloadStr = "{\"clientKeys\":\"" + clientKeysStr + "\", \"sharedKeys\":\"" + sharedKeysStr + "\"}"; + String payloadStr = "{\"clientKeys\":\"" + CLIENT_ATTRIBUTE_KEYS + "\", \"sharedKeys\":\"" + SHARED_ATTRIBUTE_KEYS + "\"}"; client.publishAndWait(attrReqTopicPrefix + "1", payloadStr.getBytes()); String expectedResponse = "{\"client\":" + CLIENT_ATTRIBUTES_PAYLOAD + ",\"shared\":" + SHARED_ATTRIBUTES_PAYLOAD + "}"; validateJsonResponse(callback, expectedResponse); @@ -398,10 +396,8 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt MqttTestClient client = new MqttTestClient(); client.connectAndWait(accessToken); DeviceTypeFilter dtf = new DeviceTypeFilter(List.of(savedDevice.getType()), savedDevice.getName()); - String clientKeysStr = CLIENT_ATTRIBUTE_KEYS; - String sharedKeysStr = SHARED_ATTRIBUTE_KEYS; - List clientKeysList = List.of(clientKeysStr.split(",")); - List sharedKeysList = List.of(sharedKeysStr.split(",")); + List clientKeysList = List.of(CLIENT_ATTRIBUTE_KEYS.split(",")); + List sharedKeysList = List.of(SHARED_ATTRIBUTE_KEYS.split(",")); List csKeys = getEntityKeys(clientKeysList, CLIENT_ATTRIBUTE); List shKeys = getEntityKeys(sharedKeysList, SHARED_ATTRIBUTE); List keys = new ArrayList<>(); @@ -419,8 +415,8 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt MqttTestCallback callback = new MqttTestSubscribeOnTopicCallback(attrSubTopic.replace("+", "1")); client.setCallback(callback); TransportApiProtos.AttributesRequest.Builder attributesRequestBuilder = TransportApiProtos.AttributesRequest.newBuilder(); - attributesRequestBuilder.setClientKeys(clientKeysStr); - attributesRequestBuilder.setSharedKeys(sharedKeysStr); + attributesRequestBuilder.setClientKeys(CLIENT_ATTRIBUTE_KEYS); + attributesRequestBuilder.setSharedKeys(SHARED_ATTRIBUTE_KEYS); TransportApiProtos.AttributesRequest attributesRequest = attributesRequestBuilder.build(); client.publishAndWait(attrReqTopicPrefix + "1", attributesRequest.toByteArray()); validateProtoResponse(callback, getExpectedAttributeResponseMsg()); @@ -439,9 +435,8 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt 100); assertNotNull(device); - String clientKeysStr = CLIENT_ATTRIBUTE_KEYS; - String attributeValuesUrl = "/api/plugins/telemetry/DEVICE/" + device.getId() + "/values/attributes/CLIENT_SCOPE?keys=" + clientKeysStr; + String attributeValuesUrl = "/api/plugins/telemetry/DEVICE/" + device.getId() + "/values/attributes/CLIENT_SCOPE?keys=" + CLIENT_ATTRIBUTE_KEYS; Awaitility.await() .atMost(10, TimeUnit.SECONDS) @@ -454,9 +449,8 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt SingleEntityFilter dtf = new SingleEntityFilter(); dtf.setSingleEntity(AliasEntityId.fromEntityId(device.getId())); - String sharedKeysStr = SHARED_ATTRIBUTE_KEYS; - List clientKeysList = List.of(clientKeysStr.split(",")); - List sharedKeysList = List.of(sharedKeysStr.split(",")); + List clientKeysList = List.of(CLIENT_ATTRIBUTE_KEYS.split(",")); + List sharedKeysList = List.of(SHARED_ATTRIBUTE_KEYS.split(",")); List csKeys = getEntityKeys(clientKeysList, CLIENT_ATTRIBUTE); List shKeys = getEntityKeys(sharedKeysList, SHARED_ATTRIBUTE); List keys = new ArrayList<>(); @@ -544,8 +538,7 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt client.connectAndWait(gatewayAccessToken); String deviceName = "Gateway Device Request Attributes"; - String clientKeysStr = CLIENT_ATTRIBUTE_KEYS; - List clientKeysList = List.of(clientKeysStr.split(",")); + List clientKeysList = List.of(CLIENT_ATTRIBUTE_KEYS.split(",")); client.publishAndWait(GATEWAY_ATTRIBUTES_TOPIC, getProtoGatewayDeviceClientAttributesPayload(deviceName, clientKeysList)); Device device = doExecuteWithRetriesAndInterval(() -> doGet("/api/tenant/devices?deviceName=" + deviceName, Device.class), @@ -555,8 +548,7 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt SingleEntityFilter dtf = new SingleEntityFilter(); dtf.setSingleEntity(AliasEntityId.fromEntityId(device.getId())); - String sharedKeysStr = SHARED_ATTRIBUTE_KEYS; - List sharedKeysList = List.of(sharedKeysStr.split(",")); + List sharedKeysList = List.of(SHARED_ATTRIBUTE_KEYS.split(",")); List csKeys = getEntityKeys(clientKeysList, CLIENT_ATTRIBUTE); List shKeys = getEntityKeys(sharedKeysList, SHARED_ATTRIBUTE); List keys = new ArrayList<>();