Search in sources :

Example 11 with WidgetsBundle

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

the class BaseWidgetTypeServiceTest method testFindWidgetTypeByTenantIdBundleAliasAndAlias.

@Test
public void testFindWidgetTypeByTenantIdBundleAliasAndAlias() 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.findWidgetTypeByTenantIdBundleAliasAndAlias(tenantId, savedWidgetsBundle.getAlias(), savedWidgetType.getAlias());
    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 12 with WidgetsBundle

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

the class BaseWidgetTypeServiceTest method testDeleteWidgetType.

@Test
public void testDeleteWidgetType() 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);
    widgetTypeService.deleteWidgetType(savedWidgetType.getId());
    foundWidgetType = widgetTypeService.findWidgetTypeById(savedWidgetType.getId());
    Assert.assertNull(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 13 with WidgetsBundle

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

the class BaseWidgetTypeServiceTest method testSaveWidgetType.

@Test
public void testSaveWidgetType() 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);
    Assert.assertNotNull(savedWidgetType);
    Assert.assertNotNull(savedWidgetType.getId());
    Assert.assertNotNull(savedWidgetType.getAlias());
    Assert.assertTrue(savedWidgetType.getCreatedTime() > 0);
    Assert.assertEquals(widgetType.getTenantId(), savedWidgetType.getTenantId());
    Assert.assertEquals(widgetType.getName(), savedWidgetType.getName());
    Assert.assertEquals(widgetType.getDescriptor(), savedWidgetType.getDescriptor());
    Assert.assertEquals(savedWidgetsBundle.getAlias(), savedWidgetType.getBundleAlias());
    savedWidgetType.setName("New Widget Type");
    widgetTypeService.saveWidgetType(savedWidgetType);
    WidgetType foundWidgetType = widgetTypeService.findWidgetTypeById(savedWidgetType.getId());
    Assert.assertEquals(foundWidgetType.getName(), savedWidgetType.getName());
    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 14 with WidgetsBundle

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

the class BaseWidgetTypeServiceTest method testSaveWidgetTypeWithEmptyName.

@Test(expected = DataValidationException.class)
public void testSaveWidgetTypeWithEmptyName() 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.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    try {
        widgetTypeService.saveWidgetType(widgetType);
    } 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 15 with WidgetsBundle

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

the class BaseWidgetsBundleServiceTest method testUpdateWidgetsBundleAlias.

@Test(expected = DataValidationException.class)
public void testUpdateWidgetsBundleAlias() {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTitle("My widgets bundle");
    widgetsBundle.setTenantId(tenantId);
    WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
    savedWidgetsBundle.setAlias("new_alias");
    try {
        widgetsBundleService.saveWidgetsBundle(savedWidgetsBundle);
    } finally {
        widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
    }
}
Also used : WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) Test(org.junit.Test)

Aggregations

WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)48 Test (org.junit.Test)38 TenantId (org.thingsboard.server.common.data.id.TenantId)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ArrayList (java.util.ArrayList)12 WidgetType (org.thingsboard.server.common.data.widget.WidgetType)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)11 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)5 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)5 List (java.util.List)4 Tenant (org.thingsboard.server.common.data.Tenant)4 WidgetsBundleId (org.thingsboard.server.common.data.id.WidgetsBundleId)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 UUID (java.util.UUID)3 NULL_UUID (org.thingsboard.server.dao.model.ModelConstants.NULL_UUID)3 DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)2 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1