Search in sources :

Example 46 with PluginMetaData

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

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

the class BasePluginControllerTest method testPluginsCreation.

private List<PluginMetaData> testPluginsCreation(String url) throws Exception {
    List<PluginMetaData> plugins = new ArrayList<>();
    for (int i = 0; i < 111; i++) {
        PluginMetaData plugin = new PluginMetaData();
        plugin.setName("My plugin");
        plugin.setApiToken("myplugin" + i);
        plugin.setConfiguration(mapper.readTree("{}"));
        plugin.setClazz(TelemetryStoragePlugin.class.getName());
        plugins.add(doPost("/api/plugin", plugin, PluginMetaData.class));
    }
    List<PluginMetaData> loadedPlugins = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(23);
    TextPageData<PluginMetaData> pageData;
    do {
        pageData = doGetTypedWithPageLink(url + "?", new TypeReference<TextPageData<PluginMetaData>>() {
        }, pageLink);
        loadedPlugins.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    loadedPlugins = loadedPlugins.stream().filter(p -> !p.getName().equals("System Telemetry Plugin")).filter(p -> !p.getName().equals("Mail Sender Plugin")).filter(p -> !p.getName().equals("System RPC Plugin")).collect(Collectors.toList());
    Collections.sort(plugins, idComparator);
    Collections.sort(loadedPlugins, idComparator);
    Assert.assertEquals(plugins, loadedPlugins);
    return loadedPlugins;
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tenant(org.thingsboard.server.common.data.Tenant) Test(org.junit.Test) TextPageData(org.thingsboard.server.common.data.page.TextPageData) Authority(org.thingsboard.server.common.data.security.Authority) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) User(org.thingsboard.server.common.data.User) List(java.util.List) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) After(org.junit.After) TelemetryStoragePlugin(org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Assert(org.junit.Assert) Collections(java.util.Collections) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Before(org.junit.Before) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) ArrayList(java.util.ArrayList) TelemetryStoragePlugin(org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Example 48 with PluginMetaData

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

the class BasePluginControllerTest method testFindSystemPlugins.

@Test
public void testFindSystemPlugins() throws Exception {
    loginSysAdmin();
    List<PluginMetaData> plugins = testPluginsCreation("/api/plugin/system");
    for (PluginMetaData plugin : plugins) {
        doDelete("/api/plugin/" + plugin.getId().getId()).andExpect(status().isOk());
    }
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) Test(org.junit.Test)

Example 49 with PluginMetaData

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

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

the class BasePluginControllerTest method testFindPluginByToken.

@Test
public void testFindPluginByToken() 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);
    PluginMetaData foundPlugin = doGet("/api/plugin/token/" + "myplugin", PluginMetaData.class);
    Assert.assertNotNull(foundPlugin);
    Assert.assertEquals(savedPlugin, foundPlugin);
}
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