Fixed edge controller tests
This commit is contained in:
parent
3946b058cd
commit
04cfa2021d
@ -309,7 +309,8 @@ public abstract class BaseEdgeProcessor {
|
||||
EdgeEventActionType action,
|
||||
EntityId entityId,
|
||||
JsonNode body) {
|
||||
ListenableFuture<Optional<AttributeKvEntry>> future = attributesService.find(tenantId, edgeId, DataConstants.SERVER_SCOPE, DefaultDeviceStateService.ACTIVITY_STATE);
|
||||
ListenableFuture<Optional<AttributeKvEntry>> future =
|
||||
attributesService.find(tenantId, edgeId, DataConstants.SERVER_SCOPE, DefaultDeviceStateService.ACTIVITY_STATE);
|
||||
return Futures.transformAsync(future, activeOpt -> {
|
||||
if (activeOpt.isEmpty()) {
|
||||
log.trace("Edge is not activated. Skipping event. tenantId [{}], edgeId [{}], type[{}], " +
|
||||
|
||||
@ -17,6 +17,7 @@ package org.thingsboard.server.controller;
|
||||
|
||||
import com.datastax.oss.driver.api.core.uuid.Uuids;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
@ -34,8 +35,10 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.common.util.ThingsBoardExecutors;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.DataConstants;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.EntitySubtype;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
@ -852,6 +855,11 @@ public class EdgeControllerTest extends AbstractControllerTest {
|
||||
|
||||
Edge edge = doPost("/api/edge", constructEdge("Test Sync Edge", "test"), Edge.class);
|
||||
|
||||
// simulate edge activation
|
||||
ObjectNode attributes = JacksonUtil.newObjectNode();
|
||||
attributes.put("active", true);
|
||||
doPost("/api/plugins/telemetry/EDGE/" + edge.getId() + "/attributes/" + DataConstants.SERVER_SCOPE, attributes);
|
||||
|
||||
doPost("/api/edge/" + edge.getId().getId().toString()
|
||||
+ "/device/" + savedDevice.getId().getId().toString(), Device.class);
|
||||
doPost("/api/edge/" + edge.getId().getId().toString()
|
||||
@ -860,13 +868,12 @@ public class EdgeControllerTest extends AbstractControllerTest {
|
||||
EdgeImitator edgeImitator = new EdgeImitator(EDGE_HOST, EDGE_PORT, edge.getRoutingKey(), edge.getSecret());
|
||||
edgeImitator.ignoreType(UserCredentialsUpdateMsg.class);
|
||||
|
||||
edgeImitator.expectMessageAmount(25);
|
||||
edgeImitator.expectMessageAmount(24);
|
||||
edgeImitator.connect();
|
||||
assertThat(edgeImitator.waitForMessages()).as("await for messages on first connect").isTrue();
|
||||
|
||||
verifyFetchersMsgs(edgeImitator);
|
||||
// verify queue msgs
|
||||
Assert.assertTrue(popRuleChainMsg(edgeImitator.getDownlinkMsgs(), UpdateMsgType.ENTITY_UPDATED_RPC_MESSAGE, "Edge Root Rule Chain"));
|
||||
Assert.assertTrue(popDeviceProfileMsg(edgeImitator.getDownlinkMsgs(), UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, "default"));
|
||||
Assert.assertTrue(popDeviceMsg(edgeImitator.getDownlinkMsgs(), UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, "Test Sync Edge Device 1"));
|
||||
Assert.assertTrue(popAssetProfileMsg(edgeImitator.getDownlinkMsgs(), UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, "test"));
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
package org.thingsboard.server.controller;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.After;
|
||||
@ -26,6 +27,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.DataConstants;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.asset.Asset;
|
||||
import org.thingsboard.server.common.data.edge.Edge;
|
||||
@ -86,6 +89,11 @@ public class EdgeEventControllerTest extends AbstractControllerTest {
|
||||
Edge edge = constructEdge("TestEdge", "default");
|
||||
edge = doPost("/api/edge", edge, Edge.class);
|
||||
|
||||
// simulate edge activation
|
||||
ObjectNode attributes = JacksonUtil.newObjectNode();
|
||||
attributes.put("active", true);
|
||||
doPost("/api/plugins/telemetry/EDGE/" + edge.getId() + "/attributes/" + DataConstants.SERVER_SCOPE, attributes);
|
||||
|
||||
Device device = constructDevice("TestDevice", "default");
|
||||
Device savedDevice = doPost("/api/device", device, Device.class);
|
||||
|
||||
@ -99,14 +107,13 @@ public class EdgeEventControllerTest extends AbstractControllerTest {
|
||||
|
||||
EntityRelation relation = new EntityRelation(savedAsset.getId(), savedDevice.getId(), EntityRelation.CONTAINS_TYPE);
|
||||
|
||||
awaitForNumberOfEdgeEvents(edgeId, 3);
|
||||
awaitForNumberOfEdgeEvents(edgeId, 2);
|
||||
|
||||
doPost("/api/relation", relation);
|
||||
|
||||
awaitForNumberOfEdgeEvents(edgeId, 4);
|
||||
awaitForNumberOfEdgeEvents(edgeId, 3);
|
||||
|
||||
List<EdgeEvent> edgeEvents = findEdgeEvents(edgeId);
|
||||
Assert.assertTrue(popEdgeEvent(edgeEvents, EdgeEventType.RULE_CHAIN)); // root rule chain
|
||||
Assert.assertTrue(popEdgeEvent(edgeEvents, EdgeEventType.DEVICE)); // TestDevice
|
||||
Assert.assertTrue(popEdgeEvent(edgeEvents, EdgeEventType.ASSET)); // TestAsset
|
||||
Assert.assertTrue(popEdgeEvent(edgeEvents, EdgeEventType.RELATION));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user