Search in sources :

Example 21 with WidgetType

use of org.thingsboard.server.common.data.widget.WidgetType 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);
    WidgetType widgetType = new WidgetType();
    widgetType.setTenantId(tenantId);
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
    WidgetType foundWidgetType = widgetTypeService.findWidgetTypeById(savedWidgetType.getId());
    Assert.assertNotNull(foundWidgetType);
    Assert.assertEquals(savedWidgetType, foundWidgetType);
    widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 22 with WidgetType

use of org.thingsboard.server.common.data.widget.WidgetType 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);
    WidgetType widgetType = new WidgetType();
    widgetType.setTenantId(tenantId);
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
    savedWidgetType.setAlias("some_alias");
    try {
        widgetTypeService.saveWidgetType(savedWidgetType);
    } finally {
        widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 23 with WidgetType

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

the class BaseWidgetTypeServiceTest method testFindWidgetTypesByTenantIdAndBundleAlias.

@Test
public void testFindWidgetTypesByTenantIdAndBundleAlias() throws IOException {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTenantId(tenantId);
    widgetsBundle.setTitle("Widgets bundle");
    WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
    List<WidgetType> widgetTypes = new ArrayList<>();
    for (int i = 0; i < 121; i++) {
        WidgetType widgetType = new WidgetType();
        widgetType.setTenantId(tenantId);
        widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
        widgetType.setName("Widget Type " + i);
        widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
        widgetTypes.add(widgetTypeService.saveWidgetType(widgetType));
    }
    List<WidgetType> loadedWidgetTypes = widgetTypeService.findWidgetTypesByTenantIdAndBundleAlias(tenantId, savedWidgetsBundle.getAlias());
    Collections.sort(widgetTypes, idComparator);
    Collections.sort(loadedWidgetTypes, idComparator);
    Assert.assertEquals(widgetTypes, loadedWidgetTypes);
    widgetTypeService.deleteWidgetTypesByTenantIdAndBundleAlias(tenantId, savedWidgetsBundle.getAlias());
    loadedWidgetTypes = widgetTypeService.findWidgetTypesByTenantIdAndBundleAlias(tenantId, savedWidgetsBundle.getAlias());
    Assert.assertTrue(loadedWidgetTypes.isEmpty());
    widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 24 with WidgetType

use of org.thingsboard.server.common.data.widget.WidgetType 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);
    WidgetType widgetType = new WidgetType();
    widgetType.setTenantId(new TenantId(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(savedWidgetsBundle.getId());
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 25 with WidgetType

use of org.thingsboard.server.common.data.widget.WidgetType 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);
    WidgetType widgetType = new WidgetType();
    widgetType.setTenantId(tenantId);
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
    savedWidgetType.setTenantId(new TenantId(ModelConstants.NULL_UUID));
    try {
        widgetTypeService.saveWidgetType(savedWidgetType);
    } finally {
        widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

WidgetType (org.thingsboard.server.common.data.widget.WidgetType)32 Test (org.junit.Test)26 JsonNode (com.fasterxml.jackson.databind.JsonNode)25 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)24 WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)12 TenantId (org.thingsboard.server.common.data.id.TenantId)5 WidgetTypeId (org.thingsboard.server.common.data.id.WidgetTypeId)3 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)2 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 List (java.util.List)1 MessagingException (javax.mail.MessagingException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)1 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)1