Search in sources :

Example 36 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class BaseRuleServiceTest method findRuleById.

@Test
public void findRuleById() throws Exception {
    PluginMetaData plugin = generatePlugin(null, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    pluginService.savePlugin(plugin);
    RuleMetaData expected = ruleService.saveRule(generateRule(plugin.getTenantId(), null, plugin.getApiToken()));
    Assert.assertNotNull(expected.getId());
    RuleMetaData found = ruleService.findRuleById(expected.getId());
    Assert.assertEquals(expected, found);
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest) Test(org.junit.Test)

Example 37 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class BaseRuleServiceTest method findPluginRules.

@Test
public void findPluginRules() throws Exception {
    TenantId tenantIdA = new TenantId(UUIDs.timeBased());
    TenantId tenantIdB = new TenantId(UUIDs.timeBased());
    PluginMetaData pluginA = generatePlugin(tenantIdA, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    PluginMetaData pluginB = generatePlugin(tenantIdB, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    pluginService.savePlugin(pluginA);
    pluginService.savePlugin(pluginB);
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdA, null, pluginA.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
    ruleService.saveRule(generateRule(tenantIdB, null, pluginB.getApiToken()));
    List<RuleMetaData> foundA = ruleService.findPluginRules(pluginA.getApiToken());
    Assert.assertEquals(3, foundA.size());
    List<RuleMetaData> foundB = ruleService.findPluginRules(pluginB.getApiToken());
    Assert.assertEquals(2, foundB.size());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest) Test(org.junit.Test)

Example 38 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class BasePluginControllerTest method testSuspendPlugin.

@Test
public void testSuspendPlugin() throws Exception {
    PluginMetaData plugin = new PluginMetaData();
    plugin.setName("My plugin");
    plugin.setApiToken("myplugin");
    plugin.setConfiguration(mapper.readTree("{}"));
    plugin.setClazz(TelemetryStoragePlugin.class.getName());
    PluginMetaData savedPlugin = doPost("/api/plugin", plugin, PluginMetaData.class);
    doPost("/api/plugin/" + savedPlugin.getId().getId().toString() + "/activate").andExpect(status().isOk());
    RuleMetaData rule = BaseRuleControllerTest.createRuleMetaData(savedPlugin);
    RuleMetaData savedRule = doPost("/api/rule", rule, RuleMetaData.class);
    doPost("/api/rule/" + savedRule.getId().getId().toString() + "/activate").andExpect(status().isOk());
    doPost("/api/plugin/" + savedPlugin.getId().getId().toString() + "/suspend").andExpect(status().isBadRequest());
    doPost("/api/rule/" + savedRule.getId().getId().toString() + "/suspend").andExpect(status().isOk());
    doPost("/api/plugin/" + savedPlugin.getId().getId().toString() + "/suspend").andExpect(status().isOk());
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) TelemetryStoragePlugin(org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) Test(org.junit.Test)

Example 39 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class BasePluginControllerTest method testDeletePluginById.

@Test
public void testDeletePluginById() throws Exception {
    PluginMetaData plugin = new PluginMetaData();
    plugin.setName("My plugin");
    plugin.setApiToken("myplugin");
    plugin.setConfiguration(mapper.readTree("{}"));
    plugin.setClazz(TelemetryStoragePlugin.class.getName());
    PluginMetaData savedPlugin = doPost("/api/plugin", plugin, PluginMetaData.class);
    RuleMetaData rule = BaseRuleControllerTest.createRuleMetaData(savedPlugin);
    RuleMetaData savedRule = doPost("/api/rule", rule, RuleMetaData.class);
    doDelete("/api/plugin/" + savedPlugin.getId().getId()).andExpect(status().isBadRequest());
    doDelete("/api/rule/" + savedRule.getId().getId()).andExpect(status().isOk());
    doDelete("/api/plugin/" + savedPlugin.getId().getId()).andExpect(status().isOk());
    doGet("/api/plugin/" + savedPlugin.getId().getId().toString()).andExpect(status().isNotFound());
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) TelemetryStoragePlugin(org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) Test(org.junit.Test)

Example 40 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class BaseRuleControllerTest method testActivateRule.

@Test
public void testActivateRule() throws Exception {
    RuleMetaData rule = createRuleMetaData(tenantPlugin);
    RuleMetaData savedRule = doPost("/api/rule", rule, RuleMetaData.class);
    doPost("/api/rule/" + savedRule.getId().getId().toString() + "/activate").andExpect(status().isBadRequest());
    doPost("/api/plugin/" + tenantPlugin.getId().getId().toString() + "/activate").andExpect(status().isOk());
    doPost("/api/rule/" + savedRule.getId().getId().toString() + "/activate").andExpect(status().isOk());
}
Also used : RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) 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