/**
   * @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
   * @throws Exception
   */
  @Test
  public void shouldDisableJmxReporting() throws Exception {

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.setJmxReportingEnabled(false);
    bean.afterPropertiesSet();

    assertThat(getConfiguration(bean).getMetricsOptions().isJMXReportingEnabled()).isFalse();
  }
  /**
   * @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
   * @throws Exception
   */
  @Test
  public void shouldShutdownClusterInstance() throws Exception {

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.afterPropertiesSet();
    bean.destroy();

    assertThat(bean.getObject().isClosed()).isTrue();
  }
  /** @see <a href="https://jira.spring.io/browse/DATACASS-319">DATACASS-319</a> */
  @Test
  public void shouldSetMaxSchemaAgreementWaitSeconds() throws Exception {

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();

    bean.setMaxSchemaAgreementWaitSeconds(20);
    bean.afterPropertiesSet();

    assertThat(getProtocolOptions(bean).getMaxSchemaAgreementWaitSeconds()).isEqualTo(20);
  }
  @Test
  public void shouldCallClusterBuilderConfigurer() throws Exception {

    ClusterBuilderConfigurer mockClusterBuilderConfigurer = mock(ClusterBuilderConfigurer.class);
    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();

    bean.setClusterBuilderConfigurer(mockClusterBuilderConfigurer);
    bean.afterPropertiesSet();

    verify(mockClusterBuilderConfigurer, times(1)).configure(isA(Cluster.Builder.class));
  }
  /**
   * @see <a href="https://jira.spring.io/browse/DATACASS-217">DATACASS-217</a>
   * @throws Exception
   */
  @Test
  public void shouldSetLZ4CompressionType() throws Exception {

    CompressionType compressionType = CompressionType.LZ4;

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.setCompressionType(compressionType);
    bean.afterPropertiesSet();

    assertThat(getProtocolOptions(bean).getCompression()).isEqualTo(Compression.LZ4);
  }
  /**
   * @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
   * @throws Exception
   */
  @Test
  public void shouldSetQueryOptions() throws Exception {

    QueryOptions queryOptions = new QueryOptions();

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.setQueryOptions(queryOptions);
    bean.afterPropertiesSet();

    assertThat(getConfiguration(bean).getQueryOptions()).isEqualTo(queryOptions);
  }
  /**
   * @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
   * @throws Exception
   */
  @Test
  public void shouldInitializeWithoutAnyOptions() throws Exception {

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.afterPropertiesSet();

    assertThat(bean.getObject()).isNotNull();
    assertThat(bean.getObject().isClosed()).isFalse();
    assertThat(getConfiguration(bean).getMetricsOptions()).isNotNull();
    assertThat(getConfiguration(bean).getMetricsOptions().isJMXReportingEnabled()).isTrue();
  }
  /** @see <a href="https://jira.spring.io/browse/DATACASS-238">DATACASS-238</a> */
  @Test
  public void shouldSetTimestampGenerator() throws Exception {

    TimestampGenerator mockTimestampGenerator = mock(TimestampGenerator.class);
    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();

    bean.setTimestampGenerator(mockTimestampGenerator);
    bean.afterPropertiesSet();

    assertThat(getPolicies(bean).getTimestampGenerator()).isEqualTo(mockTimestampGenerator);
  }
  /** @see <a href="https://jira.spring.io/browse/DATACASS-316">DATACASS-316</a> */
  @Test
  public void shouldSetAddressTranslator() throws Exception {

    AddressTranslator mockAddressTranslator = mock(AddressTranslator.class);
    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();

    bean.setAddressTranslator(mockAddressTranslator);
    bean.afterPropertiesSet();

    assertThat(getPolicies(bean).getAddressTranslator()).isEqualTo(mockAddressTranslator);
  }
  /**
   * @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
   * @throws Exception
   */
  @Test
  public void defaultQueryOptionsShouldHaveOwnObjectIdentity() throws Exception {

    QueryOptions queryOptions = new QueryOptions();

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.afterPropertiesSet();

    assertThat(getConfiguration(bean).getQueryOptions()).isNotNull();
    assertThat(getConfiguration(bean).getQueryOptions()).isNotEqualTo(queryOptions);
  }
  /**
   * @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
   * @throws Exception
   */
  @Test
  public void shouldSetProtocolVersion() throws Exception {

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.setProtocolVersion(ProtocolVersion.V2);
    bean.afterPropertiesSet();

    assertThat(getConfiguration(bean).getProtocolOptions())
        .extracting("initialProtocolVersion")
        .contains(ProtocolVersion.V2);
  }
  /**
   * @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
   * @see <a href="https://jira.spring.io/browse/DATACASS-263">DATACASS-263</a>
   * @throws Exception
   */
  @Test
  public void shouldSetAuthenticationProvider() throws Exception {

    AuthProvider authProvider = new PlainTextAuthProvider("x", "y");

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.setAuthProvider(authProvider);
    bean.afterPropertiesSet();

    AuthProvider result = getConfiguration(bean).getProtocolOptions().getAuthProvider();
    assertThat(result).isEqualTo(authProvider);
  }
  /**
   * @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
   * @throws Exception
   */
  @Test
  public void shouldSetLoadBalancingPolicy() throws Exception {

    LoadBalancingPolicy loadBalancingPolicy = new RoundRobinPolicy();

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.setLoadBalancingPolicy(loadBalancingPolicy);
    bean.afterPropertiesSet();

    assertThat(getConfiguration(bean).getPolicies().getLoadBalancingPolicy())
        .isEqualTo(loadBalancingPolicy);
  }
  /**
   * @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
   * @throws Exception
   */
  @Test
  public void shouldSetSslOptions() throws Exception {

    SSLOptions sslOptions = JdkSSLOptions.builder().build();

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.setSslEnabled(true);
    bean.setSslOptions(sslOptions);
    bean.afterPropertiesSet();

    assertThat(getConfiguration(bean).getProtocolOptions().getSSLOptions()).isEqualTo(sslOptions);
  }
  /**
   * @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
   * @throws Exception
   */
  @Test
  public void shouldSetReconnectionPolicy() throws Exception {

    ReconnectionPolicy reconnectionPolicy = new ExponentialReconnectionPolicy(1, 2);

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.setReconnectionPolicy(reconnectionPolicy);
    bean.afterPropertiesSet();

    assertThat(getConfiguration(bean).getPolicies().getReconnectionPolicy())
        .isEqualTo(reconnectionPolicy);
  }
  /** @see <a href="https://jira.spring.io/browse/DATACASS-320">DATACASS-320</a> */
  @Test
  public void shouldSetSpeculativeExecutionPolicy() throws Exception {

    SpeculativeExecutionPolicy mockSpeculativeExecutionPolicy =
        mock(SpeculativeExecutionPolicy.class);
    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();

    bean.setSpeculativeExecutionPolicy(mockSpeculativeExecutionPolicy);
    bean.afterPropertiesSet();

    assertThat(getPolicies(bean).getSpeculativeExecutionPolicy())
        .isEqualTo(mockSpeculativeExecutionPolicy);
  }
  /**
   * @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
   * @see <a href="https://jira.spring.io/browse/DATACASS-263">DATACASS-263</a>
   * @throws Exception
   */
  @Test
  public void shouldSetAuthentication() throws Exception {

    CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
    bean.setUsername("user");
    bean.setPassword("password");
    bean.afterPropertiesSet();

    AuthProvider result = getConfiguration(bean).getProtocolOptions().getAuthProvider();
    assertThat(result).isNotNull();
    assertThat(ReflectionTestUtils.getField(result, "username")).isEqualTo((Object) "user");
    assertThat(ReflectionTestUtils.getField(result, "password")).isEqualTo((Object) "password");
  }
  /** @see <a href="https://jira.spring.io/browse/DATACASS-317">DATACASS-317</a> */
  @Test
  public void shouldSetClusterNameWithClusterNameProperty() throws Exception {

    final Cluster.Builder mockClusterBuilder = mock(Cluster.Builder.class);

    when(mockClusterBuilder.addContactPoints(Matchers.<String[]>anyVararg()))
        .thenReturn(mockClusterBuilder);

    CassandraCqlClusterFactoryBean bean =
        new CassandraCqlClusterFactoryBean() {
          @Override
          Cluster.Builder newClusterBuilder() {
            return mockClusterBuilder;
          }
        };

    bean.setBeanName("ABC");
    bean.setClusterName("XYZ");
    bean.afterPropertiesSet();

    verify(mockClusterBuilder, times(1)).withClusterName(eq("XYZ"));
  }
 private Configuration getConfiguration(CassandraCqlClusterFactoryBean bean) throws Exception {
   return bean.getObject().getConfiguration();
 }