This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
/
ConfigureDhcpWorkflowServiceTest.java
596 lines (504 loc) · 23.8 KB
/
ConfigureDhcpWorkflowServiceTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
/*
* Copyright 2016 VMware, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, without warranties or
* conditions of any kind, EITHER EXPRESS OR IMPLIED. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.vmware.photon.controller.apibackend.workflows;
import com.vmware.photon.controller.apibackend.helpers.ReflectionUtils;
import com.vmware.photon.controller.apibackend.helpers.TestEnvironment;
import com.vmware.photon.controller.apibackend.helpers.TestHelper;
import com.vmware.photon.controller.apibackend.servicedocuments.ConfigureDhcpWorkflowDocument;
import com.vmware.photon.controller.apibackend.utils.TaskStateHelper;
import com.vmware.photon.controller.cloudstore.xenon.entity.DeploymentService;
import com.vmware.photon.controller.cloudstore.xenon.entity.DeploymentServiceFactory;
import com.vmware.photon.controller.common.tests.nsx.NsxClientMock;
import com.vmware.photon.controller.common.xenon.CloudStoreHelper;
import com.vmware.photon.controller.common.xenon.ControlFlags;
import com.vmware.photon.controller.common.xenon.exceptions.XenonRuntimeException;
import com.vmware.photon.controller.common.xenon.validation.Immutable;
import com.vmware.photon.controller.common.xenon.validation.NotBlank;
import com.vmware.photon.controller.nsxclient.NsxClientFactory;
import com.vmware.xenon.common.Operation;
import com.vmware.xenon.common.Service;
import com.vmware.xenon.common.TaskState;
import org.hamcrest.Matchers;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.testng.Assert.assertEquals;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.EnumSet;
/**
* Tests for {@link com.vmware.photon.controller.apibackend.workflows.ConfigureDhcpWorkflowService}.
*/
public class ConfigureDhcpWorkflowServiceTest {
private static final TaskStateHelper<ConfigureDhcpWorkflowDocument.TaskState.SubStage> taskStateHelper =
new TaskStateHelper<>(ConfigureDhcpWorkflowDocument.TaskState.SubStage.class);
@Test(enabled = false)
private void dummy() {
}
/**
* Creates a new ConfigureDhcpWorkflowDocument object to create a new ConfigureDhcpWorkflowService instance.
*/
private static ConfigureDhcpWorkflowDocument buildStartState(
ConfigureDhcpWorkflowDocument.TaskState.TaskStage startStage,
ConfigureDhcpWorkflowDocument.TaskState.SubStage subStage,
int controlFlag) {
ConfigureDhcpWorkflowDocument startState = new ConfigureDhcpWorkflowDocument();
startState.taskState = new ConfigureDhcpWorkflowDocument.TaskState();
startState.taskState.stage = startStage;
startState.taskState.subStage = subStage;
startState.controlFlags = controlFlag;
startState.nsxAddress = "https://192.168.1.1";
startState.nsxUsername = "username";
startState.nsxPassword = "password";
startState.dhcpServerAddresses = new ArrayList<>();
startState.dhcpServerAddresses.add("1.2.3.4");
return startState;
}
/**
* Creates a patch object which is sufficient to patch a ConfigureDhcpWorkflowService instance.
*/
private static ConfigureDhcpWorkflowDocument buildPatchState(
ConfigureDhcpWorkflowDocument.TaskState.TaskStage patchStage,
ConfigureDhcpWorkflowDocument.TaskState.SubStage patchSubStage) {
ConfigureDhcpWorkflowDocument patchState = new ConfigureDhcpWorkflowDocument();
patchState.taskState = new ConfigureDhcpWorkflowDocument.TaskState();
patchState.taskState.stage = patchStage;
patchState.taskState.subStage = patchSubStage;
return patchState;
}
/**
* Creates a DeploymentService.State object in cloud-store.
*/
private DeploymentService.State createDeploymentDocumentInCloudStore(TestEnvironment testEnvironment)
throws Throwable {
return createDeploymentDocumentInCloudStore(testEnvironment, "nsxAddress", "username", "password");
}
private DeploymentService.State createDeploymentDocumentInCloudStore(TestEnvironment testEnvironment,
String nsxServerAddress,
String username,
String password) throws Throwable {
DeploymentService.State startState = ReflectionUtils.buildValidStartState(DeploymentService.State.class);
startState.sdnEnabled = true;
startState.networkManagerAddress = nsxServerAddress;
startState.networkManagerUsername = username;
startState.networkManagerPassword = password;
Operation result = testEnvironment.sendPostAndWait(DeploymentServiceFactory.SELF_LINK, startState);
assertThat(result.getStatusCode(), is(Operation.STATUS_CODE_OK));
return result.getBody(DeploymentService.State.class);
}
/**
* Tests for the initialization of service itself.
*/
public static class InitializationTest {
@Test
public void testCapabilities() {
EnumSet<Service.ServiceOption> expected = EnumSet.of(
Service.ServiceOption.CONCURRENT_GET_HANDLING,
Service.ServiceOption.OWNER_SELECTION,
Service.ServiceOption.PERSISTENCE,
Service.ServiceOption.REPLICATION,
Service.ServiceOption.INSTRUMENTATION);
ConfigureDhcpWorkflowService service = new ConfigureDhcpWorkflowService();
assertThat(service.getOptions(), is(expected));
}
}
/**
* Tests that when {@link com.vmware.photon.controller.apibackend.workflows.ConfigureDhcpWorkflowService#handleCreate}
* is called, the workflow will validate the state object and behave correctly.
*/
public class HandleCreateTest {
private ConfigureDhcpWorkflowDocument startState;
private TestEnvironment testEnvironment;
@BeforeMethod
public void setUpTest() throws Throwable {
testEnvironment = new TestEnvironment.Builder()
.hostCount(1)
.cloudStoreHelper(new CloudStoreHelper())
.build();
createDeploymentDocumentInCloudStore(testEnvironment);
startState = buildStartState(
TaskState.TaskStage.CREATED,
null,
new ControlFlags.Builder()
.disableOperationProcessingOnHandleStart()
.disableOperationProcessingOnHandlePatch()
.build());
}
@AfterMethod
public void tearDownTest() throws Throwable {
if (null != testEnvironment) {
testEnvironment.stop();
testEnvironment = null;
}
startState = null;
}
/**
* Verifies that when a field of the initial state has null value and is annotated with
* default value, the workflow will initialize the state with the default value and succeed.
*/
@Test
public void succeedsWithNullDefaultFields() throws Throwable {
startState.taskState = null;
ConfigureDhcpWorkflowDocument finalState =
testEnvironment.callServiceAndWaitForState(
ConfigureDhcpWorkflowService.FACTORY_LINK,
startState,
ConfigureDhcpWorkflowDocument.class,
(state) -> TaskState.TaskStage.CREATED == state.taskState.stage);
assertThat(finalState.taskState, notNullValue());
}
/**
* Verifies that when a field of the initial state has null value but is annotated as mandatory,
* the workflow will validate the state and fail.
* @throws Throwable
*/
@Test(expectedExceptions = XenonRuntimeException.class,
expectedExceptionsMessageRegExp = "^.* cannot be null",
dataProvider = "NotNullFields")
public void failsWithNullMandatoryFields(String fieldName) throws Throwable {
Field declaredField = startState.getClass().getDeclaredField(fieldName);
declaredField.set(startState, null);
testEnvironment.callServiceAndWaitForState(
ConfigureDhcpWorkflowService.FACTORY_LINK,
startState,
ConfigureDhcpWorkflowDocument.class,
(state) -> TaskState.TaskStage.CREATED == state.taskState.stage);
}
@DataProvider(name = "NotNullFields")
public Object[][] getNotNullFields() {
return TestHelper.toDataProvidersList(
ReflectionUtils.getAttributeNamesWithAnnotation(
ConfigureDhcpWorkflowDocument.class, NotBlank.class));
}
}
/**
* Tests that when {@link com.vmware.photon.controller.apibackend.workflows.ConfigureDhcpWorkflowService#handleStart}
* is called, the workflow will validate the state object and behave correctly.
*/
public class HandleStartTest {
private ConfigureDhcpWorkflowDocument startState;
private TestEnvironment testEnvironment;
private DeploymentService.State deploymentState;
@BeforeMethod
public void setUpTest() throws Throwable {
testEnvironment = new TestEnvironment.Builder()
.hostCount(1)
.cloudStoreHelper(new CloudStoreHelper())
.build();
deploymentState = createDeploymentDocumentInCloudStore(testEnvironment);
startState = buildStartState(
TaskState.TaskStage.CREATED,
null,
new ControlFlags.Builder()
.disableOperationProcessingOnHandleStart()
.disableOperationProcessingOnHandlePatch()
.build());
}
@AfterMethod
public void tearDownTest() throws Throwable {
if (null != testEnvironment) {
testEnvironment.stop();
testEnvironment = null;
}
startState = null;
}
/**
* Verifies that when a valid start state is given, the workflow will validate the state and succeed.
*/
@Test
public void succeedsWithValidStartState() throws Throwable {
ConfigureDhcpWorkflowDocument finalState =
testEnvironment.callServiceAndWaitForState(
ConfigureDhcpWorkflowService.FACTORY_LINK,
startState,
ConfigureDhcpWorkflowDocument.class,
(state) -> TaskState.TaskStage.CREATED == state.taskState.stage);
assertThat(finalState.taskState, notNullValue());
}
/**
* Verifies that when an invalid start state is given, the workflow will validate the state and fail.
*/
@Test(dataProvider = "InvalidStartState", expectedExceptions = XenonRuntimeException.class)
public void failsWithInvalidStartState(TaskState.TaskStage stage,
ConfigureDhcpWorkflowDocument.TaskState.SubStage subStage)
throws Throwable {
startState = buildStartState(stage,
subStage,
new ControlFlags.Builder()
.disableOperationProcessingOnHandleStart()
.disableOperationProcessingOnHandlePatch()
.build());
testEnvironment.callServiceAndWaitForState(
ConfigureDhcpWorkflowService.FACTORY_LINK,
startState,
ConfigureDhcpWorkflowDocument.class,
(state) -> TaskState.TaskStage.CREATED == state.taskState.stage);
}
@DataProvider(name = "InvalidStartState")
public Object[][] getInvalidStartStateTestData() throws Throwable {
return taskStateHelper.getInvalidStartState();
}
}
/**
* Tests that when {@link com.vmware.photon.controller.apibackend.workflows.ConfigureDhcpWorkflowService#handlePatch}
* is called, the workflow will validate the state object and behave correctly.
*/
public class HandlePatchTest {
private ConfigureDhcpWorkflowDocument startState;
private TestEnvironment testEnvironment;
@BeforeMethod
public void setUpTest() throws Throwable {
testEnvironment = new TestEnvironment.Builder()
.hostCount(1)
.cloudStoreHelper(new CloudStoreHelper())
.build();
createDeploymentDocumentInCloudStore(testEnvironment);
startState = buildStartState(
TaskState.TaskStage.CREATED,
null,
new ControlFlags.Builder()
.disableOperationProcessingOnHandlePatch()
.disableOperationProcessingOnStageTransition()
.build());
}
@AfterMethod
public void tearDownTest() throws Throwable {
if (null != testEnvironment) {
testEnvironment.stop();
testEnvironment = null;
}
startState = null;
}
/**
* Verifies that when a valid stage/sub-stage patch state is given, the workflow will validate
* the state and succeed.
*/
@Test(dataProvider = "ValidStageAndSubStagePatch")
public void succeedsWithValidStageAndSubStagePatch(
TaskState.TaskStage currentStage,
ConfigureDhcpWorkflowDocument.TaskState.SubStage currentSubStage,
TaskState.TaskStage patchStage,
ConfigureDhcpWorkflowDocument.TaskState.SubStage patchSubStage) throws Throwable {
ConfigureDhcpWorkflowDocument finalState =
testEnvironment.callServiceAndWaitForState(
ConfigureDhcpWorkflowService.FACTORY_LINK,
startState,
ConfigureDhcpWorkflowDocument.class,
(state) -> TaskState.TaskStage.STARTED == state.taskState.stage &&
ConfigureDhcpWorkflowDocument.TaskState.SubStage.CREATE_DHCP_RELAY_PROFILE
== state.taskState.subStage);
if (!(currentStage == ConfigureDhcpWorkflowDocument.TaskState.TaskStage.STARTED &&
currentSubStage == ConfigureDhcpWorkflowDocument.TaskState.SubStage.CREATE_DHCP_RELAY_PROFILE)) {
testEnvironment.sendPatchAndWait(finalState.documentSelfLink,
buildPatchState(currentStage, currentSubStage));
}
finalState = testEnvironment.sendPatchAndWait(finalState.documentSelfLink,
buildPatchState(patchStage, patchSubStage))
.getBody(ConfigureDhcpWorkflowDocument.class);
assertThat(finalState.taskState.stage, is(patchStage));
assertThat(finalState.taskState.subStage, is(patchSubStage));
}
@DataProvider(name = "ValidStageAndSubStagePatch")
public Object[][] getValidStageAndSubStagePatch() throws Throwable {
return taskStateHelper.getValidPatchState();
}
/**
* Verifies that when an invalid stage/sub-stage patch state is given, the workflow will validate
* the state and fail.
*/
@Test(expectedExceptions = XenonRuntimeException.class, dataProvider = "InvalidStageAndSubStagePatch")
public void failsWithInvalidStageAndSubStagePatch(
TaskState.TaskStage currentStage,
ConfigureDhcpWorkflowDocument.TaskState.SubStage currentSubStage,
TaskState.TaskStage patchStage,
ConfigureDhcpWorkflowDocument.TaskState.SubStage patchSubStage) throws Throwable {
ConfigureDhcpWorkflowDocument finalState =
testEnvironment.callServiceAndWaitForState(
ConfigureDhcpWorkflowService.FACTORY_LINK,
startState,
ConfigureDhcpWorkflowDocument.class,
(state) -> TaskState.TaskStage.STARTED == state.taskState.stage &&
ConfigureDhcpWorkflowDocument.TaskState.SubStage.CREATE_DHCP_RELAY_PROFILE
== state.taskState.subStage);
if (!(currentStage == ConfigureDhcpWorkflowDocument.TaskState.TaskStage.STARTED &&
currentSubStage == ConfigureDhcpWorkflowDocument.TaskState.SubStage.CREATE_DHCP_RELAY_PROFILE)) {
testEnvironment.sendPatchAndWait(finalState.documentSelfLink,
buildPatchState(currentStage, currentSubStage));
}
testEnvironment.sendPatchAndWait(finalState.documentSelfLink,
buildPatchState(patchStage, patchSubStage))
.getBody(ConfigureDhcpWorkflowDocument.class);
}
@DataProvider(name = "InvalidStageAndSubStagePatch")
public Object[][] getInvalidStageAndSubStagePatch() throws Throwable {
return taskStateHelper.getInvalidPatchState();
}
/**
* Verifies that when a immutable field is set to non-null value in the patch state, the workflow will
* validate the state and fail.
*/
@Test(expectedExceptions = XenonRuntimeException.class,
expectedExceptionsMessageRegExp = "^.* is immutable",
dataProvider = "ImmutableFields")
public void failsWithNonNullImmutableFieldPatch(String fieldName) throws Throwable {
ConfigureDhcpWorkflowDocument finalState =
testEnvironment.callServiceAndWaitForState(
ConfigureDhcpWorkflowService.FACTORY_LINK,
startState,
ConfigureDhcpWorkflowDocument.class,
(state) -> TaskState.TaskStage.STARTED == state.taskState.stage &&
ConfigureDhcpWorkflowDocument.TaskState.SubStage.CREATE_DHCP_RELAY_PROFILE
== state.taskState.subStage);
ConfigureDhcpWorkflowDocument patchState = buildPatchState(TaskState.TaskStage.STARTED,
ConfigureDhcpWorkflowDocument.TaskState.SubStage.CREATE_DHCP_RELAY_SERVICE);
Field declaredField = patchState.getClass().getDeclaredField(fieldName);
declaredField.set(patchState, ReflectionUtils.getDefaultAttributeValue(declaredField));
testEnvironment.sendPatchAndWait(finalState.documentSelfLink, patchState)
.getBody(ConfigureDhcpWorkflowDocument.class);
}
@DataProvider(name = "ImmutableFields")
public Object[][] getImmutableFields() {
return TestHelper.toDataProvidersList(
ReflectionUtils.getAttributeNamesWithAnnotation(
ConfigureDhcpWorkflowDocument.class, Immutable.class));
}
}
/**
* Tests end-to-end scenarios of the {@link ConfigureDhcpWorkflowService}.
*/
public class EndToEndTest {
private static final String NETWORK_MANAGER_ADDRESS = "networkManagerAddress";
private static final String NETWORK_MANAGER_USERNAME = "networkManagerUsername";
private static final String NETWORK_MANAGER_PASSWORD = "networkManagerPassword";
private static final String DHCP_RELAY_PROFILE_ID = "dhcpRelayProfileId";
private static final String DHCP_RELAY_SERVICE_ID = "dhcpRelayServiceId";
private ConfigureDhcpWorkflowDocument startState;
private NsxClientFactory nsxClientFactory;
private NsxClientMock nsxClientMock;
private TestEnvironment testEnvironment;
@BeforeMethod
public void setUpTest() throws Throwable {
startState = buildStartState(
TaskState.TaskStage.CREATED,
null,
new ControlFlags.Builder().build());
nsxClientFactory = mock(NsxClientFactory.class);
}
@AfterMethod
public void tearDownTest() throws Throwable {
if (null != testEnvironment) {
testEnvironment.stop();
testEnvironment = null;
}
}
@Test(dataProvider = "hostCount")
public void succeedsToConfigureDhcp(int hostCount) throws Throwable {
nsxClientMock = new NsxClientMock.Builder()
.createDhcpRelayProfile(true, DHCP_RELAY_PROFILE_ID)
.createDhcpRelayService(true, DHCP_RELAY_SERVICE_ID)
.build();
doReturn(nsxClientMock).when(nsxClientFactory).create(anyString(), anyString(), anyString());
testEnvironment = new TestEnvironment.Builder()
.hostCount(hostCount)
.cloudStoreHelper(new CloudStoreHelper())
.nsxClientFactory(nsxClientFactory)
.build();
createDeploymentDocumentInCloudStore(testEnvironment,
NETWORK_MANAGER_ADDRESS,
NETWORK_MANAGER_USERNAME,
NETWORK_MANAGER_PASSWORD);
ConfigureDhcpWorkflowDocument finalState = testEnvironment.callServiceAndWaitForState(
ConfigureDhcpWorkflowService.FACTORY_LINK,
startState,
ConfigureDhcpWorkflowDocument.class,
(state) -> TaskState.TaskStage.FINISHED == state.taskState.stage);
// Verifies that NSX configuration is cached in the service document.
assertThat(finalState.nsxAddress, Matchers.is(NETWORK_MANAGER_ADDRESS));
assertThat(finalState.nsxUsername, Matchers.is(NETWORK_MANAGER_USERNAME));
assertThat(finalState.nsxPassword, Matchers.is(NETWORK_MANAGER_PASSWORD));
// Verifies that the DHCP relay profile ID and service ID are cached in the service document,
// and persisted in the deployment entity.
DeploymentService.State expectedDeploymentState = finalState.taskServiceEntity;
DeploymentService.State actualDeploymentState = testEnvironment.getServiceState(
finalState.taskServiceEntity.documentSelfLink,
DeploymentService.State.class);
assertThat(expectedDeploymentState.dhcpRelayProfileId, is(DHCP_RELAY_PROFILE_ID));
assertThat(expectedDeploymentState.dhcpRelayServiceId, is(DHCP_RELAY_SERVICE_ID));
assertEquals(actualDeploymentState.dhcpRelayProfileId, expectedDeploymentState.dhcpRelayProfileId);
assertEquals(actualDeploymentState.dhcpRelayServiceId, expectedDeploymentState.dhcpRelayServiceId);
}
@Test(dataProvider = "hostCount")
public void failsToCreateDhcpRelayProfile(int hostCount) throws Throwable {
nsxClientMock = new NsxClientMock.Builder()
.createDhcpRelayProfile(false, DHCP_RELAY_PROFILE_ID)
.createDhcpRelayService(true, DHCP_RELAY_SERVICE_ID)
.build();
doReturn(nsxClientMock).when(nsxClientFactory).create(anyString(), anyString(), anyString());
testEnvironment = new TestEnvironment.Builder()
.hostCount(hostCount)
.cloudStoreHelper(new CloudStoreHelper())
.nsxClientFactory(nsxClientFactory)
.build();
createDeploymentDocumentInCloudStore(testEnvironment,
NETWORK_MANAGER_ADDRESS,
NETWORK_MANAGER_USERNAME,
NETWORK_MANAGER_PASSWORD);
ConfigureDhcpWorkflowDocument finalState = testEnvironment.callServiceAndWaitForState(
ConfigureDhcpWorkflowService.FACTORY_LINK,
startState,
ConfigureDhcpWorkflowDocument.class,
(state) -> TaskState.TaskStage.FAILED == state.taskState.stage);
// Verifies that DHCP relay profile ID is empty in the service document.
assertThat(finalState.taskServiceEntity.dhcpRelayProfileId, nullValue());
}
@Test(dataProvider = "hostCount")
public void failsToCreateDhcpRelayService(int hostCount) throws Throwable {
nsxClientMock = new NsxClientMock.Builder()
.createDhcpRelayProfile(true, DHCP_RELAY_PROFILE_ID)
.createDhcpRelayService(false, DHCP_RELAY_SERVICE_ID)
.build();
doReturn(nsxClientMock).when(nsxClientFactory).create(anyString(), anyString(), anyString());
testEnvironment = new TestEnvironment.Builder()
.hostCount(hostCount)
.cloudStoreHelper(new CloudStoreHelper())
.nsxClientFactory(nsxClientFactory)
.build();
createDeploymentDocumentInCloudStore(testEnvironment,
NETWORK_MANAGER_ADDRESS,
NETWORK_MANAGER_USERNAME,
NETWORK_MANAGER_PASSWORD);
ConfigureDhcpWorkflowDocument finalState = testEnvironment.callServiceAndWaitForState(
ConfigureDhcpWorkflowService.FACTORY_LINK,
startState,
ConfigureDhcpWorkflowDocument.class,
(state) -> TaskState.TaskStage.FAILED == state.taskState.stage);
// Verifies that DHCP relay service ID is empty in the service document.
assertThat(finalState.taskServiceEntity.dhcpRelayServiceId, nullValue());
}
@DataProvider(name = "hostCount")
public Object[][] getHostCount() {
return new Object[][]{
{1},
{TestEnvironment.DEFAULT_MULTI_HOST_COUNT}
};
}
}
}