|
|
|
@ -30,6 +30,8 @@ import org.springframework.test.context.ContextConfiguration; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.rule.engine.action.TbCreateAlarmNode; |
|
|
|
import org.thingsboard.rule.engine.action.TbCreateAlarmNodeConfiguration; |
|
|
|
import org.thingsboard.rule.engine.debug.TbMsgGeneratorNode; |
|
|
|
import org.thingsboard.rule.engine.debug.TbMsgGeneratorNodeConfiguration; |
|
|
|
import org.thingsboard.rule.engine.metadata.TbGetRelatedAttributeNode; |
|
|
|
import org.thingsboard.rule.engine.metadata.TbGetRelatedDataNodeConfiguration; |
|
|
|
import org.thingsboard.server.common.data.StringUtils; |
|
|
|
@ -356,6 +358,47 @@ public class RuleChainControllerTest extends AbstractControllerTest { |
|
|
|
assertThat(error).contains("alarmType is malformed"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSaveRuleChainWithOutdatedVersion() throws Exception { |
|
|
|
RuleChain ruleChain = createRuleChain("Rule chain with invalid nodes"); |
|
|
|
|
|
|
|
RuleChainMetaData ruleChainMetaData = new RuleChainMetaData(); |
|
|
|
ruleChainMetaData.setRuleChainId(ruleChain.getId()); |
|
|
|
RuleNode ruleNode = new RuleNode(); |
|
|
|
ruleNode.setName("Test"); |
|
|
|
ruleNode.setType(TbMsgGeneratorNode.class.getName()); |
|
|
|
TbMsgGeneratorNodeConfiguration config = new TbMsgGeneratorNodeConfiguration(); |
|
|
|
ruleNode.setConfiguration(JacksonUtil.valueToTree(config)); |
|
|
|
List<RuleNode> ruleNodes = new ArrayList<>(); |
|
|
|
ruleNodes.add(ruleNode); |
|
|
|
ruleChainMetaData.setFirstNodeIndex(0); |
|
|
|
ruleChainMetaData.setNodes(ruleNodes); |
|
|
|
|
|
|
|
ruleChainMetaData = doPost("/api/ruleChain/metadata", ruleChainMetaData, RuleChainMetaData.class); |
|
|
|
assertThat(ruleChainMetaData.getVersion()).isEqualTo(2); // in this case when saving metadata, rule chain will also be updated
|
|
|
|
|
|
|
|
ruleChain = doGet("/api/ruleChain/" + ruleChain.getId(), RuleChain.class); |
|
|
|
assertThat(ruleChain.getVersion()).isEqualTo(2); |
|
|
|
|
|
|
|
ruleChain.setName("Updated"); |
|
|
|
ruleChain = doPost("/api/ruleChain", ruleChain, RuleChain.class); |
|
|
|
assertThat(ruleChain.getVersion()).isEqualTo(3); |
|
|
|
|
|
|
|
ruleChain.setVersion(1L); |
|
|
|
doPost("/api/ruleChain", ruleChain) |
|
|
|
.andExpect(status().isConflict()); |
|
|
|
ruleChainMetaData.setVersion(1L); |
|
|
|
doPost("/api/ruleChain/metadata", ruleChainMetaData) |
|
|
|
.andExpect(status().isConflict()); |
|
|
|
|
|
|
|
ruleChainMetaData.setVersion(3L); |
|
|
|
doPost("/api/ruleChain/metadata", ruleChainMetaData) |
|
|
|
.andExpect(status().isOk()); |
|
|
|
ruleChain.setVersion(3L); |
|
|
|
doPost("/api/ruleChain", ruleChain) |
|
|
|
.andExpect(status().isOk()); |
|
|
|
} |
|
|
|
|
|
|
|
private RuleChain createRuleChain(String name) { |
|
|
|
RuleChain ruleChain = new RuleChain(); |
|
|
|
ruleChain.setName(name); |
|
|
|
|