Search in sources :

Example 86 with TypeReference

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

the class BaseRuleControllerTest method testFindTenantPlugins.

@Test
public void testFindTenantPlugins() throws Exception {
    List<RuleMetaData> rules = testRulesCreation("/api/rule", tenantPlugin);
    loginSysAdmin();
    List<RuleMetaData> loadedRules = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(3);
    TextPageData<RuleMetaData> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/rule/tenant/" + savedTenant.getId().getId().toString() + "?", new TypeReference<TextPageData<RuleMetaData>>() {
        }, pageLink);
        loadedRules.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(rules, idComparator);
    Collections.sort(loadedRules, idComparator);
    Assert.assertEquals(rules, loadedRules);
    for (RuleMetaData rule : rules) {
        doDelete("/api/rule/" + rule.getId().getId()).andExpect(status().isOk());
    }
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 87 with TypeReference

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

the class BaseTenantControllerTest method testFindTenants.

@Test
public void testFindTenants() throws Exception {
    loginSysAdmin();
    List<Tenant> tenants = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(17);
    TextPageData<Tenant> pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<TextPageData<Tenant>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getData().size());
    tenants.addAll(pageData.getData());
    for (int i = 0; i < 56; i++) {
        Tenant tenant = new Tenant();
        tenant.setTitle("Tenant" + i);
        tenants.add(doPost("/api/tenant", tenant, Tenant.class));
    }
    List<Tenant> loadedTenants = new ArrayList<>();
    pageLink = new TextPageLink(17);
    do {
        pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<TextPageData<Tenant>>() {
        }, pageLink);
        loadedTenants.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenants, idComparator);
    Collections.sort(loadedTenants, idComparator);
    Assert.assertEquals(tenants, loadedTenants);
    for (Tenant tenant : loadedTenants) {
        if (!tenant.getTitle().equals(TEST_TENANT_NAME)) {
            doDelete("/api/tenant/" + tenant.getId().getId().toString()).andExpect(status().isOk());
        }
    }
    pageLink = new TextPageLink(17);
    pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<TextPageData<Tenant>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getData().size());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) TextPageData(org.thingsboard.server.common.data.page.TextPageData) ArrayList(java.util.ArrayList) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 88 with TypeReference

use of com.fasterxml.jackson.core.type.TypeReference 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<>();
    TextPageLink pageLink = new TextPageLink(15, title1);
    TextPageData<Tenant> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<TextPageData<Tenant>>() {
        }, pageLink);
        loadedTenantsTitle1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantsTitle1, idComparator);
    Collections.sort(loadedTenantsTitle1, idComparator);
    Assert.assertEquals(tenantsTitle1, loadedTenantsTitle1);
    List<Tenant> loadedTenantsTitle2 = new ArrayList<>();
    pageLink = new TextPageLink(4, title2);
    do {
        pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<TextPageData<Tenant>>() {
        }, pageLink);
        loadedTenantsTitle2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } 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 TextPageLink(4, title1);
    pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<TextPageData<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 TextPageLink(4, title2);
    pageData = doGetTypedWithPageLink("/api/tenants?", new TypeReference<TextPageData<Tenant>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) 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 89 with TypeReference

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

the class BaseUserControllerTest method testFindTenantAdminsByEmail.

