Search in sources :

Example 41 with PluginMetaData

use of org.thingsboard.server.common.data.plugin.PluginMetaData in project thingsboard by thingsboard.

the class BasePluginServiceTest method findPluginById.

@Test
public void findPluginById() throws Exception {
    PluginMetaData expected = pluginService.savePlugin(generatePlugin(null, null));
    Assert.assertNotNull(expected.getId());
    PluginMetaData found = pluginService.findPluginById(expected.getId());
    Assert.assertEquals(expected, found);
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) AbstractServiceTest(org.thingsboard.server.dao.service.AbstractServiceTest) Test(org.junit.Test)

Example 42 with PluginMetaData

use of org.thingsboard.server.common.data.plugin.PluginMetaData in project thingsboard by thingsboard.

the class BaseRuleServiceTest method saveRule.

@Test
public void saveRule() throws Exception {
    PluginMetaData plugin = generatePlugin(null, "testPluginToken" + ThreadLocalRandom.current().nextInt());
    pluginService.savePlugin(plugin);
    RuleMetaData ruleMetaData = ruleService.saveRule(generateRule(plugin.getTenantId(), null, plugin.getApiToken()));
    Assert.assertNotNull(ruleMetaData.getId());
    Assert.assertNotNull(ruleMetaData.getAdditionalInfo());
    ruleMetaData.setAdditionalInfo(mapper.readTree("{\"description\":\"test\"}"));
    RuleMetaData newRuleMetaData = ruleService.saveRule(ruleMetaData);
    Assert.assertEquals(ruleMetaData.getAdditionalInfo(), newRuleMetaData.getAdditionalInfo());
}
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 43 with PluginMetaData

use of org.thingsboard.server.common.data.plugin.PluginMetaData 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 44 with PluginMetaData

use of org.thingsboard.server.common.data.plugin.PluginMetaData 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 45 with PluginMetaData

use of org.thingsboard.server.common.data.plugin.PluginMetaData in project thingsboard by thingsboard.

the class BasePluginControllerTest method testSavePlugin.

@Test
public void testSavePlugin() throws Exception {
    PluginMetaData plugin = new PluginMetaData();
    doPost("/api/plugin", plugin).andExpect(status().isBadRequest());
    plugin.setName("My plugin");
    doPost("/api/plugin", plugin).andExpect(status().isBadRequest());
    plugin.setApiToken("myplugin");
    doPost("/api/plugin", plugin).andExpect(status().isBadRequest());
    plugin.setConfiguration(mapper.readTree("{}"));
    doPost("/api/plugin", plugin).andExpect(status().isBadRequest());
    plugin.setClazz(TelemetryStoragePlugin.class.getName());
    PluginMetaData savedPlugin = doPost("/api/plugin", plugin, PluginMetaData.class);
    Assert.assertNotNull(savedPlugin);
    Assert.assertNotNull(savedPlugin.getId());
    Assert.assertTrue(savedPlugin.getCreatedTime() > 0);
    Assert.assertEquals(savedTenant.getId(), savedPlugin.getTenantId());
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) TelemetryStoragePlugin(org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin) Test(org.junit.Test)

Aggregations

PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)50 Test (org.junit.Test)24 TenantId (org.thingsboard.server.common.data.id.TenantId)17 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)14 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)13 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)13 PluginId (org.thingsboard.server.common.data.id.PluginId)8 TelemetryStoragePlugin (org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)5 ArrayList (java.util.ArrayList)4 TextPageData (org.thingsboard.server.common.data.page.TextPageData)4 List (java.util.List)3 UUID (java.util.UUID)3 Before (org.junit.Before)3 Tenant (org.thingsboard.server.common.data.Tenant)3 ComponentDescriptor (org.thingsboard.server.common.data.plugin.ComponentDescriptor)3 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)2