use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.
the class BaseRuleControllerTest method testSaveRule.
@Test
public void testSaveRule() throws Exception {
RuleMetaData rule = new RuleMetaData();
doPost("/api/rule", rule).andExpect(status().isBadRequest());
rule.setName("My Rule");
doPost("/api/rule", rule).andExpect(status().isBadRequest());
rule.setPluginToken(tenantPlugin.getApiToken());
doPost("/api/rule", rule).andExpect(status().isBadRequest());
rule.setFilters(mapper.readTree("[{\"clazz\":\"org.thingsboard.server.extensions.core.filter.MsgTypeFilter\", " + "\"name\":\"TelemetryFilter\", " + "\"configuration\": {\"messageTypes\":[\"POST_TELEMETRY\",\"POST_ATTRIBUTES\",\"GET_ATTRIBUTES\"]}}]"));
doPost("/api/rule", rule).andExpect(status().isBadRequest());
rule.setAction(mapper.readTree("{\"clazz\":\"org.thingsboard.server.extensions.core.action.telemetry.TelemetryPluginAction\", \"name\":\"TelemetryMsgConverterAction\", \"configuration\":{\"timeUnit\":\"DAYS\", \"ttlValue\":1}}"));
RuleMetaData savedRule = doPost("/api/rule", rule, RuleMetaData.class);
Assert.assertNotNull(savedRule);
Assert.assertNotNull(savedRule.getId());
Assert.assertTrue(savedRule.getCreatedTime() > 0);
Assert.assertEquals(savedTenant.getId(), savedRule.getTenantId());
}
use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.
the class BaseRuleControllerTest method testRulesCreation.
private List<RuleMetaData> testRulesCreation(String url, PluginMetaData plugin) throws Exception {
List<RuleMetaData> rules = new ArrayList<>();
for (int i = 0; i < 6; i++) {
RuleMetaData rule = createRuleMetaData(plugin);
rule.setPluginToken(plugin.getApiToken());
rule.setName(rule.getName() + i);
rules.add(doPost("/api/rule", rule, RuleMetaData.class));
}
List<RuleMetaData> loadedRules = new ArrayList<>();
TextPageLink pageLink = new TextPageLink(3);
TextPageData<RuleMetaData> pageData;
do {
pageData = doGetTypedWithPageLink(url + "?", new TypeReference<TextPageData<RuleMetaData>>() {
}, pageLink);
loadedRules.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
loadedRules = loadedRules.stream().filter(p -> !p.getName().equals("System Telemetry Rule")).collect(Collectors.toList());
Collections.sort(rules, idComparator);
Collections.sort(loadedRules, idComparator);
Assert.assertEquals(rules, loadedRules);
return loadedRules;
}
use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.
the class BaseRuleControllerTest method testFindRuleByPluginToken.
@Test
public void testFindRuleByPluginToken() throws Exception {
RuleMetaData rule = createRuleMetaData(tenantPlugin);
RuleMetaData savedRule = doPost("/api/rule", rule, RuleMetaData.class);
List<RuleMetaData> foundRules = doGetTyped("/api/rule/token/" + savedRule.getPluginToken(), new TypeReference<List<RuleMetaData>>() {
});
Assert.assertNotNull(foundRules);
Assert.assertEquals(1, foundRules.size());
Assert.assertEquals(savedRule, foundRules.get(0));
}
Aggregations