Search in sources :

Example 36 with EntityView

use of org.thingsboard.server.common.data.EntityView in project thingsboard by thingsboard.

the class BaseEntityViewControllerTest method testTheCopyOfAttrsIntoTSForTheView.

@Test
public void testTheCopyOfAttrsIntoTSForTheView() throws Exception {
    Set<String> actualAttributesSet = getAttributesByKeys("{\"caKey1\":\"value1\", \"caKey2\":true, \"caKey3\":42.0, \"caKey4\":73}");
    Set<String> expectedActualAttributesSet = new HashSet<>(Arrays.asList("caKey1", "caKey2", "caKey3", "caKey4"));
    assertTrue(actualAttributesSet.containsAll(expectedActualAttributesSet));
    EntityView savedView = getNewSavedEntityView("Test entity view");
    Thread.sleep(1000);
    List<Map<String, Object>> values = doGetAsyncTyped("/api/plugins/telemetry/ENTITY_VIEW/" + savedView.getId().getId().toString() + "/values/attributes?keys=" + String.join(",", actualAttributesSet), new TypeReference<>() {
    });
    assertEquals("value1", getValue(values, "caKey1"));
    assertEquals(true, getValue(values, "caKey2"));
    assertEquals(42.0, getValue(values, "caKey3"));
    assertEquals(73, getValue(values, "caKey4"));
}
Also used : AttributesEntityView(org.thingsboard.server.common.data.objects.AttributesEntityView) TelemetryEntityView(org.thingsboard.server.common.data.objects.TelemetryEntityView) EntityView(org.thingsboard.server.common.data.EntityView) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 37 with EntityView

use of org.thingsboard.server.common.data.EntityView in project thingsboard by thingsboard.

the class BaseEntityViewControllerTest method testGetCustomerEntityViewsByName.

@Test
public void testGetCustomerEntityViewsByName() throws Exception {
    CustomerId customerId = doPost("/api/customer", getNewCustomer("Test customer"), Customer.class).getId();
    String urlTemplate = "/api/customer/" + customerId.getId().toString() + "/entityViews?";
    String name1 = "Entity view name1";
    List<EntityView> namesOfView1 = fillListOf(125, name1, "/api/customer/" + customerId.getId().toString() + "/entityView/");
    List<EntityView> loadedNamesOfView1 = loadListOf(new PageLink(15, 0, name1), urlTemplate);
    Collections.sort(namesOfView1, idComparator);
    Collections.sort(loadedNamesOfView1, idComparator);
    assertEquals(namesOfView1, loadedNamesOfView1);
    String name2 = "Entity view name2";
    List<EntityView> NamesOfView2 = fillListOf(143, name2, "/api/customer/" + customerId.getId().toString() + "/entityView/");
    List<EntityView> loadedNamesOfView2 = loadListOf(new PageLink(4, 0, name2), urlTemplate);
    Collections.sort(NamesOfView2, idComparator);
    Collections.sort(loadedNamesOfView2, idComparator);
    assertEquals(NamesOfView2, loadedNamesOfView2);
    for (EntityView view : loadedNamesOfView1) {
        doDelete("/api/customer/entityView/" + view.getId().getId().toString()).andExpect(status().isOk());
    }
    PageData<EntityView> pageData = doGetTypedWithPageLink(urlTemplate, new TypeReference<PageData<EntityView>>() {
    }, new PageLink(4, 0, name1));
    Assert.assertFalse(pageData.hasNext());
    assertEquals(0, pageData.getData().size());
    for (EntityView view : loadedNamesOfView2) {
        doDelete("/api/customer/entityView/" + view.getId().getId().toString()).andExpect(status().isOk());
    }
    pageData = doGetTypedWithPageLink(urlTemplate, new TypeReference<PageData<EntityView>>() {
    }, new PageLink(4, 0, name2));
    Assert.assertFalse(pageData.hasNext());
    assertEquals(0, pageData.getData().size());
}
Also used : PageData(org.thingsboard.server.common.data.page.PageData) Customer(org.thingsboard.server.common.data.Customer) AttributesEntityView(org.thingsboard.server.common.data.objects.AttributesEntityView) TelemetryEntityView(org.thingsboard.server.common.data.objects.TelemetryEntityView) EntityView(org.thingsboard.server.common.data.EntityView) PageLink(org.thingsboard.server.common.data.page.PageLink) CustomerId(org.thingsboard.server.common.data.id.CustomerId) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 38 with EntityView

use of org.thingsboard.server.common.data.EntityView in project thingsboard by thingsboard.

the class BaseEntityViewControllerTest method testAssignEntityViewToCustomerFromDifferentTenant.

