Search in sources :

Example 6 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseEdgeControllerTest method testSaveEdgeWithViolationOfLengthValidation.

@Test
public void testSaveEdgeWithViolationOfLengthValidation() throws Exception {
    Edge edge = constructEdge(RandomStringUtils.randomAlphabetic(300), "default");
    doPost("/api/edge", edge).andExpect(statusReason(containsString("length of name must be equal or less than 255")));
    edge.setName("normal name");
    edge.setType(RandomStringUtils.randomAlphabetic(300));
    doPost("/api/edge", edge).andExpect(statusReason(containsString("length of type must be equal or less than 255")));
    edge.setType("normal type");
    edge.setLabel(RandomStringUtils.randomAlphabetic(300));
    doPost("/api/edge", edge).andExpect(statusReason(containsString("length of label must be equal or less than 255")));
}
Also used : Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Example 7 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseEdgeControllerTest method testFindEdgeById.

@Test
public void testFindEdgeById() throws Exception {
    Edge edge = constructEdge("My edge", "default");
    Edge savedEdge = doPost("/api/edge", edge, Edge.class);
    Edge foundEdge = doGet("/api/edge/" + savedEdge.getId().getId().toString(), Edge.class);
    Assert.assertNotNull(foundEdge);
    Assert.assertEquals(savedEdge, foundEdge);
}
Also used : Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Example 8 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseEdgeControllerTest method testSaveEdge.

@Test
public void testSaveEdge() throws Exception {
    Edge edge = constructEdge("My edge", "default");
    Edge savedEdge = doPost("/api/edge", edge, Edge.class);
    Assert.assertNotNull(savedEdge);
    Assert.assertNotNull(savedEdge.getId());
    Assert.assertTrue(savedEdge.getCreatedTime() > 0);
    Assert.assertEquals(savedTenant.getId(), savedEdge.getTenantId());
    Assert.assertNotNull(savedEdge.getCustomerId());
    Assert.assertEquals(NULL_UUID, savedEdge.getCustomerId().getId());
    Assert.assertEquals(edge.getName(), savedEdge.getName());
    savedEdge.setName("My new edge");
    doPost("/api/edge", savedEdge, Edge.class);
    Edge foundEdge = doGet("/api/edge/" + savedEdge.getId().getId().toString(), Edge.class);
    Assert.assertEquals(foundEdge.getName(), savedEdge.getName());
}
Also used : Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Example 9 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseEdgeControllerTest method testFindCustomerEdges.

@Test
public void testFindCustomerEdges() throws Exception {
    Customer customer = new Customer();
    customer.setTitle("Test customer");
    customer = doPost("/api/customer", customer, Customer.class);
    CustomerId customerId = customer.getId();
    List<Edge> edges = new ArrayList<>();
    for (int i = 0; i < 128; i++) {
        Edge edge = constructEdge("Edge" + i, "default");
        edge = doPost("/api/edge", edge, Edge.class);
        edges.add(doPost("/api/customer/" + customerId.getId().toString() + "/edge/" + edge.getId().getId().toString(), Edge.class));
    }
    List<Edge> loadedEdges = new ArrayList<>();
    PageLink pageLink = new PageLink(23);
    PageData<Edge> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/edges?", new TypeReference<PageData<Edge>>() {
        }, pageLink);
        loadedEdges.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(edges, idComparator);
    Collections.sort(loadedEdges, idComparator);
    Assert.assertEquals(edges, loadedEdges);
}
Also used : Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Example 10 with Edge

use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.

the class BaseEdgeControllerTest method testFindCustomerEdgesByType.

@Test
public void testFindCustomerEdgesByType() throws Exception {
    Customer customer = new Customer();
    customer.setTitle("Test customer");
    customer = doPost("/api/customer", customer, Customer.class);
    CustomerId customerId = customer.getId();
    String title1 = "Edge title 1";
    String type1 = "typeC";
    List<Edge> edgesType1 = new ArrayList<>();
    for (int i = 0; i < 125; i++) {
        String suffix = RandomStringUtils.randomAlphanumeric(15);
        String name = title1 + suffix;
        name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
        Edge edge = constructEdge(name, type1);
        edge = doPost("/api/edge", edge, Edge.class);
        edgesType1.add(doPost("/api/customer/" + customerId.getId().toString() + "/edge/" + edge.getId().getId().toString(), Edge.class));
    }
    String title2 = "Edge title 2";
    String type2 = "typeD";
    List<Edge> edgesType2 = new ArrayList<>();
    for (int i = 0; i < 143; i++) {
        String suffix = RandomStringUtils.randomAlphanumeric(15);
        String name = title2 + suffix;
        name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
        Edge edge = constructEdge(name, type2);
        edge = doPost("/api/edge", edge, Edge.class);
        edgesType2.add(doPost("/api/customer/" + customerId.getId().toString() + "/edge/" + edge.getId().getId().toString(), Edge.class));
    }
    List<Edge> loadedEdgesType1 = new ArrayList<>();
    PageLink pageLink = new PageLink(15, 0, title1);
    PageData<Edge> pageData = null;
    do {
        pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/edges?type={type}&", new TypeReference<PageData<Edge>>() {
        }, pageLink, type1);
        loadedEdgesType1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(edgesType1, idComparator);
    Collections.sort(loadedEdgesType1, idComparator);
    Assert.assertEquals(edgesType1, loadedEdgesType1);
    List<Edge> loadedEdgesType2 = new ArrayList<>();
    pageLink = new PageLink(4, 0, title2);
    do {
        pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/edges?type={type}&", new TypeReference<PageData<Edge>>() {
        }, pageLink, type2);
        loadedEdgesType2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(edgesType2, idComparator);
    Collections.sort(loadedEdgesType2, idComparator);
    Assert.assertEquals(edgesType2, loadedEdgesType2);
    for (Edge edge : loadedEdgesType1) {
        doDelete("/api/customer/edge/" + edge.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new PageLink(4, 0, title1);
    pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/edges?type={type}&", new TypeReference<PageData<Edge>>() {
    }, pageLink, type1);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (Edge edge : loadedEdgesType2) {
        doDelete("/api/customer/edge/" + edge.getId().getId().toString()).andExpect(status().isOk());
    }
    pageLink = new PageLink(4, 0, title2);
    pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/edges?type={type}&", new TypeReference<PageData<Edge>>() {
    }, pageLink, type2);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
}
Also used : Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) 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) Edge(org.thingsboard.server.common.data.edge.Edge) Test(org.junit.Test)

Aggregations

Edge (org.thingsboard.server.common.data.edge.Edge)98 Test (org.junit.Test)46 EdgeId (org.thingsboard.server.common.data.id.EdgeId)32 PageLink (org.thingsboard.server.common.data.page.PageLink)31 ArrayList (java.util.ArrayList)25 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)25 ApiOperation (io.swagger.annotations.ApiOperation)23 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)22 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)22 CustomerId (org.thingsboard.server.common.data.id.CustomerId)21 Customer (org.thingsboard.server.common.data.Customer)20 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)20 EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)16 TypeReference (com.fasterxml.jackson.core.type.TypeReference)15 TenantId (org.thingsboard.server.common.data.id.TenantId)14 Device (org.thingsboard.server.common.data.Device)13 Asset (org.thingsboard.server.common.data.asset.Asset)13 PageData (org.thingsboard.server.common.data.page.PageData)13