Search in sources :

Example 31 with TenantProfile

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

the class BaseTenantProfileControllerTest method testFindTenantProfileInfos.

@Test
public void testFindTenantProfileInfos() throws Exception {
    loginSysAdmin();
    List<TenantProfile> tenantProfiles = new ArrayList<>();
    PageLink pageLink = new PageLink(17);
    PageData<TenantProfile> tenantProfilePageData = doGetTypedWithPageLink("/api/tenantProfiles?", new TypeReference<PageData<TenantProfile>>() {
    }, pageLink);
    Assert.assertFalse(tenantProfilePageData.hasNext());
    Assert.assertEquals(1, tenantProfilePageData.getTotalElements());
    tenantProfiles.addAll(tenantProfilePageData.getData());
    for (int i = 0; i < 28; i++) {
        TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile" + i);
        tenantProfiles.add(doPost("/api/tenantProfile", tenantProfile, TenantProfile.class));
    }
    List<EntityInfo> loadedTenantProfileInfos = new ArrayList<>();
    pageLink = new PageLink(17);
    PageData<EntityInfo> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/tenantProfileInfos?", new TypeReference<PageData<EntityInfo>>() {
        }, 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 (TenantProfile tenantProfile : tenantProfiles) {
        if (!tenantProfile.isDefault()) {
            doDelete("/api/tenantProfile/" + tenantProfile.getId().getId().toString()).andExpect(status().isOk());
        }
    }
    pageLink = new PageLink(17);
    pageData = doGetTypedWithPageLink("/api/tenantProfileInfos?", new TypeReference<PageData<EntityInfo>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getTotalElements());
}
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) Autowired(org.springframework.beans.factory.annotation.Autowired) 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) List(java.util.List) TenantProfile(org.thingsboard.server.common.data.TenantProfile) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) After(org.junit.After) PageData(org.thingsboard.server.common.data.page.PageData) TenantProfileService(org.thingsboard.server.dao.tenant.TenantProfileService) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Assert(org.junit.Assert) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) ArrayList(java.util.ArrayList) PageData(org.thingsboard.server.common.data.page.PageData) EntityInfo(org.thingsboard.server.common.data.EntityInfo) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantProfile(org.thingsboard.server.common.data.TenantProfile) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 32 with TenantProfile

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

the class BaseTenantProfileControllerTest method testSaveTenantProfileWithEmptyName.

@Test
public void testSaveTenantProfileWithEmptyName() throws Exception {
    loginSysAdmin();
    TenantProfile tenantProfile = new TenantProfile();
    doPost("/api/tenantProfile", tenantProfile).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Tenant profile name should be specified")));
}
Also used : TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 33 with TenantProfile

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

the class BaseTenantProfileControllerTest method testSaveTenantProfileWithSameName.

@Test
public void testSaveTenantProfileWithSameName() throws Exception {
    loginSysAdmin();
    TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile");
    doPost("/api/tenantProfile", tenantProfile).andExpect(status().isOk());
    TenantProfile tenantProfile2 = this.createTenantProfile("Tenant Profile");
    doPost("/api/tenantProfile", tenantProfile2).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Tenant profile with such name already exists")));
}
Also used : TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 34 with TenantProfile

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

the class BaseTenantProfileControllerTest method testSaveTenantProfileWithViolationOfLengthValidation.

@Test
public void testSaveTenantProfileWithViolationOfLengthValidation() throws Exception {
    loginSysAdmin();
    TenantProfile tenantProfile = this.createTenantProfile(RandomStringUtils.randomAlphabetic(300));
    doPost("/api/tenantProfile", tenantProfile).andExpect(statusReason(containsString("length of name must be equal or less than 255")));
}
Also used : TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 35 with TenantProfile

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

the class BaseTenantProfileControllerTest method testFindTenantProfiles.

@Test
public void testFindTenantProfiles() throws Exception {
    loginSysAdmin();
    List<TenantProfile> tenantProfiles = new ArrayList<>();
    PageLink pageLink = new PageLink(17);
    PageData<TenantProfile> pageData = doGetTypedWithPageLink("/api/tenantProfiles?", new TypeReference<PageData<TenantProfile>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getTotalElements());
    tenantProfiles.addAll(pageData.getData());
    for (int i = 0; i < 28; i++) {
        TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile" + i);
        tenantProfiles.add(doPost("/api/tenantProfile", tenantProfile, TenantProfile.class));
    }
    List<TenantProfile> loadedTenantProfiles = new ArrayList<>();
    pageLink = new PageLink(17);
    do {
        pageData = doGetTypedWithPageLink("/api/tenantProfiles?", new TypeReference<PageData<TenantProfile>>() {
        }, pageLink);
        loadedTenantProfiles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(tenantProfiles, idComparator);
    Collections.sort(loadedTenantProfiles, idComparator);
    Assert.assertEquals(tenantProfiles, loadedTenantProfiles);
    for (TenantProfile tenantProfile : loadedTenantProfiles) {
        if (!tenantProfile.isDefault()) {
            doDelete("/api/tenantProfile/" + tenantProfile.getId().getId().toString()).andExpect(status().isOk());
        }
    }
    pageLink = new PageLink(17);
    pageData = doGetTypedWithPageLink("/api/tenantProfiles?", new TypeReference<PageData<TenantProfile>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getTotalElements());
}
Also used : PageData(org.thingsboard.server.common.data.page.PageData) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TenantProfile(org.thingsboard.server.common.data.TenantProfile) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Aggregations

TenantProfile (org.thingsboard.server.common.data.TenantProfile)56 Test (org.junit.Test)33 Tenant (org.thingsboard.server.common.data.Tenant)10 DefaultTenantProfileConfiguration (org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration)10 TenantId (org.thingsboard.server.common.data.id.TenantId)9 TenantProfileData (org.thingsboard.server.common.data.tenant.profile.TenantProfileData)9 ArrayList (java.util.ArrayList)8 EntityInfo (org.thingsboard.server.common.data.EntityInfo)7 List (java.util.List)6 TenantProfileId (org.thingsboard.server.common.data.id.TenantProfileId)6 ApiUsageState (org.thingsboard.server.common.data.ApiUsageState)5 EntityType (org.thingsboard.server.common.data.EntityType)5 Collections (java.util.Collections)4 Collectors (java.util.stream.Collectors)4 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)4 BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)4 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)4 PageLink (org.thingsboard.server.common.data.page.PageLink)4 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)4 Map (java.util.Map)3