|
|
|
@ -16,11 +16,13 @@ |
|
|
|
package org.thingsboard.server.dao.service; |
|
|
|
|
|
|
|
import com.datastax.oss.driver.api.core.uuid.Uuids; |
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
import org.apache.commons.lang3.RandomStringUtils; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
|
import org.thingsboard.server.common.data.EntitySubtype; |
|
|
|
import org.thingsboard.server.common.data.Tenant; |
|
|
|
@ -30,10 +32,13 @@ import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
|
import org.thingsboard.server.common.data.rule.RuleChain; |
|
|
|
import org.thingsboard.server.common.data.rule.RuleChainMetaData; |
|
|
|
import org.thingsboard.server.common.data.rule.RuleChainType; |
|
|
|
import org.thingsboard.server.common.data.rule.RuleNode; |
|
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
@ -614,17 +619,45 @@ public abstract class BaseEdgeServiceTest extends AbstractServiceTest { |
|
|
|
ruleChain.setName("Rule Chain #1"); |
|
|
|
ruleChain.setType(RuleChainType.EDGE); |
|
|
|
RuleChain ruleChain1 = ruleChainService.saveRuleChain(ruleChain); |
|
|
|
ruleChainService.assignRuleChainToEdge(tenantId, ruleChain1.getId(), savedEdge.getId()); |
|
|
|
|
|
|
|
ruleChain = new RuleChain(); |
|
|
|
ruleChain.setTenantId(tenantId); |
|
|
|
ruleChain.setName("Rule Chain #2"); |
|
|
|
ruleChain.setType(RuleChainType.EDGE); |
|
|
|
RuleChain ruleChain2 = ruleChainService.saveRuleChain(ruleChain); |
|
|
|
ruleChainService.assignRuleChainToEdge(tenantId, ruleChain2.getId(), savedEdge.getId()); |
|
|
|
|
|
|
|
String missingToRelatedRuleChains = edgeService.findMissingToRelatedRuleChains(tenantId, savedEdge.getId()); |
|
|
|
Assert.assertEquals("[]", missingToRelatedRuleChains); |
|
|
|
ruleChain = new RuleChain(); |
|
|
|
ruleChain.setTenantId(tenantId); |
|
|
|
ruleChain.setName("Rule Chain #3"); |
|
|
|
ruleChain.setType(RuleChainType.EDGE); |
|
|
|
RuleChain ruleChain3 = ruleChainService.saveRuleChain(ruleChain); |
|
|
|
|
|
|
|
RuleNode ruleNode1 = new RuleNode(); |
|
|
|
ruleNode1.setName("Input rule node 1"); |
|
|
|
ruleNode1.setType("org.thingsboard.rule.engine.flow.TbRuleChainInputNode"); |
|
|
|
ObjectNode configuration = JacksonUtil.OBJECT_MAPPER.createObjectNode(); |
|
|
|
configuration.put("ruleChainId", ruleChain1.getUuidId().toString()); |
|
|
|
ruleNode1.setConfiguration(configuration); |
|
|
|
|
|
|
|
RuleNode ruleNode2 = new RuleNode(); |
|
|
|
ruleNode2.setName("Input rule node 2"); |
|
|
|
ruleNode2.setType("org.thingsboard.rule.engine.flow.TbRuleChainInputNode"); |
|
|
|
configuration = JacksonUtil.OBJECT_MAPPER.createObjectNode(); |
|
|
|
configuration.put("ruleChainId", ruleChain2.getUuidId().toString()); |
|
|
|
ruleNode2.setConfiguration(configuration); |
|
|
|
|
|
|
|
RuleChainMetaData ruleChainMetaData3 = new RuleChainMetaData(); |
|
|
|
ruleChainMetaData3.setNodes(Arrays.asList(ruleNode1, ruleNode2)); |
|
|
|
ruleChainMetaData3.setFirstNodeIndex(0); |
|
|
|
ruleChainMetaData3.setRuleChainId(ruleChain3.getId()); |
|
|
|
ruleChainService.saveRuleChainMetaData(tenantId, ruleChainMetaData3); |
|
|
|
|
|
|
|
ruleChainService.assignRuleChainToEdge(tenantId, ruleChain3.getId(), savedEdge.getId()); |
|
|
|
|
|
|
|
String missingToRelatedRuleChains = edgeService.findMissingToRelatedRuleChains(tenantId, |
|
|
|
savedEdge.getId(), |
|
|
|
"org.thingsboard.rule.engine.flow.TbRuleChainInputNode"); |
|
|
|
Assert.assertEquals("{\"Rule Chain #3\":[\"Rule Chain #1\",\"Rule Chain #2\"]}", missingToRelatedRuleChains); |
|
|
|
} |
|
|
|
|
|
|
|
} |