@Test
  public void newServiceInstanceBindingCreatedSuccessfully()
      throws ServiceBrokerException, ServiceInstanceBindingExistsException {

    when(admin.getCredentialsFromSensors(
            anyString(),
            any(Predicate.class),
            any(Predicate.class),
            any(Predicate.class),
            any(Predicate.class)))
        .thenReturn(new AsyncResult<>(Collections.<String, Object>emptyMap()));
    when(admin.hasEffector(anyString(), anyString(), anyString()))
        .thenReturn(new AsyncResult<>(false));
    when(instanceRepository.findOne(anyString(), anyBoolean())).thenReturn(serviceInstance);
    when(serviceDefinition.getMetadata()).thenReturn(ImmutableMap.of());
    when(brooklynCatalogService.getServiceDefinition(anyString())).thenReturn(serviceDefinition);
    CreateServiceInstanceBindingRequest request =
        new CreateServiceInstanceBindingRequest(
            serviceInstance.getServiceDefinitionId(), "planId", "appGuid");
    ServiceInstanceBinding binding =
        bindingService.createServiceInstanceBinding(request.withBindingId(SVC_INST_BIND_ID));

    assertNotNull(binding);
    assertEquals(SVC_INST_BIND_ID, binding.getId());
  }
  @Test
  public void newServiceInstanceBindingCreatedSuccessfullyWithBindEffector()
      throws ServiceBrokerException, ServiceInstanceBindingExistsException, PollingException {
    when(admin.getRestApi()).thenReturn(brooklynApi);
    when(admin.getCredentialsFromSensors(
            anyString(),
            any(Predicate.class),
            any(Predicate.class),
            any(Predicate.class),
            any(Predicate.class)))
        .thenReturn(new AsyncResult<>(Collections.<String, Object>emptyMap()));
    when(admin.hasEffector(anyString(), anyString(), anyString()))
        .thenReturn(new AsyncResult<>(true));
    when(admin.invokeEffector(anyString(), anyString(), anyString(), anyString(), anyMap()))
        .thenReturn(new AsyncResult<>(TASK_RESPONSE_INCOMPLETE));
    when(brooklynApi.getActivityApi()).thenReturn(activityApi);
    when(activityApi.get(anyString()))
        .thenReturn(TASK_SUMMARY_INCOMPLETE)
        .thenReturn(TASK_SUMMARY_INCOMPLETE)
        .thenReturn(TASK_SUMMARY_INCOMPLETE)
        .thenReturn(TASK_SUMMARY_INCOMPLETE)
        .thenReturn(TASK_SUMMARY_COMPLETE);
    doCallRealMethod().when(admin).blockUntilTaskCompletes(anyString());
    doCallRealMethod().when(admin).blockUntilTaskCompletes(anyString(), any(Duration.class));
    when(instanceRepository.findOne(anyString(), anyBoolean())).thenReturn(serviceInstance);
    when(serviceDefinition.getMetadata()).thenReturn(ImmutableMap.of());
    when(brooklynCatalogService.getServiceDefinition(anyString())).thenReturn(serviceDefinition);
    CreateServiceInstanceBindingRequest request =
        new CreateServiceInstanceBindingRequest(
            serviceInstance.getServiceDefinitionId(), "planId", "appGuid");
    ServiceInstanceBinding binding =
        bindingService.createServiceInstanceBinding(request.withBindingId(SVC_INST_BIND_ID));

    assertNotNull(binding);
    assertEquals(SVC_INST_BIND_ID, binding.getId());
  }
  @Test
  public void testWhitelistCreatedSuccessfully()
      throws ServiceInstanceBindingExistsException, ServiceBrokerException {

    bindingService =
        new BrooklynServiceInstanceBindingService(
            new BrooklynRestAdmin(brooklynApi, httpClient, config),
            bindingRepository,
            instanceRepository,
            brooklynCatalogService);

    when(admin.getCredentialsFromSensors(
            anyString(),
            any(Predicate.class),
            any(Predicate.class),
            any(Predicate.class),
            any(Predicate.class)))
        .thenCallRealMethod();

    when(brooklynApi.getSensorApi()).thenReturn(sensorApi);
    when(sensorApi.list(anyString(), anyString()))
        .thenReturn(
            ImmutableList.of(
                new SensorSummary(
                    "my.sensor", "my sensor type", "my sensor description", ImmutableMap.of()),
                new SensorSummary(
                    "sensor.one.name",
                    "sensor one type",
                    "sensor one description",
                    ImmutableMap.of())));
    when(brooklynApi.getEntityApi()).thenReturn(entityApi);
    when(entityApi.list(any()))
        .thenReturn(
            ImmutableList.of(
                new EntitySummary(
                    "entityId", "name", "entityType", "catalogItemId", ImmutableMap.of())));
    when(instanceRepository.findOne(anyString(), anyBoolean())).thenReturn(serviceInstance);
    when(brooklynCatalogService.getServiceDefinition(Mockito.anyString()))
        .thenReturn(serviceDefinition);
    when(serviceInstance.getServiceDefinitionId()).thenReturn(SVC_DEFN_ID);
    when(serviceDefinition.getMetadata()).thenReturn(ImmutableMap.of("planYaml", WHITELIST_YAML));
    when(brooklynApi.getEffectorApi()).thenReturn(effectorApi);
    when(effectorApi.invoke(anyString(), anyString(), anyString(), anyString(), anyMap()))
        .thenReturn(bindEffectorResponse);

    CreateServiceInstanceBindingRequest request =
        new CreateServiceInstanceBindingRequest(
            serviceInstance.getServiceDefinitionId(), "planId", "appGuid");
    ServiceInstanceBinding binding =
        bindingService.createServiceInstanceBinding(request.withBindingId(SVC_INST_BIND_ID));

    ServiceInstanceBinding expectedBinding =
        new ServiceInstanceBinding(
            SVC_INST_BIND_ID,
            serviceInstance.getServiceInstanceId(),
            EXPECTED_CREDENTIALS,
            null,
            "appGuid");

    assertEquals(expectedBinding.getAppGuid(), binding.getAppGuid());
    assertEquals(expectedBinding.getCredentials(), binding.getCredentials());
    assertEquals(expectedBinding.getId(), binding.getId());
    assertEquals(expectedBinding.getServiceInstanceId(), binding.getServiceInstanceId());
    assertEquals(expectedBinding.getSyslogDrainUrl(), binding.getSyslogDrainUrl());
  }