Search in sources :

Example 81 with TypeReference

use of com.fasterxml.jackson.core.type.TypeReference in project thingsboard by thingsboard.

the class BaseAssetControllerTest method testFindTenantAssetsByType.

@Test
public void testFindTenantAssetsByType() throws Exception {
    String title1 = "Asset title 1";
    String type1 = "typeA";
    List<Asset> assetsType1 = new ArrayList<>();
    for (int i = 0; i < 143; i++) {
        Asset asset = new Asset();
        String suffix = RandomStringUtils.randomAlphanumeric(15);
        String name = title1 + suffix;
        name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
        asset.setName(name);
        asset.setType(type1);
        assetsType1.add(doPost("/api/asset", asset, Asset.class));
    }
    String title2 = "Asset title 2";
    String type2 = "typeB";
    List<Asset> assetsType2 = new ArrayList<>();
    for (int i = 0; i < 75; i++) {
        Asset asset = new Asset();
        String suffix = RandomStringUtils.randomAlphanumeric(15);
        String name = title2 + suffix;
        name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
        asset.setName(name);
        asset.setType(type2);
        assetsType2.add(doPost("/api/asset", asset, Asset.class));
    }
    List<Asset> loadedAssetsType1 = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(15);
    TextPageData<Asset> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/assets?type={type}&", new TypeReference<TextPageData<Asset>>() {
        }, pageLink, type1);
        loadedAssetsType1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(assetsType1, idComparator);
    Collections.sort(loadedAssetsType1, idComparator);
    Assert.assertEquals(assetsType1, loadedAssetsType1);
    List<Asset> loadedAssetsType2 = new ArrayList<>();
    pageLink = new TextPageLink(4);
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/assets?type={type}&", new TypeReference<TextPageData<Asset>>() {
        }, pageLink, type2);
        loadedAssetsType2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(assetsType2, idComparator);
    Collections.sort(loadedAssetsType2, idComparator);
    Assert.assertEquals(assetsType2, loadedAssetsType2);
    for (Asset asset : loadedAssetsType1) {
        doDelete("/api/asset/" + asset.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new TextPageLink(4);
    pageData = doGetTypedWithPageLink("/api/tenant/assets?type={type}&", new TypeReference<TextPageData<Asset>>() {
    }, pageLink, type1);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (Asset asset : loadedAssetsType2) {
        doDelete("/api/asset/" + asset.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new TextPageLink(4);
    pageData = doGetTypedWithPageLink("/api/tenant/assets?type={type}&", new TypeReference<TextPageData<Asset>>() {
    }, pageLink, type2);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) Asset(org.thingsboard.server.common.data.asset.Asset) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 82 with TypeReference

use of com.fasterxml.jackson.core.type.TypeReference in project thingsboard by thingsboard.

the class BaseDashboardControllerTest method testFindCustomerDashboards.

@Test
public void testFindCustomerDashboards() throws Exception {
    Customer customer = new Customer();
    customer.setTitle("Test customer");
    customer = doPost("/api/customer", customer, Customer.class);
    CustomerId customerId = customer.getId();
    List<DashboardInfo> dashboards = new ArrayList<>();
    for (int i = 0; i < 173; i++) {
        Dashboard dashboard = new Dashboard();
        dashboard.setTitle("Dashboard" + i);
        dashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
        dashboards.add(new DashboardInfo(doPost("/api/customer/" + customerId.getId().toString() + "/dashboard/" + dashboard.getId().getId().toString(), Dashboard.class)));
    }
    List<DashboardInfo> loadedDashboards = new ArrayList<>();
    TimePageLink pageLink = new TimePageLink(21);
    TimePageData<DashboardInfo> pageData = null;
    do {
        pageData = doGetTypedWithTimePageLink("/api/customer/" + customerId.getId().toString() + "/dashboards?", new TypeReference<TimePageData<DashboardInfo>>() {
        }, pageLink);
        loadedDashboards.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(dashboards, idComparator);
    Collections.sort(loadedDashboards, idComparator);
    Assert.assertEquals(dashboards, loadedDashboards);
}
Also used : ArrayList(java.util.ArrayList) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 83 with TypeReference

use of com.fasterxml.jackson.core.type.TypeReference in project thingsboard by thingsboard.

the class BaseDeviceControllerTest method testFindTenantDevicesByName.

@Test
public void testFindTenantDevicesByName() throws Exception {
    String title1 = "Device title 1";
    List<Device> devicesTitle1 = new ArrayList<>();
    for (int i = 0; i < 143; i++) {
        Device device = new Device();
        String suffix = RandomStringUtils.randomAlphanumeric(15);
        String name = title1 + suffix;
        name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
        device.setName(name);
        device.setType("default");
        devicesTitle1.add(doPost("/api/device", device, Device.class));
    }
    String title2 = "Device title 2";
    List<Device> devicesTitle2 = new ArrayList<>();
    for (int i = 0; i < 75; i++) {
        Device device = new Device();
        String suffix = RandomStringUtils.randomAlphanumeric(15);
        String name = title2 + suffix;
        name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
        device.setName(name);
        device.setType("default");
        devicesTitle2.add(doPost("/api/device", device, Device.class));
    }
    List<Device> loadedDevicesTitle1 = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(15, title1);
    TextPageData<Device> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/devices?", new TypeReference<TextPageData<Device>>() {
        }, pageLink);
        loadedDevicesTitle1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(devicesTitle1, idComparator);
    Collections.sort(loadedDevicesTitle1, idComparator);
    Assert.assertEquals(devicesTitle1, loadedDevicesTitle1);
    List<Device> loadedDevicesTitle2 = new ArrayList<>();
    pageLink = new TextPageLink(4, title2);
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/devices?", new TypeReference<TextPageData<Device>>() {
        }, pageLink);
        loadedDevicesTitle2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(devicesTitle2, idComparator);
    Collections.sort(loadedDevicesTitle2, idComparator);
    Assert.assertEquals(devicesTitle2, loadedDevicesTitle2);
    for (Device device : loadedDevicesTitle1) {
        doDelete("/api/device/" + device.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new TextPageLink(4, title1);
    pageData = doGetTypedWithPageLink("/api/tenant/devices?", new TypeReference<TextPageData<Device>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (Device device : loadedDevicesTitle2) {
        doDelete("/api/device/" + device.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new TextPageLink(4, title2);
    pageData = doGetTypedWithPageLink("/api/tenant/devices?", new TypeReference<TextPageData<Device>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 84 with TypeReference

use of com.fasterxml.jackson.core.type.TypeReference in project thingsboard by thingsboard.

the class BaseDeviceControllerTest method testFindTenantDevicesByType.

@Test
public void testFindTenantDevicesByType() throws Exception {
    String title1 = "Device title 1";
    String type1 = "typeA";
    List<Device> devicesType1 = new ArrayList<>();
    for (int i = 0; i < 143; i++) {
        Device device = new Device();
        String suffix = RandomStringUtils.randomAlphanumeric(15);
        String name = title1 + suffix;
        name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
        device.setName(name);
        device.setType(type1);
        devicesType1.add(doPost("/api/device", device, Device.class));
    }
    String title2 = "Device title 2";
    String type2 = "typeB";
    List<Device> devicesType2 = new ArrayList<>();
    for (int i = 0; i < 75; i++) {
        Device device = new Device();
        String suffix = RandomStringUtils.randomAlphanumeric(15);
        String name = title2 + suffix;
        name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
        device.setName(name);
        device.setType(type2);
        devicesType2.add(doPost("/api/device", device, Device.class));
    }
    List<Device> loadedDevicesType1 = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(15);
    TextPageData<Device> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/devices?type={type}&", new TypeReference<TextPageData<Device>>() {
        }, pageLink, type1);
        loadedDevicesType1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(devicesType1, idComparator);
    Collections.sort(loadedDevicesType1, idComparator);
    Assert.assertEquals(devicesType1, loadedDevicesType1);
    List<Device> loadedDevicesType2 = new ArrayList<>();
    pageLink = new TextPageLink(4);
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/devices?type={type}&", new TypeReference<TextPageData<Device>>() {
        }, pageLink, type2);
        loadedDevicesType2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(devicesType2, idComparator);
    Collections.sort(loadedDevicesType2, idComparator);
    Assert.assertEquals(devicesType2, loadedDevicesType2);
    for (Device device : loadedDevicesType1) {
        doDelete("/api/device/" + device.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new TextPageLink(4);
    pageData = doGetTypedWithPageLink("/api/tenant/devices?type={type}&", new TypeReference<TextPageData<Device>>() {
    }, pageLink, type1);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (Device device : loadedDevicesType2) {
        doDelete("/api/device/" + device.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new TextPageLink(4);
    pageData = doGetTypedWithPageLink("/api/tenant/devices?type={type}&", new TypeReference<TextPageData<Device>>() {
    }, pageLink, type2);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 85 with TypeReference

use of com.fasterxml.jackson.core.type.TypeReference in project thingsboard by thingsboard.

the class BaseDeviceControllerTest method testFindTenantDevices.

@Test
public void testFindTenantDevices() throws Exception {
    List<Device> devices = new ArrayList<>();
    for (int i = 0; i < 178; i++) {
        Device device = new Device();
        device.setName("Device" + i);
        device.setType("default");
        devices.add(doPost("/api/device", device, Device.class));
    }
    List<Device> loadedDevices = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(23);
    TextPageData<Device> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/devices?", new TypeReference<TextPageData<Device>>() {
        }, pageLink);
        loadedDevices.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(devices, idComparator);
    Collections.sort(loadedDevices, idComparator);
    Assert.assertEquals(devices, loadedDevices);
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)316 IOException (java.io.IOException)130 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)113 Test (org.junit.Test)95 ArrayList (java.util.ArrayList)74 Map (java.util.Map)74 List (java.util.List)60 HashMap (java.util.HashMap)58 File (java.io.File)34 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)27 Collectors (java.util.stream.Collectors)25 InputStream (java.io.InputStream)23 JsonNode (com.fasterxml.jackson.databind.JsonNode)19 ImmutableMap (com.google.common.collect.ImmutableMap)19 lombok.val (lombok.val)18 Matchers.containsString (org.hamcrest.Matchers.containsString)17 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)14 Collections (java.util.Collections)13 ISE (org.apache.druid.java.util.common.ISE)12 URL (java.net.URL)10