Search in sources :

Example 1 with TextPageData

use of org.thingsboard.server.common.data.page.TextPageData in project thingsboard by thingsboard.

the class BaseTenantControllerTest method testFindTenants.

@Test
public void testFindTenants() throws Exception {
    loginSysAdmin();
    List<Tenant> tenants = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(17);
    TextPageData<Tenant> pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<TextPageData<Tenant>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getData().size());
    tenants.addAll(pageData.getData());
    for (int i = 0; i < 56; i++) {
        Tenant tenant = new Tenant();
        tenant.setTitle("Tenant" + i);
        tenants.add(doPost("/api/tenant", tenant, Tenant.class));
    }
    List<Tenant> loadedTenants = new ArrayList<>();
    pageLink = new TextPageLink(17);
    do {
        pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<TextPageData<Tenant>>() {
        }, pageLink);
        loadedTenants.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenants, idComparator);
    Collections.sort(loadedTenants, idComparator);
    Assert.assertEquals(tenants, loadedTenants);
    for (Tenant tenant : loadedTenants) {
        if (!tenant.getTitle().equals(TEST_TENANT_NAME)) {
            doDelete("/api/tenant/" + tenant.getId().getId().toString()).andExpect(status().isOk());
        }
    }
    pageLink = new TextPageLink(17);
    pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<TextPageData<Tenant>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getData().size());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) TextPageData(org.thingsboard.server.common.data.page.TextPageData) ArrayList(java.util.ArrayList) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 2 with TextPageData

use of org.thingsboard.server.common.data.page.TextPageData in project thingsboard by thingsboard.

the class DefaultActorServiceTest method before.