@Test
public void testAssignEntityViewToCustomerFromDifferentTenant() throws Exception {
    loginSysAdmin();
    Tenant tenant2 = getNewTenant("Different tenant");
    Tenant savedTenant2 = doPost("/api/tenant", tenant2, Tenant.class);
    Assert.assertNotNull(savedTenant2);
    User tenantAdmin2 = new User();
    tenantAdmin2.setAuthority(Authority.TENANT_ADMIN);
    tenantAdmin2.setTenantId(savedTenant2.getId());
    tenantAdmin2.setEmail("tenant3@thingsboard.org");
    tenantAdmin2.setFirstName("Joe");
    tenantAdmin2.setLastName("Downs");
    createUserAndLogin(tenantAdmin2, "testPassword1");
    Customer customer = getNewCustomer("Different customer");
    Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
    login(tenantAdmin.getEmail(), "testPassword1");
    EntityView savedView = getNewSavedEntityView("Test entity view");
    doPost("/api/customer/" + savedCustomer.getId().getId().toString() + "/entityView/" + savedView.getId().getId().toString()).andExpect(status().isForbidden());
    loginSysAdmin();
    doDelete("/api/tenant/" + savedTenant2.getId().getId().toString()).andExpect(status().isOk());
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) User(org.thingsboard.server.common.data.User) Customer(org.thingsboard.server.common.data.Customer) AttributesEntityView(org.thingsboard.server.common.data.objects.AttributesEntityView) TelemetryEntityView(org.thingsboard.server.common.data.objects.TelemetryEntityView) EntityView(org.thingsboard.server.common.data.EntityView) Test(org.junit.Test)

Example 39 with EntityView

use of org.thingsboard.server.common.data.EntityView in project thingsboard by thingsboard.

the class BaseEntityViewControllerTest method testTheCopyOfAttrsOutOfTSForTheView.

@Test
public void testTheCopyOfAttrsOutOfTSForTheView() throws Exception {
    Set<String> actualAttributesSet = getAttributesByKeys("{\"caKey1\":\"value1\", \"caKey2\":true, \"caKey3\":42.0, \"caKey4\":73}");
    Set<String> expectedActualAttributesSet = new HashSet<>(Arrays.asList("caKey1", "caKey2", "caKey3", "caKey4"));
    assertTrue(actualAttributesSet.containsAll(expectedActualAttributesSet));
    List<Map<String, Object>> valueTelemetryOfDevices = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + testDevice.getId().getId().toString() + "/values/attributes?keys=" + String.join(",", actualAttributesSet), new TypeReference<>() {
    });
    EntityView view = new EntityView();
    view.setEntityId(testDevice.getId());
    view.setTenantId(savedTenant.getId());
    view.setName("Test entity view");
    view.setType("default");
    view.setKeys(telemetry);
    view.setStartTimeMs((long) getValue(valueTelemetryOfDevices, "lastActivityTime") * 10);
    view.setEndTimeMs((long) getValue(valueTelemetryOfDevices, "lastActivityTime") / 10);
    EntityView savedView = doPost("/api/entityView", view, EntityView.class);
    Thread.sleep(1000);
    List<Map<String, Object>> values = doGetAsyncTyped("/api/plugins/telemetry/ENTITY_VIEW/" + savedView.getId().getId().toString() + "/values/attributes?keys=" + String.join(",", actualAttributesSet), new TypeReference<>() {
    });
    assertEquals(0, values.size());
}
Also used : AttributesEntityView(org.thingsboard.server.common.data.objects.AttributesEntityView) TelemetryEntityView(org.thingsboard.server.common.data.objects.TelemetryEntityView) EntityView(org.thingsboard.server.common.data.EntityView) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with EntityView

use of org.thingsboard.server.common.data.EntityView in project thingsboard by thingsboard.

the class BaseEntityViewControllerTest method testAssignEntityViewToEdge.

@Test
public void testAssignEntityViewToEdge() throws Exception {
    Edge edge = constructEdge("My edge", "default");
    Edge savedEdge = doPost("/api/edge", edge, Edge.class);
    EntityView savedEntityView = getNewSavedEntityView("My entityView");
    doPost("/api/edge/" + savedEdge.getId().getId().toString() + "/device/" + testDevice.getId().getId().toString(), Device.class);
    doPost("/api/edge/" + savedEdge.getId().getId().toString() + "/entityView/" + savedEntityView.getId().getId().toString(), EntityView.class);
    PageData<EntityView> pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/entityViews?", new TypeReference<PageData<EntityView>>() {
    }, new PageLink(100));
    Assert.assertEquals(1, pageData.getData().size());
    doDelete("/api/edge/" + savedEdge.getId().getId().toString() + "/entityView/" + savedEntityView.getId().getId().toString(), EntityView.class);
    pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/entityViews?", new TypeReference<PageData<EntityView>>() {
    }, new PageLink(100));
    Assert.assertEquals(0, pageData.getData().size());
}
Also used : PageData(org.thingsboard.server.common.data.page.PageData) AttributesEntityView(org.thingsboard.server.common.data.objects.AttributesEntityView) TelemetryEntityView(org.thingsboard.server.common.data.objects.TelemetryEntityView) EntityView(org.thingsboard.server.common.data.EntityView) PageLink(org.thingsboard.server.common.data.page.PageLink) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Aggregations

EntityView (org.thingsboard.server.common.data.EntityView)51 TelemetryEntityView (org.thingsboard.server.common.data.objects.TelemetryEntityView)21 Test (org.junit.Test)18 AttributesEntityView (org.thingsboard.server.common.data.objects.AttributesEntityView)17 ExecutionException (java.util.concurrent.ExecutionException)16 EntityViewId (org.thingsboard.server.common.data.id.EntityViewId)15 ArrayList (java.util.ArrayList)13 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)12 Customer (org.thingsboard.server.common.data.Customer)11 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)11 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)10 ApiOperation (io.swagger.annotations.ApiOperation)9 List (java.util.List)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 Edge (org.thingsboard.server.common.data.edge.Edge)8 PageLink (org.thingsboard.server.common.data.page.PageLink)7 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)7 Matchers.containsString (org.hamcrest.Matchers.containsString)6