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);
}
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());
}
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);
}
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());
}
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());
}
Aggregations