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