Search in sources :

Example 6 with PageLink

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

the class BaseOtaPackageControllerTest method testFindTenantFirmwaresByHasData.

@Test
public void testFindTenantFirmwaresByHasData() throws Exception {
    List<OtaPackageInfo> otaPackagesWithData = new ArrayList<>();
    List<OtaPackageInfo> allOtaPackages = new ArrayList<>();
    for (int i = 0; i < 165; i++) {
        SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest();
        firmwareInfo.setDeviceProfileId(deviceProfileId);
        firmwareInfo.setType(FIRMWARE);
        firmwareInfo.setTitle(TITLE);
        firmwareInfo.setVersion(VERSION + i);
        firmwareInfo.setUsesUrl(false);
        OtaPackageInfo savedFirmwareInfo = save(firmwareInfo);
        if (i > 100) {
            MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array());
            OtaPackageInfo savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM);
            savedFirmwareInfo = new OtaPackageInfo(savedFirmware);
            otaPackagesWithData.add(savedFirmwareInfo);
        }
        allOtaPackages.add(savedFirmwareInfo);
    }
    List<OtaPackageInfo> loadedOtaPackagesWithData = new ArrayList<>();
    PageLink pageLink = new PageLink(24);
    PageData<OtaPackageInfo> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/otaPackages/" + deviceProfileId.toString() + "/FIRMWARE?", new TypeReference<>() {
        }, pageLink);
        loadedOtaPackagesWithData.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    List<OtaPackageInfo> allLoadedOtaPackages = new ArrayList<>();
    pageLink = new PageLink(24);
    do {
        pageData = doGetTypedWithPageLink("/api/otaPackages?", new TypeReference<>() {
        }, pageLink);
        allLoadedOtaPackages.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(otaPackagesWithData, idComparator);
    Collections.sort(allOtaPackages, idComparator);
    Collections.sort(loadedOtaPackagesWithData, idComparator);
    Collections.sort(allLoadedOtaPackages, idComparator);
    Assert.assertEquals(otaPackagesWithData, loadedOtaPackagesWithData);
    Assert.assertEquals(allOtaPackages, allLoadedOtaPackages);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SaveOtaPackageInfoRequest(org.thingsboard.server.common.data.SaveOtaPackageInfoRequest) Test(org.junit.Test)

Example 7 with PageLink

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

the class BaseRuleChainControllerTest method testFindEdgeRuleChainsByTenantIdAndName.

@Test
public void testFindEdgeRuleChainsByTenantIdAndName() throws Exception {
    Edge edge = constructEdge("My edge", "default");
    Edge savedEdge = doPost("/api/edge", edge, Edge.class);
    List<RuleChain> edgeRuleChains = new ArrayList<>();
    PageLink pageLink = new PageLink(17);
    PageData<RuleChain> pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId() + "/ruleChains?", new TypeReference<>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getTotalElements());
    edgeRuleChains.addAll(pageData.getData());
    for (int i = 0; i < 28; i++) {
        RuleChain ruleChain = new RuleChain();
        ruleChain.setName("RuleChain " + i);
        ruleChain.setType(RuleChainType.EDGE);
        RuleChain savedRuleChain = doPost("/api/ruleChain", ruleChain, RuleChain.class);
        doPost("/api/edge/" + savedEdge.getId().getId().toString() + "/ruleChain/" + savedRuleChain.getId().getId().toString(), RuleChain.class);
        edgeRuleChains.add(savedRuleChain);
    }
    List<RuleChain> loadedEdgeRuleChains = new ArrayList<>();
    pageLink = new PageLink(17);
    do {
        pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId() + "/ruleChains?", new TypeReference<>() {
        }, pageLink);
        loadedEdgeRuleChains.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(edgeRuleChains, idComparator);
    Collections.sort(loadedEdgeRuleChains, idComparator);
    Assert.assertEquals(edgeRuleChains, loadedEdgeRuleChains);
    for (RuleChain ruleChain : loadedEdgeRuleChains) {
        if (!ruleChain.isRoot()) {
            doDelete("/api/edge/" + savedEdge.getId().getId().toString() + "/ruleChain/" + ruleChain.getId().getId().toString(), RuleChain.class);
        }
    }
    pageLink = new PageLink(17);
    pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId() + "/ruleChains?", new TypeReference<>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getTotalElements());
}
Also used : RuleChain(org.thingsboard.server.common.data.rule.RuleChain) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Example 8 with PageLink

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

