Skip to content

Commit

Permalink
Add test testUpdateRootRuleChain to handle changes in root rule chain
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiLandiak committed Feb 5, 2024
1 parent 95ad4ba commit de28e6b
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@

import lombok.extern.slf4j.Slf4j;
import org.awaitility.Awaitility;
import org.junit.Assert;
import org.junit.Test;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.IdBased;
import org.thingsboard.server.common.data.id.RuleChainId;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.page.TimePageLink;
import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.common.data.rule.RuleChainMetaData;
import org.thingsboard.server.msa.AbstractContainerTest;

import java.util.Collections;
Expand Down Expand Up @@ -61,4 +64,35 @@ public void testRuleChains() throws Exception {
unAssignFromEdgeAndDeleteRuleChain(savedRuleChainId);
}

@Test
public void testUpdateRootRuleChain() {
PageData<RuleChain> ruleChains = cloudRestClient.getEdgeRuleChains(edge.getId(), new TimePageLink(100));
RuleChain rootRuleChain = ruleChains.getData().stream().filter(ruleChain -> ruleChain.getId().equals(edge.getRootRuleChainId())).findAny().orElse(null);
Assert.assertNotNull(rootRuleChain);
RuleChainMetaData rootRuleChainMetadata = cloudRestClient.getRuleChainMetaData(rootRuleChain.getId()).orElse(null);
Assert.assertNotNull(rootRuleChainMetadata);

// update metadata: enable debug mode for each node in rule chain
rootRuleChainMetadata.getNodes().forEach(s -> s.setDebugMode(true));
cloudRestClient.saveRuleChainMetaData(rootRuleChainMetadata);
Awaitility.await()
.pollInterval(500, TimeUnit.MILLISECONDS)
.atMost(30, TimeUnit.SECONDS)
.until(() -> {
PageData<RuleChain> edgeRuleChains = cloudRestClient.getEdgeRuleChains(edge.getId(), new TimePageLink(100));
return edgeRuleChains.getData().stream().filter(RuleChain::isRoot).count() == 1;
});

// revert metadata: disable debug mode for each node in rule chain
rootRuleChainMetadata.getNodes().forEach(s -> s.setDebugMode(false));
cloudRestClient.saveRuleChainMetaData(rootRuleChainMetadata);
Awaitility.await()
.pollInterval(500, TimeUnit.MILLISECONDS)
.atMost(30, TimeUnit.SECONDS)
.until(() -> {
PageData<RuleChain> edgeRuleChains = cloudRestClient.getEdgeRuleChains(edge.getId(), new TimePageLink(100));
return edgeRuleChains.getData().stream().filter(RuleChain::isRoot).count() == 1;
});
}

}

0 comments on commit de28e6b

Please sign in to comment.