Search in sources :

Example 26 with WidgetTypeDetails

use of org.thingsboard.server.common.data.widget.WidgetTypeDetails in project thingsboard by thingsboard.

the class BaseWidgetTypeServiceTest method testSaveWidgetTypeWithEmptyBundleAlias.

@Test(expected = DataValidationException.class)
public void testSaveWidgetTypeWithEmptyBundleAlias() throws IOException {
    WidgetTypeDetails widgetType = new WidgetTypeDetails();
    widgetType.setTenantId(tenantId);
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    widgetTypeService.saveWidgetType(widgetType);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 27 with WidgetTypeDetails

use of org.thingsboard.server.common.data.widget.WidgetTypeDetails in project thingsboard by thingsboard.

the class BaseWidgetTypeServiceTest method testSaveWidgetTypeWithInvalidTenant.

@Test(expected = DataValidationException.class)
public void testSaveWidgetTypeWithInvalidTenant() throws IOException {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTenantId(tenantId);
    widgetsBundle.setTitle("Widgets bundle");
    WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
    WidgetTypeDetails widgetType = new WidgetTypeDetails();
    widgetType.setTenantId(TenantId.fromUUID(Uuids.timeBased()));
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    try {
        widgetTypeService.saveWidgetType(widgetType);
    } finally {
        widgetsBundleService.deleteWidgetsBundle(tenantId, savedWidgetsBundle.getId());
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 28 with WidgetTypeDetails

use of org.thingsboard.server.common.data.widget.WidgetTypeDetails in project thingsboard by thingsboard.

the class BaseWidgetTypeServiceTest method testUpdateWidgetTypeTenant.

@Test(expected = DataValidationException.class)
public void testUpdateWidgetTypeTenant() throws IOException {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTenantId(tenantId);
    widgetsBundle.setTitle("Widgets bundle");
    WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
    WidgetTypeDetails widgetType = new WidgetTypeDetails();
    widgetType.setTenantId(tenantId);
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetTypeDetails savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
    savedWidgetType.setTenantId(TenantId.fromUUID(ModelConstants.NULL_UUID));
    try {
        widgetTypeService.saveWidgetType(savedWidgetType);
    } finally {
        widgetsBundleService.deleteWidgetsBundle(tenantId, savedWidgetsBundle.getId());
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 29 with WidgetTypeDetails

use of org.thingsboard.server.common.data.widget.WidgetTypeDetails in project thingsboard by thingsboard.

the class BaseWidgetTypeServiceTest method testUpdateWidgetTypeAlias.

@Test(expected = DataValidationException.class)
public void testUpdateWidgetTypeAlias() throws IOException {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTenantId(tenantId);
    widgetsBundle.setTitle("Widgets bundle");
    WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
    WidgetTypeDetails widgetType = new WidgetTypeDetails();
    widgetType.setTenantId(tenantId);
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetTypeDetails savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
    savedWidgetType.setAlias("some_alias");
    try {
        widgetTypeService.saveWidgetType(savedWidgetType);
    } finally {
        widgetsBundleService.deleteWidgetsBundle(tenantId, savedWidgetsBundle.getId());
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 30 with WidgetTypeDetails

use of org.thingsboard.server.common.data.widget.WidgetTypeDetails in project thingsboard by thingsboard.

the class BaseWidgetTypeServiceTest method testFindWidgetTypeById.

@Test
public void testFindWidgetTypeById() throws IOException {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTenantId(tenantId);
    widgetsBundle.setTitle("Widgets bundle");
    WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
    WidgetTypeDetails widgetType = new WidgetTypeDetails();
    widgetType.setTenantId(tenantId);
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetTypeDetails savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
    WidgetTypeDetails foundWidgetType = widgetTypeService.findWidgetTypeDetailsById(tenantId, savedWidgetType.getId());
    Assert.assertNotNull(foundWidgetType);
    Assert.assertEquals(savedWidgetType, foundWidgetType);
    widgetsBundleService.deleteWidgetsBundle(tenantId, savedWidgetsBundle.getId());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

WidgetTypeDetails (org.thingsboard.server.common.data.widget.WidgetTypeDetails)30 JsonNode (com.fasterxml.jackson.databind.JsonNode)26 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 Test (org.junit.Test)25 WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)12 WidgetType (org.thingsboard.server.common.data.widget.WidgetType)6 ArrayList (java.util.ArrayList)2 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 MessagingException (javax.mail.MessagingException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 WidgetTypeId (org.thingsboard.server.common.data.id.WidgetTypeId)1 BaseWidgetType (org.thingsboard.server.common.data.widget.BaseWidgetType)1 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)1 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)1