Search in sources :

Example 1 with TenantInfo

use of org.thingsboard.server.common.data.TenantInfo in project thingsboard by thingsboard.

the class BaseTenantControllerTest method testFindTenantInfoById.

@Test
public void testFindTenantInfoById() throws Exception {
    loginSysAdmin();
    Tenant tenant = new Tenant();
    tenant.setTitle("My tenant");
    Tenant savedTenant = doPost("/api/tenant", tenant, Tenant.class);
    TenantInfo foundTenant = doGet("/api/tenant/info/" + savedTenant.getId().getId().toString(), TenantInfo.class);
    Assert.assertNotNull(foundTenant);
    Assert.assertEquals(new TenantInfo(savedTenant, "Default"), foundTenant);
    doDelete("/api/tenant/" + savedTenant.getId().getId().toString()).andExpect(status().isOk());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) TenantInfo(org.thingsboard.server.common.data.TenantInfo) Test(org.junit.Test)

Example 2 with TenantInfo

use of org.thingsboard.server.common.data.TenantInfo in project thingsboard by thingsboard.

the class BaseTenantServiceTest method testFindTenantInfos.

@Test
public void testFindTenantInfos() {
    List<TenantInfo> tenants = new ArrayList<>();
    PageLink pageLink = new PageLink(17);
    PageData<TenantInfo> pageData = tenantService.findTenantInfos(pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertTrue(pageData.getData().isEmpty());
    tenants.addAll(pageData.getData());
    for (int i = 0; i < 156; i++) {
        Tenant tenant = new Tenant();
        tenant.setTitle("Tenant" + i);
        tenants.add(new TenantInfo(tenantService.saveTenant(tenant), "Default"));
    }
    List<TenantInfo> loadedTenants = new ArrayList<>();
    pageLink = new PageLink(17);
    do {
        pageData = tenantService.findTenantInfos(pageLink);
        loadedTenants.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenants, idComparator);
    Collections.sort(loadedTenants, idComparator);
    Assert.assertEquals(tenants, loadedTenants);
    for (TenantInfo tenant : loadedTenants) {
        tenantService.deleteTenant(tenant.getId());
    }
    pageLink = new PageLink(17);
    pageData = tenantService.findTenantInfos(pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertTrue(pageData.getData().isEmpty());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantInfo(org.thingsboard.server.common.data.TenantInfo) Test(org.junit.Test)

Example 3 with TenantInfo

use of org.thingsboard.server.common.data.TenantInfo in project thingsboard by thingsboard.

the class BaseTenantServiceTest method testFindTenantInfoById.

@Test
public void testFindTenantInfoById() {
    Tenant tenant = new Tenant();
    tenant.setTitle("My tenant");
    Tenant savedTenant = tenantService.saveTenant(tenant);
    TenantInfo foundTenant = tenantService.findTenantInfoById(savedTenant.getId());
    Assert.assertNotNull(foundTenant);
    Assert.assertEquals(new TenantInfo(savedTenant, "Default"), foundTenant);
    tenantService.deleteTenant(savedTenant.getId());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) TenantInfo(org.thingsboard.server.common.data.TenantInfo) Test(org.junit.Test)

Example 4 with TenantInfo

use of org.thingsboard.server.common.data.TenantInfo in project thingsboard by thingsboard.

the class BaseTenantControllerTest method testFindTenantInfos.

@Test
public void testFindTenantInfos() throws Exception {
    loginSysAdmin();
    List<TenantInfo> tenants = new ArrayList<>();
    PageLink pageLink = new PageLink(17);
    PageData<TenantInfo> pageData = doGetTypedWithPageLink("/api/tenantInfos?", new TypeReference<PageData<TenantInfo>>() {
    }, 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(new TenantInfo(doPost("/api/tenant", tenant, Tenant.class), "Default"));
    }
    List<TenantInfo> loadedTenants = new ArrayList<>();
    pageLink = new PageLink(17);
    do {
        pageData = doGetTypedWithPageLink("/api/tenantInfos?", new TypeReference<PageData<TenantInfo>>() {
        }, pageLink);
        loadedTenants.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenants, idComparator);
    Collections.sort(loadedTenants, idComparator);
    Assert.assertEquals(tenants, loadedTenants);
    for (TenantInfo tenant : loadedTenants) {
        if (!tenant.getTitle().equals(TEST_TENANT_NAME)) {
            doDelete("/api/tenant/" + tenant.getId().getId().toString()).andExpect(status().isOk());
        }
    }
    pageLink = new PageLink(17);
    pageData = doGetTypedWithPageLink("/api/tenantInfos?", new TypeReference<PageData<TenantInfo>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getData().size());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) PageData(org.thingsboard.server.common.data.page.PageData) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantInfo(org.thingsboard.server.common.data.TenantInfo) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 5 with TenantInfo

use of org.thingsboard.server.common.data.TenantInfo in project thingsboard by thingsboard.

the class BaseController method checkTenantInfoId.

TenantInfo checkTenantInfoId(TenantId tenantId, Operation operation) throws ThingsboardException {
    try {
        validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
        TenantInfo tenant = tenantService.findTenantInfoById(tenantId);
        checkNotNull(tenant, "Tenant with id [" + tenantId + "] is not found");
        accessControlService.checkPermission(getCurrentUser(), Resource.TENANT, operation, tenantId, tenant);
        return tenant;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : TenantInfo(org.thingsboard.server.common.data.TenantInfo) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) MessagingException(javax.mail.MessagingException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

TenantInfo (org.thingsboard.server.common.data.TenantInfo)5 Test (org.junit.Test)4 Tenant (org.thingsboard.server.common.data.Tenant)4 ArrayList (java.util.ArrayList)2 PageLink (org.thingsboard.server.common.data.page.PageLink)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 MessagingException (javax.mail.MessagingException)1 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)1 PageData (org.thingsboard.server.common.data.page.PageData)1 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)1 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)1