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