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