Search in sources :

Example 1 with EdgeImitator

use of org.thingsboard.server.edge.imitator.EdgeImitator in project thingsboard by thingsboard.

the class BaseEdgeTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    loginSysAdmin();
    Tenant tenant = new Tenant();
    tenant.setTitle("My tenant");
    savedTenant = doPost("/api/tenant", tenant, Tenant.class);
    tenantId = savedTenant.getId();
    Assert.assertNotNull(savedTenant);
    tenantAdmin = new User();
    tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
    tenantAdmin.setTenantId(savedTenant.getId());
    tenantAdmin.setEmail("tenant2@thingsboard.org");
    tenantAdmin.setFirstName("Joe");
    tenantAdmin.setLastName("Downs");
    tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1");
    // sleep 0.5 second to avoid CREDENTIALS updated message for the user
    // user credentials is going to be stored and updated event pushed to edge notification service
    // while service will be processing this event edge could be already added and additional message will be pushed
    Thread.sleep(500);
    installation();
    edgeImitator = new EdgeImitator("localhost", 7070, edge.getRoutingKey(), edge.getSecret());
    edgeImitator.expectMessageAmount(13);
    edgeImitator.connect();
    verifyEdgeConnectionAndInitialData();
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) User(org.thingsboard.server.common.data.User) EdgeImitator(org.thingsboard.server.edge.imitator.EdgeImitator) Before(org.junit.Before)

Example 2 with EdgeImitator

use of org.thingsboard.server.edge.imitator.EdgeImitator in project thingsboard by thingsboard.

the class BaseEdgeControllerTest method testSyncEdge.

@Test
public void testSyncEdge() throws Exception {
    Edge edge = doPost("/api/edge", constructEdge("Test Sync Edge", "test"), Edge.class);
    Device device = new Device();
    device.setName("Test Sync Edge Device 1");
    device.setType("default");
    Device savedDevice = doPost("/api/device", device, Device.class);
    doPost("/api/edge/" + edge.getId().getId().toString() + "/device/" + savedDevice.getId().getId().toString(), Device.class);
    Asset asset = new Asset();
    asset.setName("Test Sync Edge Asset 1");
    asset.setType("test");
    Asset savedAsset = doPost("/api/asset", asset, Asset.class);
    doPost("/api/edge/" + edge.getId().getId().toString() + "/asset/" + savedAsset.getId().getId().toString(), Asset.class);
    EdgeImitator edgeImitator = new EdgeImitator(EDGE_HOST, EDGE_PORT, edge.getRoutingKey(), edge.getSecret());
    edgeImitator.ignoreType(UserCredentialsUpdateMsg.class);
    edgeImitator.expectMessageAmount(11);
    edgeImitator.connect();
    assertThat(edgeImitator.waitForMessages()).as("await for messages on first connect").isTrue();
    assertThat(edgeImitator.findAllMessagesByType(RuleChainUpdateMsg.class)).as("one msg during sync process, another from edge creation").hasSize(2);
    assertThat(edgeImitator.findAllMessagesByType(DeviceProfileUpdateMsg.class)).as("one msg during sync process for 'default' device profile").hasSize(1);
    assertThat(edgeImitator.findAllMessagesByType(DeviceUpdateMsg.class)).as("one msg once device assigned to edge").hasSize(1);
    assertThat(edgeImitator.findAllMessagesByType(AssetUpdateMsg.class)).as("two msgs - one during sync process, and one more once asset assigned to edge").hasSize(2);
    assertThat(edgeImitator.findAllMessagesByType(UserUpdateMsg.class)).as("one msg during sync process for tenant admin user").hasSize(1);
    assertThat(edgeImitator.findAllMessagesByType(AdminSettingsUpdateMsg.class)).as("admin setting update").hasSize(4);
    edgeImitator.expectMessageAmount(8);
    doPost("/api/edge/sync/" + edge.getId());
    assertThat(edgeImitator.waitForMessages()).as("await for messages after edge sync rest api call").isTrue();
    assertThat(edgeImitator.findAllMessagesByType(RuleChainUpdateMsg.class)).as("rule chain msg").hasSize(1);
    assertThat(edgeImitator.findAllMessagesByType(DeviceProfileUpdateMsg.class)).as("device profile msg").hasSize(1);
    assertThat(edgeImitator.findAllMessagesByType(AssetUpdateMsg.class)).as("asset update msg").hasSize(1);
    assertThat(edgeImitator.findAllMessagesByType(UserUpdateMsg.class)).as("user update msg").hasSize(1);
    assertThat(edgeImitator.findAllMessagesByType(AdminSettingsUpdateMsg.class)).as("admin setting update msg").hasSize(4);
    edgeImitator.allowIgnoredTypes();
    try {
        edgeImitator.disconnect();
    } catch (Exception ignored) {
    }
    doDelete("/api/device/" + savedDevice.getId().getId().toString()).andExpect(status().isOk());
    doDelete("/api/asset/" + savedAsset.getId().getId().toString()).andExpect(status().isOk());
    doDelete("/api/edge/" + edge.getId().getId().toString()).andExpect(status().isOk());
}
Also used : DeviceProfileUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg) Device(org.thingsboard.server.common.data.Device) AssetUpdateMsg(org.thingsboard.server.gen.edge.v1.AssetUpdateMsg) AdminSettingsUpdateMsg(org.thingsboard.server.gen.edge.v1.AdminSettingsUpdateMsg) Asset(org.thingsboard.server.common.data.asset.Asset) DeviceUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg) EdgeImitator(org.thingsboard.server.edge.imitator.EdgeImitator) Edge(org.thingsboard.server.common.data.edge.Edge) UserUpdateMsg(org.thingsboard.server.gen.edge.v1.UserUpdateMsg) RuleChainUpdateMsg(org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg) Test(org.junit.Test)

Aggregations

EdgeImitator (org.thingsboard.server.edge.imitator.EdgeImitator)2 Before (org.junit.Before)1 Test (org.junit.Test)1 Device (org.thingsboard.server.common.data.Device)1 Tenant (org.thingsboard.server.common.data.Tenant)1 User (org.thingsboard.server.common.data.User)1 Asset (org.thingsboard.server.common.data.asset.Asset)1 Edge (org.thingsboard.server.common.data.edge.Edge)1 AdminSettingsUpdateMsg (org.thingsboard.server.gen.edge.v1.AdminSettingsUpdateMsg)1 AssetUpdateMsg (org.thingsboard.server.gen.edge.v1.AssetUpdateMsg)1 DeviceProfileUpdateMsg (org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg)1 DeviceUpdateMsg (org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg)1 RuleChainUpdateMsg (org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg)1 UserUpdateMsg (org.thingsboard.server.gen.edge.v1.UserUpdateMsg)1