Search in sources :

Example 41 with RuleMetaData

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());
}
Also used : RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) Test(org.junit.Test)

Example 42 with RuleMetaData

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;
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Example 43 with RuleMetaData

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));
}
Also used : RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)43 Test (org.junit.Test)20 TenantId (org.thingsboard.server.common.data.id.TenantId)12 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)12 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)10 RuleId (org.thingsboard.server.common.data.id.RuleId)8 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)7 ArrayList (java.util.ArrayList)6 UUID (java.util.UUID)5 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)4 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)3 ActorRef (akka.actor.ActorRef)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 List (java.util.List)2 Slf4j (lombok.extern.slf4j.Slf4j)2 RuleActorMetaData (org.thingsboard.server.actors.rule.RuleActorMetaData)2 SimpleRuleActorChain (org.thingsboard.server.actors.rule.SimpleRuleActorChain)2 PageDataIterable (org.thingsboard.server.common.data.page.PageDataIterable)2