Search in sources :

Example 1 with Customer

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

the class BaseCustomerServiceTest method testSaveCustomer.

@Test
public void testSaveCustomer() {
    Customer customer = new Customer();
    customer.setTenantId(tenantId);
    customer.setTitle("My customer");
    Customer savedCustomer = customerService.saveCustomer(customer);
    Assert.assertNotNull(savedCustomer);
    Assert.assertNotNull(savedCustomer.getId());
    Assert.assertTrue(savedCustomer.getCreatedTime() > 0);
    Assert.assertEquals(customer.getTenantId(), savedCustomer.getTenantId());
    Assert.assertEquals(customer.getTitle(), savedCustomer.getTitle());
    savedCustomer.setTitle("My new customer");
    customerService.saveCustomer(savedCustomer);
    Customer foundCustomer = customerService.findCustomerById(savedCustomer.getId());
    Assert.assertEquals(foundCustomer.getTitle(), savedCustomer.getTitle());
    customerService.deleteCustomer(savedCustomer.getId());
}
Also used : Customer(org.thingsboard.server.common.data.Customer) Test(org.junit.Test)

Example 2 with Customer

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

the class BaseCustomerServiceTest method testDeleteCustomer.

@Test
public void testDeleteCustomer() {
    Customer customer = new Customer();
    customer.setTitle("My customer");
    customer.setTenantId(tenantId);
    Customer savedCustomer = customerService.saveCustomer(customer);
    customerService.deleteCustomer(savedCustomer.getId());
    Customer foundCustomer = customerService.findCustomerById(savedCustomer.getId());
    Assert.assertNull(foundCustomer);
}
Also used : Customer(org.thingsboard.server.common.data.Customer) Test(org.junit.Test)

Example 3 with Customer

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

the class BaseCustomerServiceTest method testFindCustomersByTenantId.

@Test
public void testFindCustomersByTenantId() {
    Tenant tenant = new Tenant();
    tenant.setTitle("Test tenant");
    tenant = tenantService.saveTenant(tenant);
    TenantId tenantId = tenant.getId();
    List<Customer> customers = new ArrayList<>();
    for (int i = 0; i < 135; i++) {
        Customer customer = new Customer();
        customer.setTenantId(tenantId);
        customer.setTitle("Customer" + i);
        customers.add(customerService.saveCustomer(customer));
    }
    List<Customer> loadedCustomers = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(23);
    TextPageData<Customer> pageData = null;
    do {
        pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
        loadedCustomers.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(customers, idComparator);
    Collections.sort(loadedCustomers, idComparator);
    Assert.assertEquals(customers, loadedCustomers);
    customerService.deleteCustomersByTenantId(tenantId);
    pageLink = new TextPageLink(33);
    pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertTrue(pageData.getData().isEmpty());
    tenantService.deleteTenant(tenantId);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with Customer

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

the class BaseDashboardServiceTest method testFindDashboardsByTenantIdAndCustomerId.

@Test
public void testFindDashboardsByTenantIdAndCustomerId() throws ExecutionException, InterruptedException {
    Tenant tenant = new Tenant();
    tenant.setTitle("Test tenant");
    tenant = tenantService.saveTenant(tenant);
    TenantId tenantId = tenant.getId();
    Customer customer = new Customer();
    customer.setTitle("Test customer");
    customer.setTenantId(tenantId);
    customer = customerService.saveCustomer(customer);
    CustomerId customerId = customer.getId();
    List<DashboardInfo> dashboards = new ArrayList<>();
    for (int i = 0; i < 223; i++) {
        Dashboard dashboard = new Dashboard();
        dashboard.setTenantId(tenantId);
        dashboard.setTitle("Dashboard" + i);
        dashboard = dashboardService.saveDashboard(dashboard);
        dashboards.add(new DashboardInfo(dashboardService.assignDashboardToCustomer(dashboard.getId(), customerId)));
    }
    List<DashboardInfo> loadedDashboards = new ArrayList<>();
    TimePageLink pageLink = new TimePageLink(23);
    TimePageData<DashboardInfo> pageData = null;
    do {
        pageData = dashboardService.findDashboardsByTenantIdAndCustomerId(tenantId, customerId, pageLink).get();
        loadedDashboards.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(dashboards, idComparator);
    Collections.sort(loadedDashboards, idComparator);
    Assert.assertEquals(dashboards, loadedDashboards);
    dashboardService.unassignCustomerDashboards(customerId);
    pageLink = new TimePageLink(42);
    pageData = dashboardService.findDashboardsByTenantIdAndCustomerId(tenantId, customerId, pageLink).get();
    Assert.assertFalse(pageData.hasNext());
    Assert.assertTrue(pageData.getData().isEmpty());
    tenantService.deleteTenant(tenantId);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Tenant(org.thingsboard.server.common.data.Tenant) Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) Dashboard(org.thingsboard.server.common.data.Dashboard) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) DashboardInfo(org.thingsboard.server.common.data.DashboardInfo) Test(org.junit.Test)

Example 5 with Customer

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

the class BaseDashboardServiceTest method testAssignDashboardToCustomerFromDifferentTenant.

@Test(expected = DataValidationException.class)
public void testAssignDashboardToCustomerFromDifferentTenant() {
    Dashboard dashboard = new Dashboard();
    dashboard.setTitle("My dashboard");
    dashboard.setTenantId(tenantId);
    dashboard = dashboardService.saveDashboard(dashboard);
    Tenant tenant = new Tenant();
    tenant.setTitle("Test different tenant");
    tenant = tenantService.saveTenant(tenant);
    Customer customer = new Customer();
    customer.setTenantId(tenant.getId());
    customer.setTitle("Test different customer");
    customer = customerService.saveCustomer(customer);
    try {
        dashboardService.assignDashboardToCustomer(dashboard.getId(), customer.getId());
    } finally {
        dashboardService.deleteDashboard(dashboard.getId());
        tenantService.deleteTenant(tenant.getId());
    }
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) Customer(org.thingsboard.server.common.data.Customer) Dashboard(org.thingsboard.server.common.data.Dashboard) Test(org.junit.Test)

Aggregations

Customer (org.thingsboard.server.common.data.Customer)59 Test (org.junit.Test)37 CustomerId (org.thingsboard.server.common.data.id.CustomerId)24 Tenant (org.thingsboard.server.common.data.Tenant)21 ArrayList (java.util.ArrayList)18 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)18 User (org.thingsboard.server.common.data.User)16 TenantId (org.thingsboard.server.common.data.id.TenantId)14 Asset (org.thingsboard.server.common.data.asset.Asset)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)10 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)8 TypeReference (com.fasterxml.jackson.core.type.TypeReference)7 Device (org.thingsboard.server.common.data.Device)7 Matchers.containsString (org.hamcrest.Matchers.containsString)4 AssetId (org.thingsboard.server.common.data.id.AssetId)3 DeviceId (org.thingsboard.server.common.data.id.DeviceId)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 UUID (java.util.UUID)2 Before (org.junit.Before)2