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());
}
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);
}
}
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")));
}
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")));
}
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());
}
Aggregations