Search in sources :

Example 16 with RuleMetaData

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

the class JpaBaseRuleDaoTest method testDelete.

@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
public void testDelete() throws IOException {
    UUID id = UUIDs.timeBased();
    RuleMetaData ruleMetaData = getRuleMetaData(id);
    ruleDao.save(ruleMetaData);
    RuleMetaData savedRule = ruleDao.findById(id);
    assertNotNull(savedRule);
    assertTrue(ruleDao.removeById(id));
    RuleMetaData afterDelete = ruleDao.findById(id);
    assertNull(afterDelete);
}
Also used : RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 17 with RuleMetaData

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

the class JpaBaseRuleDaoTest method testSave.

@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
public void testSave() throws IOException {
    UUID id = UUIDs.timeBased();
    RuleMetaData ruleMetaData = getRuleMetaData(id);
    String filters = "{\"filters\":\"value-1\"}";
    String processor = "{\"processor\":\"value-2\"}";
    String action = "{\"action\":\"value-3\"}";
    String additionalInfo = "{\"additionalInfo\":\"value-4\"}";
    ObjectMapper mapper = new ObjectMapper();
    ruleMetaData.setFilters(mapper.readTree(filters));
    ruleMetaData.setProcessor(mapper.readTree(processor));
    ruleMetaData.setAction(mapper.readTree(action));
    ruleMetaData.setAdditionalInfo(mapper.readTree(additionalInfo));
    ruleDao.save(ruleMetaData);
    RuleMetaData savedRule = ruleDao.findById(id);
    assertNotNull(savedRule);
    assertEquals(filters, savedRule.getFilters().toString());
    assertEquals(processor, savedRule.getProcessor().toString());
    assertEquals(action, savedRule.getAction().toString());
    assertEquals(additionalInfo, savedRule.getAdditionalInfo().toString());
}
Also used : RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) UUID(java.util.UUID) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 18 with RuleMetaData

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

the class BaseRuleServiceTest method deleteRuleById.

@Test
public void deleteRuleById() 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);
    ruleService.deleteRuleById(expected.getId());
    found = ruleService.findRuleById(expected.getId());
    Assert.assertNull(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 19 with RuleMetaData

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

the class BaseRuleServiceTest method findTenantRules.

@Test
public void findTenantRules() 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()));
    TextPageData<RuleMetaData> foundA = ruleService.findTenantRules(tenantIdA, new TextPageLink(100));
    Assert.assertEquals(3, foundA.getData().size());
    TextPageData<RuleMetaData> foundB = ruleService.findTenantRules(tenantIdB, new TextPageLink(100));
    Assert.assertEquals(2, foundB.getData().size());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) 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 20 with RuleMetaData

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

the class BaseRuleServiceTest method deleteRulesByTenantId.

@Test
public void deleteRulesByTenantId() 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()));
    TextPageData<RuleMetaData> foundA = ruleService.findTenantRules(tenantIdA, new TextPageLink(100));
    Assert.assertEquals(3, foundA.getData().size());
    TextPageData<RuleMetaData> foundB = ruleService.findTenantRules(tenantIdB, new TextPageLink(100));
    Assert.assertEquals(2, foundB.getData().size());
    ruleService.deleteRulesByTenantId(tenantIdA);
    foundA = ruleService.findTenantRules(tenantIdA, new TextPageLink(100));
    Assert.assertEquals(0, foundA.getData().size());
    foundB = ruleService.findTenantRules(tenantIdB, new TextPageLink(100));
    Assert.assertEquals(2, foundB.getData().size());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) 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)

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