Search in sources :

Example 21 with WidgetTypeDetails

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

the class BaseWidgetTypeControllerTest method testGetBundleWidgetTypes.

@Test
public void testGetBundleWidgetTypes() throws Exception {
    List<WidgetType> widgetTypes = new ArrayList<>();
    for (int i = 0; i < 89; i++) {
        WidgetTypeDetails widgetType = new WidgetTypeDetails();
        widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
        widgetType.setName("Widget Type " + i);
        widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
        widgetTypes.add(new WidgetType(doPost("/api/widgetType", widgetType, WidgetTypeDetails.class)));
    }
    List<WidgetType> loadedWidgetTypes = doGetTyped("/api/widgetTypes?isSystem={isSystem}&bundleAlias={bundleAlias}", new TypeReference<>() {
    }, false, savedWidgetsBundle.getAlias());
    Collections.sort(widgetTypes, idComparator);
    Collections.sort(loadedWidgetTypes, idComparator);
    Assert.assertEquals(widgetTypes, loadedWidgetTypes);
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 22 with WidgetTypeDetails

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

the class BaseWidgetTypeControllerTest method testUpdateWidgetTypeBundleAlias.

@Test
public void testUpdateWidgetTypeBundleAlias() throws Exception {
    WidgetTypeDetails widgetType = new WidgetTypeDetails();
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetTypeDetails savedWidgetType = doPost("/api/widgetType", widgetType, WidgetTypeDetails.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) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 23 with WidgetTypeDetails

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

the class BaseWidgetTypeControllerTest method testSaveWidgetType.

@Test
public void testSaveWidgetType() throws Exception {
    WidgetTypeDetails widgetType = new WidgetTypeDetails();
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetTypeDetails savedWidgetType = doPost("/api/widgetType", widgetType, WidgetTypeDetails.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);
    WidgetTypeDetails foundWidgetType = doGet("/api/widgetType/" + savedWidgetType.getId().getId().toString(), WidgetTypeDetails.class);
    Assert.assertEquals(foundWidgetType.getName(), savedWidgetType.getName());
}
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 24 with WidgetTypeDetails

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

the class BaseWidgetTypeControllerTest method testSaveWidgetTypeWithEmptyBundleAlias.

@Test
public void testSaveWidgetTypeWithEmptyBundleAlias() throws Exception {
    WidgetTypeDetails widgetType = new WidgetTypeDetails();
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    doPost("/api/widgetType", widgetType).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Widgets type bundle alias should be specified")));
}
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 25 with WidgetTypeDetails

use of org.thingsboard.server.common.data.widget.WidgetTypeDetails 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++) {
        WidgetTypeDetails widgetType = new WidgetTypeDetails();
        widgetType.setTenantId(tenantId);
        widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
        widgetType.setName("Widget Type " + i);
        widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
        widgetTypes.add(new WidgetType(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(tenantId, 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) 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