Commit 96d344fabd559d2f60e57ea4ffa02353a8db0a5f

Authored by Andrew Shvayka
1 parent 7020e60a

Fixed outdated tests

@@ -288,7 +288,7 @@ public class CustomerControllerTest extends AbstractControllerTest { @@ -288,7 +288,7 @@ public class CustomerControllerTest extends AbstractControllerTest {
288 for (int i=0;i<143;i++) { 288 for (int i=0;i<143;i++) {
289 Customer customer = new Customer(); 289 Customer customer = new Customer();
290 customer.setTenantId(tenantId); 290 customer.setTenantId(tenantId);
291 - String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15)); 291 + String suffix = RandomStringUtils.randomAlphanumeric((int)(5 + Math.random()*10));
292 String title = title1+suffix; 292 String title = title1+suffix;
293 title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase(); 293 title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
294 customer.setTitle(title); 294 customer.setTitle(title);
@@ -299,7 +299,7 @@ public class CustomerControllerTest extends AbstractControllerTest { @@ -299,7 +299,7 @@ public class CustomerControllerTest extends AbstractControllerTest {
299 for (int i=0;i<175;i++) { 299 for (int i=0;i<175;i++) {
300 Customer customer = new Customer(); 300 Customer customer = new Customer();
301 customer.setTenantId(tenantId); 301 customer.setTenantId(tenantId);
302 - String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15)); 302 + String suffix = RandomStringUtils.randomAlphanumeric((int)(5 + Math.random()*10));
303 String title = title2+suffix; 303 String title = title2+suffix;
304 title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase(); 304 title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
305 customer.setTitle(title); 305 customer.setTitle(title);
@@ -149,7 +149,7 @@ public class TenantControllerTest extends AbstractControllerTest { @@ -149,7 +149,7 @@ public class TenantControllerTest extends AbstractControllerTest {
149 List<Tenant> tenantsTitle1 = new ArrayList<>(); 149 List<Tenant> tenantsTitle1 = new ArrayList<>();
150 for (int i=0;i<134;i++) { 150 for (int i=0;i<134;i++) {
151 Tenant tenant = new Tenant(); 151 Tenant tenant = new Tenant();
152 - String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15)); 152 + String suffix = RandomStringUtils.randomAlphanumeric((int)(5 + Math.random()*10));
153 String title = title1+suffix; 153 String title = title1+suffix;
154 title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase(); 154 title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
155 tenant.setTitle(title); 155 tenant.setTitle(title);
@@ -159,7 +159,7 @@ public class TenantControllerTest extends AbstractControllerTest { @@ -159,7 +159,7 @@ public class TenantControllerTest extends AbstractControllerTest {
159 List<Tenant> tenantsTitle2 = new ArrayList<>(); 159 List<Tenant> tenantsTitle2 = new ArrayList<>();
160 for (int i=0;i<127;i++) { 160 for (int i=0;i<127;i++) {
161 Tenant tenant = new Tenant(); 161 Tenant tenant = new Tenant();
162 - String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15)); 162 + String suffix = RandomStringUtils.randomAlphanumeric((int)(5 + Math.random()*10));
163 String title = title2+suffix; 163 String title = title2+suffix;
164 title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase(); 164 title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
165 tenant.setTitle(title); 165 tenant.setTitle(title);
@@ -34,11 +34,11 @@ import org.junit.Test; @@ -34,11 +34,11 @@ import org.junit.Test;
34 import com.datastax.driver.core.utils.UUIDs; 34 import com.datastax.driver.core.utils.UUIDs;
35 35
36 public class CustomerServiceImplTest extends AbstractServiceTest { 36 public class CustomerServiceImplTest extends AbstractServiceTest {
37 - 37 +
38 private IdComparator<Customer> idComparator = new IdComparator<>(); 38 private IdComparator<Customer> idComparator = new IdComparator<>();
39 - 39 +
40 private TenantId tenantId; 40 private TenantId tenantId;
41 - 41 +
42 @Before 42 @Before
43 public void before() { 43 public void before() {
44 Tenant tenant = new Tenant(); 44 Tenant tenant = new Tenant();
@@ -59,23 +59,23 @@ public class CustomerServiceImplTest extends AbstractServiceTest { @@ -59,23 +59,23 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
59 customer.setTenantId(tenantId); 59 customer.setTenantId(tenantId);
60 customer.setTitle("My customer"); 60 customer.setTitle("My customer");
61 Customer savedCustomer = customerService.saveCustomer(customer); 61 Customer savedCustomer = customerService.saveCustomer(customer);
62 - 62 +
63 Assert.assertNotNull(savedCustomer); 63 Assert.assertNotNull(savedCustomer);
64 Assert.assertNotNull(savedCustomer.getId()); 64 Assert.assertNotNull(savedCustomer.getId());
65 Assert.assertTrue(savedCustomer.getCreatedTime() > 0); 65 Assert.assertTrue(savedCustomer.getCreatedTime() > 0);
66 Assert.assertEquals(customer.getTenantId(), savedCustomer.getTenantId()); 66 Assert.assertEquals(customer.getTenantId(), savedCustomer.getTenantId());
67 Assert.assertEquals(customer.getTitle(), savedCustomer.getTitle()); 67 Assert.assertEquals(customer.getTitle(), savedCustomer.getTitle());
68 -  
69 - 68 +
  69 +
70 savedCustomer.setTitle("My new customer"); 70 savedCustomer.setTitle("My new customer");
71 - 71 +
72 customerService.saveCustomer(savedCustomer); 72 customerService.saveCustomer(savedCustomer);
73 Customer foundCustomer = customerService.findCustomerById(savedCustomer.getId()); 73 Customer foundCustomer = customerService.findCustomerById(savedCustomer.getId());
74 Assert.assertEquals(foundCustomer.getTitle(), savedCustomer.getTitle()); 74 Assert.assertEquals(foundCustomer.getTitle(), savedCustomer.getTitle());
75 - 75 +
76 customerService.deleteCustomer(savedCustomer.getId()); 76 customerService.deleteCustomer(savedCustomer.getId());
77 } 77 }
78 - 78 +
79 @Test 79 @Test
80 public void testFindCustomerById() { 80 public void testFindCustomerById() {
81 Customer customer = new Customer(); 81 Customer customer = new Customer();
@@ -87,21 +87,21 @@ public class CustomerServiceImplTest extends AbstractServiceTest { @@ -87,21 +87,21 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
87 Assert.assertEquals(savedCustomer, foundCustomer); 87 Assert.assertEquals(savedCustomer, foundCustomer);
88 customerService.deleteCustomer(savedCustomer.getId()); 88 customerService.deleteCustomer(savedCustomer.getId());
89 } 89 }
90 - 90 +
91 @Test(expected = DataValidationException.class) 91 @Test(expected = DataValidationException.class)
92 public void testSaveCustomerWithEmptyTitle() { 92 public void testSaveCustomerWithEmptyTitle() {
93 Customer customer = new Customer(); 93 Customer customer = new Customer();
94 customer.setTenantId(tenantId); 94 customer.setTenantId(tenantId);
95 customerService.saveCustomer(customer); 95 customerService.saveCustomer(customer);
96 } 96 }
97 - 97 +
98 @Test(expected = DataValidationException.class) 98 @Test(expected = DataValidationException.class)
99 public void testSaveCustomerWithEmptyTenant() { 99 public void testSaveCustomerWithEmptyTenant() {
100 Customer customer = new Customer(); 100 Customer customer = new Customer();
101 customer.setTitle("My customer"); 101 customer.setTitle("My customer");
102 customerService.saveCustomer(customer); 102 customerService.saveCustomer(customer);
103 } 103 }
104 - 104 +
105 @Test(expected = DataValidationException.class) 105 @Test(expected = DataValidationException.class)
106 public void testSaveCustomerWithInvalidTenant() { 106 public void testSaveCustomerWithInvalidTenant() {
107 Customer customer = new Customer(); 107 Customer customer = new Customer();
@@ -109,7 +109,7 @@ public class CustomerServiceImplTest extends AbstractServiceTest { @@ -109,7 +109,7 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
109 customer.setTenantId(new TenantId(UUIDs.timeBased())); 109 customer.setTenantId(new TenantId(UUIDs.timeBased()));
110 customerService.saveCustomer(customer); 110 customerService.saveCustomer(customer);
111 } 111 }
112 - 112 +
113 @Test(expected = DataValidationException.class) 113 @Test(expected = DataValidationException.class)
114 public void testSaveCustomerWithInvalidEmail() { 114 public void testSaveCustomerWithInvalidEmail() {
115 Customer customer = new Customer(); 115 Customer customer = new Customer();
@@ -118,7 +118,7 @@ public class CustomerServiceImplTest extends AbstractServiceTest { @@ -118,7 +118,7 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
118 customer.setEmail("invalid@mail"); 118 customer.setEmail("invalid@mail");
119 customerService.saveCustomer(customer); 119 customerService.saveCustomer(customer);
120 } 120 }
121 - 121 +
122 @Test 122 @Test
123 public void testDeleteCustomer() { 123 public void testDeleteCustomer() {
124 Customer customer = new Customer(); 124 Customer customer = new Customer();
@@ -129,23 +129,23 @@ public class CustomerServiceImplTest extends AbstractServiceTest { @@ -129,23 +129,23 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
129 Customer foundCustomer = customerService.findCustomerById(savedCustomer.getId()); 129 Customer foundCustomer = customerService.findCustomerById(savedCustomer.getId());
130 Assert.assertNull(foundCustomer); 130 Assert.assertNull(foundCustomer);
131 } 131 }
132 - 132 +
133 @Test 133 @Test
134 public void testFindCustomersByTenantId() { 134 public void testFindCustomersByTenantId() {
135 Tenant tenant = new Tenant(); 135 Tenant tenant = new Tenant();
136 tenant.setTitle("Test tenant"); 136 tenant.setTitle("Test tenant");
137 tenant = tenantService.saveTenant(tenant); 137 tenant = tenantService.saveTenant(tenant);
138 - 138 +
139 TenantId tenantId = tenant.getId(); 139 TenantId tenantId = tenant.getId();
140 - 140 +
141 List<Customer> customers = new ArrayList<>(); 141 List<Customer> customers = new ArrayList<>();
142 - for (int i=0;i<135;i++) { 142 + for (int i = 0; i < 135; i++) {
143 Customer customer = new Customer(); 143 Customer customer = new Customer();
144 customer.setTenantId(tenantId); 144 customer.setTenantId(tenantId);
145 - customer.setTitle("Customer"+i); 145 + customer.setTitle("Customer" + i);
146 customers.add(customerService.saveCustomer(customer)); 146 customers.add(customerService.saveCustomer(customer));
147 } 147 }
148 - 148 +
149 List<Customer> loadedCustomers = new ArrayList<>(); 149 List<Customer> loadedCustomers = new ArrayList<>();
150 TextPageLink pageLink = new TextPageLink(23); 150 TextPageLink pageLink = new TextPageLink(23);
151 TextPageData<Customer> pageData = null; 151 TextPageData<Customer> pageData = null;
@@ -156,47 +156,47 @@ public class CustomerServiceImplTest extends AbstractServiceTest { @@ -156,47 +156,47 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
156 pageLink = pageData.getNextPageLink(); 156 pageLink = pageData.getNextPageLink();
157 } 157 }
158 } while (pageData.hasNext()); 158 } while (pageData.hasNext());
159 - 159 +
160 Collections.sort(customers, idComparator); 160 Collections.sort(customers, idComparator);
161 Collections.sort(loadedCustomers, idComparator); 161 Collections.sort(loadedCustomers, idComparator);
162 - 162 +
163 Assert.assertEquals(customers, loadedCustomers); 163 Assert.assertEquals(customers, loadedCustomers);
164 - 164 +
165 customerService.deleteCustomersByTenantId(tenantId); 165 customerService.deleteCustomersByTenantId(tenantId);
166 166
167 pageLink = new TextPageLink(33); 167 pageLink = new TextPageLink(33);
168 pageData = customerService.findCustomersByTenantId(tenantId, pageLink); 168 pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
169 Assert.assertFalse(pageData.hasNext()); 169 Assert.assertFalse(pageData.hasNext());
170 Assert.assertTrue(pageData.getData().isEmpty()); 170 Assert.assertTrue(pageData.getData().isEmpty());
171 - 171 +
172 tenantService.deleteTenant(tenantId); 172 tenantService.deleteTenant(tenantId);
173 } 173 }
174 - 174 +
175 @Test 175 @Test
176 public void testFindCustomersByTenantIdAndTitle() { 176 public void testFindCustomersByTenantIdAndTitle() {
177 String title1 = "Customer title 1"; 177 String title1 = "Customer title 1";
178 List<Customer> customersTitle1 = new ArrayList<>(); 178 List<Customer> customersTitle1 = new ArrayList<>();
179 - for (int i=0;i<143;i++) { 179 + for (int i = 0; i < 143; i++) {
180 Customer customer = new Customer(); 180 Customer customer = new Customer();
181 customer.setTenantId(tenantId); 181 customer.setTenantId(tenantId);
182 - String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15));  
183 - String title = title1+suffix; 182 + String suffix = RandomStringUtils.randomAlphanumeric((int)(5 + Math.random()*10));
  183 + String title = title1 + suffix;
184 title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase(); 184 title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
185 customer.setTitle(title); 185 customer.setTitle(title);
186 customersTitle1.add(customerService.saveCustomer(customer)); 186 customersTitle1.add(customerService.saveCustomer(customer));
187 } 187 }
188 String title2 = "Customer title 2"; 188 String title2 = "Customer title 2";
189 List<Customer> customersTitle2 = new ArrayList<>(); 189 List<Customer> customersTitle2 = new ArrayList<>();
190 - for (int i=0;i<175;i++) { 190 + for (int i = 0; i < 175; i++) {
191 Customer customer = new Customer(); 191 Customer customer = new Customer();
192 customer.setTenantId(tenantId); 192 customer.setTenantId(tenantId);
193 - String suffix = RandomStringUtils.randomAlphanumeric((int)(Math.random()*15));  
194 - String title = title2+suffix; 193 + String suffix = RandomStringUtils.randomAlphanumeric((int)(5 + Math.random()*10));
  194 + String title = title2 + suffix;
195 title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase(); 195 title = i % 2 == 0 ? title.toLowerCase() : title.toUpperCase();
196 customer.setTitle(title); 196 customer.setTitle(title);
197 customersTitle2.add(customerService.saveCustomer(customer)); 197 customersTitle2.add(customerService.saveCustomer(customer));
198 } 198 }
199 - 199 +
200 List<Customer> loadedCustomersTitle1 = new ArrayList<>(); 200 List<Customer> loadedCustomersTitle1 = new ArrayList<>();
201 TextPageLink pageLink = new TextPageLink(15, title1); 201 TextPageLink pageLink = new TextPageLink(15, title1);
202 TextPageData<Customer> pageData = null; 202 TextPageData<Customer> pageData = null;
@@ -207,12 +207,12 @@ public class CustomerServiceImplTest extends AbstractServiceTest { @@ -207,12 +207,12 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
207 pageLink = pageData.getNextPageLink(); 207 pageLink = pageData.getNextPageLink();
208 } 208 }
209 } while (pageData.hasNext()); 209 } while (pageData.hasNext());
210 - 210 +
211 Collections.sort(customersTitle1, idComparator); 211 Collections.sort(customersTitle1, idComparator);
212 Collections.sort(loadedCustomersTitle1, idComparator); 212 Collections.sort(loadedCustomersTitle1, idComparator);
213 - 213 +
214 Assert.assertEquals(customersTitle1, loadedCustomersTitle1); 214 Assert.assertEquals(customersTitle1, loadedCustomersTitle1);
215 - 215 +
216 List<Customer> loadedCustomersTitle2 = new ArrayList<>(); 216 List<Customer> loadedCustomersTitle2 = new ArrayList<>();
217 pageLink = new TextPageLink(4, title2); 217 pageLink = new TextPageLink(4, title2);
218 do { 218 do {
@@ -225,22 +225,22 @@ public class CustomerServiceImplTest extends AbstractServiceTest { @@ -225,22 +225,22 @@ public class CustomerServiceImplTest extends AbstractServiceTest {
225 225
226 Collections.sort(customersTitle2, idComparator); 226 Collections.sort(customersTitle2, idComparator);
227 Collections.sort(loadedCustomersTitle2, idComparator); 227 Collections.sort(loadedCustomersTitle2, idComparator);
228 - 228 +
229 Assert.assertEquals(customersTitle2, loadedCustomersTitle2); 229 Assert.assertEquals(customersTitle2, loadedCustomersTitle2);
230 230
231 for (Customer customer : loadedCustomersTitle1) { 231 for (Customer customer : loadedCustomersTitle1) {
232 customerService.deleteCustomer(customer.getId()); 232 customerService.deleteCustomer(customer.getId());
233 } 233 }
234 - 234 +
235 pageLink = new TextPageLink(4, title1); 235 pageLink = new TextPageLink(4, title1);
236 pageData = customerService.findCustomersByTenantId(tenantId, pageLink); 236 pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
237 Assert.assertFalse(pageData.hasNext()); 237 Assert.assertFalse(pageData.hasNext());
238 Assert.assertEquals(0, pageData.getData().size()); 238 Assert.assertEquals(0, pageData.getData().size());
239 - 239 +
240 for (Customer customer : loadedCustomersTitle2) { 240 for (Customer customer : loadedCustomersTitle2) {
241 customerService.deleteCustomer(customer.getId()); 241 customerService.deleteCustomer(customer.getId());
242 } 242 }
243 - 243 +
244 pageLink = new TextPageLink(4, title2); 244 pageLink = new TextPageLink(4, title2);
245 pageData = customerService.findCustomersByTenantId(tenantId, pageLink); 245 pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
246 Assert.assertFalse(pageData.hasNext()); 246 Assert.assertFalse(pageData.hasNext());