the class BaseTenantControllerTest method testFindTenantsByTitle.

@Test
public void testFindTenantsByTitle() throws Exception {
    loginSysAdmin();
    String title1 = "Tenant title 1";
    List<Tenant> tenantsTitle1 = new ArrayList<>();
    for (int i = 0; i < 134; i++) {
        Tenant tenant = new Tenant();
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String title = title1 + suffix;
        title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
        tenant.setTitle(title);
        tenantsTitle1.add(doPost("/api/tenant", tenant, Tenant.class));
    }
    String title2 = "Tenant title 2";
    List<Tenant> tenantsTitle2 = new ArrayList<>();
    for (int i = 0; i < 127; i++) {
        Tenant tenant = new Tenant();
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String title = title2 + suffix;
        title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
        tenant.setTitle(title);
        tenantsTitle2.add(doPost("/api/tenant", tenant, Tenant.class));
    }
    List<Tenant> loadedTenantsTitle1 = new ArrayList<>();
    PageLink pageLink = new PageLink(15, 0, title1);
    PageData<Tenant> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<PageData<Tenant>>() {
        }, pageLink);
        loadedTenantsTitle1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantsTitle1, idComparator);
    Collections.sort(loadedTenantsTitle1, idComparator);
    Assert.assertEquals(tenantsTitle1, loadedTenantsTitle1);
    List<Tenant> loadedTenantsTitle2 = new ArrayList<>();
    pageLink = new PageLink(4, 0, title2);
    do {
        pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<PageData<Tenant>>() {
        }, pageLink);
        loadedTenantsTitle2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantsTitle2, idComparator);
    Collections.sort(loadedTenantsTitle2, idComparator);
    Assert.assertEquals(tenantsTitle2, loadedTenantsTitle2);
    for (Tenant tenant : loadedTenantsTitle1) {
        doDelete("/api/tenant/" + tenant.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new PageLink(4, 0, title1);
    pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<PageData<Tenant>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (Tenant tenant : loadedTenantsTitle2) {
        doDelete("/api/tenant/" + tenant.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new PageLink(4, 0, title2);
    pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<PageData<Tenant>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 9 with PageLink

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

the class BaseEdgeControllerTest method testFindTenantEdges.

@Test
public void testFindTenantEdges() throws Exception {
    List<Edge> edges = new ArrayList<>();
    for (int i = 0; i < 178; i++) {
        Edge edge = constructEdge("Edge" + i, "default");
        edges.add(doPost("/api/edge", edge, Edge.class));
    }
    List<Edge> loadedEdges = new ArrayList<>();
    PageLink pageLink = new PageLink(23);
    PageData<Edge> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/edges?", new TypeReference<PageData<Edge>>() {
        }, 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);
}
Also used : ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Example 10 with PageLink

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

the class BaseEdgeControllerTest method testFindCustomerEdges.

@Test
public void testFindCustomerEdges() throws Exception {
    Customer customer = new Customer();
    customer.setTitle("Test customer");
    customer = doPost("/api/customer", customer, Customer.class);
    CustomerId customerId = customer.getId();
    List<Edge> edges = new ArrayList<>();
    for (int i = 0; i < 128; i++) {
        Edge edge = constructEdge("Edge" + i, "default");
        edge = doPost("/api/edge", edge, Edge.class);
        edges.add(doPost("/api/customer/" + customerId.getId().toString() + "/edge/" + edge.getId().getId().toString(), Edge.class));
    }
    List<Edge> loadedEdges = new ArrayList<>();
    PageLink pageLink = new PageLink(23);
    PageData<Edge> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/edges?", new TypeReference<PageData<Edge>>() {
        }, 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);
}
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) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Edge(org.thingsboard.server.common.data.edge.Edge) 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