Search in sources :

Example 36 with TenantProfile

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

the class BaseEdgeTest method testDeviceReachedMaximumAllowedOnCloud.

@Test
public void testDeviceReachedMaximumAllowedOnCloud() throws Exception {
    // update tenant profile configuration
    loginSysAdmin();
    TenantProfile tenantProfile = doGet("/api/tenantProfile/" + savedTenant.getTenantProfileId().getId(), TenantProfile.class);
    DefaultTenantProfileConfiguration profileConfiguration = (DefaultTenantProfileConfiguration) tenantProfile.getProfileData().getConfiguration();
    profileConfiguration.setMaxDevices(1);
    tenantProfile.getProfileData().setConfiguration(profileConfiguration);
    doPost("/api/tenantProfile/", tenantProfile, TenantProfile.class);
    loginTenantAdmin();
    UUID uuid = Uuids.timeBased();
    UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
    DeviceUpdateMsg.Builder deviceUpdateMsgBuilder = DeviceUpdateMsg.newBuilder();
    deviceUpdateMsgBuilder.setIdMSB(uuid.getMostSignificantBits());
    deviceUpdateMsgBuilder.setIdLSB(uuid.getLeastSignificantBits());
    deviceUpdateMsgBuilder.setName("Edge Device");
    deviceUpdateMsgBuilder.setType("default");
    deviceUpdateMsgBuilder.setMsgType(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE);
    uplinkMsgBuilder.addDeviceUpdateMsg(deviceUpdateMsgBuilder.build());
    edgeImitator.expectResponsesAmount(1);
    edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
    Assert.assertTrue(edgeImitator.waitForResponses());
    UplinkResponseMsg latestResponseMsg = edgeImitator.getLatestResponseMsg();
    Assert.assertTrue(latestResponseMsg.getSuccess());
}
Also used : UplinkMsg(org.thingsboard.server.gen.edge.v1.UplinkMsg) DeviceUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceUpdateMsg) TenantProfile(org.thingsboard.server.common.data.TenantProfile) UUID(java.util.UUID) DefaultTenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration) UplinkResponseMsg(org.thingsboard.server.gen.edge.v1.UplinkResponseMsg) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Example 37 with TenantProfile

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

the class BaseOtaPackageServiceTest method testSaveOtaPackageWithMaxSumDataSizeOutOfLimit.

@Test
public void testSaveOtaPackageWithMaxSumDataSizeOutOfLimit() {
    TenantProfile defaultTenantProfile = tenantProfileService.findDefaultTenantProfile(tenantId);
    defaultTenantProfile.getProfileData().setConfiguration(DefaultTenantProfileConfiguration.builder().maxOtaPackagesInBytes(DATA_SIZE).build());
    tenantProfileService.saveTenantProfile(tenantId, defaultTenantProfile);
    Assert.assertEquals(0, otaPackageService.sumDataSizeByTenantId(tenantId));
    createFirmware(tenantId, "1");
    Assert.assertEquals(1, otaPackageService.sumDataSizeByTenantId(tenantId));
    thrown.expect(DataValidationException.class);
    thrown.expectMessage(String.format("Failed to create the ota package, files size limit is exhausted %d bytes!", DATA_SIZE));
    createFirmware(tenantId, "2");
}
Also used : TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 38 with TenantProfile

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

the class BaseTenantProfileServiceTest method testSaveTenantProfile.

@Test
public void testSaveTenantProfile() {
    TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile");
    TenantProfile savedTenantProfile = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile);
    Assert.assertNotNull(savedTenantProfile);
    Assert.assertNotNull(savedTenantProfile.getId());
    Assert.assertTrue(savedTenantProfile.getCreatedTime() > 0);
    Assert.assertEquals(tenantProfile.getName(), savedTenantProfile.getName());
    Assert.assertEquals(tenantProfile.getDescription(), savedTenantProfile.getDescription());
    Assert.assertEquals(tenantProfile.getProfileData(), savedTenantProfile.getProfileData());
    Assert.assertEquals(tenantProfile.isDefault(), savedTenantProfile.isDefault());
    Assert.assertEquals(tenantProfile.isIsolatedTbCore(), savedTenantProfile.isIsolatedTbCore());
    Assert.assertEquals(tenantProfile.isIsolatedTbRuleEngine(), savedTenantProfile.isIsolatedTbRuleEngine());
    savedTenantProfile.setName("New tenant profile");
    tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile);
    TenantProfile foundTenantProfile = tenantProfileService.findTenantProfileById(TenantId.SYS_TENANT_ID, savedTenantProfile.getId());
    Assert.assertEquals(foundTenantProfile.getName(), savedTenantProfile.getName());
}
Also used : TenantProfile(org.thingsboard.server.common.data.TenantProfile) Test(org.junit.Test)

Example 39 with TenantProfile

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

Example 40 with TenantProfile

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

the class BaseTenantProfileServiceTest method testSaveTenantProfileWithEmptyName.

@Test(expected = DataValidationException.class)
public void testSaveTenantProfileWithEmptyName() {
    TenantProfile tenantProfile = new TenantProfile();
    tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile);
}
Also used : TenantProfile(org.thingsboard.server.common.data.TenantProfile) 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