Search in sources :

Example 6 with EntityInfo

use of org.thingsboard.server.common.data.EntityInfo 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 7 with EntityInfo

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

the class BaseTenantProfileControllerTest method testFindDefaultTenantProfileInfo.

@Test
public void testFindDefaultTenantProfileInfo() throws Exception {
    loginSysAdmin();
    EntityInfo foundDefaultTenantProfile = doGet("/api/tenantProfileInfo/default", EntityInfo.class);
    Assert.assertNotNull(foundDefaultTenantProfile);
    Assert.assertEquals("Default", foundDefaultTenantProfile.getName());
}
Also used : EntityInfo(org.thingsboard.server.common.data.EntityInfo) Test(org.junit.Test)

Example 8 with EntityInfo

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

the class BaseTenantProfileServiceTest method testFindTenantProfileInfoById.

@Test
public void testFindTenantProfileInfoById() {
    TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile");
    TenantProfile savedTenantProfile = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile);
    EntityInfo foundTenantProfileInfo = tenantProfileService.findTenantProfileInfoById(TenantId.SYS_TENANT_ID, savedTenantProfile.getId());
    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)

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