Search in sources :

Example 36 with Customer

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

the class BaseCustomerServiceTest method testSaveCustomerWithEmptyTenant.

@Test(expected = DataValidationException.class)
public void testSaveCustomerWithEmptyTenant() {
    Customer customer = new Customer();
    customer.setTitle("My customer");
    customerService.saveCustomer(customer);
}
Also used : Customer(org.thingsboard.server.common.data.Customer) Test(org.junit.Test)

Example 37 with Customer

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

the class BaseCustomerServiceTest method testSaveCustomerWithInvalidTenant.

@Test(expected = DataValidationException.class)
public void testSaveCustomerWithInvalidTenant() {
    Customer customer = new Customer();
    customer.setTitle("My customer");
    customer.setTenantId(new TenantId(UUIDs.timeBased()));
    customerService.saveCustomer(customer);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Customer(org.thingsboard.server.common.data.Customer) Test(org.junit.Test)

Example 38 with Customer

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

the class BaseCustomerServiceTest method testFindCustomersByTenantIdAndTitle.

@Test
public void testFindCustomersByTenantIdAndTitle() {
    String title1 = "Customer title 1";
    List<Customer> customersTitle1 = new ArrayList<>();
    for (int i = 0; i < 143; i++) {
        Customer customer = new Customer();
        customer.setTenantId(tenantId);
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String title = title1 + suffix;
        title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
        customer.setTitle(title);
        customersTitle1.add(customerService.saveCustomer(customer));
    }
    String title2 = "Customer title 2";
    List<Customer> customersTitle2 = new ArrayList<>();
    for (int i = 0; i < 175; i++) {
        Customer customer = new Customer();
        customer.setTenantId(tenantId);
        String suffix = RandomStringUtils.randomAlphanumeric((int) (5 + Math.random() * 10));
        String title = title2 + suffix;
        title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
        customer.setTitle(title);
        customersTitle2.add(customerService.saveCustomer(customer));
    }
    List<Customer> loadedCustomersTitle1 = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(15, title1);
    TextPageData<Customer> pageData = null;
    do {
        pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
        loadedCustomersTitle1.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(customersTitle1, idComparator);
    Collections.sort(loadedCustomersTitle1, idComparator);
    Assert.assertEquals(customersTitle1, loadedCustomersTitle1);
    List<Customer> loadedCustomersTitle2 = new ArrayList<>();
    pageLink = new TextPageLink(4, title2);
    do {
        pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
        loadedCustomersTitle2.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(customersTitle2, idComparator);
    Collections.sort(loadedCustomersTitle2, idComparator);
    Assert.assertEquals(customersTitle2, loadedCustomersTitle2);
    for (Customer customer : loadedCustomersTitle1) {
        customerService.deleteCustomer(customer.getId());
    }
    pageLink = new TextPageLink(4, title1);
    pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
    for (Customer customer : loadedCustomersTitle2) {
        customerService.deleteCustomer(customer.getId());
    }
    pageLink = new TextPageLink(4, title2);
    pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(0, pageData.getData().size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Customer(org.thingsboard.server.common.data.Customer) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 39 with Customer

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

the class BaseCustomerServiceTest method testFindCustomerById.

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

Example 40 with Customer

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

the class BaseCustomerServiceTest method testSaveCustomerWithInvalidEmail.

@Test(expected = DataValidationException.class)
public void testSaveCustomerWithInvalidEmail() {
    Customer customer = new Customer();
    customer.setTenantId(tenantId);
    customer.setTitle("My customer");
    customer.setEmail("invalid@mail");
    customerService.saveCustomer(customer);
}
Also used : Customer(org.thingsboard.server.common.data.Customer) 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