@Test
public void testFindTenantAdminsByEmail() throws Exception {
    loginSysAdmin();
    Tenant tenant = new Tenant();
    tenant.setTitle("My tenant");
    Tenant savedTenant = doPost("/api/tenant", tenant, Tenant.class);
    Assert.assertNotNull(savedTenant);
    TenantId tenantId = savedTenant.getId();
    String email1 = "testEmail1";
    List<User> tenantAdminsEmail1 = new ArrayList<>();
    for (int i = 0; i < 124; i++) {
        User user = new User();
        user.setAuthority(Authority.TENANT_ADMIN);
        user.setTenantId(tenantId);
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String email = email1 + suffix + "@thingsboard.org";
        email = i % 2 == 0 ? email.toLowerCase() : email.toUpperCase();
        user.setEmail(email);
        tenantAdminsEmail1.add(doPost("/api/user", user, User.class));
    }
    String email2 = "testEmail2";
    List<User> tenantAdminsEmail2 = new ArrayList<>();
    for (int i = 0; i < 112; i++) {
        User user = new User();
        user.setAuthority(Authority.TENANT_ADMIN);
        user.setTenantId(tenantId);
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String email = email2 + suffix + "@thingsboard.org";
        email = i % 2 == 0 ? email.toLowerCase() : email.toUpperCase();
        user.setEmail(email);
        tenantAdminsEmail2.add(doPost("/api/user", user, User.class));
    }
    List<User> loadedTenantAdminsEmail1 = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(33, email1);
    TextPageData<User> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/" + tenantId.getId().toString() + "/users?", new TypeReference<TextPageData<User>>() {
        }, pageLink);
        loadedTenantAdminsEmail1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantAdminsEmail1, idComparator);
    Collections.sort(loadedTenantAdminsEmail1, idComparator);
    Assert.assertEquals(tenantAdminsEmail1, loadedTenantAdminsEmail1);
    List<User> loadedTenantAdminsEmail2 = new ArrayList<>();
    pageLink = new TextPageLink(16, email2);
    do {
        pageData = doGetTypedWithPageLink("/api/tenant/" + tenantId.getId().toString() + "/users?", new TypeReference<TextPageData<User>>() {
        }, pageLink);
        loadedTenantAdminsEmail2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantAdminsEmail2, idComparator);
    Collections.sort(loadedTenantAdminsEmail2, idComparator);
    Assert.assertEquals(tenantAdminsEmail2, loadedTenantAdminsEmail2);
    for (User user : loadedTenantAdminsEmail1) {
        doDelete("/api/user/" + user.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new TextPageLink(4, email1);
    pageData = doGetTypedWithPageLink("/api/tenant/" + tenantId.getId().toString() + "/users?", new TypeReference<TextPageData<User>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (User user : loadedTenantAdminsEmail2) {
        doDelete("/api/user/" + user.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new TextPageLink(4, email2);
    pageData = doGetTypedWithPageLink("/api/tenant/" + tenantId.getId().toString() + "/users?", new TypeReference<TextPageData<User>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    doDelete("/api/tenant/" + savedTenant.getId().getId().toString()).andExpect(status().isOk());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) User(org.thingsboard.server.common.data.User) 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 90 with TypeReference

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

the class BaseUserControllerTest method testFindCustomerUsers.

@Test
public void testFindCustomerUsers() throws Exception {
    loginSysAdmin();
    Tenant tenant = new Tenant();
    tenant.setTitle("My tenant");
    Tenant savedTenant = doPost("/api/tenant", tenant, Tenant.class);
    Assert.assertNotNull(savedTenant);
    TenantId tenantId = savedTenant.getId();
    User tenantAdmin = new User();
    tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
    tenantAdmin.setTenantId(tenantId);
    tenantAdmin.setEmail("tenant2@thingsboard.org");
    tenantAdmin.setFirstName("Joe");
    tenantAdmin.setLastName("Downs");
    tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1");
    Customer customer = new Customer();
    customer.setTitle("My customer");
    Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
    CustomerId customerId = savedCustomer.getId();
    List<User> customerUsers = new ArrayList<>();
    for (int i = 0; i < 56; i++) {
        User user = new User();
        user.setAuthority(Authority.CUSTOMER_USER);
        user.setCustomerId(customerId);
        user.setEmail("testCustomer" + i + "@thingsboard.org");
        customerUsers.add(doPost("/api/user", user, User.class));
    }
    List<User> loadedCustomerUsers = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(33);
    TextPageData<User> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/users?", new TypeReference<TextPageData<User>>() {
        }, pageLink);
        loadedCustomerUsers.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(customerUsers, idComparator);
    Collections.sort(loadedCustomerUsers, idComparator);
    Assert.assertEquals(customerUsers, loadedCustomerUsers);
    doDelete("/api/customer/" + customerId.getId().toString()).andExpect(status().isOk());
    loginSysAdmin();
    doDelete("/api/tenant/" + savedTenant.getId().getId().toString()).andExpect(status().isOk());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) User(org.thingsboard.server.common.data.User) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) CustomerId(org.thingsboard.server.common.data.id.CustomerId) 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