Search in sources :

Example 11 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class BaseRuleControllerTest method testFindTenantPlugins.

@Test
public void testFindTenantPlugins() throws Exception {
    List<RuleMetaData> rules = testRulesCreation("/api/rule", tenantPlugin);
    loginSysAdmin();
    List<RuleMetaData> loadedRules = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(3);
    TextPageData<RuleMetaData> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/rule/tenant/" + savedTenant.getId().getId().toString() + "?", new TypeReference<TextPageData<RuleMetaData>>() {
        }, pageLink);
        loadedRules.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(rules, idComparator);
    Collections.sort(loadedRules, idComparator);
    Assert.assertEquals(rules, loadedRules);
    for (RuleMetaData rule : rules) {
        doDelete("/api/rule/" + rule.getId().getId()).andExpect(status().isOk());
    }
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 12 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class BaseRuleControllerTest method createRuleMetaData.

public static RuleMetaData createRuleMetaData(PluginMetaData plugin) throws IOException {
    RuleMetaData rule = new RuleMetaData();
    rule.setName("My Rule");
    rule.setPluginToken(plugin.getApiToken());
    rule.setFilters(mapper.readTree("[{\"clazz\":\"org.thingsboard.server.extensions.core.filter.MsgTypeFilter\", " + "\"name\":\"TelemetryFilter\", " + "\"configuration\": {\"messageTypes\":[\"POST_TELEMETRY\",\"POST_ATTRIBUTES\",\"GET_ATTRIBUTES\"]}}]"));
    rule.setAction(mapper.readTree("{\"clazz\":\"org.thingsboard.server.extensions.core.action.telemetry.TelemetryPluginAction\", \"name\":\"TelemetryMsgConverterAction\", " + "\"configuration\":{\"timeUnit\":\"DAYS\", \"ttlValue\":1}}"));
    return rule;
}
Also used : RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Example 13 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData 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 14 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class JpaBaseRuleDaoTest method testFindByTenantIdAndPageLink.

@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
public void testFindByTenantIdAndPageLink() {
    UUID tenantId1 = UUIDs.timeBased();
    UUID tenantId2 = UUIDs.timeBased();
    createRulesTwoTenants(tenantId1, tenantId2, "name_", "token");
    List<RuleMetaData> rules1 = ruleDao.findByTenantIdAndPageLink(new TenantId(tenantId1), new TextPageLink(20, "name_"));
    assertEquals(20, rules1.size());
    List<RuleMetaData> rules2 = ruleDao.findByTenantIdAndPageLink(new TenantId(tenantId1), new TextPageLink(20, "name_", rules1.get(19).getId().getId(), null));
    assertEquals(10, rules2.size());
    List<RuleMetaData> rules3 = ruleDao.findByTenantIdAndPageLink(new TenantId(tenantId1), new TextPageLink(20, "name_", rules2.get(9).getId().getId(), null));
    assertEquals(0, rules3.size());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 15 with RuleMetaData

use of org.thingsboard.server.common.data.rule.RuleMetaData in project thingsboard by thingsboard.

the class JpaBaseRuleDaoTest method createRule.

private void createRule(UUID tenantId, String namePrefix, String pluginToken, int i) {
    RuleMetaData ruleMetaData = new RuleMetaData();
    ruleMetaData.setId(new RuleId(UUIDs.timeBased()));
    ruleMetaData.setTenantId(new TenantId(tenantId));
    ruleMetaData.setName(namePrefix + i);
    ruleMetaData.setPluginToken(pluginToken);
    ruleDao.save(ruleMetaData);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) RuleId(org.thingsboard.server.common.data.id.RuleId) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Aggregations

RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)43 Test (org.junit.Test)20 TenantId (org.thingsboard.server.common.data.id.TenantId)12 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)12 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)10 RuleId (org.thingsboard.server.common.data.id.RuleId)8 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)7 ArrayList (java.util.ArrayList)6 UUID (java.util.UUID)5 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)4 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)3 ActorRef (akka.actor.ActorRef)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 List (java.util.List)2 Slf4j (lombok.extern.slf4j.Slf4j)2 RuleActorMetaData (org.thingsboard.server.actors.rule.RuleActorMetaData)2 SimpleRuleActorChain (org.thingsboard.server.actors.rule.SimpleRuleActorChain)2 PageDataIterable (org.thingsboard.server.common.data.page.PageDataIterable)2