Search in sources :

Example 1 with EntityInfo

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

the class BaseTbResourceServiceTest method testSaveResourceWithMaxSumDataSizeOutOfLimit.

@Test
public void testSaveResourceWithMaxSumDataSizeOutOfLimit() throws Exception {
    loginSysAdmin();
    long limit = 1;
    EntityInfo defaultTenantProfileInfo = doGet("/api/tenantProfileInfo/default", EntityInfo.class);
    TenantProfile defaultTenantProfile = doGet("/api/tenantProfile/" + defaultTenantProfileInfo.getId().getId().toString(), TenantProfile.class);
    defaultTenantProfile.getProfileData().setConfiguration(DefaultTenantProfileConfiguration.builder().maxResourcesInBytes(limit).build());
    doPost("/api/tenantProfile", defaultTenantProfile, TenantProfile.class);
    loginTenantAdmin();
    Assert.assertEquals(0, resourceService.sumDataSizeByTenantId(tenantId));
    createResource("test", DEFAULT_FILE_NAME);
    Assert.assertEquals(1, resourceService.sumDataSizeByTenantId(tenantId));
    try {
        thrown.expect(DataValidationException.class);
        thrown.expectMessage(String.format("Failed to create the tb resource, files size limit is exhausted %d bytes!", limit));
        createResource("test1", 1 + DEFAULT_FILE_NAME);
    } finally {
        defaultTenantProfile.getProfileData().setConfiguration(DefaultTenantProfileConfiguration.builder().maxResourcesInBytes(0).build());
        loginSysAdmin();
        doPost("/api/tenantProfile", defaultTenantProfile, TenantProfile.class);
    }
}
Also used : EntityInfo(org.thingsboard.server.common.data.EntityInfo) TenantProfile(org.thingsboard.server.common.data.TenantProfile) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test) DaoSqlTest(org.thingsboard.server.dao.service.DaoSqlTest)

Example 2 with EntityInfo

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

the class BaseTenantProfileControllerTest method testSetDefaultTenantProfile.

@Test
public void testSetDefaultTenantProfile() throws Exception {
    loginSysAdmin();
    TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile 1");
    TenantProfile savedTenantProfile = doPost("/api/tenantProfile", tenantProfile, TenantProfile.class);
    TenantProfile defaultTenantProfile = doPost("/api/tenantProfile/" + savedTenantProfile.getId().getId().toString() + "/default", null, TenantProfile.class);
    Assert.assertNotNull(defaultTenantProfile);
    EntityInfo foundDefaultTenantProfile = doGet("/api/tenantProfileInfo/default", EntityInfo.class);
    Assert.assertNotNull(foundDefaultTenantProfile);
    Assert.assertEquals(savedTenantProfile.getName(), foundDefaultTenantProfile.getName());
    Assert.assertEquals(savedTenantProfile.getId(), foundDefaultTenantProfile.getId());
}
Also used : EntityInfo(org.thingsboard.server.common.data.EntityInfo) TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 3 with EntityInfo

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

the class BaseTenantProfileControllerTest method testFindTenantProfileInfoById.

@Test
public void testFindTenantProfileInfoById() throws Exception {
    loginSysAdmin();
    TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile");
    TenantProfile savedTenantProfile = doPost("/api/tenantProfile", tenantProfile, TenantProfile.class);
    EntityInfo foundTenantProfileInfo = doGet("/api/tenantProfileInfo/" + savedTenantProfile.getId().getId().toString(), EntityInfo.class);
    Assert.assertNotNull(foundTenantProfileInfo);
    Assert.assertEquals(savedTenantProfile.getId(), foundTenantProfileInfo.getId());
    Assert.assertEquals(savedTenantProfile.getName(), foundTenantProfileInfo.getName());
}
Also used : EntityInfo(org.thingsboard.server.common.data.EntityInfo) TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 4 with EntityInfo

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

the class BaseTenantProfileServiceTest method testFindDefaultTenantProfileInfo.

