Search in sources :

Example 81 with PageLink

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

the class BaseEdgeServiceTest method testFindEdgesByTenantIdAndType.

@Test
public void testFindEdgesByTenantIdAndType() {
    String title1 = "Edge title 1";
    String type1 = "typeA";
    List<Edge> edgesType1 = new ArrayList<>();
    for (int i = 0; i < 143; i++) {
        String suffix = RandomStringUtils.randomAlphanumeric(15);
        String name = title1 + suffix;
        name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
        Edge edge = constructEdge(name, type1);
        edgesType1.add(edgeService.saveEdge(edge));
    }
    String title2 = "Edge title 2";
    String type2 = "typeB";
    List<Edge> edgesType2 = new ArrayList<>();
    for (int i = 0; i < 175; i++) {
        String suffix = RandomStringUtils.randomAlphanumeric(15);
        String name = title2 + suffix;
        name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
        Edge edge = constructEdge(name, type2);
        edgesType2.add(edgeService.saveEdge(edge));
    }
    List<Edge> loadedEdgesType1 = new ArrayList<>();
    PageLink pageLink = new PageLink(15, 0, title1);
    PageData<Edge> pageData = null;
    do {
        pageData = edgeService.findEdgesByTenantIdAndType(tenantId, 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, 0, title2);
    do {
        pageData = edgeService.findEdgesByTenantIdAndType(tenantId, 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, 0, title1);
    pageData = edgeService.findEdgesByTenantIdAndType(tenantId, 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, 0, title2);
    pageData = edgeService.findEdgesByTenantIdAndType(tenantId, type2, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
}
Also used : 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 82 with PageLink

use of org.thingsboard.server.common.data.page.PageLink 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 83 with PageLink

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

Example 84 with PageLink

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

the class BaseEdgeServiceTest method testFindEdgesByTenantIdCustomerIdAndName.

@Test
public void testFindEdgesByTenantIdCustomerIdAndName() {
    Customer customer = new Customer();
    customer.setTitle("Test customer");
    customer.setTenantId(tenantId);
    customer = customerService.saveCustomer(customer);
    CustomerId customerId = customer.getId();
    String title1 = "Edge title 1";
    List<Edge> edgesTitle1 = 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, "default");
        edge = edgeService.saveEdge(edge);
        edgesTitle1.add(edgeService.assignEdgeToCustomer(tenantId, edge.getId(), customerId));
    }
    String title2 = "Edge title 2";
    List<Edge> edgesTitle2 = 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, "default");
        edge = edgeService.saveEdge(edge);
        edgesTitle2.add(edgeService.assignEdgeToCustomer(tenantId, edge.getId(), customerId));
    }
    List<Edge> loadedEdgesTitle1 = new ArrayList<>();
    PageLink pageLink = new PageLink(15, 0, title1);
    PageData<Edge> pageData = null;
    do {
        pageData = edgeService.findEdgesByTenantIdAndCustomerId(tenantId, customerId, pageLink);
        loadedEdgesTitle1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(edgesTitle1, idComparator);
    Collections.sort(loadedEdgesTitle1, idComparator);
    Assert.assertEquals(edgesTitle1, loadedEdgesTitle1);
    List<Edge> loadedEdgesTitle2 = new ArrayList<>();
    pageLink = new PageLink(4, 0, title2);
    do {
        pageData = edgeService.findEdgesByTenantIdAndCustomerId(tenantId, customerId, pageLink);
        loadedEdgesTitle2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(edgesTitle2, idComparator);
    Collections.sort(loadedEdgesTitle2, idComparator);
    Assert.assertEquals(edgesTitle2, loadedEdgesTitle2);
    for (Edge edge : loadedEdgesTitle1) {
        edgeService.deleteEdge(tenantId, edge.getId());
    }
    pageLink = new PageLink(4, 0, title1);
    pageData = edgeService.findEdgesByTenantIdAndCustomerId(tenantId, customerId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (Edge edge : loadedEdgesTitle2) {
        edgeService.deleteEdge(tenantId, edge.getId());
    }
    pageLink = new PageLink(4, 0, title2);
    pageData = edgeService.findEdgesByTenantIdAndCustomerId(tenantId, customerId, 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)

Example 85 with PageLink

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

the class BaseOtaPackageServiceTest method testFindTenantFirmwaresByTenantIdAndHasData.

@Test
public void testFindTenantFirmwaresByTenantIdAndHasData() {
    List<OtaPackageInfo> firmwares = new ArrayList<>();
    for (int i = 0; i < 165; i++) {
        firmwares.add(new OtaPackageInfo(otaPackageService.saveOtaPackage(createFirmware(tenantId, VERSION + i))));
    }
    OtaPackageInfo firmwareWithUrl = new OtaPackageInfo();
    firmwareWithUrl.setTenantId(tenantId);
    firmwareWithUrl.setDeviceProfileId(deviceProfileId);
    firmwareWithUrl.setType(FIRMWARE);
    firmwareWithUrl.setTitle(TITLE);
    firmwareWithUrl.setVersion(VERSION);
    firmwareWithUrl.setUrl(URL);
    firmwareWithUrl.setDataSize(0L);
    OtaPackageInfo savedFwWithUrl = otaPackageService.saveOtaPackageInfo(firmwareWithUrl, true);
    savedFwWithUrl.setHasData(true);
    firmwares.add(savedFwWithUrl);
    List<OtaPackageInfo> loadedFirmwares = new ArrayList<>();
    PageLink pageLink = new PageLink(16);
    PageData<OtaPackageInfo> pageData;
    do {
        pageData = otaPackageService.findTenantOtaPackagesByTenantIdAndDeviceProfileIdAndTypeAndHasData(tenantId, deviceProfileId, FIRMWARE, pageLink);
        loadedFirmwares.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    loadedFirmwares = new ArrayList<>();
    pageLink = new PageLink(16);
    do {
        pageData = otaPackageService.findTenantOtaPackagesByTenantIdAndDeviceProfileIdAndTypeAndHasData(tenantId, deviceProfileId, FIRMWARE, pageLink);
        loadedFirmwares.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(firmwares, idComparator);
    Collections.sort(loadedFirmwares, idComparator);
    assertThat(firmwares).isEqualTo(loadedFirmwares);
    otaPackageService.deleteOtaPackagesByTenantId(tenantId);
    pageLink = new PageLink(31);
    pageData = otaPackageService.findTenantOtaPackagesByTenantId(tenantId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertTrue(pageData.getData().isEmpty());
}
Also used : ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) Test(org.junit.Test)

Aggregations

PageLink (org.thingsboard.server.common.data.page.PageLink)187 Test (org.junit.Test)117 ArrayList (java.util.ArrayList)106 TenantId (org.thingsboard.server.common.data.id.TenantId)67 TypeReference (com.fasterxml.jackson.core.type.TypeReference)54 CustomerId (org.thingsboard.server.common.data.id.CustomerId)47 Tenant (org.thingsboard.server.common.data.Tenant)45 Customer (org.thingsboard.server.common.data.Customer)43 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)34 ApiOperation (io.swagger.annotations.ApiOperation)33 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)33 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)33 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)33 Edge (org.thingsboard.server.common.data.edge.Edge)32 Device (org.thingsboard.server.common.data.Device)28 PageData (org.thingsboard.server.common.data.page.PageData)28 Matchers.containsString (org.hamcrest.Matchers.containsString)22 UUID (java.util.UUID)20 Asset (org.thingsboard.server.common.data.asset.Asset)20 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)20