Search in sources :

Example 1 with TbResource

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());
}
Also used : TbResource(org.thingsboard.server.common.data.TbResource) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test) DaoSqlTest(org.thingsboard.server.dao.service.DaoSqlTest)

Example 2 with TbResource

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());
    }
}
Also used : TbResource(org.thingsboard.server.common.data.TbResource) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test) DaoSqlTest(org.thingsboard.server.dao.service.DaoSqlTest)

Example 3 with TbResource

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());
}
Also used : TbResource(org.thingsboard.server.common.data.TbResource) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test) DaoSqlTest(org.thingsboard.server.dao.service.DaoSqlTest)

Example 4 with TbResource

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);
}
Also used : TbResource(org.thingsboard.server.common.data.TbResource) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test) DaoSqlTest(org.thingsboard.server.dao.service.DaoSqlTest)

Example 5 with TbResource

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);
}
Also used : TbResource(org.thingsboard.server.common.data.TbResource)

Aggregations

TbResource (org.thingsboard.server.common.data.TbResource)29 Test (org.junit.Test)19 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)11 DaoSqlTest (org.thingsboard.server.dao.service.DaoSqlTest)11 ArrayList (java.util.ArrayList)5 TbResourceInfo (org.thingsboard.server.common.data.TbResourceInfo)5 PageLink (org.thingsboard.server.common.data.page.PageLink)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)4 ApiOperation (io.swagger.annotations.ApiOperation)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 TbResourceId (org.thingsboard.server.common.data.id.TbResourceId)3 TenantId (org.thingsboard.server.common.data.id.TenantId)3 UUID (java.util.UUID)2 Tenant (org.thingsboard.server.common.data.Tenant)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ByteString (com.google.protobuf.ByteString)1 MessagingException (javax.mail.MessagingException)1