Fixed outdated tests
This commit is contained in:
parent
7020e60aed
commit
96d344fabd
@ -288,7 +288,7 @@ public class CustomerControllerTest extends AbstractControllerTest {
|
|||||||
for (int i=0;i<143;i++) {
|
for (int i=0;i<143;i++) {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
customer.setTenantId(tenantId);
|
customer.setTenantId(tenantId);
|
||||||
String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15));
|
String suffix = RandomStringUtils.randomAlphanumeric((int)(5 + Math.random()*10));
|
||||||
String title = title1+suffix;
|
String title = title1+suffix;
|
||||||
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
||||||
customer.setTitle(title);
|
customer.setTitle(title);
|
||||||
@ -299,7 +299,7 @@ public class CustomerControllerTest extends AbstractControllerTest {
|
|||||||
for (int i=0;i<175;i++) {
|
for (int i=0;i<175;i++) {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
customer.setTenantId(tenantId);
|
customer.setTenantId(tenantId);
|
||||||
String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15));
|
String suffix = RandomStringUtils.randomAlphanumeric((int)(5 + Math.random()*10));
|
||||||
String title = title2+suffix;
|
String title = title2+suffix;
|
||||||
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
||||||
customer.setTitle(title);
|
customer.setTitle(title);
|
||||||
|
|||||||
@ -149,7 +149,7 @@ public class TenantControllerTest extends AbstractControllerTest {
|
|||||||
List<Tenant> tenantsTitle1 = new ArrayList<>();
|
List<Tenant> tenantsTitle1 = new ArrayList<>();
|
||||||
for (int i=0;i<134;i++) {
|
for (int i=0;i<134;i++) {
|
||||||
Tenant tenant = new Tenant();
|
Tenant tenant = new Tenant();
|
||||||
String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15));
|
String suffix = RandomStringUtils.randomAlphanumeric((int)(5 + Math.random()*10));
|
||||||
String title = title1+suffix;
|
String title = title1+suffix;
|
||||||
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
||||||
tenant.setTitle(title);
|
tenant.setTitle(title);
|
||||||
@ -159,7 +159,7 @@ public class TenantControllerTest extends AbstractControllerTest {
|
|||||||
List<Tenant> tenantsTitle2 = new ArrayList<>();
|
List<Tenant> tenantsTitle2 = new ArrayList<>();
|
||||||
for (int i=0;i<127;i++) {
|
for (int i=0;i<127;i++) {
|
||||||
Tenant tenant = new Tenant();
|
Tenant tenant = new Tenant();
|
||||||
String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15));
|
String suffix = RandomStringUtils.randomAlphanumeric((int)(5 + Math.random()*10));
|
||||||
String title = title2+suffix;
|
String title = title2+suffix;
|
||||||
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
||||||
tenant.setTitle(title);
|
tenant.setTitle(title);
|
||||||
|
|||||||
@ -34,11 +34,11 @@ import org.junit.Test;
|
|||||||
import com.datastax.driver.core.utils.UUIDs;
|
import com.datastax.driver.core.utils.UUIDs;
|
||||||
|
|
||||||
public class CustomerServiceImplTest extends AbstractServiceTest {
|
public class CustomerServiceImplTest extends AbstractServiceTest {
|
||||||
|
|
||||||
private IdComparator<Customer> idComparator = new IdComparator<>();
|
private IdComparator<Customer> idComparator = new IdComparator<>();
|
||||||
|
|
||||||
private TenantId tenantId;
|
private TenantId tenantId;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
Tenant tenant = new Tenant();
|
Tenant tenant = new Tenant();
|
||||||
@ -59,23 +59,23 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
|
|||||||
customer.setTenantId(tenantId);
|
customer.setTenantId(tenantId);
|
||||||
customer.setTitle("My customer");
|
customer.setTitle("My customer");
|
||||||
Customer savedCustomer = customerService.saveCustomer(customer);
|
Customer savedCustomer = customerService.saveCustomer(customer);
|
||||||
|
|
||||||
Assert.assertNotNull(savedCustomer);
|
Assert.assertNotNull(savedCustomer);
|
||||||
Assert.assertNotNull(savedCustomer.getId());
|
Assert.assertNotNull(savedCustomer.getId());
|
||||||
Assert.assertTrue(savedCustomer.getCreatedTime() > 0);
|
Assert.assertTrue(savedCustomer.getCreatedTime() > 0);
|
||||||
Assert.assertEquals(customer.getTenantId(), savedCustomer.getTenantId());
|
Assert.assertEquals(customer.getTenantId(), savedCustomer.getTenantId());
|
||||||
Assert.assertEquals(customer.getTitle(), savedCustomer.getTitle());
|
Assert.assertEquals(customer.getTitle(), savedCustomer.getTitle());
|
||||||
|
|
||||||
|
|
||||||
savedCustomer.setTitle("My new customer");
|
savedCustomer.setTitle("My new customer");
|
||||||
|
|
||||||
customerService.saveCustomer(savedCustomer);
|
customerService.saveCustomer(savedCustomer);
|
||||||
Customer foundCustomer = customerService.findCustomerById(savedCustomer.getId());
|
Customer foundCustomer = customerService.findCustomerById(savedCustomer.getId());
|
||||||
Assert.assertEquals(foundCustomer.getTitle(), savedCustomer.getTitle());
|
Assert.assertEquals(foundCustomer.getTitle(), savedCustomer.getTitle());
|
||||||
|
|
||||||
customerService.deleteCustomer(savedCustomer.getId());
|
customerService.deleteCustomer(savedCustomer.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindCustomerById() {
|
public void testFindCustomerById() {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
@ -87,21 +87,21 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
|
|||||||
Assert.assertEquals(savedCustomer, foundCustomer);
|
Assert.assertEquals(savedCustomer, foundCustomer);
|
||||||
customerService.deleteCustomer(savedCustomer.getId());
|
customerService.deleteCustomer(savedCustomer.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DataValidationException.class)
|
@Test(expected = DataValidationException.class)
|
||||||
public void testSaveCustomerWithEmptyTitle() {
|
public void testSaveCustomerWithEmptyTitle() {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
customer.setTenantId(tenantId);
|
customer.setTenantId(tenantId);
|
||||||
customerService.saveCustomer(customer);
|
customerService.saveCustomer(customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DataValidationException.class)
|
@Test(expected = DataValidationException.class)
|
||||||
public void testSaveCustomerWithEmptyTenant() {
|
public void testSaveCustomerWithEmptyTenant() {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
customer.setTitle("My customer");
|
customer.setTitle("My customer");
|
||||||
customerService.saveCustomer(customer);
|
customerService.saveCustomer(customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DataValidationException.class)
|
@Test(expected = DataValidationException.class)
|
||||||
public void testSaveCustomerWithInvalidTenant() {
|
public void testSaveCustomerWithInvalidTenant() {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
@ -109,7 +109,7 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
|
|||||||
customer.setTenantId(new TenantId(UUIDs.timeBased()));
|
customer.setTenantId(new TenantId(UUIDs.timeBased()));
|
||||||
customerService.saveCustomer(customer);
|
customerService.saveCustomer(customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DataValidationException.class)
|
@Test(expected = DataValidationException.class)
|
||||||
public void testSaveCustomerWithInvalidEmail() {
|
public void testSaveCustomerWithInvalidEmail() {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
@ -118,7 +118,7 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
|
|||||||
customer.setEmail("invalid@mail");
|
customer.setEmail("invalid@mail");
|
||||||
customerService.saveCustomer(customer);
|
customerService.saveCustomer(customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteCustomer() {
|
public void testDeleteCustomer() {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
@ -129,23 +129,23 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
|
|||||||
Customer foundCustomer = customerService.findCustomerById(savedCustomer.getId());
|
Customer foundCustomer = customerService.findCustomerById(savedCustomer.getId());
|
||||||
Assert.assertNull(foundCustomer);
|
Assert.assertNull(foundCustomer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindCustomersByTenantId() {
|
public void testFindCustomersByTenantId() {
|
||||||
Tenant tenant = new Tenant();
|
Tenant tenant = new Tenant();
|
||||||
tenant.setTitle("Test tenant");
|
tenant.setTitle("Test tenant");
|
||||||
tenant = tenantService.saveTenant(tenant);
|
tenant = tenantService.saveTenant(tenant);
|
||||||
|
|
||||||
TenantId tenantId = tenant.getId();
|
TenantId tenantId = tenant.getId();
|
||||||
|
|
||||||
List<Customer> customers = new ArrayList<>();
|
List<Customer> customers = new ArrayList<>();
|
||||||
for (int i=0;i<135;i++) {
|
for (int i = 0; i < 135; i++) {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
customer.setTenantId(tenantId);
|
customer.setTenantId(tenantId);
|
||||||
customer.setTitle("Customer"+i);
|
customer.setTitle("Customer" + i);
|
||||||
customers.add(customerService.saveCustomer(customer));
|
customers.add(customerService.saveCustomer(customer));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Customer> loadedCustomers = new ArrayList<>();
|
List<Customer> loadedCustomers = new ArrayList<>();
|
||||||
TextPageLink pageLink = new TextPageLink(23);
|
TextPageLink pageLink = new TextPageLink(23);
|
||||||
TextPageData<Customer> pageData = null;
|
TextPageData<Customer> pageData = null;
|
||||||
@ -156,47 +156,47 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
|
|||||||
pageLink = pageData.getNextPageLink();
|
pageLink = pageData.getNextPageLink();
|
||||||
}
|
}
|
||||||
} while (pageData.hasNext());
|
} while (pageData.hasNext());
|
||||||
|
|
||||||
Collections.sort(customers, idComparator);
|
Collections.sort(customers, idComparator);
|
||||||
Collections.sort(loadedCustomers, idComparator);
|
Collections.sort(loadedCustomers, idComparator);
|
||||||
|
|
||||||
Assert.assertEquals(customers, loadedCustomers);
|
Assert.assertEquals(customers, loadedCustomers);
|
||||||
|
|
||||||
customerService.deleteCustomersByTenantId(tenantId);
|
customerService.deleteCustomersByTenantId(tenantId);
|
||||||
|
|
||||||
pageLink = new TextPageLink(33);
|
pageLink = new TextPageLink(33);
|
||||||
pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
|
pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
|
||||||
Assert.assertFalse(pageData.hasNext());
|
Assert.assertFalse(pageData.hasNext());
|
||||||
Assert.assertTrue(pageData.getData().isEmpty());
|
Assert.assertTrue(pageData.getData().isEmpty());
|
||||||
|
|
||||||
tenantService.deleteTenant(tenantId);
|
tenantService.deleteTenant(tenantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindCustomersByTenantIdAndTitle() {
|
public void testFindCustomersByTenantIdAndTitle() {
|
||||||
String title1 = "Customer title 1";
|
String title1 = "Customer title 1";
|
||||||
List<Customer> customersTitle1 = new ArrayList<>();
|
List<Customer> customersTitle1 = new ArrayList<>();
|
||||||
for (int i=0;i<143;i++) {
|
for (int i = 0; i < 143; i++) {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
customer.setTenantId(tenantId);
|
customer.setTenantId(tenantId);
|
||||||
String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15));
|
String suffix = RandomStringUtils.randomAlphanumeric((int)(5 + Math.random()*10));
|
||||||
String title = title1+suffix;
|
String title = title1 + suffix;
|
||||||
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
||||||
customer.setTitle(title);
|
customer.setTitle(title);
|
||||||
customersTitle1.add(customerService.saveCustomer(customer));
|
customersTitle1.add(customerService.saveCustomer(customer));
|
||||||
}
|
}
|
||||||
String title2 = "Customer title 2";
|
String title2 = "Customer title 2";
|
||||||
List<Customer> customersTitle2 = new ArrayList<>();
|
List<Customer> customersTitle2 = new ArrayList<>();
|
||||||
for (int i=0;i<175;i++) {
|
for (int i = 0; i < 175; i++) {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
customer.setTenantId(tenantId);
|
customer.setTenantId(tenantId);
|
||||||
String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15));
|
String suffix = RandomStringUtils.randomAlphanumeric((int)(5 + Math.random()*10));
|
||||||
String title = title2+suffix;
|
String title = title2 + suffix;
|
||||||
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
|
||||||
customer.setTitle(title);
|
customer.setTitle(title);
|
||||||
customersTitle2.add(customerService.saveCustomer(customer));
|
customersTitle2.add(customerService.saveCustomer(customer));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Customer> loadedCustomersTitle1 = new ArrayList<>();
|
List<Customer> loadedCustomersTitle1 = new ArrayList<>();
|
||||||
TextPageLink pageLink = new TextPageLink(15, title1);
|
TextPageLink pageLink = new TextPageLink(15, title1);
|
||||||
TextPageData<Customer> pageData = null;
|
TextPageData<Customer> pageData = null;
|
||||||
@ -207,12 +207,12 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
|
|||||||
pageLink = pageData.getNextPageLink();
|
pageLink = pageData.getNextPageLink();
|
||||||
}
|
}
|
||||||
} while (pageData.hasNext());
|
} while (pageData.hasNext());
|
||||||
|
|
||||||
Collections.sort(customersTitle1, idComparator);
|
Collections.sort(customersTitle1, idComparator);
|
||||||
Collections.sort(loadedCustomersTitle1, idComparator);
|
Collections.sort(loadedCustomersTitle1, idComparator);
|
||||||
|
|
||||||
Assert.assertEquals(customersTitle1, loadedCustomersTitle1);
|
Assert.assertEquals(customersTitle1, loadedCustomersTitle1);
|
||||||
|
|
||||||
List<Customer> loadedCustomersTitle2 = new ArrayList<>();
|
List<Customer> loadedCustomersTitle2 = new ArrayList<>();
|
||||||
pageLink = new TextPageLink(4, title2);
|
pageLink = new TextPageLink(4, title2);
|
||||||
do {
|
do {
|
||||||
@ -225,22 +225,22 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
|
|||||||
|
|
||||||
Collections.sort(customersTitle2, idComparator);
|
Collections.sort(customersTitle2, idComparator);
|
||||||
Collections.sort(loadedCustomersTitle2, idComparator);
|
Collections.sort(loadedCustomersTitle2, idComparator);
|
||||||
|
|
||||||
Assert.assertEquals(customersTitle2, loadedCustomersTitle2);
|
Assert.assertEquals(customersTitle2, loadedCustomersTitle2);
|
||||||
|
|
||||||
for (Customer customer : loadedCustomersTitle1) {
|
for (Customer customer : loadedCustomersTitle1) {
|
||||||
customerService.deleteCustomer(customer.getId());
|
customerService.deleteCustomer(customer.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
pageLink = new TextPageLink(4, title1);
|
pageLink = new TextPageLink(4, title1);
|
||||||
pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
|
pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
|
||||||
Assert.assertFalse(pageData.hasNext());
|
Assert.assertFalse(pageData.hasNext());
|
||||||
Assert.assertEquals(0, pageData.getData().size());
|
Assert.assertEquals(0, pageData.getData().size());
|
||||||
|
|
||||||
for (Customer customer : loadedCustomersTitle2) {
|
for (Customer customer : loadedCustomersTitle2) {
|
||||||
customerService.deleteCustomer(customer.getId());
|
customerService.deleteCustomer(customer.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
pageLink = new TextPageLink(4, title2);
|
pageLink = new TextPageLink(4, title2);
|
||||||
pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
|
pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
|
||||||
Assert.assertFalse(pageData.hasNext());
|
Assert.assertFalse(pageData.hasNext());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user