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);
}
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);
}
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());
}
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());
}
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);
}
Aggregations