@Before
public void before() throws Exception {
    actorService = new DefaultActorService();
    actorContext = new ActorSystemContext();
    tenantService = mock(TenantService.class);
    pluginService = mock(PluginService.class);
    ruleService = mock(RuleService.class);
    deviceAuthService = mock(DeviceAuthService.class);
    deviceService = mock(DeviceService.class);
    tsService = mock(TimeseriesService.class);
    rpcService = mock(ClusterRpcService.class);
    discoveryService = mock(DiscoveryService.class);
    routingService = mock(ClusterRoutingService.class);
    attributesService = mock(AttributesService.class);
    componentService = mock(ComponentDiscoveryService.class);
    eventService = mock(EventService.class);
    serverInstance = new ServerInstance(ServerInstanceProtos.ServerInfo.newBuilder().setHost("localhost").setPort(8080).build());
    ReflectionTestUtils.setField(actorService, "actorContext", actorContext);
    ReflectionTestUtils.setField(actorService, "rpcService", rpcService);
    ReflectionTestUtils.setField(actorService, "discoveryService", discoveryService);
    ReflectionTestUtils.setField(actorContext, "syncSessionTimeout", 10000L);
    ReflectionTestUtils.setField(actorContext, "pluginActorTerminationDelay", 10000L);
    ReflectionTestUtils.setField(actorContext, "pluginErrorPersistFrequency", 10000L);
    ReflectionTestUtils.setField(actorContext, "ruleActorTerminationDelay", 10000L);
    ReflectionTestUtils.setField(actorContext, "ruleErrorPersistFrequency", 10000L);
    ReflectionTestUtils.setField(actorContext, "pluginProcessingTimeout", 60000L);
    ReflectionTestUtils.setField(actorContext, "tenantService", tenantService);
    ReflectionTestUtils.setField(actorContext, "pluginService", pluginService);
    ReflectionTestUtils.setField(actorContext, "ruleService", ruleService);
    ReflectionTestUtils.setField(actorContext, "deviceAuthService", deviceAuthService);
    ReflectionTestUtils.setField(actorContext, "deviceService", deviceService);
    ReflectionTestUtils.setField(actorContext, "tsService", tsService);
    ReflectionTestUtils.setField(actorContext, "rpcService", rpcService);
    ReflectionTestUtils.setField(actorContext, "discoveryService", discoveryService);
    ReflectionTestUtils.setField(actorContext, "tsService", tsService);
    ReflectionTestUtils.setField(actorContext, "routingService", routingService);
    ReflectionTestUtils.setField(actorContext, "attributesService", attributesService);
    ReflectionTestUtils.setField(actorContext, "componentService", componentService);
    ReflectionTestUtils.setField(actorContext, "eventService", eventService);
    when(routingService.resolveById((EntityId) any())).thenReturn(Optional.empty());
    when(discoveryService.getCurrentServer()).thenReturn(serverInstance);
    ruleMock = mock(RuleMetaData.class);
    when(ruleMock.getId()).thenReturn(ruleId);
    when(ruleMock.getState()).thenReturn(ComponentLifecycleState.ACTIVE);
    when(ruleMock.getPluginToken()).thenReturn("telemetry");
    TextPageData<RuleMetaData> systemRules = new TextPageData<>(Collections.emptyList(), null, false);
    TextPageData<RuleMetaData> tenantRules = new TextPageData<>(Collections.singletonList(ruleMock), null, false);
    when(ruleService.findSystemRules(any())).thenReturn(systemRules);
    when(ruleService.findTenantRules(any(), any())).thenReturn(tenantRules);
    when(ruleService.findRuleById(ruleId)).thenReturn(ruleMock);
    pluginMock = mock(PluginMetaData.class);
    when(pluginMock.getTenantId()).thenReturn(SYSTEM_TENANT);
    when(pluginMock.getId()).thenReturn(pluginId);
    when(pluginMock.getState()).thenReturn(ComponentLifecycleState.ACTIVE);
    TextPageData<PluginMetaData> systemPlugins = new TextPageData<>(Collections.singletonList(pluginMock), null, false);
    TextPageData<PluginMetaData> tenantPlugins = new TextPageData<>(Collections.emptyList(), null, false);
    when(pluginService.findSystemPlugins(any())).thenReturn(systemPlugins);
    when(pluginService.findTenantPlugins(any(), any())).thenReturn(tenantPlugins);
    when(pluginService.findPluginByApiToken("telemetry")).thenReturn(pluginMock);
    when(pluginService.findPluginById(pluginId)).thenReturn(pluginMock);
    TextPageData<Tenant> tenants = new TextPageData<>(Collections.emptyList(), null, false);
    when(tenantService.findTenants(any())).thenReturn(tenants);
}
Also used : ComponentDiscoveryService(org.thingsboard.server.service.component.ComponentDiscoveryService) PluginService(org.thingsboard.server.dao.plugin.PluginService) AttributesService(org.thingsboard.server.dao.attributes.AttributesService) TextPageData(org.thingsboard.server.common.data.page.TextPageData) DeviceService(org.thingsboard.server.dao.device.DeviceService) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) EventService(org.thingsboard.server.dao.event.EventService) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) ClusterRoutingService(org.thingsboard.server.service.cluster.routing.ClusterRoutingService) TenantService(org.thingsboard.server.dao.tenant.TenantService) Tenant(org.thingsboard.server.common.data.Tenant) DeviceAuthService(org.thingsboard.server.common.transport.auth.DeviceAuthService) ClusterRpcService(org.thingsboard.server.service.cluster.rpc.ClusterRpcService) RuleService(org.thingsboard.server.dao.rule.RuleService) TimeseriesService(org.thingsboard.server.dao.timeseries.TimeseriesService) DefaultActorService(org.thingsboard.server.actors.service.DefaultActorService) DiscoveryService(org.thingsboard.server.service.cluster.discovery.DiscoveryService) ComponentDiscoveryService(org.thingsboard.server.service.component.ComponentDiscoveryService) ServerInstance(org.thingsboard.server.service.cluster.discovery.ServerInstance) Before(org.junit.Before)

Example 3 with TextPageData

use of org.thingsboard.server.common.data.page.TextPageData 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)

Aggregations

Tenant (org.thingsboard.server.common.data.Tenant)3 TextPageData (org.thingsboard.server.common.data.page.TextPageData)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 Test (org.junit.Test)2 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)2 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)2 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 After (org.junit.After)1 Assert (org.junit.Assert)1 MockMvcResultMatchers.status (org.springframework.test.web.servlet.result.MockMvcResultMatchers.status)1 DefaultActorService (org.thingsboard.server.actors.service.DefaultActorService)1 User (org.thingsboard.server.common.data.User)1 Authority (org.thingsboard.server.common.data.security.Authority)1 DeviceAuthService (org.thingsboard.server.common.transport.auth.DeviceAuthService)1