Search in sources :

Example 1 with WidgetsBundle

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

the class WidgetsBundleEntity method toData.

@Override
public WidgetsBundle toData() {
    WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(UUIDConverter.fromString(id)));
    widgetsBundle.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id)));
    if (tenantId != null) {
        widgetsBundle.setTenantId(new TenantId(UUIDConverter.fromString(tenantId)));
    }
    widgetsBundle.setAlias(alias);
    widgetsBundle.setTitle(title);
    return widgetsBundle;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) WidgetsBundleId(org.thingsboard.server.common.data.id.WidgetsBundleId) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle)

Example 2 with WidgetsBundle

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

the class BaseWidgetTypeControllerTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    loginSysAdmin();
    Tenant tenant = new Tenant();
    tenant.setTitle("My tenant");
    savedTenant = doPost("/api/tenant", tenant, Tenant.class);
    Assert.assertNotNull(savedTenant);
    tenantAdmin = new User();
    tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
    tenantAdmin.setTenantId(savedTenant.getId());
    tenantAdmin.setEmail("tenant2@thingsboard.org");
    tenantAdmin.setFirstName("Joe");
    tenantAdmin.setLastName("Downs");
    tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1");
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTitle("My widgets bundle");
    savedWidgetsBundle = doPost("/api/widgetsBundle", widgetsBundle, WidgetsBundle.class);
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) User(org.thingsboard.server.common.data.User) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) Before(org.junit.Before)

Example 3 with WidgetsBundle

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

the class BaseWidgetsBundleControllerTest method testFindSystemAndTenantWidgetsBundles.

@Test
public void testFindSystemAndTenantWidgetsBundles() throws Exception {
    loginSysAdmin();
    List<WidgetsBundle> sysWidgetsBundles = doGetTyped("/api/widgetsBundles?", new TypeReference<List<WidgetsBundle>>() {
    });
    List<WidgetsBundle> createdSystemWidgetsBundles = new ArrayList<>();
    for (int i = 0; i < 82; i++) {
        WidgetsBundle widgetsBundle = new WidgetsBundle();
        widgetsBundle.setTitle("Sys widgets bundle" + i);
        createdSystemWidgetsBundles.add(doPost("/api/widgetsBundle", widgetsBundle, WidgetsBundle.class));
    }
    List<WidgetsBundle> systemWidgetsBundles = new ArrayList<>(createdSystemWidgetsBundles);
    systemWidgetsBundles.addAll(sysWidgetsBundles);
    List<WidgetsBundle> widgetsBundles = new ArrayList<>();
    widgetsBundles.addAll(systemWidgetsBundles);
    login(tenantAdmin.getEmail(), "testPassword1");
    for (int i = 0; i < 127; i++) {
        WidgetsBundle widgetsBundle = new WidgetsBundle();
        widgetsBundle.setTitle("Tenant widgets bundle" + i);
        widgetsBundles.add(doPost("/api/widgetsBundle", widgetsBundle, WidgetsBundle.class));
    }
    List<WidgetsBundle> loadedWidgetsBundles = doGetTyped("/api/widgetsBundles?", new TypeReference<List<WidgetsBundle>>() {
    });
    Collections.sort(widgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(widgetsBundles, loadedWidgetsBundles);
    loginSysAdmin();
    loadedWidgetsBundles = doGetTyped("/api/widgetsBundles?", new TypeReference<List<WidgetsBundle>>() {
    });
    Collections.sort(systemWidgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(systemWidgetsBundles, loadedWidgetsBundles);
    for (WidgetsBundle widgetsBundle : createdSystemWidgetsBundles) {
        doDelete("/api/widgetsBundle/" + widgetsBundle.getId().getId().toString()).andExpect(status().isOk());
    }
    loadedWidgetsBundles = doGetTyped("/api/widgetsBundles?", new TypeReference<List<WidgetsBundle>>() {
    });
    Collections.sort(sysWidgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(sysWidgetsBundles, loadedWidgetsBundles);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) Test(org.junit.Test)

Example 4 with WidgetsBundle

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

the class BaseWidgetsBundleControllerTest method testSaveWidgetsBundle.

@Test
public void testSaveWidgetsBundle() throws Exception {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTitle("My widgets bundle");
    WidgetsBundle savedWidgetsBundle = doPost("/api/widgetsBundle", widgetsBundle, WidgetsBundle.class);
    Assert.assertNotNull(savedWidgetsBundle);
    Assert.assertNotNull(savedWidgetsBundle.getId());
    Assert.assertNotNull(savedWidgetsBundle.getAlias());
    Assert.assertTrue(savedWidgetsBundle.getCreatedTime() > 0);
    Assert.assertEquals(savedTenant.getId(), savedWidgetsBundle.getTenantId());
    Assert.assertEquals(widgetsBundle.getTitle(), savedWidgetsBundle.getTitle());
    savedWidgetsBundle.setTitle("My new widgets bundle");
    doPost("/api/widgetsBundle", savedWidgetsBundle, WidgetsBundle.class);
    WidgetsBundle foundWidgetsBundle = doGet("/api/widgetsBundle/" + savedWidgetsBundle.getId().getId().toString(), WidgetsBundle.class);
    Assert.assertEquals(foundWidgetsBundle.getTitle(), savedWidgetsBundle.getTitle());
}
Also used : WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) Test(org.junit.Test)

Example 5 with WidgetsBundle

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

the class BaseWidgetsBundleControllerTest method testFindSystemWidgetsBundlesByPageLink.

@Test
public void testFindSystemWidgetsBundlesByPageLink() throws Exception {
    loginSysAdmin();
    List<WidgetsBundle> sysWidgetsBundles = doGetTyped("/api/widgetsBundles?", new TypeReference<List<WidgetsBundle>>() {
    });
    List<WidgetsBundle> createdWidgetsBundles = new ArrayList<>();
    for (int i = 0; i < 120; i++) {
        WidgetsBundle widgetsBundle = new WidgetsBundle();
        widgetsBundle.setTitle("Widgets bundle" + i);
        createdWidgetsBundles.add(doPost("/api/widgetsBundle", widgetsBundle, WidgetsBundle.class));
    }
    List<WidgetsBundle> widgetsBundles = new ArrayList<>(createdWidgetsBundles);
    widgetsBundles.addAll(sysWidgetsBundles);
    List<WidgetsBundle> loadedWidgetsBundles = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(14);
    TextPageData<WidgetsBundle> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/widgetsBundles?", new TypeReference<TextPageData<WidgetsBundle>>() {
        }, pageLink);
        loadedWidgetsBundles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(widgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(widgetsBundles, loadedWidgetsBundles);
    for (WidgetsBundle widgetsBundle : createdWidgetsBundles) {
        doDelete("/api/widgetsBundle/" + widgetsBundle.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new TextPageLink(17);
    loadedWidgetsBundles.clear();
    do {
        pageData = doGetTypedWithPageLink("/api/widgetsBundles?", new TypeReference<TextPageData<WidgetsBundle>>() {
        }, pageLink);
        loadedWidgetsBundles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(sysWidgetsBundles, idComparator);
    Collections.sort(loadedWidgetsBundles, idComparator);
    Assert.assertEquals(sysWidgetsBundles, loadedWidgetsBundles);
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) 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