Browse Source
# Conflicts: # application/pom.xml # common/actor/pom.xml # common/cache/pom.xml # common/cluster-api/pom.xml # common/coap-server/pom.xml # common/dao-api/pom.xml # common/data/pom.xml # common/discovery-api/pom.xml # common/edge-api/pom.xml # common/edqs/pom.xml # common/message/pom.xml # common/pom.xml # common/proto/pom.xml # common/queue/pom.xml # common/script/pom.xml # common/script/remote-js-client/pom.xml # common/script/script-api/pom.xml # common/stats/pom.xml # common/transport/coap/pom.xml # common/transport/http/pom.xml # common/transport/lwm2m/pom.xml # common/transport/mqtt/pom.xml # common/transport/pom.xml # common/transport/snmp/pom.xml # common/transport/transport-api/pom.xml # common/util/pom.xml # common/version-control/pom.xml # dao/pom.xml # edqs/pom.xml # monitoring/pom.xml # msa/black-box-tests/pom.xml # msa/edqs/pom.xml # msa/js-executor/pom.xml # msa/monitoring/pom.xml # msa/pom.xml # msa/tb-node/pom.xml # msa/tb/pom.xml # msa/transport/coap/pom.xml # msa/transport/http/pom.xml # msa/transport/lwm2m/pom.xml # msa/transport/mqtt/pom.xml # msa/transport/pom.xml # msa/transport/snmp/pom.xml # msa/vc-executor-docker/pom.xml # msa/vc-executor/pom.xml # msa/web-ui/pom.xml # netty-mqtt/pom.xml # pom.xml # rest-client/pom.xml # rule-engine/pom.xml # rule-engine/rule-engine-api/pom.xml # rule-engine/rule-engine-components/pom.xml # tools/pom.xml # transport/coap/pom.xml # transport/http/pom.xml # transport/lwm2m/pom.xml # transport/mqtt/pom.xml # transport/pom.xml # transport/snmp/pom.xml # ui-ngx/pom.xmlrelease-4.3
384 changed files with 3900 additions and 1737 deletions
@ -0,0 +1,221 @@ |
|||
/** |
|||
* Copyright © 2016-2026 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.edge.rpc.processor; |
|||
|
|||
import com.google.common.util.concurrent.Futures; |
|||
import com.google.common.util.concurrent.ListenableFuture; |
|||
import org.junit.jupiter.api.Test; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.Dashboard; |
|||
import org.thingsboard.server.common.data.Device; |
|||
import org.thingsboard.server.common.data.EntityView; |
|||
import org.thingsboard.server.common.data.User; |
|||
import org.thingsboard.server.common.data.asset.Asset; |
|||
import org.thingsboard.server.common.data.device.data.DeviceData; |
|||
import org.thingsboard.server.common.data.device.data.DefaultDeviceConfiguration; |
|||
import org.thingsboard.server.common.data.device.data.DefaultDeviceTransportConfiguration; |
|||
import org.thingsboard.server.common.data.id.AssetId; |
|||
import org.thingsboard.server.common.data.id.DashboardId; |
|||
import org.thingsboard.server.common.data.id.DeviceId; |
|||
import org.thingsboard.server.common.data.id.EntityViewId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.UserId; |
|||
import org.thingsboard.server.gen.transport.TransportProtos; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
|
|||
public class BaseEdgeProcessorTest { |
|||
|
|||
private final BaseEdgeProcessor processor = new BaseEdgeProcessor() { |
|||
@Override |
|||
public ListenableFuture<Void> processEntityNotification(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto msg) { |
|||
return Futures.immediateFuture(null); |
|||
} |
|||
}; |
|||
|
|||
@Test |
|||
public void dashboardSaveRequiredWhenConfigurationChanges() { |
|||
DashboardId dashboardId = new DashboardId(UUID.randomUUID()); |
|||
Dashboard current = new Dashboard(dashboardId); |
|||
current.setTitle("Dashboard"); |
|||
current.setConfiguration(JacksonUtil.toJsonNode("{\"widgets\":{\"w1\":{\"type\":\"timeseries\"}}}")); |
|||
|
|||
Dashboard updated = new Dashboard(current); |
|||
updated.setConfiguration(JacksonUtil.toJsonNode("{\"widgets\":{\"w1\":{\"type\":\"latest\"}}}")); |
|||
|
|||
assertThat(processor.isSaveRequired(current, updated)).isTrue(); |
|||
} |
|||
|
|||
@Test |
|||
public void dashboardSaveNotRequiredWhenOnlyVersionChanges() { |
|||
DashboardId dashboardId = new DashboardId(UUID.randomUUID()); |
|||
Dashboard current = new Dashboard(dashboardId); |
|||
current.setTitle("Dashboard"); |
|||
current.setConfiguration(JacksonUtil.toJsonNode("{\"widgets\":{\"w1\":{\"type\":\"timeseries\"}}}")); |
|||
current.setVersion(1L); |
|||
|
|||
Dashboard updated = new Dashboard(current); |
|||
updated.setVersion(2L); |
|||
|
|||
assertThat(processor.isSaveRequired(current, updated)).isFalse(); |
|||
} |
|||
|
|||
@Test |
|||
public void dashboardSaveNotRequiredWhenIdentical() { |
|||
DashboardId dashboardId = new DashboardId(UUID.randomUUID()); |
|||
Dashboard current = new Dashboard(dashboardId); |
|||
current.setTitle("Dashboard"); |
|||
current.setConfiguration(JacksonUtil.toJsonNode("{\"widgets\":{\"w1\":{\"type\":\"timeseries\"}}}")); |
|||
|
|||
Dashboard updated = new Dashboard(current); |
|||
|
|||
assertThat(processor.isSaveRequired(current, updated)).isFalse(); |
|||
} |
|||
|
|||
@Test |
|||
public void deviceSaveRequiredWhenDeviceDataChanges() { |
|||
DeviceId deviceId = new DeviceId(UUID.randomUUID()); |
|||
Device current = new Device(deviceId); |
|||
current.setName("Device"); |
|||
current.setDeviceData(deviceDataWithTransport()); |
|||
|
|||
Device updated = new Device(current); |
|||
DeviceData withoutTransport = new DeviceData(); |
|||
withoutTransport.setConfiguration(new DefaultDeviceConfiguration()); |
|||
updated.setDeviceData(withoutTransport); |
|||
|
|||
assertThat(processor.isSaveRequired(current, updated)).isTrue(); |
|||
} |
|||
|
|||
@Test |
|||
public void deviceSaveRequiredWhenAdditionalInfoChanges() { |
|||
DeviceId deviceId = new DeviceId(UUID.randomUUID()); |
|||
Device current = new Device(deviceId); |
|||
current.setName("Device"); |
|||
current.setAdditionalInfo(JacksonUtil.toJsonNode("{\"description\":\"old\"}")); |
|||
|
|||
Device updated = new Device(current); |
|||
updated.setAdditionalInfo(JacksonUtil.toJsonNode("{\"description\":\"new\"}")); |
|||
|
|||
assertThat(processor.isSaveRequired(current, updated)).isTrue(); |
|||
} |
|||
|
|||
@Test |
|||
public void deviceSaveNotRequiredWhenOnlyVersionChanges() { |
|||
DeviceId deviceId = new DeviceId(UUID.randomUUID()); |
|||
Device current = new Device(deviceId); |
|||
current.setName("Device"); |
|||
current.setDeviceData(deviceDataWithTransport()); |
|||
current.setAdditionalInfo(JacksonUtil.toJsonNode("{\"description\":\"same\"}")); |
|||
current.setVersion(1L); |
|||
|
|||
Device updated = new Device(current); |
|||
updated.setVersion(2L); |
|||
|
|||
assertThat(processor.isSaveRequired(current, updated)).isFalse(); |
|||
} |
|||
|
|||
@Test |
|||
public void assetSaveRequiredWhenAdditionalInfoChanges() { |
|||
AssetId assetId = new AssetId(UUID.randomUUID()); |
|||
Asset current = new Asset(assetId); |
|||
current.setName("Asset"); |
|||
current.setAdditionalInfo(JacksonUtil.toJsonNode("{\"description\":\"old\"}")); |
|||
|
|||
Asset updated = new Asset(current); |
|||
updated.setAdditionalInfo(JacksonUtil.toJsonNode("{\"description\":\"new\"}")); |
|||
|
|||
assertThat(processor.isSaveRequired(current, updated)).isTrue(); |
|||
} |
|||
|
|||
@Test |
|||
public void assetSaveNotRequiredWhenOnlyVersionChanges() { |
|||
AssetId assetId = new AssetId(UUID.randomUUID()); |
|||
Asset current = new Asset(assetId); |
|||
current.setName("Asset"); |
|||
current.setAdditionalInfo(JacksonUtil.toJsonNode("{\"description\":\"same\"}")); |
|||
current.setVersion(1L); |
|||
|
|||
Asset updated = new Asset(current); |
|||
updated.setVersion(2L); |
|||
|
|||
assertThat(processor.isSaveRequired(current, updated)).isFalse(); |
|||
} |
|||
|
|||
@Test |
|||
public void entityViewSaveRequiredWhenAdditionalInfoChanges() { |
|||
EntityViewId entityViewId = new EntityViewId(UUID.randomUUID()); |
|||
EntityView current = new EntityView(entityViewId); |
|||
current.setName("EntityView"); |
|||
current.setAdditionalInfo(JacksonUtil.toJsonNode("{\"description\":\"old\"}")); |
|||
|
|||
EntityView updated = new EntityView(current); |
|||
updated.setAdditionalInfo(JacksonUtil.toJsonNode("{\"description\":\"new\"}")); |
|||
|
|||
assertThat(processor.isSaveRequired(current, updated)).isTrue(); |
|||
} |
|||
|
|||
@Test |
|||
public void entityViewSaveNotRequiredWhenOnlyVersionChanges() { |
|||
EntityViewId entityViewId = new EntityViewId(UUID.randomUUID()); |
|||
EntityView current = new EntityView(entityViewId); |
|||
current.setName("EntityView"); |
|||
current.setAdditionalInfo(JacksonUtil.toJsonNode("{\"description\":\"same\"}")); |
|||
current.setVersion(1L); |
|||
|
|||
EntityView updated = new EntityView(current); |
|||
updated.setVersion(2L); |
|||
|
|||
assertThat(processor.isSaveRequired(current, updated)).isFalse(); |
|||
} |
|||
|
|||
@Test |
|||
public void userSaveRequiredWhenAdditionalInfoChanges() { |
|||
UserId userId = new UserId(UUID.randomUUID()); |
|||
User current = new User(userId); |
|||
current.setEmail("user@thingsboard.io"); |
|||
current.setAdditionalInfo(JacksonUtil.toJsonNode("{\"description\":\"old\"}")); |
|||
|
|||
User updated = new User(current); |
|||
updated.setAdditionalInfo(JacksonUtil.toJsonNode("{\"description\":\"new\"}")); |
|||
|
|||
assertThat(processor.isSaveRequired(current, updated)).isTrue(); |
|||
} |
|||
|
|||
@Test |
|||
public void userSaveNotRequiredWhenOnlyVersionChanges() { |
|||
UserId userId = new UserId(UUID.randomUUID()); |
|||
User current = new User(userId); |
|||
current.setEmail("user@thingsboard.io"); |
|||
current.setAdditionalInfo(JacksonUtil.toJsonNode("{\"description\":\"same\"}")); |
|||
current.setVersion(1L); |
|||
|
|||
User updated = new User(current); |
|||
updated.setVersion(2L); |
|||
|
|||
assertThat(processor.isSaveRequired(current, updated)).isFalse(); |
|||
} |
|||
|
|||
private static DeviceData deviceDataWithTransport() { |
|||
DeviceData deviceData = new DeviceData(); |
|||
deviceData.setConfiguration(new DefaultDeviceConfiguration()); |
|||
deviceData.setTransportConfiguration(new DefaultDeviceTransportConfiguration()); |
|||
return deviceData; |
|||
} |
|||
|
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue