Search in sources :

Example 36 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseEdgeServiceTest method testDeleteEdge.

@Test
public void testDeleteEdge() {
    Edge edge = constructEdge("My edge", "default");
    Edge savedEdge = edgeService.saveEdge(edge);
    Edge foundEdge = edgeService.findEdgeById(tenantId, savedEdge.getId());
    Assert.assertNotNull(foundEdge);
    edgeService.deleteEdge(tenantId, savedEdge.getId());
    foundEdge = edgeService.findEdgeById(tenantId, savedEdge.getId());
    Assert.assertNull(foundEdge);
}
Also used : Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Example 37 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseEdgeServiceTest method testFindEdgesByTenantId.

@Test
public void testFindEdgesByTenantId() {
    Tenant tenant = new Tenant();
    tenant.setTitle("Test tenant");
    tenant = tenantService.saveTenant(tenant);
    TenantId tenantId = tenant.getId();
    List<Edge> edges = new ArrayList<>();
    for (int i = 0; i < 178; i++) {
        Edge edge = constructEdge(tenantId, "Edge " + i, "default");
        edges.add(edgeService.saveEdge(edge));
    }
    List<Edge> loadedEdges = new ArrayList<>();
    PageLink pageLink = new PageLink(23);
    PageData<Edge> pageData = null;
    do {
        pageData = edgeService.findEdgesByTenantId(tenantId, pageLink);
        loadedEdges.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(edges, idComparator);
    Collections.sort(loadedEdges, idComparator);
    Assert.assertEquals(edges, loadedEdges);
    edgeService.deleteEdgesByTenantId(tenantId);
    pageLink = new PageLink(33);
    pageData = edgeService.findEdgesByTenantId(tenantId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertTrue(pageData.getData().isEmpty());
    tenantService.deleteTenant(tenantId);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Example 38 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseEdgeServiceTest method testAssignEdgeToNonExistentCustomer.

@Test(expected = DataValidationException.class)
public void testAssignEdgeToNonExistentCustomer() {
    Edge edge = constructEdge("My edge", "default");
    edge = edgeService.saveEdge(edge);
    try {
        edgeService.assignEdgeToCustomer(tenantId, edge.getId(), new CustomerId(Uuids.timeBased()));
    } finally {
        edgeService.deleteEdge(tenantId, edge.getId());
    }
}
Also used : CustomerId(org.thingsboard.server.common.data.id.CustomerId) Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Example 39 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseEdgeServiceTest method testSaveEdgeWithEmptyTenant.

@Test(expected = DataValidationException.class)
public void testSaveEdgeWithEmptyTenant() {
    Edge edge = new Edge();
    edge.setName("My edge");
    edge.setType("default");
    edgeService.saveEdge(edge);
}
Also used : Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Example 40 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseEdgeServiceTest method testFindEdgesByTenantIdCustomerIdAndType.

@Test
public void testFindEdgesByTenantIdCustomerIdAndType() {
    Customer customer = new Customer();
    customer.setTitle("Test customer");
    customer.setTenantId(tenantId);
    customer = customerService.saveCustomer(customer);
    CustomerId customerId = customer.getId();
    String title1 = "Edge title 1";
    String type1 = "typeC";
    List<Edge> edgesType1 = new ArrayList<>();
    for (int i = 0; i < 175; i++) {
        String suffix = RandomStringUtils.randomAlphanumeric(15);
        String name = title1 + suffix;
        name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
        Edge edge = constructEdge(name, type1);
        edge = edgeService.saveEdge(edge);
        edgesType1.add(edgeService.assignEdgeToCustomer(tenantId, edge.getId(), customerId));
    }
    String title2 = "Edge title 2";
    String type2 = "typeD";
    List<Edge> edgesType2 = new ArrayList<>();
    for (int i = 0; i < 143; i++) {
        String suffix = RandomStringUtils.randomAlphanumeric(15);
        String name = title2 + suffix;
        name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
        Edge edge = constructEdge(name, type2);
        edge = edgeService.saveEdge(edge);
        edgesType2.add(edgeService.assignEdgeToCustomer(tenantId, edge.getId(), customerId));
    }
    List<Edge> loadedEdgesType1 = new ArrayList<>();
    PageLink pageLink = new PageLink(15);
    PageData<Edge> pageData = null;
    do {
        pageData = edgeService.findEdgesByTenantIdAndCustomerIdAndType(tenantId, customerId, type1, pageLink);
        loadedEdgesType1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(edgesType1, idComparator);
    Collections.sort(loadedEdgesType1, idComparator);
    Assert.assertEquals(edgesType1, loadedEdgesType1);
    List<Edge> loadedEdgesType2 = new ArrayList<>();
    pageLink = new PageLink(4);
    do {
        pageData = edgeService.findEdgesByTenantIdAndCustomerIdAndType(tenantId, customerId, type2, pageLink);
        loadedEdgesType2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(edgesType2, idComparator);
    Collections.sort(loadedEdgesType2, idComparator);
    Assert.assertEquals(edgesType2, loadedEdgesType2);
    for (Edge edge : loadedEdgesType1) {
        edgeService.deleteEdge(tenantId, edge.getId());
    }
    pageLink = new PageLink(4);
    pageData = edgeService.findEdgesByTenantIdAndCustomerIdAndType(tenantId, customerId, type1, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (Edge edge : loadedEdgesType2) {
        edgeService.deleteEdge(tenantId, edge.getId());
    }
    pageLink = new PageLink(4);
    pageData = edgeService.findEdgesByTenantIdAndCustomerIdAndType(tenantId, customerId, type2, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    customerService.deleteCustomer(tenantId, customerId);
}
Also used : Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) CustomerId(org.thingsboard.server.common.data.id.CustomerId) Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Aggregations

Edge (org.thingsboard.server.common.data.edge.Edge)98 Test (org.junit.Test)46 EdgeId (org.thingsboard.server.common.data.id.EdgeId)32 PageLink (org.thingsboard.server.common.data.page.PageLink)31 ArrayList (java.util.ArrayList)25 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)25 ApiOperation (io.swagger.annotations.ApiOperation)23 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)22 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)22 CustomerId (org.thingsboard.server.common.data.id.CustomerId)21 Customer (org.thingsboard.server.common.data.Customer)20 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)20 EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)16 TypeReference (com.fasterxml.jackson.core.type.TypeReference)15 TenantId (org.thingsboard.server.common.data.id.TenantId)14 Device (org.thingsboard.server.common.data.Device)13 Asset (org.thingsboard.server.common.data.asset.Asset)13 PageData (org.thingsboard.server.common.data.page.PageData)13