use of org.thingsboard.server.common.data.TbResource in project thingsboard by thingsboard.
the class BaseTbResourceServiceTest method testFindResourceById.
@Test
public void testFindResourceById() throws Exception {
TbResource resource = new TbResource();
resource.setResourceType(ResourceType.JKS);
resource.setTitle("My resource");
resource.setFileName(DEFAULT_FILE_NAME);
resource.setData("Test Data");
TbResource savedResource = resourceService.saveResource(resource);
TbResource foundResource = resourceService.findResourceById(tenantId, savedResource.getId());
Assert.assertNotNull(foundResource);
Assert.assertEquals(savedResource, foundResource);
resourceService.deleteResource(tenantId, savedResource.getId());
}
use of org.thingsboard.server.common.data.TbResource in project thingsboard by thingsboard.
the class BaseTbResourceServiceTest method testSaveTbResourceWithExistsFileName.
@Test(expected = DataValidationException.class)
public void testSaveTbResourceWithExistsFileName() throws Exception {
TbResource resource = new TbResource();
resource.setTenantId(tenantId);
resource.setResourceType(ResourceType.JKS);
resource.setTitle("My resource");
resource.setFileName(DEFAULT_FILE_NAME);
resource.setData("Test Data");
TbResource savedResource = resourceService.saveResource(resource);
TbResource resource2 = new TbResource();
resource.setTenantId(tenantId);
resource.setResourceType(ResourceType.JKS);
resource.setTitle("My resource");
resource.setFileName(DEFAULT_FILE_NAME);
resource.setData("Test Data");
try {
resourceService.saveResource(resource2);
} finally {
resourceService.deleteResource(tenantId, savedResource.getId());
}
}
use of org.thingsboard.server.common.data.TbResource in project thingsboard by thingsboard.
the class BaseTbResourceServiceTest method testSaveTbResourceWithEmptyTenant.
@Test
public void testSaveTbResourceWithEmptyTenant() throws Exception {
TbResource resource = new TbResource();
resource.setResourceType(ResourceType.JKS);
resource.setTitle("My resource");
resource.setFileName(DEFAULT_FILE_NAME);
resource.setData("Test Data");
TbResource savedResource = resourceService.saveResource(resource);
Assert.assertEquals(TenantId.SYS_TENANT_ID, savedResource.getTenantId());
resourceService.deleteResource(tenantId, savedResource.getId());
}
use of org.thingsboard.server.common.data.TbResource in project thingsboard by thingsboard.
the class BaseTbResourceServiceTest method testSaveTbResourceWithEmptyTitle.
@Test(expected = DataValidationException.class)
public void testSaveTbResourceWithEmptyTitle() throws Exception {
TbResource resource = new TbResource();
resource.setTenantId(tenantId);
resource.setResourceType(ResourceType.JKS);
resource.setFileName(DEFAULT_FILE_NAME);
resource.setData("Test Data");
resourceService.saveResource(resource);
}
use of org.thingsboard.server.common.data.TbResource in project thingsboard by thingsboard.
the class BaseTbResourceServiceTest method createResource.
private TbResource createResource(String title, String filename) throws ThingsboardException {
TbResource resource = new TbResource();
resource.setTenantId(tenantId);
resource.setTitle(title);
resource.setResourceType(ResourceType.JKS);
resource.setFileName(filename);
resource.setData("1");
return resourceService.saveResource(resource);
}
Aggregations