@Test
public void testFindDefaultTenantProfileInfo() {
    TenantProfile tenantProfile = this.createTenantProfile("Default Tenant Profile");
    tenantProfile.setDefault(true);
    TenantProfile savedTenantProfile = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile);
    EntityInfo foundDefaultTenantProfileInfo = tenantProfileService.findDefaultTenantProfileInfo(TenantId.SYS_TENANT_ID);
    Assert.assertNotNull(foundDefaultTenantProfileInfo);
    Assert.assertEquals(savedTenantProfile.getId(), foundDefaultTenantProfileInfo.getId());
    Assert.assertEquals(savedTenantProfile.getName(), foundDefaultTenantProfileInfo.getName());
}
Also used : EntityInfo(org.thingsboard.server.common.data.EntityInfo) TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 5 with EntityInfo

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

the class BaseTenantProfileServiceTest method testFindTenantProfileInfos.

@Test
public void testFindTenantProfileInfos() {
    List<TenantProfile> tenantProfiles = new ArrayList<>();
    for (int i = 0; i < 28; i++) {
        TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile" + i);
        tenantProfiles.add(tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile));
    }
    List<EntityInfo> loadedTenantProfileInfos = new ArrayList<>();
    PageLink pageLink = new PageLink(17);
    PageData<EntityInfo> pageData;
    do {
        pageData = tenantProfileService.findTenantProfileInfos(TenantId.SYS_TENANT_ID, pageLink);
        loadedTenantProfileInfos.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantProfiles, idComparator);
    Collections.sort(loadedTenantProfileInfos, tenantProfileInfoIdComparator);
    List<EntityInfo> tenantProfileInfos = tenantProfiles.stream().map(tenantProfile -> new EntityInfo(tenantProfile.getId(), tenantProfile.getName())).collect(Collectors.toList());
    Assert.assertEquals(tenantProfileInfos, loadedTenantProfileInfos);
    for (EntityInfo tenantProfile : loadedTenantProfileInfos) {
        tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, new TenantProfileId(tenantProfile.getId().getId()));
    }
    pageLink = new PageLink(17);
    pageData = tenantProfileService.findTenantProfileInfos(TenantId.SYS_TENANT_ID, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertTrue(pageData.getData().isEmpty());
}
Also used : EntityInfo(org.thingsboard.server.common.data.EntityInfo) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantProfileData(org.thingsboard.server.common.data.tenant.profile.TenantProfileData) Tenant(org.thingsboard.server.common.data.Tenant) Test(org.junit.Test) DefaultTenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration) Collectors(java.util.stream.Collectors) TenantId(org.thingsboard.server.common.data.id.TenantId) ArrayList(java.util.ArrayList) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) List(java.util.List) TenantProfile(org.thingsboard.server.common.data.TenantProfile) After(org.junit.After) TenantProfileId(org.thingsboard.server.common.data.id.TenantProfileId) PageData(org.thingsboard.server.common.data.page.PageData) Assert(org.junit.Assert) Collections(java.util.Collections) EntityInfo(org.thingsboard.server.common.data.EntityInfo) TenantProfileId(org.thingsboard.server.common.data.id.TenantProfileId) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 EntityInfo (org.thingsboard.server.common.data.EntityInfo)8 TenantProfile (org.thingsboard.server.common.data.TenantProfile)7 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 After (org.junit.After)2 Assert (org.junit.Assert)2 Tenant (org.thingsboard.server.common.data.Tenant)2 TenantId (org.thingsboard.server.common.data.id.TenantId)2 PageData (org.thingsboard.server.common.data.page.PageData)2 PageLink (org.thingsboard.server.common.data.page.PageLink)2 DefaultTenantProfileConfiguration (org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration)2 TenantProfileData (org.thingsboard.server.common.data.tenant.profile.TenantProfileData)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 RandomStringUtils (org.apache.commons.lang3.RandomStringUtils)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 MockMvcResultMatchers.status (org.springframework.test.web.servlet.result.MockMvcResultMatchers.status)1