Search in sources :

Example 26 with WidgetType

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

the class JpaWidgetTypeDaoTest method testFindByTenantIdAndBundleAliasAndAlias.

@Test
@DatabaseSetup(("classpath:dbunit/widget_type.xml"))
public void testFindByTenantIdAndBundleAliasAndAlias() {
    UUID tenantId = UUID.fromString("2b7e4c90-2dfe-11e7-94aa-f7f6dbfb4833");
    WidgetType widgetType = widgetTypeDao.findByTenantIdBundleAliasAndAlias(tenantId, "BUNDLE_ALIAS_1", "ALIAS3");
    UUID id = UUID.fromString("2b7e4c93-2dfe-11e7-94aa-f7f6dbfb4833");
    assertEquals(id, widgetType.getId().getId());
}
Also used : UUID(java.util.UUID) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 27 with WidgetType

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

the class BaseController method checkWidgetTypeId.

WidgetType checkWidgetTypeId(WidgetTypeId widgetTypeId, boolean modify) throws ThingsboardException {
    try {
        validateId(widgetTypeId, "Incorrect widgetTypeId " + widgetTypeId);
        WidgetType widgetType = widgetTypeService.findWidgetTypeById(widgetTypeId);
        checkWidgetType(widgetType, modify);
        return widgetType;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : WidgetType(org.thingsboard.server.common.data.widget.WidgetType) MessagingException(javax.mail.MessagingException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException)

Example 28 with WidgetType

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

the class BaseWidgetTypeControllerTest method testUpdateWidgetTypeBundleAlias.

@Test
public void testUpdateWidgetTypeBundleAlias() throws Exception {
    WidgetType widgetType = new WidgetType();
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetType savedWidgetType = doPost("/api/widgetType", widgetType, WidgetType.class);
    savedWidgetType.setBundleAlias("some_alias");
    doPost("/api/widgetType", savedWidgetType).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Update of widget type bundle alias is prohibited")));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 29 with WidgetType

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

the class BaseWidgetTypeControllerTest method testSaveWidgetTypeWithInvalidBundleAlias.

@Test
public void testSaveWidgetTypeWithInvalidBundleAlias() throws Exception {
    WidgetType widgetType = new WidgetType();
    widgetType.setBundleAlias("some_alias");
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    doPost("/api/widgetType", widgetType).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Widget type is referencing to non-existent widgets bundle")));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 30 with WidgetType

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

the class BaseWidgetTypeControllerTest method testSaveWidgetType.

@Test
public void testSaveWidgetType() throws Exception {
    WidgetType widgetType = new WidgetType();
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetType savedWidgetType = doPost("/api/widgetType", widgetType, WidgetType.class);
    Assert.assertNotNull(savedWidgetType);
    Assert.assertNotNull(savedWidgetType.getId());
    Assert.assertNotNull(savedWidgetType.getAlias());
    Assert.assertTrue(savedWidgetType.getCreatedTime() > 0);
    Assert.assertEquals(savedTenant.getId(), 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");
    doPost("/api/widgetType", savedWidgetType, WidgetType.class);
    WidgetType foundWidgetType = doGet("/api/widgetType/" + savedWidgetType.getId().getId().toString(), WidgetType.class);
    Assert.assertEquals(foundWidgetType.getName(), savedWidgetType.getName());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) 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