@Test
public void failNodeGroupReferenceValidation() throws Throwable {

    URI sourceUri = this.host.getPeerHost().getUri();
    URI destUri = getDestinationHost().getUri();
    // both sourceNodeGroupReference and sourceReferences are specified
    MigrationTaskService.State migrationState = validMigrationState(ExampleService.FACTORY_LINK);
    migrationState.sourceReferences = Collections.singletonList(sourceUri);
    Operation op = Operation.createPost(this.destinationFactoryUri).setBody(migrationState);
    FailureResponse response = this.sender.sendAndWaitFailure(op);
    assertEquals(Operation.STATUS_CODE_BAD_REQUEST, response.op.getStatusCode());
    // neither sourceNodeGroupReference nor sourceReferences are specified
    migrationState = validMigrationState(ExampleService.FACTORY_LINK);
    migrationState.sourceNodeGroupReference = null;
    op = Operation.createPost(this.destinationFactoryUri).setBody(migrationState);
    response = this.sender.sendAndWaitFailure(op);
    assertEquals(Operation.STATUS_CODE_BAD_REQUEST, response.op.getStatusCode());
    // both destNodeGroupReference and destUris are specified
    migrationState = validMigrationState(ExampleService.FACTORY_LINK);
    migrationState.destinationReferences = Collections.singletonList(destUri);
    op = Operation.createPost(this.destinationFactoryUri).setBody(migrationState);
    response = this.sender.sendAndWaitFailure(op);
    assertEquals(Operation.STATUS_CODE_BAD_REQUEST, response.op.getStatusCode());
    // neither destNodeGroupReference nor destUris are specified
    migrationState = validMigrationState(ExampleService.FACTORY_LINK);
    migrationState.destinationFactoryLink = null;
    op = Operation.createPost(this.destinationFactoryUri).setBody(migrationState);
    response = this.sender.sendAndWaitFailure(op);
    assertEquals(Operation.STATUS_CODE_BAD_REQUEST, response.op.getStatusCode());
}