DATACASS-333 - Switch tests to AssertJ.
This commit is contained in:
83
spring-cql/src/test/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBeanUnitTests.java
Normal file → Executable file
83
spring-cql/src/test/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBeanUnitTests.java
Normal file → Executable file
@@ -16,28 +16,15 @@
|
||||
|
||||
package org.springframework.cassandra.config;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.isA;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.datastax.driver.core.AuthProvider;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Configuration;
|
||||
import com.datastax.driver.core.JdkSSLOptions;
|
||||
import com.datastax.driver.core.PlainTextAuthProvider;
|
||||
import com.datastax.driver.core.PoolingOptions;
|
||||
import com.datastax.driver.core.ProtocolOptions;
|
||||
import com.datastax.driver.core.*;
|
||||
import com.datastax.driver.core.ProtocolOptions.Compression;
|
||||
import com.datastax.driver.core.ProtocolVersion;
|
||||
import com.datastax.driver.core.QueryOptions;
|
||||
import com.datastax.driver.core.SSLOptions;
|
||||
import com.datastax.driver.core.SocketOptions;
|
||||
import com.datastax.driver.core.TimestampGenerator;
|
||||
import com.datastax.driver.core.policies.AddressTranslator;
|
||||
import com.datastax.driver.core.policies.ExponentialReconnectionPolicy;
|
||||
import com.datastax.driver.core.policies.LoadBalancingPolicy;
|
||||
@@ -65,10 +52,10 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(bean.getObject(), is(not(nullValue())));
|
||||
assertThat(bean.getObject().isClosed(), is(false));
|
||||
assertThat(getConfiguration(bean).getMetricsOptions(), is(not(nullValue())));
|
||||
assertThat(getConfiguration(bean).getMetricsOptions().isJMXReportingEnabled(), is(true));
|
||||
assertThat(bean.getObject()).isNotNull();
|
||||
assertThat(bean.getObject().isClosed()).isFalse();
|
||||
assertThat(getConfiguration(bean).getMetricsOptions()).isNotNull();
|
||||
assertThat(getConfiguration(bean).getMetricsOptions().isJMXReportingEnabled()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +69,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.afterPropertiesSet();
|
||||
bean.destroy();
|
||||
|
||||
assertThat(bean.getObject().isClosed(), is(true));
|
||||
assertThat(bean.getObject().isClosed()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +85,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setCompressionType(compressionType);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getProtocolOptions(bean).getCompression(), is(Compression.LZ4));
|
||||
assertThat(getProtocolOptions(bean).getCompression()).isEqualTo(Compression.LZ4);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,7 +101,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setCompressionType(compressionType);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getProtocolOptions(bean).getCompression(), is(Compression.SNAPPY));
|
||||
assertThat(getConfiguration(bean).getProtocolOptions().getCompression()).isEqualTo(Compression.SNAPPY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,7 +117,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setPoolingOptions(poolingOptions);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getConfiguration(bean).getPoolingOptions(), is(poolingOptions));
|
||||
assertThat(getConfiguration(bean).getPoolingOptions()).isEqualTo(poolingOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +133,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setSocketOptions(socketOptions);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getConfiguration(bean).getSocketOptions(), is(socketOptions));
|
||||
assertThat(getConfiguration(bean).getSocketOptions()).isEqualTo(socketOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +149,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setQueryOptions(queryOptions);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getConfiguration(bean).getQueryOptions(), is(queryOptions));
|
||||
assertThat(getConfiguration(bean).getQueryOptions()).isEqualTo(queryOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,8 +164,8 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getConfiguration(bean).getQueryOptions(), is(not(nullValue())));
|
||||
assertThat(getConfiguration(bean).getQueryOptions(), is(not(queryOptions)));
|
||||
assertThat(getConfiguration(bean).getQueryOptions()).isNotNull();
|
||||
assertThat(getConfiguration(bean).getQueryOptions()).isNotEqualTo(queryOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +181,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setAuthProvider(authProvider);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getConfiguration(bean).getProtocolOptions().getAuthProvider(), is(authProvider));
|
||||
assertThat(getConfiguration(bean).getProtocolOptions().getAuthProvider()).isEqualTo(authProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,7 +199,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
AuthProvider result = getConfiguration(bean).getProtocolOptions().getAuthProvider();
|
||||
assertThat(result, is(equalTo(authProvider)));
|
||||
assertThat(result).isEqualTo(authProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,9 +216,9 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
AuthProvider result = getConfiguration(bean).getProtocolOptions().getAuthProvider();
|
||||
assertThat(result, is(not(nullValue())));
|
||||
assertThat(ReflectionTestUtils.getField(result, "username"), is(equalTo((Object) "user")));
|
||||
assertThat(ReflectionTestUtils.getField(result, "password"), is(equalTo((Object) "password")));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(ReflectionTestUtils.getField(result, "username")).isEqualTo((Object) "user");
|
||||
assertThat(ReflectionTestUtils.getField(result, "password")).isEqualTo((Object) "password");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,7 +234,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setLoadBalancingPolicy(loadBalancingPolicy);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getConfiguration(bean).getPolicies().getLoadBalancingPolicy(), is(loadBalancingPolicy));
|
||||
assertThat(getConfiguration(bean).getPolicies().getLoadBalancingPolicy()).isEqualTo(loadBalancingPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,7 +250,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setReconnectionPolicy(reconnectionPolicy);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getConfiguration(bean).getPolicies().getReconnectionPolicy(), is(reconnectionPolicy));
|
||||
assertThat(getConfiguration(bean).getPolicies().getReconnectionPolicy()).isEqualTo(reconnectionPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,8 +264,8 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setProtocolVersion(ProtocolVersion.V2);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(ReflectionTestUtils.getField(getConfiguration(bean).getProtocolOptions(), "initialProtocolVersion"),
|
||||
is((Object) ProtocolVersion.V2));
|
||||
assertThat(getConfiguration(bean).getProtocolOptions()).extracting("initialProtocolVersion")
|
||||
.contains(ProtocolVersion.V2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -295,7 +282,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setSslOptions(sslOptions);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getConfiguration(bean).getProtocolOptions().getSSLOptions(), is(sslOptions));
|
||||
assertThat(getConfiguration(bean).getProtocolOptions().getSSLOptions()).isEqualTo(sslOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,7 +296,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setMetricsEnabled(false);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getConfiguration(bean).getMetricsOptions().isEnabled(), is(false));
|
||||
assertThat(getConfiguration(bean).getMetricsOptions().isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,7 +310,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setJmxReportingEnabled(false);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getConfiguration(bean).getMetricsOptions().isJMXReportingEnabled(), is(false));
|
||||
assertThat(getConfiguration(bean).getMetricsOptions().isJMXReportingEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -350,7 +337,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setAddressTranslator(mockAddressTranslator);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getPolicies(bean).getAddressTranslator(), is(equalTo(mockAddressTranslator)));
|
||||
assertThat(getPolicies(bean).getAddressTranslator()).isEqualTo(mockAddressTranslator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,10 +348,11 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
|
||||
final Cluster.Builder mockClusterBuilder = mock(Cluster.Builder.class);
|
||||
|
||||
when(mockClusterBuilder.addContactPoints(Matchers.<String[]>anyVararg())).thenReturn(mockClusterBuilder);
|
||||
when(mockClusterBuilder.addContactPoints(Matchers.<String[]> anyVararg())).thenReturn(mockClusterBuilder);
|
||||
|
||||
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean() {
|
||||
@Override Cluster.Builder newClusterBuilder() {
|
||||
@Override
|
||||
Cluster.Builder newClusterBuilder() {
|
||||
return mockClusterBuilder;
|
||||
}
|
||||
};
|
||||
@@ -384,10 +372,11 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
|
||||
final Cluster.Builder mockClusterBuilder = mock(Cluster.Builder.class);
|
||||
|
||||
when(mockClusterBuilder.addContactPoints(Matchers.<String[]>anyVararg())).thenReturn(mockClusterBuilder);
|
||||
when(mockClusterBuilder.addContactPoints(Matchers.<String[]> anyVararg())).thenReturn(mockClusterBuilder);
|
||||
|
||||
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean() {
|
||||
@Override Cluster.Builder newClusterBuilder() {
|
||||
@Override
|
||||
Cluster.Builder newClusterBuilder() {
|
||||
return mockClusterBuilder;
|
||||
}
|
||||
};
|
||||
@@ -410,7 +399,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setMaxSchemaAgreementWaitSeconds(20);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getProtocolOptions(bean).getMaxSchemaAgreementWaitSeconds(), is(equalTo(20)));
|
||||
assertThat(getProtocolOptions(bean).getMaxSchemaAgreementWaitSeconds()).isEqualTo(20);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -425,7 +414,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setSpeculativeExecutionPolicy(mockSpeculativeExecutionPolicy);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getPolicies(bean).getSpeculativeExecutionPolicy(), is(equalTo(mockSpeculativeExecutionPolicy)));
|
||||
assertThat(getPolicies(bean).getSpeculativeExecutionPolicy()).isEqualTo(mockSpeculativeExecutionPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -440,7 +429,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
bean.setTimestampGenerator(mockTimestampGenerator);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getPolicies(bean).getTimestampGenerator(), is(equalTo(mockTimestampGenerator)));
|
||||
assertThat(getPolicies(bean).getTimestampGenerator()).isEqualTo(mockTimestampGenerator);
|
||||
}
|
||||
|
||||
private Policies getPolicies(CassandraCqlClusterFactoryBean bean) throws Exception {
|
||||
|
||||
119
spring-cql/src/test/java/org/springframework/cassandra/config/CassandraCqlSessionFactoryBeanUnitTests.java
Normal file → Executable file
119
spring-cql/src/test/java/org/springframework/cassandra/config/CassandraCqlSessionFactoryBeanUnitTests.java
Normal file → Executable file
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.cassandra.config;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -41,8 +40,8 @@ import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
/**
|
||||
* The CassandraCqlSessionFactoryBeanUnitTests class is a test suite of test cases testing the contract
|
||||
* and functionality of the {@link CassandraCqlSessionFactoryBean} class.
|
||||
* The CassandraCqlSessionFactoryBeanUnitTests class is a test suite of test cases testing the contract and
|
||||
* functionality of the {@link CassandraCqlSessionFactoryBean} class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.cassandra.config.CassandraCqlSessionFactoryBean
|
||||
@@ -52,14 +51,11 @@ import com.datastax.driver.core.Session;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CassandraCqlSessionFactoryBeanUnitTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
@Rule public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private Cluster mockCluster;
|
||||
@Mock private Cluster mockCluster;
|
||||
|
||||
@Mock
|
||||
private Session mockSession;
|
||||
@Mock private Session mockSession;
|
||||
|
||||
private CassandraCqlSessionFactoryBean factoryBean;
|
||||
|
||||
@@ -68,8 +64,8 @@ public class CassandraCqlSessionFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
protected void assertNonNullEmptyCollection(Collection<?> collection) {
|
||||
assertThat(collection, is(notNullValue()));
|
||||
assertThat(collection.isEmpty(), is(true));
|
||||
assertThat(collection).isNotNull();
|
||||
assertThat(collection.isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -79,13 +75,13 @@ public class CassandraCqlSessionFactoryBeanUnitTests {
|
||||
|
||||
@Test
|
||||
public void cassandraCqlSessionFactoryBeanIsSingleton() {
|
||||
assertThat(factoryBean.isSingleton(), is(true));
|
||||
assertThat(factoryBean.isSingleton()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectTypeWhenSessionHasNotBeenInitializedIsSessionClass() {
|
||||
assertThat(factoryBean.getObject(), is(nullValue()));
|
||||
assertEquals(Session.class, factoryBean.<Session>getObjectType());
|
||||
assertThat(factoryBean.getObject()).isNull();
|
||||
assertThat(factoryBean.<Session> getObjectType()).isEqualTo(Session.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,14 +97,14 @@ public class CassandraCqlSessionFactoryBeanUnitTests {
|
||||
factoryBean.setKeyspaceName("TestKeyspace");
|
||||
factoryBean.setStartupScripts(expectedStartupScripts);
|
||||
|
||||
assertThat(factoryBean.getKeyspaceName(), is(equalTo("TestKeyspace")));
|
||||
assertThat(factoryBean.getStartupScripts(), is(equalTo(expectedStartupScripts)));
|
||||
assertThat(factoryBean.getKeyspaceName()).isEqualTo("TestKeyspace");
|
||||
assertThat(factoryBean.getStartupScripts()).isEqualTo(expectedStartupScripts);
|
||||
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
assertEquals(mockSession.getClass(), factoryBean.getObjectType());
|
||||
assertThat(factoryBean.getObject(), is(equalTo(mockSession)));
|
||||
assertThat(factoryBean.getSession(), is(equalTo(mockSession)));
|
||||
assertThat(factoryBean.getObjectType()).isEqualTo(mockSession.getClass());
|
||||
assertThat(factoryBean.getObject()).isEqualTo(mockSession);
|
||||
assertThat(factoryBean.getSession()).isEqualTo(mockSession);
|
||||
|
||||
InOrder inOrder = inOrder(factoryBean);
|
||||
|
||||
@@ -125,7 +121,7 @@ public class CassandraCqlSessionFactoryBeanUnitTests {
|
||||
|
||||
factoryBean.setCluster(mockCluster);
|
||||
|
||||
assertThat(factoryBean.connect(null), is(equalTo(mockSession)));
|
||||
assertThat(factoryBean.connect(null)).isEqualTo(mockSession);
|
||||
|
||||
verify(mockCluster, times(1)).connect();
|
||||
verify(mockCluster, never()).connect(anyString());
|
||||
@@ -137,7 +133,7 @@ public class CassandraCqlSessionFactoryBeanUnitTests {
|
||||
|
||||
factoryBean.setCluster(mockCluster);
|
||||
|
||||
assertThat(factoryBean.connect("TestKeyspace"), is(equalTo(mockSession)));
|
||||
assertThat(factoryBean.connect("TestKeyspace")).isEqualTo(mockSession);
|
||||
|
||||
verify(mockCluster, never()).connect();
|
||||
verify(mockCluster, times(1)).connect(eq("TestKeyspace"));
|
||||
@@ -165,15 +161,15 @@ public class CassandraCqlSessionFactoryBeanUnitTests {
|
||||
|
||||
@Test
|
||||
public void isConnectedWithNullSessionIsFalse() {
|
||||
assertThat(factoryBean.getObject(), is(nullValue()));
|
||||
assertThat(factoryBean.isConnected(), is(false));
|
||||
assertThat(factoryBean.getObject()).isNull();
|
||||
assertThat(factoryBean.isConnected()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isConnectedWithClosedSessionIsFalse() {
|
||||
doReturn(mockSession).when(factoryBean).getObject();
|
||||
when(mockSession.isClosed()).thenReturn(true);
|
||||
assertThat(factoryBean.isConnected(), is(false));
|
||||
assertThat(factoryBean.isConnected()).isFalse();
|
||||
verify(mockSession, times(1)).isClosed();
|
||||
}
|
||||
|
||||
@@ -181,56 +177,64 @@ public class CassandraCqlSessionFactoryBeanUnitTests {
|
||||
public void isConnectedWithOpenSessionIsTrue() {
|
||||
doReturn(mockSession).when(factoryBean).getObject();
|
||||
when(mockSession.isClosed()).thenReturn(false);
|
||||
assertThat(factoryBean.isConnected(), is(true));
|
||||
assertThat(factoryBean.isConnected()).isTrue();
|
||||
verify(mockSession, times(1)).isClosed();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetCluster() {
|
||||
factoryBean.setCluster(mockCluster);
|
||||
assertThat(factoryBean.getCluster(), is(equalTo(mockCluster)));
|
||||
assertThat(factoryBean.getCluster()).isEqualTo(mockCluster);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setClusterToNullThrowsIllegalArgumentException() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("Cluster must not be null");
|
||||
|
||||
factoryBean.setCluster(null);
|
||||
try {
|
||||
factoryBean.setCluster(null);
|
||||
fail("Missing IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e).hasMessageContaining("Cluster must not be null");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getClusterWhenUninitializedThrowsIllegalStateException() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("Cluster was not properly initialized");
|
||||
|
||||
factoryBean.getCluster();
|
||||
try {
|
||||
factoryBean.getCluster();
|
||||
fail("Missing IllegalStateException");
|
||||
} catch (IllegalStateException e) {
|
||||
assertThat(e).hasMessageContaining("Cluster was not properly initialized");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetKeyspaceName() {
|
||||
assertThat(factoryBean.getKeyspaceName(), is(nullValue()));
|
||||
assertThat(factoryBean.getKeyspaceName()).isNull();
|
||||
|
||||
factoryBean.setKeyspaceName("TEST");
|
||||
|
||||
assertThat(factoryBean.getKeyspaceName(), is(equalTo("TEST")));
|
||||
assertThat(factoryBean.getKeyspaceName()).isEqualTo("TEST");
|
||||
|
||||
factoryBean.setKeyspaceName(null);
|
||||
|
||||
assertThat(factoryBean.getKeyspaceName(), is(nullValue()));
|
||||
assertThat(factoryBean.getKeyspaceName()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSessionWhenUninitializedThrowsIllegalStateException() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(is(equalTo("Session was not properly initialized")));
|
||||
|
||||
assertThat(factoryBean.getObject(), is(nullValue()));
|
||||
assertThat(factoryBean.getObject()).isNull();
|
||||
|
||||
try {
|
||||
factoryBean.getSession();
|
||||
fail("Missing IllegalStateException");
|
||||
} catch (IllegalStateException e) {
|
||||
assertThat(e).hasMessageContaining("Session was not properly initialized");
|
||||
}
|
||||
|
||||
factoryBean.getSession();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -243,8 +247,7 @@ public class CassandraCqlSessionFactoryBeanUnitTests {
|
||||
|
||||
List<String> actualStartupScripts = factoryBean.getStartupScripts();
|
||||
|
||||
assertThat(actualStartupScripts, is(not(sameInstance(expectedStartupScripts))));
|
||||
assertThat(actualStartupScripts, is(equalTo(expectedStartupScripts)));
|
||||
assertThat(actualStartupScripts).isNotSameAs(expectedStartupScripts).isEqualTo(expectedStartupScripts);
|
||||
|
||||
factoryBean.setStartupScripts(null);
|
||||
|
||||
@@ -259,23 +262,21 @@ public class CassandraCqlSessionFactoryBeanUnitTests {
|
||||
|
||||
List<String> actualStartupScripts = factoryBean.getStartupScripts();
|
||||
|
||||
assertThat(actualStartupScripts, is(notNullValue()));
|
||||
assertThat(actualStartupScripts, is(not(sameInstance(startupScripts))));
|
||||
assertThat(actualStartupScripts, is(equalTo(startupScripts)));
|
||||
assertThat(actualStartupScripts).isEqualTo(startupScripts).isNotSameAs(startupScripts);
|
||||
|
||||
startupScripts.add("/path/to/another.cql");
|
||||
|
||||
actualStartupScripts = factoryBean.getStartupScripts();
|
||||
|
||||
assertThat(actualStartupScripts, is(not(equalTo(startupScripts))));
|
||||
assertThat(actualStartupScripts.size(), is(equalTo(1)));
|
||||
assertThat(actualStartupScripts.get(0), is(equalTo(startupScripts.get(0))));
|
||||
assertThat(actualStartupScripts).isNotEqualTo(startupScripts);
|
||||
assertThat(actualStartupScripts).hasSize(1);
|
||||
assertThat(actualStartupScripts.get(0)).isEqualTo(startupScripts.get(0));
|
||||
|
||||
try {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
actualStartupScripts.add("/path/to/yetAnother.cql");
|
||||
} finally {
|
||||
assertThat(actualStartupScripts.size(), is(equalTo(1)));
|
||||
assertThat(actualStartupScripts).hasSize(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,8 +290,7 @@ public class CassandraCqlSessionFactoryBeanUnitTests {
|
||||
|
||||
List<String> actualShutdownScripts = factoryBean.getShutdownScripts();
|
||||
|
||||
assertThat(actualShutdownScripts, is(not(sameInstance(expectedShutdownScripts))));
|
||||
assertThat(actualShutdownScripts, is(equalTo(expectedShutdownScripts)));
|
||||
assertThat(actualShutdownScripts).isEqualTo(expectedShutdownScripts).isNotSameAs(expectedShutdownScripts);
|
||||
|
||||
factoryBean.setShutdownScripts(null);
|
||||
|
||||
@@ -305,23 +305,20 @@ public class CassandraCqlSessionFactoryBeanUnitTests {
|
||||
|
||||
List<String> actualShutdownScripts = factoryBean.getShutdownScripts();
|
||||
|
||||
assertThat(actualShutdownScripts, is(notNullValue()));
|
||||
assertThat(actualShutdownScripts, is(not(sameInstance(shutdownScripts))));
|
||||
assertThat(actualShutdownScripts, is(equalTo(shutdownScripts)));
|
||||
assertThat(actualShutdownScripts).isEqualTo(shutdownScripts).isNotSameAs(shutdownScripts);
|
||||
|
||||
shutdownScripts.add("/path/to/corruptSession.cql");
|
||||
|
||||
actualShutdownScripts = factoryBean.getShutdownScripts();
|
||||
|
||||
assertThat(actualShutdownScripts, is(not(sameInstance(shutdownScripts))));
|
||||
assertThat(actualShutdownScripts, is(not(equalTo(shutdownScripts))));
|
||||
assertThat(actualShutdownScripts.size(), is(equalTo(1)));
|
||||
assertThat(actualShutdownScripts).isNotEqualTo(shutdownScripts);
|
||||
assertThat(actualShutdownScripts).hasSize(1);
|
||||
|
||||
try {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
actualShutdownScripts.add("/path/to/blowUpCluster.cql");
|
||||
} finally {
|
||||
assertThat(actualShutdownScripts.size(), is(equalTo(1)));
|
||||
assertThat(actualShutdownScripts).hasSize(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
111
spring-cql/src/test/java/org/springframework/cassandra/config/PoolingOptionsFactoryBeanUnitTests.java
Normal file → Executable file
111
spring-cql/src/test/java/org/springframework/cassandra/config/PoolingOptionsFactoryBeanUnitTests.java
Normal file → Executable file
@@ -15,15 +15,14 @@
|
||||
*/
|
||||
package org.springframework.cassandra.config;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.assumeNotNull;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.same;
|
||||
import static org.springframework.util.ReflectionUtils.invokeMethod;
|
||||
import static org.springframework.util.ReflectionUtils.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -36,10 +35,10 @@ import org.mockito.Spy;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import com.datastax.driver.core.HostDistance;
|
||||
import com.datastax.driver.core.PoolingOptions;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PoolingOptionsFactoryBean}.
|
||||
@@ -66,18 +65,18 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
|
||||
@Test
|
||||
public void getObjectReturnsNullWhenNotInitialized() throws Exception {
|
||||
assertThat(poolingOptionsFactoryBean.getObject(), is(nullValue(PoolingOptions.class)));
|
||||
assertThat(poolingOptionsFactoryBean.getObject()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getObjectTypeReturnsPoolingOptionsClassWhenNotInitialized() {
|
||||
assertThat((Class<PoolingOptions>) poolingOptionsFactoryBean.getObjectType(), is(equalTo(PoolingOptions.class)));
|
||||
assertThat((Class<PoolingOptions>) poolingOptionsFactoryBean.getObjectType()).isEqualTo(PoolingOptions.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSingletonIsTrue() {
|
||||
assertThat(poolingOptionsFactoryBean.isSingleton(), is(true));
|
||||
assertThat(poolingOptionsFactoryBean.isSingleton()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,18 +99,18 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
poolingOptionsFactoryBean.setRemoteMaxSimultaneousRequests(100);
|
||||
poolingOptionsFactoryBean.setRemoteMinSimultaneousRequests(50);
|
||||
|
||||
assertThat(poolingOptionsFactoryBean.getHeartbeatIntervalSeconds(), is(equalTo(15)));
|
||||
assertThat(poolingOptionsFactoryBean.getIdleTimeoutSeconds(), is(equalTo(120)));
|
||||
assertThat(poolingOptionsFactoryBean.getInitializationExecutor(), is(equalTo(mockExecutor)));
|
||||
assertThat(poolingOptionsFactoryBean.getLocalCoreConnections(), is(equalTo(50)));
|
||||
assertThat(poolingOptionsFactoryBean.getLocalMaxConnections(), is(equalTo(1000)));
|
||||
assertThat(poolingOptionsFactoryBean.getLocalMaxSimultaneousRequests(), is(equalTo(200)));
|
||||
assertThat(poolingOptionsFactoryBean.getLocalMinSimultaneousRequests(), is(equalTo(100)));
|
||||
assertThat(poolingOptionsFactoryBean.getPoolTimeoutMilliseconds(), is(equalTo(300)));
|
||||
assertThat(poolingOptionsFactoryBean.getRemoteCoreConnections(), is(equalTo(25)));
|
||||
assertThat(poolingOptionsFactoryBean.getRemoteMaxConnections(), is(equalTo(250)));
|
||||
assertThat(poolingOptionsFactoryBean.getRemoteMaxSimultaneousRequests(), is(equalTo(100)));
|
||||
assertThat(poolingOptionsFactoryBean.getRemoteMinSimultaneousRequests(), is(equalTo(50)));
|
||||
assertThat(poolingOptionsFactoryBean.getHeartbeatIntervalSeconds()).isEqualTo(15);
|
||||
assertThat(poolingOptionsFactoryBean.getIdleTimeoutSeconds()).isEqualTo(120);
|
||||
assertThat(poolingOptionsFactoryBean.getInitializationExecutor()).isEqualTo(mockExecutor);
|
||||
assertThat(poolingOptionsFactoryBean.getLocalCoreConnections()).isEqualTo(50);
|
||||
assertThat(poolingOptionsFactoryBean.getLocalMaxConnections()).isEqualTo(1000);
|
||||
assertThat(poolingOptionsFactoryBean.getLocalMaxSimultaneousRequests()).isEqualTo(200);
|
||||
assertThat(poolingOptionsFactoryBean.getLocalMinSimultaneousRequests()).isEqualTo(100);
|
||||
assertThat(poolingOptionsFactoryBean.getPoolTimeoutMilliseconds()).isEqualTo(300);
|
||||
assertThat(poolingOptionsFactoryBean.getRemoteCoreConnections()).isEqualTo(25);
|
||||
assertThat(poolingOptionsFactoryBean.getRemoteMaxConnections()).isEqualTo(250);
|
||||
assertThat(poolingOptionsFactoryBean.getRemoteMaxSimultaneousRequests()).isEqualTo(100);
|
||||
assertThat(poolingOptionsFactoryBean.getRemoteMinSimultaneousRequests()).isEqualTo(50);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,12 +136,12 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
poolingOptionsFactoryBean.setLocalMinSimultaneousRequests(5);
|
||||
poolingOptionsFactoryBean.setPoolTimeoutMilliseconds(180);
|
||||
|
||||
assertThat(poolingOptionsFactoryBean.getObject(), is(nullValue(PoolingOptions.class)));
|
||||
assertThat(poolingOptionsFactoryBean.getObject()).isNull();
|
||||
|
||||
poolingOptionsFactoryBean.afterPropertiesSet();
|
||||
|
||||
assertThat(poolingOptionsFactoryBean.getObject(), is(sameInstance(poolingOptionsSpy)));
|
||||
assertThat(poolingOptionsFactoryBean.getObjectType(), is(equalTo((Class) poolingOptionsSpy.getClass())));
|
||||
assertThat(poolingOptionsFactoryBean.getObject()).isSameAs(poolingOptionsSpy);
|
||||
assertThat(poolingOptionsFactoryBean.getObjectType()).isEqualTo(poolingOptionsSpy.getClass());
|
||||
|
||||
verify(poolingOptionsSpy).setHeartbeatIntervalSeconds(eq(60));
|
||||
verify(poolingOptionsSpy).setIdleTimeoutSeconds(eq(300));
|
||||
@@ -181,12 +180,12 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
poolingOptionsFactoryBean.setRemoteMaxSimultaneousRequests(20);
|
||||
poolingOptionsFactoryBean.setRemoteMinSimultaneousRequests(5);
|
||||
|
||||
assertThat(poolingOptionsFactoryBean.getObject(), is(nullValue(PoolingOptions.class)));
|
||||
assertThat(poolingOptionsFactoryBean.getObject()).isNull();
|
||||
|
||||
poolingOptionsFactoryBean.afterPropertiesSet();
|
||||
|
||||
assertThat(poolingOptionsFactoryBean.getObject(), is(sameInstance(poolingOptionsSpy)));
|
||||
assertThat(poolingOptionsFactoryBean.getObjectType(), is(equalTo((Class) poolingOptionsSpy.getClass())));
|
||||
assertThat(poolingOptionsFactoryBean.getObject()).isSameAs(poolingOptionsSpy);
|
||||
assertThat(poolingOptionsFactoryBean.getObjectType()).isEqualTo(poolingOptionsSpy.getClass());
|
||||
|
||||
verify(poolingOptionsSpy).setHeartbeatIntervalSeconds(eq(33));
|
||||
verify(poolingOptionsSpy).setIdleTimeoutSeconds(eq(112));
|
||||
@@ -208,11 +207,9 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
@Test
|
||||
public void afterPropertiesSetInitializesMaxQueueSize() throws Exception {
|
||||
|
||||
Method setMaxQueueSize = ReflectionUtils
|
||||
.findMethod(PoolingOptions.class, "setMaxQueueSize", int.class);
|
||||
Method setMaxQueueSize = ReflectionUtils.findMethod(PoolingOptions.class, "setMaxQueueSize", int.class);
|
||||
|
||||
Method getMaxQueueSize = ReflectionUtils
|
||||
.findMethod(PoolingOptions.class, "getMaxQueueSize");
|
||||
Method getMaxQueueSize = ReflectionUtils.findMethod(PoolingOptions.class, "getMaxQueueSize");
|
||||
|
||||
assumeNotNull(setMaxQueueSize);
|
||||
|
||||
@@ -227,9 +224,9 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
|
||||
poolingOptionsFactoryBean.afterPropertiesSet();
|
||||
|
||||
assertThat(poolingOptionsFactoryBean.getObject(), is(sameInstance(poolingOptionsSpy)));
|
||||
assertThat(poolingOptionsFactoryBean.getObjectType(), is(equalTo((Class) poolingOptionsSpy.getClass())));
|
||||
assertThat(invokeMethod(getMaxQueueSize, poolingOptionsSpy), is(equalTo((Object) 1234)));
|
||||
assertThat(poolingOptionsFactoryBean.getObject()).isSameAs(poolingOptionsSpy);
|
||||
assertThat(poolingOptionsFactoryBean.getObjectType()).isEqualTo(poolingOptionsSpy.getClass());
|
||||
assertThat(invokeMethod(getMaxQueueSize, poolingOptionsSpy)).isEqualTo(1234);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,21 +257,21 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
poolingOptionsFactoryBean.setRemoteMaxSimultaneousRequests(127);
|
||||
poolingOptionsFactoryBean.setRemoteMinSimultaneousRequests(111);
|
||||
|
||||
assertThat(poolingOptionsFactoryBean.getObject(), is(nullValue(PoolingOptions.class)));
|
||||
assertThat(poolingOptionsFactoryBean.getObject()).isNull();
|
||||
|
||||
poolingOptionsFactoryBean.afterPropertiesSet();
|
||||
|
||||
PoolingOptions poolingOptions = poolingOptionsFactoryBean.getObject();
|
||||
|
||||
assertThat(poolingOptions, is(notNullValue(PoolingOptions.class)));
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL), is(equalTo(100)));
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL), is(equalTo(200)));
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.LOCAL), is(equalTo(99)));
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.LOCAL), is(equalTo(97)));
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.REMOTE), is(equalTo(110)));
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.REMOTE), is(equalTo(210)));
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE), is(equalTo(127)));
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.REMOTE), is(equalTo(111)));
|
||||
assertThat(poolingOptions).isNotNull();
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(100);
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(200);
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.LOCAL)).isEqualTo(99);
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.LOCAL)).isEqualTo(97);
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.REMOTE)).isEqualTo(110);
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.REMOTE)).isEqualTo(210);
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE)).isEqualTo(127);
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.REMOTE)).isEqualTo(111);
|
||||
|
||||
verify(poolingOptions).setMaxConnectionsPerHost(eq(HostDistance.LOCAL), eq(200));
|
||||
verify(poolingOptions).setCoreConnectionsPerHost(eq(HostDistance.LOCAL), eq(100));
|
||||
@@ -304,11 +301,11 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
PoolingOptionsFactoryBean.HostDistancePoolingOptions poolingOptions = poolingOptionsFactoryBean
|
||||
.newLocalHostDistancePoolingOptions();
|
||||
|
||||
assertThat(poolingOptions.getHostDistance(), is(equalTo(HostDistance.LOCAL)));
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(), is(equalTo(50)));
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(), is(equalTo(500)));
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(), is(equalTo(1000)));
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(), is(equalTo(100)));
|
||||
assertThat(poolingOptions.getHostDistance()).isEqualTo(HostDistance.LOCAL);
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost()).isEqualTo(50);
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost()).isEqualTo(500);
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection()).isEqualTo(1000);
|
||||
assertThat(poolingOptions.getNewConnectionThreshold()).isEqualTo(100);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,11 +326,11 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
PoolingOptionsFactoryBean.HostDistancePoolingOptions poolingOptions = poolingOptionsFactoryBean
|
||||
.newRemoteHostDistancePoolingOptions();
|
||||
|
||||
assertThat(poolingOptions.getHostDistance(), is(equalTo(HostDistance.REMOTE)));
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(), is(equalTo(20)));
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(), is(equalTo(200)));
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(), is(equalTo(400)));
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(), is(equalTo(40)));
|
||||
assertThat(poolingOptions.getHostDistance()).isEqualTo(HostDistance.REMOTE);
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost()).isEqualTo(20);
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost()).isEqualTo(200);
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection()).isEqualTo(400);
|
||||
assertThat(poolingOptions.getNewConnectionThreshold()).isEqualTo(40);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -359,8 +356,8 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(poolingOptionsFactoryBean.configureLocalHostDistancePoolingOptions(poolingOptionsSpy),
|
||||
is(sameInstance(poolingOptionsSpy)));
|
||||
assertThat(poolingOptionsFactoryBean.configureLocalHostDistancePoolingOptions(poolingOptionsSpy))
|
||||
.isSameAs(poolingOptionsSpy);
|
||||
|
||||
verify(mockHostDistancePoolingOptions).configure(same(poolingOptionsSpy));
|
||||
}
|
||||
@@ -388,8 +385,8 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(poolingOptionsFactoryBean.configureRemoteHostDistancePoolingOptions(poolingOptionsSpy),
|
||||
is(sameInstance(poolingOptionsSpy)));
|
||||
assertThat(poolingOptionsFactoryBean.configureRemoteHostDistancePoolingOptions(poolingOptionsSpy))
|
||||
.isSameAs(poolingOptionsSpy);
|
||||
|
||||
verify(mockHostDistancePoolingOptions).configure(same(poolingOptionsSpy));
|
||||
}
|
||||
|
||||
100
spring-cql/src/test/java/org/springframework/cassandra/config/java/AbstractClusterConfigurationUnitTests.java
Normal file → Executable file
100
spring-cql/src/test/java/org/springframework/cassandra/config/java/AbstractClusterConfigurationUnitTests.java
Normal file → Executable file
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.cassandra.config.java;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.isA;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -30,19 +28,9 @@ import org.springframework.cassandra.config.ClusterBuilderConfigurer;
|
||||
import org.springframework.cassandra.config.CompressionType;
|
||||
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.datastax.driver.core.AuthProvider;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Configuration;
|
||||
import com.datastax.driver.core.PlainTextAuthProvider;
|
||||
import com.datastax.driver.core.PoolingOptions;
|
||||
import com.datastax.driver.core.ProtocolOptions;
|
||||
import com.datastax.driver.core.*;
|
||||
import com.datastax.driver.core.ProtocolOptions.Compression;
|
||||
import com.datastax.driver.core.ProtocolVersion;
|
||||
import com.datastax.driver.core.QueryOptions;
|
||||
import com.datastax.driver.core.SocketOptions;
|
||||
import com.datastax.driver.core.TimestampGenerator;
|
||||
import com.datastax.driver.core.policies.AddressTranslator;
|
||||
import com.datastax.driver.core.policies.ExponentialReconnectionPolicy;
|
||||
import com.datastax.driver.core.policies.LoadBalancingPolicy;
|
||||
@@ -74,10 +62,10 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
AbstractClusterConfiguration clusterConfiguration = new AbstractClusterConfiguration() {};
|
||||
|
||||
Cluster cluster = getCluster(clusterConfiguration);
|
||||
assertThat(cluster, is(not(nullValue())));
|
||||
assertThat(cluster.isClosed(), is(false));
|
||||
assertThat(getConfiguration(cluster).getMetricsOptions(), is(not(nullValue())));
|
||||
assertThat(getConfiguration(cluster).getMetricsOptions().isJMXReportingEnabled(), is(true));
|
||||
assertThat(cluster).isNotNull();
|
||||
assertThat(cluster.isClosed()).isFalse();
|
||||
assertThat(getConfiguration(cluster).getMetricsOptions()).isNotNull();
|
||||
assertThat(getConfiguration(cluster).getMetricsOptions().isJMXReportingEnabled()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +85,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
};
|
||||
|
||||
Cluster cluster = getCluster(clusterConfiguration);
|
||||
assertThat(getConfiguration(cluster).getProtocolOptions().getCompression(), is(Compression.SNAPPY));
|
||||
assertThat(getConfiguration(cluster).getProtocolOptions().getCompression()).isEqualTo(Compression.SNAPPY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +105,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
};
|
||||
|
||||
Cluster cluster = getCluster(clusterConfiguration);
|
||||
assertThat(getConfiguration(cluster).getPoolingOptions(), is(poolingOptions));
|
||||
assertThat(getConfiguration(cluster).getPoolingOptions()).isEqualTo(poolingOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +125,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
};
|
||||
|
||||
Cluster cluster = getCluster(clusterConfiguration);
|
||||
assertThat(getConfiguration(cluster).getSocketOptions(), is(socketOptions));
|
||||
assertThat(getConfiguration(cluster).getSocketOptions()).isEqualTo(socketOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,7 +145,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
};
|
||||
|
||||
Cluster cluster = getCluster(clusterConfiguration);
|
||||
assertThat(getConfiguration(cluster).getQueryOptions(), is(queryOptions));
|
||||
assertThat(getConfiguration(cluster).getQueryOptions()).isEqualTo(queryOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,7 +165,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
};
|
||||
|
||||
Cluster cluster = getCluster(clusterConfiguration);
|
||||
assertThat(getConfiguration(cluster).getProtocolOptions().getAuthProvider(), is(authProvider));
|
||||
assertThat(getConfiguration(cluster).getProtocolOptions().getAuthProvider()).isEqualTo(authProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,7 +185,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
};
|
||||
|
||||
Cluster cluster = getCluster(clusterConfiguration);
|
||||
assertThat(getPolicies(cluster).getLoadBalancingPolicy(), is(loadBalancingPolicy));
|
||||
assertThat(getConfiguration(cluster).getPolicies().getLoadBalancingPolicy()).isEqualTo(loadBalancingPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,7 +205,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
};
|
||||
|
||||
Cluster cluster = getCluster(clusterConfiguration);
|
||||
assertThat(getPolicies(cluster).getReconnectionPolicy(), is(reconnectionPolicy));
|
||||
assertThat(getConfiguration(cluster).getPolicies().getReconnectionPolicy()).isEqualTo(reconnectionPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,8 +223,8 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
};
|
||||
|
||||
Cluster cluster = getCluster(clusterConfiguration);
|
||||
assertThat(ReflectionTestUtils.getField(getConfiguration(cluster).getProtocolOptions(), "initialProtocolVersion"),
|
||||
is((Object) ProtocolVersion.V2));
|
||||
assertThat(getConfiguration(cluster).getProtocolOptions()).extracting("initialProtocolVersion")
|
||||
.contains(ProtocolVersion.V2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,7 +242,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
};
|
||||
|
||||
Cluster cluster = getCluster(clusterConfiguration);
|
||||
assertThat(getConfiguration(cluster).getMetricsOptions().isEnabled(), is(false));
|
||||
assertThat(getConfiguration(cluster).getMetricsOptions().isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,7 +260,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(clusterConfiguration.cluster().getKeyspaceCreations(), is(equalTo(specification)));
|
||||
assertThat(clusterConfiguration.cluster().getKeyspaceCreations()).isEqualTo(specification);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,7 +278,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(clusterConfiguration.cluster().getKeyspaceDrops(), is(equalTo(specification)));
|
||||
assertThat(clusterConfiguration.cluster().getKeyspaceDrops()).isEqualTo(specification);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,7 +295,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(clusterConfiguration.cluster().getStartupScripts(), is(equalTo(scripts)));
|
||||
assertThat(clusterConfiguration.cluster().getStartupScripts()).isEqualTo(scripts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,7 +312,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(clusterConfiguration.cluster().getShutdownScripts(), is(equalTo(scripts)));
|
||||
assertThat(clusterConfiguration.cluster().getShutdownScripts()).isEqualTo(scripts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,17 +320,17 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetAddressTranslator() throws Exception {
|
||||
|
||||
|
||||
final AddressTranslator mockAddressTranslator = mock(AddressTranslator.class);
|
||||
|
||||
AbstractClusterConfiguration clusterConfiguration = new AbstractClusterConfiguration() {
|
||||
@Override protected AddressTranslator getAddressTranslator() {
|
||||
@Override
|
||||
protected AddressTranslator getAddressTranslator() {
|
||||
return mockAddressTranslator;
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(getPolicies(getCluster(clusterConfiguration)).getAddressTranslator(),
|
||||
is(equalTo(mockAddressTranslator)));
|
||||
assertThat(getPolicies(getCluster(clusterConfiguration)).getAddressTranslator()).isEqualTo(mockAddressTranslator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -350,17 +338,17 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetAndApplyClusterBuilderConfigurer() throws Exception {
|
||||
|
||||
|
||||
final ClusterBuilderConfigurer mockClusterBuilderConfigurer = mock(ClusterBuilderConfigurer.class);
|
||||
|
||||
AbstractClusterConfiguration clusterConfiguration = new AbstractClusterConfiguration() {
|
||||
@Override protected ClusterBuilderConfigurer getClusterBuilderConfigurer() {
|
||||
@Override
|
||||
protected ClusterBuilderConfigurer getClusterBuilderConfigurer() {
|
||||
return mockClusterBuilderConfigurer;
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(getCluster(clusterConfiguration), is(notNullValue(Cluster.class)));
|
||||
|
||||
assertThat(getCluster(clusterConfiguration)).isNotNull();
|
||||
verify(mockClusterBuilderConfigurer, times(1)).configure(isA(Cluster.Builder.class));
|
||||
}
|
||||
|
||||
@@ -370,14 +358,15 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetClusterName() throws Exception {
|
||||
|
||||
|
||||
AbstractClusterConfiguration clusterConfiguration = new AbstractClusterConfiguration() {
|
||||
@Override protected String getClusterName() {
|
||||
@Override
|
||||
protected String getClusterName() {
|
||||
return "testCluster";
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(getCluster(clusterConfiguration).getClusterName(), is(equalTo("testCluster")));
|
||||
assertThat(getCluster(clusterConfiguration).getClusterName()).isEqualTo("testCluster");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,15 +374,15 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetMaxSchemaAgreementWaitInSeconds() throws Exception {
|
||||
|
||||
|
||||
AbstractClusterConfiguration clusterConfiguration = new AbstractClusterConfiguration() {
|
||||
@Override protected int getMaxSchemaAgreementWaitSeconds() {
|
||||
@Override
|
||||
protected int getMaxSchemaAgreementWaitSeconds() {
|
||||
return 30;
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(getProtocolOptions(getCluster(clusterConfiguration)).getMaxSchemaAgreementWaitSeconds(),
|
||||
is(equalTo(30)));
|
||||
assertThat(getProtocolOptions(getCluster(clusterConfiguration)).getMaxSchemaAgreementWaitSeconds()).isEqualTo(30);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -401,17 +390,18 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetSpeculativeExecutionPolicy() throws Exception {
|
||||
|
||||
|
||||
final SpeculativeExecutionPolicy mockSpeculativeExecutionPolicy = mock(SpeculativeExecutionPolicy.class);
|
||||
|
||||
AbstractClusterConfiguration clusterConfiguration = new AbstractClusterConfiguration() {
|
||||
@Override protected SpeculativeExecutionPolicy getSpeculativeExecutionPolicy() {
|
||||
@Override
|
||||
protected SpeculativeExecutionPolicy getSpeculativeExecutionPolicy() {
|
||||
return mockSpeculativeExecutionPolicy;
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(getPolicies(getCluster(clusterConfiguration)).getSpeculativeExecutionPolicy(),
|
||||
is(equalTo(mockSpeculativeExecutionPolicy)));
|
||||
assertThat(getPolicies(getCluster(clusterConfiguration)).getSpeculativeExecutionPolicy())
|
||||
.isEqualTo(mockSpeculativeExecutionPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -419,17 +409,17 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetTimestampGenerator() throws Exception {
|
||||
|
||||
|
||||
final TimestampGenerator mockTimestampGenerator = mock(TimestampGenerator.class);
|
||||
|
||||
AbstractClusterConfiguration clusterConfiguration = new AbstractClusterConfiguration() {
|
||||
@Override protected TimestampGenerator getTimestampGenerator() {
|
||||
@Override
|
||||
protected TimestampGenerator getTimestampGenerator() {
|
||||
return mockTimestampGenerator;
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(getPolicies(getCluster(clusterConfiguration)).getTimestampGenerator(),
|
||||
is(equalTo(mockTimestampGenerator)));
|
||||
assertThat(getPolicies(getCluster(clusterConfiguration)).getTimestampGenerator()).isEqualTo(mockTimestampGenerator);
|
||||
}
|
||||
|
||||
private Policies getPolicies(Cluster cluster) {
|
||||
|
||||
214
spring-cql/src/test/java/org/springframework/cassandra/config/xml/CassandraCqlClusterParserUnitTests.java
Normal file → Executable file
214
spring-cql/src/test/java/org/springframework/cassandra/config/xml/CassandraCqlClusterParserUnitTests.java
Normal file → Executable file
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.config.xml;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.cassandra.support.BeanDefinitionTestUtils.*;
|
||||
|
||||
@@ -62,7 +60,7 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
|
||||
when(mockElement.getAttribute(eq(CassandraCqlClusterParser.ID_ATTRIBUTE))).thenReturn("test");
|
||||
|
||||
assertThat(parser.resolveId(mockElement, null, null), is(equalTo("test")));
|
||||
assertThat(parser.resolveId(mockElement, null, null)).isEqualTo("test");
|
||||
verify(mockElement).getAttribute(eq(CassandraCqlClusterParser.ID_ATTRIBUTE));
|
||||
}
|
||||
|
||||
@@ -74,7 +72,7 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
|
||||
when(mockElement.getAttribute(eq(CassandraCqlClusterParser.ID_ATTRIBUTE))).thenReturn("");
|
||||
|
||||
assertThat(parser.resolveId(mockElement, null, null), is(equalTo(DefaultCqlBeanNames.CLUSTER)));
|
||||
assertThat(parser.resolveId(mockElement, null, null)).isEqualTo(DefaultCqlBeanNames.CLUSTER);
|
||||
verify(mockElement).getAttribute(eq(CassandraCqlClusterParser.ID_ATTRIBUTE));
|
||||
}
|
||||
|
||||
@@ -112,41 +110,41 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
|
||||
CassandraCqlClusterParser parser = new CassandraCqlClusterParser() {
|
||||
@Override
|
||||
protected void parseChildElements(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder) {
|
||||
}
|
||||
protected void parseChildElements(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {}
|
||||
};
|
||||
|
||||
AbstractBeanDefinition beanDefinition = parser.parseInternal(mockElement, mockParserContext(
|
||||
mockContainingBeanDefinition));
|
||||
AbstractBeanDefinition beanDefinition = parser.parseInternal(mockElement,
|
||||
mockParserContext(mockContainingBeanDefinition));
|
||||
|
||||
assertThat(beanDefinition, is(notNullValue(BeanDefinition.class)));
|
||||
assertThat(beanDefinition.getBeanClassName(), is(equalTo(CassandraCqlClusterFactoryBean.class.getName())));
|
||||
assertThat(beanDefinition.getDestroyMethodName(), is(equalTo("destroy")));
|
||||
assertThat((Element) beanDefinition.getSource(), is(equalTo(mockElement)));
|
||||
assertThat(beanDefinition.isLazyInit(), is(false));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "addressTranslator"), is(equalTo("testAddressTranslator")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "authProvider"), is(equalTo("testAuthInfoProvider")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "clusterBuilderConfigurer"), is(equalTo("testClusterBuilderConfigurer")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "hostStateListener"), is(equalTo("testHostStateListener")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "latencyTracker"), is(equalTo("testLatencyTracker")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "loadBalancingPolicy"), is(equalTo("testLoadBalancingPolicy")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "nettyOptions"), is(equalTo("testNettyOptions")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "reconnectionPolicy"), is(equalTo("testReconnectionPolicy")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "retryPolicy"), is(equalTo("testRetryPolicy")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "speculativeExecutionPolicy"), is(equalTo("testSpeculativeExecutionPolicy")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "sslOptions"), is(equalTo("testSslOptions")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "timestampGenerator"), is(equalTo("testTimestampGenerator")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "clusterName"), is(equalTo("testCluster")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "contactPoints"), is(equalTo("skullbox")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "compressionType"), is(equalTo("SNAPPY")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "jmxReportingEnabled"), is(equalTo("true")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "maxSchemaAgreementWaitSeconds"), is(equalTo("30")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "metricsEnabled"), is(equalTo("true")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "password"), is(equalTo("p@55w0rd")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "port"), is(equalTo("12345")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "sslEnabled"), is(equalTo("true")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "username"), is(equalTo("jonDoe")));
|
||||
assertThat(beanDefinition).isNotNull();
|
||||
assertThat(beanDefinition.getBeanClassName()).isEqualTo(CassandraCqlClusterFactoryBean.class.getName());
|
||||
assertThat(beanDefinition.getDestroyMethodName()).isEqualTo("destroy");
|
||||
assertThat((Element) beanDefinition.getSource()).isEqualTo(mockElement);
|
||||
assertThat(beanDefinition.isLazyInit()).isFalse();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "addressTranslator")).isEqualTo("testAddressTranslator");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "authProvider")).isEqualTo("testAuthInfoProvider");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "clusterBuilderConfigurer"))
|
||||
.isEqualTo("testClusterBuilderConfigurer");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "hostStateListener")).isEqualTo("testHostStateListener");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "latencyTracker")).isEqualTo("testLatencyTracker");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "loadBalancingPolicy")).isEqualTo("testLoadBalancingPolicy");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "nettyOptions")).isEqualTo("testNettyOptions");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "reconnectionPolicy")).isEqualTo("testReconnectionPolicy");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "retryPolicy")).isEqualTo("testRetryPolicy");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "speculativeExecutionPolicy"))
|
||||
.isEqualTo("testSpeculativeExecutionPolicy");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "sslOptions")).isEqualTo("testSslOptions");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "timestampGenerator")).isEqualTo("testTimestampGenerator");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "clusterName")).isEqualTo("testCluster");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "contactPoints")).isEqualTo("skullbox");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "compressionType")).isEqualTo("SNAPPY");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "jmxReportingEnabled")).isEqualTo("true");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "maxSchemaAgreementWaitSeconds")).isEqualTo("30");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "metricsEnabled")).isEqualTo("true");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "password")).isEqualTo("p@55w0rd");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "port")).isEqualTo("12345");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "sslEnabled")).isEqualTo("true");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "username")).isEqualTo("jonDoe");
|
||||
|
||||
verify(mockContainingBeanDefinition).getScope();
|
||||
verify(mockElement).getAttribute(eq("address-translator-ref"));
|
||||
@@ -202,20 +200,21 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
|
||||
BeanDefinition poolingOptionsBeanDefinition = getPropertyValue(beanDefinition, "poolingOptions");
|
||||
|
||||
assertThat(poolingOptionsBeanDefinition, is(notNullValue(BeanDefinition.class)));
|
||||
assertThat(poolingOptionsBeanDefinition.getBeanClassName(), is(equalTo(PoolingOptionsFactoryBean.class.getName())));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "heartbeatIntervalSeconds"), is(equalTo("15")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "idleTimeoutSeconds"), is(equalTo("120")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "initializationExecutor"), is(equalTo("testExecutor")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "poolTimeoutMilliseconds"), is(equalTo("60000")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localCoreConnections"), is(equalTo("50")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localMaxConnections"), is(equalTo("200")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localMaxSimultaneousRequests"), is(equalTo("50")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localMinSimultaneousRequests"), is(equalTo("5")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteCoreConnections"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMaxConnections"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMaxSimultaneousRequests"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMinSimultaneousRequests"), is(nullValue()));
|
||||
assertThat(poolingOptionsBeanDefinition).isNotNull();
|
||||
assertThat(poolingOptionsBeanDefinition.getBeanClassName()).isEqualTo(PoolingOptionsFactoryBean.class.getName());
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "heartbeatIntervalSeconds")).isEqualTo("15");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "idleTimeoutSeconds")).isEqualTo("120");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "initializationExecutor"))
|
||||
.isEqualTo("testExecutor");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "poolTimeoutMilliseconds")).isEqualTo("60000");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localCoreConnections")).isEqualTo("50");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localMaxConnections")).isEqualTo("200");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localMaxSimultaneousRequests")).isEqualTo("50");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localMinSimultaneousRequests")).isEqualTo("5");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteCoreConnections")).isNull();
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMaxConnections")).isNull();
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMaxSimultaneousRequests")).isNull();
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMinSimultaneousRequests")).isNull();
|
||||
|
||||
verify(mockElement).getChildNodes();
|
||||
verify(mockElement).getAttribute(eq("heartbeat-interval-seconds"));
|
||||
@@ -258,22 +257,21 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
|
||||
BeanDefinition poolingOptionsBeanDefinition = getPropertyValue(beanDefinition, "poolingOptions");
|
||||
|
||||
assertThat(poolingOptionsBeanDefinition, is(notNullValue(BeanDefinition.class)));
|
||||
assertThat(poolingOptionsBeanDefinition.getBeanClassName(), is(equalTo(PoolingOptionsFactoryBean.class.getName())));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "heartbeatIntervalSeconds"), is(equalTo("15")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "idleTimeoutSeconds"), is(equalTo("120")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "initializationExecutor"), is(equalTo("testExecutor")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "poolTimeoutMilliseconds"), is(equalTo("60000")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localCoreConnections"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localMaxConnections"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localMaxSimultaneousRequests"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localMinSimultaneousRequests"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteCoreConnections"), is(equalTo("50")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMaxConnections"), is(equalTo("200")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMaxSimultaneousRequests"), is(equalTo(
|
||||
"50")));
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMinSimultaneousRequests"), is(equalTo(
|
||||
"5")));
|
||||
assertThat(poolingOptionsBeanDefinition).isNotNull();
|
||||
assertThat(poolingOptionsBeanDefinition.getBeanClassName()).isEqualTo(PoolingOptionsFactoryBean.class.getName());
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "heartbeatIntervalSeconds")).isEqualTo("15");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "idleTimeoutSeconds")).isEqualTo("120");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "initializationExecutor"))
|
||||
.isEqualTo("testExecutor");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "poolTimeoutMilliseconds")).isEqualTo("60000");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localCoreConnections")).isNull();
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localMaxConnections")).isNull();
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localMaxSimultaneousRequests")).isNull();
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "localMinSimultaneousRequests")).isNull();
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteCoreConnections")).isEqualTo("50");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMaxConnections")).isEqualTo("200");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMaxSimultaneousRequests")).isEqualTo("50");
|
||||
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMinSimultaneousRequests")).isEqualTo("5");
|
||||
|
||||
verify(mockElement).getChildNodes();
|
||||
verify(mockElement).getAttribute(eq("heartbeat-interval-seconds"));
|
||||
@@ -307,8 +305,7 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
when(mockShutdownCqlOne.getTextContent()).thenReturn("DROP KEYSPACE test;");
|
||||
when(mockShutdownCqlTwo.getTextContent()).thenReturn("DROP USER jblum;");
|
||||
|
||||
NodeList mockNodeList = mockNodeList(mockStartupCqlOne, mockStartupCqlTwo,
|
||||
mockShutdownCqlOne, mockShutdownCqlTwo);
|
||||
NodeList mockNodeList = mockNodeList(mockStartupCqlOne, mockStartupCqlTwo, mockShutdownCqlOne, mockShutdownCqlTwo);
|
||||
|
||||
when(mockElement.getChildNodes()).thenReturn(mockNodeList);
|
||||
|
||||
@@ -319,10 +316,10 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
BeanDefinition beanDefinition = builder.getBeanDefinition();
|
||||
|
||||
List<String> startupScripts = getPropertyValue(beanDefinition, "startupScripts");
|
||||
assertThat(startupScripts, contains("CREATE KEYSPACE test;", "CREATE TABLE test.table;"));
|
||||
assertThat(startupScripts).contains("CREATE KEYSPACE test;", "CREATE TABLE test.table;");
|
||||
|
||||
List<String> shutdownScripts = getPropertyValue(beanDefinition, "shutdownScripts");
|
||||
assertThat(shutdownScripts, contains("DROP KEYSPACE test;", "DROP USER jblum;"));
|
||||
assertThat(shutdownScripts).contains("DROP KEYSPACE test;", "DROP USER jblum;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,18 +339,18 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
|
||||
BeanDefinition beanDefinition = builder.getBeanDefinition();
|
||||
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "heartbeatIntervalSeconds"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "idleTimeoutSeconds"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "initializationExecutor"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "poolTimeoutMilliseconds"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localCoreConnections"), is(equalTo("50")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localMaxConnections"), is(equalTo("200")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localMaxSimultaneousRequests"), is(equalTo("50")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localMinSimultaneousRequests"), is(equalTo("5")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteCoreConnections"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteMaxConnections"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteMaxSimultaneousRequests"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteMinSimultaneousRequests"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "heartbeatIntervalSeconds")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "idleTimeoutSeconds")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "initializationExecutor")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "poolTimeoutMilliseconds")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localCoreConnections")).isEqualTo("50");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localMaxConnections")).isEqualTo("200");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localMaxSimultaneousRequests")).isEqualTo("50");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localMinSimultaneousRequests")).isEqualTo("5");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteCoreConnections")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteMaxConnections")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteMaxSimultaneousRequests")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteMinSimultaneousRequests")).isNull();
|
||||
|
||||
verify(mockElement, never()).getAttribute(eq("heartbeat-interval-seconds"));
|
||||
verify(mockElement, never()).getAttribute(eq("idle-timeout-seconds"));
|
||||
@@ -382,18 +379,18 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
|
||||
BeanDefinition beanDefinition = builder.getBeanDefinition();
|
||||
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "heartbeatIntervalSeconds"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "idleTimeoutSeconds"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "initializationExecutor"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "poolTimeoutMilliseconds"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localCoreConnections"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localMaxConnections"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localMaxSimultaneousRequests"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localMinSimultaneousRequests"), is(nullValue()));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteCoreConnections"), is(equalTo("50")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteMaxConnections"), is(equalTo("200")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteMaxSimultaneousRequests"), is(equalTo("50")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteMinSimultaneousRequests"), is(equalTo("5")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "heartbeatIntervalSeconds")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "idleTimeoutSeconds")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "initializationExecutor")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "poolTimeoutMilliseconds")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localCoreConnections")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localMaxConnections")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localMaxSimultaneousRequests")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "localMinSimultaneousRequests")).isNull();
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteCoreConnections")).isEqualTo("50");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteMaxConnections")).isEqualTo("200");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteMaxSimultaneousRequests")).isEqualTo("50");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "remoteMinSimultaneousRequests")).isEqualTo("5");
|
||||
|
||||
verify(mockElement, never()).getAttribute(eq("heartbeat-interval-seconds"));
|
||||
verify(mockElement, never()).getAttribute(eq("idle-timeout-seconds"));
|
||||
@@ -412,7 +409,7 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
public void parseScript() {
|
||||
|
||||
when(mockElement.getTextContent()).thenReturn("CREATE TABLE schema.table;");
|
||||
assertThat(parser.parseScript(mockElement), is(equalTo("CREATE TABLE schema.table;")));
|
||||
assertThat(parser.parseScript(mockElement)).isEqualTo("CREATE TABLE schema.table;");
|
||||
verify(mockElement).getTextContent();
|
||||
}
|
||||
|
||||
@@ -433,17 +430,17 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
|
||||
BeanDefinition beanDefinition = parser.newSocketOptionsBeanDefinition(mockElement, mockParserContext(null));
|
||||
|
||||
assertThat(beanDefinition, is(notNullValue(BeanDefinition.class)));
|
||||
assertThat(beanDefinition.getBeanClassName(), is(equalTo(SocketOptionsFactoryBean.class.getName())));
|
||||
assertThat((Element) beanDefinition.getSource(), is(equalTo(mockElement)));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "connectTimeoutMillis"), is(equalTo("15000")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "keepAlive"), is(equalTo("true")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "readTimeoutMillis"), is(equalTo("20000")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "receiveBufferSize"), is(equalTo("32768")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "reuseAddress"), is(equalTo("true")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "sendBufferSize"), is(equalTo("16384")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "soLinger"), is(equalTo("false")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "tcpNoDelay"), is(equalTo("true")));
|
||||
assertThat(beanDefinition).isNotNull();
|
||||
assertThat(beanDefinition.getBeanClassName()).isEqualTo(SocketOptionsFactoryBean.class.getName());
|
||||
assertThat((Element) beanDefinition.getSource()).isEqualTo(mockElement);
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "connectTimeoutMillis")).isEqualTo("15000");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "keepAlive")).isEqualTo("true");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "readTimeoutMillis")).isEqualTo("20000");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "receiveBufferSize")).isEqualTo("32768");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "reuseAddress")).isEqualTo("true");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "sendBufferSize")).isEqualTo("16384");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "soLinger")).isEqualTo("false");
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "tcpNoDelay")).isEqualTo("true");
|
||||
|
||||
verify(mockElement).getAttribute(eq("connect-timeout-millis"));
|
||||
verify(mockElement).getAttribute(eq("keep-alive"));
|
||||
@@ -470,7 +467,8 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
|
||||
private ParserContext mockParserContext(BeanDefinition beanDefinition) {
|
||||
|
||||
XmlReaderContext readerContext = new XmlReaderContext(null, null, null, new PassThroughSourceExtractor(), null, null);
|
||||
XmlReaderContext readerContext = new XmlReaderContext(null, null, null, new PassThroughSourceExtractor(), null,
|
||||
null);
|
||||
return new ParserContext(readerContext, new BeanDefinitionParserDelegate(readerContext), beanDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
27
spring-cql/src/test/java/org/springframework/cassandra/config/xml/ParsingUtilsUnitTests.java
Normal file → Executable file
27
spring-cql/src/test/java/org/springframework/cassandra/config/xml/ParsingUtilsUnitTests.java
Normal file → Executable file
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.cassandra.config.xml;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.cassandra.support.BeanDefinitionTestUtils.*;
|
||||
|
||||
import org.junit.Rule;
|
||||
@@ -48,8 +47,8 @@ public class ParsingUtilsUnitTests {
|
||||
|
||||
RuntimeBeanReference propertyValue = getPropertyValue(builder.getBeanDefinition(), "referenceProperty");
|
||||
|
||||
assertThat(propertyValue, is(notNullValue(RuntimeBeanReference.class)));
|
||||
assertThat(propertyValue.getBeanName(), is(equalTo("defaultBeanReference")));
|
||||
assertThat(propertyValue).isNotNull();
|
||||
assertThat(propertyValue.getBeanName()).isEqualTo("defaultBeanReference");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,8 +62,8 @@ public class ParsingUtilsUnitTests {
|
||||
|
||||
BeanDefinition beanDefinition = builder.getRawBeanDefinition();
|
||||
|
||||
assertThat(beanDefinition.getPropertyValues().contains("referenceProperty"), is(false));
|
||||
assertThat(beanDefinition.getPropertyValues().isEmpty(), is(true));
|
||||
assertThat(beanDefinition.getPropertyValues().contains("referenceProperty")).isFalse();
|
||||
assertThat(beanDefinition.getPropertyValues().isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +77,7 @@ public class ParsingUtilsUnitTests {
|
||||
|
||||
String propertyValue = getPropertyValue(builder.getBeanDefinition(), "valueProperty");
|
||||
|
||||
assertThat(propertyValue, is(equalTo("defaultValue")));
|
||||
assertThat(propertyValue).isEqualTo("defaultValue");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,8 +91,8 @@ public class ParsingUtilsUnitTests {
|
||||
|
||||
BeanDefinition beanDefinition = builder.getRawBeanDefinition();
|
||||
|
||||
assertThat(beanDefinition.getPropertyValues().contains("valueProperty"), is(false));
|
||||
assertThat(beanDefinition.getPropertyValues().isEmpty(), is(true));
|
||||
assertThat(beanDefinition.getPropertyValues().contains("valueProperty")).isFalse();
|
||||
assertThat(beanDefinition.getPropertyValues().isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,8 +106,8 @@ public class ParsingUtilsUnitTests {
|
||||
|
||||
RuntimeBeanReference propertyValue = getPropertyValue(builder.getBeanDefinition(), "referenceProperty");
|
||||
|
||||
assertThat(propertyValue, is(notNullValue(RuntimeBeanReference.class)));
|
||||
assertThat(propertyValue.getBeanName(), is(equalTo("reference")));
|
||||
assertThat(propertyValue).isNotNull();
|
||||
assertThat(propertyValue.getBeanName()).isEqualTo("reference");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +117,6 @@ public class ParsingUtilsUnitTests {
|
||||
public void addRequiredReferencePropertyWithNoReferenceFails() {
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("value required for property reference [referenceProperty] on class [null]");
|
||||
|
||||
ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(), "referenceProperty", null,
|
||||
@@ -136,7 +134,7 @@ public class ParsingUtilsUnitTests {
|
||||
|
||||
String propertyValue = getPropertyValue(builder.getBeanDefinition(), "valueProperty");
|
||||
|
||||
assertThat(propertyValue, is(equalTo("value")));
|
||||
assertThat(propertyValue).isEqualTo("value");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +144,6 @@ public class ParsingUtilsUnitTests {
|
||||
public void addRequiredValuePropertyWithNoValueFails() {
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("value required for property [valueProperty] on class [null]");
|
||||
|
||||
ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(), "valueProperty", null, "defaultValue", true,
|
||||
@@ -160,7 +157,6 @@ public class ParsingUtilsUnitTests {
|
||||
public void addPropertyThrowsIllegalArgumentExceptionForNullBuilder() {
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("BeanDefinitionBuilder must not be null");
|
||||
|
||||
ParsingUtils.addProperty(null, "propertyName", "value", "defaultValue", false, false);
|
||||
@@ -173,7 +169,6 @@ public class ParsingUtilsUnitTests {
|
||||
public void addPropertyThrowsIllegalArgumentExceptionForNullPropertyName() {
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("Property name must not be null");
|
||||
|
||||
ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(), null, "value", "defaultValue", false, true);
|
||||
|
||||
11
spring-cql/src/test/java/org/springframework/cassandra/core/CachedPreparedStatementCreatorUnitTests.java
Normal file → Executable file
11
spring-cql/src/test/java/org/springframework/cassandra/core/CachedPreparedStatementCreatorUnitTests.java
Normal file → Executable file
@@ -16,8 +16,7 @@
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import static edu.umd.cs.mtc.TestFramework.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -82,7 +81,7 @@ public class CachedPreparedStatementCreatorUnitTests {
|
||||
|
||||
PreparedStatement result = cachedPreparedStatementCreator.createPreparedStatement(sessionMock);
|
||||
|
||||
assertThat(result, is(sameInstance(preparedStatement)));
|
||||
assertThat(result).isSameAs(preparedStatement);
|
||||
verify(sessionMock).prepare("my cql");
|
||||
}
|
||||
|
||||
@@ -99,7 +98,7 @@ public class CachedPreparedStatementCreatorUnitTests {
|
||||
|
||||
PreparedStatement result = cachedPreparedStatementCreator.createPreparedStatement(sessionMock);
|
||||
|
||||
assertThat(result, is(sameInstance(preparedStatement)));
|
||||
assertThat(result).isSameAs(preparedStatement);
|
||||
verify(sessionMock, times(1)).prepare("my cql");
|
||||
}
|
||||
|
||||
@@ -150,7 +149,7 @@ public class CachedPreparedStatementCreatorUnitTests {
|
||||
|
||||
preparedStatementCreator.createPreparedStatement(session);
|
||||
|
||||
assertThat(atomicInteger.get(), is(1));
|
||||
assertThat(atomicInteger.get()).isEqualTo(1);
|
||||
}
|
||||
|
||||
public void thread2() {
|
||||
@@ -159,7 +158,7 @@ public class CachedPreparedStatementCreatorUnitTests {
|
||||
|
||||
preparedStatementCreator.createPreparedStatement(session);
|
||||
|
||||
assertThat(atomicInteger.get(), is(1));
|
||||
assertThat(atomicInteger.get()).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -86,6 +85,6 @@ public class ConsistencyLevelResolverUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldResolveCorrectly() {
|
||||
assertThat(ConsistencyLevelResolver.resolve(from), is(equalTo(expected)));
|
||||
assertThat(ConsistencyLevelResolver.resolve(from)).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
|
||||
113
spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java
Normal file → Executable file
113
spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
@@ -93,7 +92,7 @@ public class CqlTemplateUnitTests {
|
||||
}
|
||||
});
|
||||
|
||||
assertThat(result, is(equalTo("test")));
|
||||
assertThat(result).isEqualTo("test");
|
||||
|
||||
verify(mockSession, times(1)).execute(eq("test"));
|
||||
}
|
||||
@@ -119,16 +118,18 @@ public class CqlTemplateUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void doExecuteInSessionCallbackTranslatesToCassandraUncategorizedException() {
|
||||
exception.expect(CassandraUncategorizedException.class);
|
||||
exception.expectCause(org.hamcrest.Matchers.isA(DriverException.class));
|
||||
exception.expectMessage(containsString("test"));
|
||||
|
||||
template.doExecute(new SessionCallback<String>() {
|
||||
@Override
|
||||
public String doInSession(Session session) throws DataAccessException {
|
||||
throw new DriverException("test");
|
||||
}
|
||||
});
|
||||
try {
|
||||
template.doExecute(new SessionCallback<String>() {
|
||||
@Override
|
||||
public String doInSession(Session session) throws DataAccessException {
|
||||
throw new DriverException("test");
|
||||
}
|
||||
});
|
||||
fail("Missing CassandraUncategorizedException");
|
||||
} catch (CassandraUncategorizedException e) {
|
||||
assertThat(e).hasMessageContaining("test").hasRootCauseInstanceOf(DriverException.class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,25 +137,29 @@ public class CqlTemplateUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void doExecuteInSessionCallbackTranslatesToCassandraUncategorizedDataAccessException() {
|
||||
exception.expect(CassandraUncategorizedDataAccessException.class);
|
||||
exception.expectCause(org.hamcrest.Matchers.isA(Error.class));
|
||||
exception.expectMessage(containsString("test"));
|
||||
|
||||
template.doExecute(new SessionCallback<String>() {
|
||||
@Override
|
||||
public String doInSession(Session session) throws DataAccessException {
|
||||
throw new Error("test");
|
||||
}
|
||||
});
|
||||
try {
|
||||
template.doExecute(new SessionCallback<String>() {
|
||||
@Override
|
||||
public String doInSession(Session session) throws DataAccessException {
|
||||
throw new Error("test");
|
||||
}
|
||||
});
|
||||
fail("Missing CassandraUncategorizedException");
|
||||
} catch (CassandraUncategorizedDataAccessException e) {
|
||||
assertThat(e).hasMessageContaining("test").hasCauseInstanceOf(Error.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doExecuteWithNullSessionCallbackThrowsIllegalArgumentException() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("SessionCallback must not be null");
|
||||
|
||||
template.doExecute((SessionCallback) null);
|
||||
try {
|
||||
template.doExecute((SessionCallback) null);
|
||||
fail("Missing IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e).hasMessageContaining("SessionCallback must not be null");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,7 +170,7 @@ public class CqlTemplateUnitTests {
|
||||
|
||||
ResultSet resultSet = template.doExecuteQueryReturnResultSet("SELECT * FROM Customers");
|
||||
|
||||
assertThat(resultSet, is(equalTo(mockResultSet)));
|
||||
assertThat(resultSet).isEqualTo(mockResultSet);
|
||||
|
||||
verify(mockSession, times(1)).execute(eq("SELECT * FROM Customers"));
|
||||
verifyZeroInteractions(mockResultSet);
|
||||
@@ -180,7 +185,7 @@ public class CqlTemplateUnitTests {
|
||||
|
||||
ResultSet resultSet = template.doExecuteQueryReturnResultSet(mockSelect);
|
||||
|
||||
assertThat(resultSet, is(equalTo(mockResultSet)));
|
||||
assertThat(resultSet).isEqualTo(mockResultSet);
|
||||
|
||||
verify(mockSession, times(1)).execute(eq(mockSelect));
|
||||
verifyZeroInteractions(mockResultSet);
|
||||
@@ -205,14 +210,14 @@ public class CqlTemplateUnitTests {
|
||||
template = new CqlTemplate() {
|
||||
@Override
|
||||
<T> T columnToObject(Row row, ColumnDefinitions.Definition columnDefinition) {
|
||||
assertThat(row, is(sameInstance(mockRow)));
|
||||
assertThat(columnDefinition, is(sameInstance(mockColumnDefinition)));
|
||||
|
||||
assertThat(row).isSameAs(mockRow);
|
||||
assertThat(columnDefinition).isSameAs(mockColumnDefinition);
|
||||
return (T) "test";
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(String.valueOf(template.firstColumnToObject(mockRow)), is(equalTo("test")));
|
||||
assertThat(String.valueOf(template.firstColumnToObject(mockRow))).isEqualTo("test");
|
||||
|
||||
verify(mockRow, times(1)).getColumnDefinitions();
|
||||
verify(mockColumnDefinitions, times(1)).iterator();
|
||||
@@ -235,7 +240,7 @@ public class CqlTemplateUnitTests {
|
||||
when(mockColumnDefinitions.iterator()).thenReturn(mockIterator);
|
||||
when(mockIterator.hasNext()).thenReturn(false);
|
||||
|
||||
assertThat(template.firstColumnToObject(mockRow), is(nullValue(Object.class)));
|
||||
assertThat(template.firstColumnToObject(mockRow)).isNull();
|
||||
|
||||
verify(mockRow, times(1)).getColumnDefinitions();
|
||||
verify(mockColumnDefinitions, times(1)).iterator();
|
||||
@@ -257,7 +262,7 @@ public class CqlTemplateUnitTests {
|
||||
when(mockResultSet.isExhausted()).thenReturn(true);
|
||||
when(mockRowMapper.mapRow(eq(mockRow), eq(0))).thenReturn("test");
|
||||
|
||||
assertThat(template.processOne(mockResultSet, mockRowMapper), is(equalTo("test")));
|
||||
assertThat(template.processOne(mockResultSet, mockRowMapper)).isEqualTo("test");
|
||||
|
||||
verify(mockResultSet, times(1)).one();
|
||||
verify(mockResultSet, times(1)).isExhausted();
|
||||
@@ -277,12 +282,11 @@ public class CqlTemplateUnitTests {
|
||||
when(mockResultSet.one()).thenReturn(null);
|
||||
|
||||
try {
|
||||
exception.expect(IncorrectResultSizeDataAccessException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(containsString("expected 1, actual 0"));
|
||||
|
||||
template.processOne(mockResultSet, mockRowMapper);
|
||||
|
||||
fail("Missing IncorrectResultSizeDataAccessException");
|
||||
} catch (IncorrectResultSizeDataAccessException e) {
|
||||
assertThat(e).hasMessageContaining("expected 1, actual 0");
|
||||
} finally {
|
||||
verify(mockResultSet, times(1)).one();
|
||||
verify(mockResultSet, never()).isExhausted();
|
||||
@@ -304,12 +308,10 @@ public class CqlTemplateUnitTests {
|
||||
when(mockResultSet.isExhausted()).thenReturn(false);
|
||||
|
||||
try {
|
||||
exception.expect(IncorrectResultSizeDataAccessException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("ResultSet size exceeds 1");
|
||||
|
||||
template.processOne(mockResultSet, mockRowMapper);
|
||||
|
||||
fail("Missing IncorrectResultSizeDataAccessException");
|
||||
} catch (IncorrectResultSizeDataAccessException e) {
|
||||
assertThat(e).hasMessage("ResultSet size exceeds 1");
|
||||
} finally {
|
||||
verify(mockResultSet, times(1)).one();
|
||||
verify(mockResultSet, times(1)).isExhausted();
|
||||
@@ -328,8 +330,6 @@ public class CqlTemplateUnitTests {
|
||||
|
||||
try {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
|
||||
template.processOne(null, mockRowMapper);
|
||||
} finally {
|
||||
verifyZeroInteractions(mockRowMapper);
|
||||
@@ -351,15 +351,14 @@ public class CqlTemplateUnitTests {
|
||||
template = new CqlTemplate() {
|
||||
@Override
|
||||
protected Object firstColumnToObject(Row row) {
|
||||
assertThat(row, is(equalTo(mockRow)));
|
||||
assertThat(row).isEqualTo(mockRow);
|
||||
return 1L;
|
||||
}
|
||||
};
|
||||
|
||||
Number value = template.processOne(mockResultSet, Long.class);
|
||||
|
||||
assertThat(value, is(instanceOf(Long.class)));
|
||||
assertThat(value.longValue(), is(equalTo(1L)));
|
||||
assertThat(value).isInstanceOf(Long.class).isEqualTo(1L);
|
||||
|
||||
verify(mockResultSet, times(1)).one();
|
||||
verify(mockResultSet, times(1)).isExhausted();
|
||||
@@ -377,12 +376,10 @@ public class CqlTemplateUnitTests {
|
||||
when(mockResultSet.one()).thenReturn(null);
|
||||
|
||||
try {
|
||||
exception.expect(IncorrectResultSizeDataAccessException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(containsString("expected 1, actual 0"));
|
||||
|
||||
template.processOne(mockResultSet, Integer.class);
|
||||
|
||||
fail("Missing IncorrectResultSizeDataAccessException");
|
||||
} catch (IncorrectResultSizeDataAccessException e) {
|
||||
assertThat(e).hasMessageContaining("expected 1, actual 0");
|
||||
} finally {
|
||||
verify(mockResultSet, times(1)).one();
|
||||
verify(mockResultSet, never()).isExhausted();
|
||||
@@ -402,12 +399,11 @@ public class CqlTemplateUnitTests {
|
||||
when(mockResultSet.isExhausted()).thenReturn(false);
|
||||
|
||||
try {
|
||||
exception.expect(IncorrectResultSizeDataAccessException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(containsString("ResultSet size exceeds 1"));
|
||||
|
||||
template.processOne(mockResultSet, Double.class);
|
||||
fail("Missing IncorrectResultSizeDataAccessException");
|
||||
|
||||
} catch (IncorrectResultSizeDataAccessException e) {
|
||||
assertThat(e).hasMessageContaining("ResultSet size exceeds 1");
|
||||
} finally {
|
||||
verify(mockResultSet, times(1)).one();
|
||||
verify(mockResultSet, times(1)).isExhausted();
|
||||
@@ -421,7 +417,6 @@ public class CqlTemplateUnitTests {
|
||||
@Test
|
||||
public void processOneWithRequiredTypePassingNullResultSetThrowsIllegalArgumentException() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
|
||||
template.processOne(null, String.class);
|
||||
}
|
||||
@@ -465,8 +460,7 @@ public class CqlTemplateUnitTests {
|
||||
@Test
|
||||
public void addStatementQueryOptionsShouldAddDriverQueryOptions() {
|
||||
|
||||
QueryOptions queryOptions = QueryOptions.builder()
|
||||
.consistencyLevel(ConsistencyLevel.EACH_QUORUM) //
|
||||
QueryOptions queryOptions = QueryOptions.builder().consistencyLevel(ConsistencyLevel.EACH_QUORUM) //
|
||||
.retryPolicy(FallthroughRetryPolicy.INSTANCE) //
|
||||
.build();
|
||||
|
||||
@@ -555,8 +549,7 @@ public class CqlTemplateUnitTests {
|
||||
.consistencyLevel(ConsistencyLevel.EACH_QUORUM) //
|
||||
.retryPolicy(FallthroughRetryPolicy.INSTANCE) //
|
||||
.ttl(10) //
|
||||
.tracing(false)
|
||||
.build();
|
||||
.tracing(false).build();
|
||||
|
||||
template.addWriteOptions(mockUpdate, writeOptions);
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -48,13 +47,13 @@ public class QueryOptionsUnitTests {
|
||||
.tracing(true)//
|
||||
.build(); //
|
||||
|
||||
assertThat((Class) queryOptions.getClass(), is(equalTo((Class) QueryOptions.class)));
|
||||
assertThat(queryOptions.getRetryPolicy(), is(RetryPolicy.DEFAULT));
|
||||
assertThat(queryOptions.getConsistencyLevel(), is(nullValue()));
|
||||
assertThat(queryOptions.getDriverConsistencyLevel(), is(ConsistencyLevel.ANY));
|
||||
assertThat(queryOptions.getReadTimeout(), is(1000L));
|
||||
assertThat(queryOptions.getFetchSize(), is(10));
|
||||
assertThat(queryOptions.getTracing(), is(true));
|
||||
assertThat(queryOptions.getClass()).isEqualTo(QueryOptions.class);
|
||||
assertThat(queryOptions.getRetryPolicy()).isEqualTo(RetryPolicy.DEFAULT);
|
||||
assertThat(queryOptions.getConsistencyLevel()).isNull();
|
||||
assertThat(queryOptions.getDriverConsistencyLevel()).isEqualTo(ConsistencyLevel.ANY);
|
||||
assertThat(queryOptions.getReadTimeout()).isEqualTo(1000);
|
||||
assertThat(queryOptions.getFetchSize()).isEqualTo(10);
|
||||
assertThat(queryOptions.getTracing()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,8 +66,8 @@ public class QueryOptionsUnitTests {
|
||||
.retryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE)) //
|
||||
.build(); //
|
||||
|
||||
assertThat(writeOptions.getRetryPolicy(), is(nullValue()));
|
||||
assertThat(writeOptions.getDriverRetryPolicy(), is(instanceOf(LoggingRetryPolicy.class)));
|
||||
assertThat(writeOptions.getRetryPolicy()).isNull();
|
||||
assertThat(writeOptions.getDriverRetryPolicy()).isInstanceOf(LoggingRetryPolicy.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,8 +80,8 @@ public class QueryOptionsUnitTests {
|
||||
.retryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY) //
|
||||
.build(); //
|
||||
|
||||
assertThat(writeOptions.getRetryPolicy(), is(RetryPolicy.DOWNGRADING_CONSISTENCY));
|
||||
assertThat(writeOptions.getDriverRetryPolicy(), is(nullValue()));
|
||||
assertThat(writeOptions.getRetryPolicy()).isEqualTo(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
assertThat(writeOptions.getDriverRetryPolicy()).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -46,13 +45,13 @@ public class WriteOptionsUnitTests {
|
||||
.withTracing()//
|
||||
.build(); //
|
||||
|
||||
assertThat(writeOptions.getTtl(), is(123));
|
||||
assertThat(writeOptions.getRetryPolicy(), is(RetryPolicy.DEFAULT));
|
||||
assertThat(writeOptions.getConsistencyLevel(), is(nullValue()));
|
||||
assertThat(writeOptions.getDriverConsistencyLevel(), is(com.datastax.driver.core.ConsistencyLevel.ANY));
|
||||
assertThat(writeOptions.getReadTimeout(), is(1L));
|
||||
assertThat(writeOptions.getFetchSize(), is(10));
|
||||
assertThat(writeOptions.getTracing(), is(true));
|
||||
assertThat(writeOptions.getTtl()).isEqualTo(123);
|
||||
assertThat(writeOptions.getRetryPolicy()).isEqualTo(RetryPolicy.DEFAULT);
|
||||
assertThat(writeOptions.getConsistencyLevel()).isNull();
|
||||
assertThat(writeOptions.getDriverConsistencyLevel()).isEqualTo(com.datastax.driver.core.ConsistencyLevel.ANY);
|
||||
assertThat(writeOptions.getReadTimeout()).isEqualTo(1);
|
||||
assertThat(writeOptions.getFetchSize()).isEqualTo(10);
|
||||
assertThat(writeOptions.getTracing()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,9 +62,9 @@ public class WriteOptionsUnitTests {
|
||||
|
||||
WriteOptions writeOptions = WriteOptions.builder().readTimeout(1, TimeUnit.MINUTES).build();
|
||||
|
||||
assertThat(writeOptions.getReadTimeout(), is(60L * 1000L));
|
||||
assertThat(writeOptions.getFetchSize(), is(nullValue()));
|
||||
assertThat(writeOptions.getTracing(), is(nullValue()));
|
||||
assertThat(writeOptions.getReadTimeout()).isEqualTo(60L * 1000L);
|
||||
assertThat(writeOptions.getFetchSize()).isNull();
|
||||
assertThat(writeOptions.getTracing()).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,9 +75,8 @@ public class WriteOptionsUnitTests {
|
||||
|
||||
QueryOptions writeOptions = QueryOptions.builder().retryPolicy(FallthroughRetryPolicy.INSTANCE).build();
|
||||
|
||||
assertThat(writeOptions.getRetryPolicy(), is(nullValue()));
|
||||
assertThat(writeOptions.getDriverRetryPolicy(),
|
||||
is(equalTo((com.datastax.driver.core.policies.RetryPolicy) FallthroughRetryPolicy.INSTANCE)));
|
||||
assertThat(writeOptions.getRetryPolicy()).isNull();
|
||||
assertThat(writeOptions.getDriverRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,8 +87,8 @@ public class WriteOptionsUnitTests {
|
||||
|
||||
QueryOptions writeOptions = QueryOptions.builder().retryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY).build();
|
||||
|
||||
assertThat(writeOptions.getRetryPolicy(), is(RetryPolicy.DOWNGRADING_CONSISTENCY));
|
||||
assertThat(writeOptions.getDriverRetryPolicy(), is(nullValue()));
|
||||
assertThat(writeOptions.getRetryPolicy()).isEqualTo(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
assertThat(writeOptions.getDriverRetryPolicy()).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
18
spring-cql/src/test/java/org/springframework/cassandra/core/cql/CqlIdentifierUnitTests.java
Normal file → Executable file
18
spring-cql/src/test/java/org/springframework/cassandra/core/cql/CqlIdentifierUnitTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.cassandra.core.cql.CqlIdentifier.*;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -36,8 +36,8 @@ public class CqlIdentifierUnitTests {
|
||||
|
||||
for (String id : ids) {
|
||||
CqlIdentifier cqlId = cqlId(id);
|
||||
assertFalse(cqlId.isQuoted());
|
||||
assertEquals(id.toLowerCase(), cqlId.toCql());
|
||||
assertThat(cqlId.isQuoted()).isFalse();
|
||||
assertThat(cqlId.toCql()).isEqualTo(id.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ public class CqlIdentifierUnitTests {
|
||||
|
||||
for (String id : ids) {
|
||||
CqlIdentifier cqlId = quotedCqlId(id);
|
||||
assertTrue(cqlId.isQuoted());
|
||||
assertEquals("\"" + id + "\"", cqlId.toCql());
|
||||
assertThat(cqlId.isQuoted()).isTrue();
|
||||
assertThat(cqlId.toCql()).isEqualTo("\"" + id + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,12 +58,12 @@ public class CqlIdentifierUnitTests {
|
||||
|
||||
for (ReservedKeyword id : ReservedKeyword.values()) {
|
||||
CqlIdentifier cqlId = cqlId(id.name());
|
||||
assertTrue(cqlId.isQuoted());
|
||||
assertEquals("\"" + id.name() + "\"", cqlId.toCql());
|
||||
assertThat(cqlId.isQuoted()).isTrue();
|
||||
assertThat(cqlId.toCql()).isEqualTo("\"" + id.name() + "\"");
|
||||
|
||||
cqlId = cqlId(id.name().toLowerCase());
|
||||
assertTrue(cqlId.isQuoted());
|
||||
assertEquals("\"" + id.name().toLowerCase() + "\"", cqlId.toCql());
|
||||
assertThat(cqlId.isQuoted()).isTrue();
|
||||
assertThat(cqlId.toCql()).isEqualTo("\"" + id.name().toLowerCase() + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
0
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractIndexOperationCqlGeneratorTest.java
Normal file → Executable file
0
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractIndexOperationCqlGeneratorTest.java
Normal file → Executable file
0
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractKeyspaceOperationCqlGeneratorTest.java
Normal file → Executable file
0
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractKeyspaceOperationCqlGeneratorTest.java
Normal file → Executable file
0
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractTableOperationCqlGeneratorTest.java
Normal file → Executable file
0
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AbstractTableOperationCqlGeneratorTest.java
Normal file → Executable file
10
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AlterKeyspaceCqlGeneratorUnitTests.java
Normal file → Executable file
10
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AlterKeyspaceCqlGeneratorUnitTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -39,20 +39,20 @@ public class AlterKeyspaceCqlGeneratorUnitTests {
|
||||
* Asserts that the preamble is first & correctly formatted in the given CQL string.
|
||||
*/
|
||||
public static void assertPreamble(String tableName, String cql) {
|
||||
assertTrue(cql.startsWith("ALTER KEYSPACE " + tableName + " "));
|
||||
assertThat(cql.startsWith("ALTER KEYSPACE " + tableName + " ")).isTrue();
|
||||
}
|
||||
|
||||
private static void assertReplicationMap(Map<Option, Object> replicationMap, String cql) {
|
||||
assertTrue(cql.contains(" WITH replication = { "));
|
||||
assertThat(cql.contains(" WITH replication = { ")).isTrue();
|
||||
|
||||
for (Map.Entry<Option, Object> entry : replicationMap.entrySet()) {
|
||||
String keyValuePair = "'" + entry.getKey().getName() + "' : '" + entry.getValue().toString() + "'";
|
||||
assertTrue(cql.contains(keyValuePair));
|
||||
assertThat(cql.contains(keyValuePair)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertDurableWrites(Boolean durableWrites, String cql) {
|
||||
assertTrue(cql.contains(" AND durable_writes = " + durableWrites));
|
||||
assertThat(cql.contains(" AND durable_writes = " + durableWrites)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
37
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AlterTableCqlGeneratorIntegrationTests.java
Normal file → Executable file
37
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AlterTableCqlGeneratorIntegrationTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -58,14 +57,14 @@ public class AlterTableCqlGeneratorIntegrationTests extends AbstractKeyspaceCrea
|
||||
session.execute(
|
||||
"CREATE TABLE addamsFamily (name varchar PRIMARY KEY, gender varchar,\n" + " lastknownlocation bigint);");
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.alter("lastKnownLocation", DataType.varint());
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").alter("lastKnownLocation",
|
||||
DataType.varint());
|
||||
|
||||
execute(spec);
|
||||
|
||||
ColumnMetadata column = getTableMetadata("addamsFamily").getColumn("lastKnownLocation");
|
||||
|
||||
assertThat(column.getType(), is(equalTo(DataType.varint())));
|
||||
assertThat(column.getType()).isEqualTo(DataType.varint());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,14 +76,14 @@ public class AlterTableCqlGeneratorIntegrationTests extends AbstractKeyspaceCrea
|
||||
session.execute(
|
||||
"CREATE TABLE addamsFamily (name varchar PRIMARY KEY, gender varchar,\n" + " lastknownlocation list<ascii>);");
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.alter("lastKnownLocation", DataType.list(DataType.varchar()));
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").alter("lastKnownLocation",
|
||||
DataType.list(DataType.varchar()));
|
||||
|
||||
execute(spec);
|
||||
|
||||
ColumnMetadata column = getTableMetadata("addamsFamily").getColumn("lastKnownLocation");
|
||||
|
||||
assertThat(column.getType(), is(equalTo((DataType) DataType.list(DataType.varchar()))));
|
||||
assertThat(column.getType()).isEqualTo((DataType) DataType.list(DataType.varchar()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,14 +95,14 @@ public class AlterTableCqlGeneratorIntegrationTests extends AbstractKeyspaceCrea
|
||||
session.execute(
|
||||
"CREATE TABLE addamsFamily (name varchar PRIMARY KEY, gender varchar,\n" + " lastknownlocation varchar);");
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.add("gravesite", DataType.varchar());
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").add("gravesite",
|
||||
DataType.varchar());
|
||||
|
||||
execute(spec);
|
||||
|
||||
ColumnMetadata column = getTableMetadata("addamsFamily").getColumn("gravesite");
|
||||
|
||||
assertThat(column.getType(), is(equalTo(DataType.varchar())));
|
||||
assertThat(column.getType()).isEqualTo(DataType.varchar());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,14 +113,14 @@ public class AlterTableCqlGeneratorIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
session.execute("CREATE TABLE users (user_name varchar PRIMARY KEY);");
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("users")
|
||||
.add("top_places", DataType.list(DataType.ascii()));
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("users").add("top_places",
|
||||
DataType.list(DataType.ascii()));
|
||||
|
||||
execute(spec);
|
||||
|
||||
ColumnMetadata column = getTableMetadata("users").getColumn("top_places");
|
||||
|
||||
assertThat(column.getType(), is(equalTo((DataType) DataType.list(DataType.ascii()))));
|
||||
assertThat(column.getType()).isEqualTo((DataType) DataType.list(DataType.ascii()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,7 +135,7 @@ public class AlterTableCqlGeneratorIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
execute(spec);
|
||||
|
||||
assertThat(getTableMetadata("addamsfamily").getColumn("gender"), is(nullValue()));
|
||||
assertThat(getTableMetadata("addamsfamily").getColumn("gender")).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,8 +150,8 @@ public class AlterTableCqlGeneratorIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
execute(spec);
|
||||
|
||||
assertThat(getTableMetadata("addamsfamily").getColumn("name"), is(nullValue()));
|
||||
assertThat(getTableMetadata("addamsfamily").getColumn("newname"), is(notNullValue()));
|
||||
assertThat(getTableMetadata("addamsfamily").getColumn("name")).isNull();
|
||||
assertThat(getTableMetadata("addamsfamily").getColumn("newname")).isNotNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,8 +170,8 @@ public class AlterTableCqlGeneratorIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
execute(spec);
|
||||
|
||||
assertThat(getTableMetadata("users").getOptions().getCaching().get("keys"), is(equalTo("NONE")));
|
||||
assertThat(getTableMetadata("users").getOptions().getCaching().get("rows_per_partition"), is(equalTo("15")));
|
||||
assertThat(getTableMetadata("users").getOptions().getCaching().get("keys")).isEqualTo("NONE");
|
||||
assertThat(getTableMetadata("users").getOptions().getCaching().get("rows_per_partition")).isEqualTo("15");
|
||||
|
||||
}
|
||||
|
||||
|
||||
46
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AlterTableCqlGeneratorUnitTests.java
Normal file → Executable file
46
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/AlterTableCqlGeneratorUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -44,10 +43,10 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
@Test
|
||||
public void alterTableAlterColumnType() {
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.alter("lastKnownLocation", DataType.uuid());
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").alter("lastKnownLocation",
|
||||
DataType.uuid());
|
||||
|
||||
assertThat(toCql(spec), is(equalTo("ALTER TABLE addamsfamily ALTER lastknownlocation TYPE uuid;")));
|
||||
assertThat(toCql(spec)).isEqualTo("ALTER TABLE addamsfamily ALTER lastknownlocation TYPE uuid;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,10 +55,10 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
@Test
|
||||
public void alterTableAlterListColumnType() {
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.alter("lastKnownLocation", DataType.list(DataType.ascii()));
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").alter("lastKnownLocation",
|
||||
DataType.list(DataType.ascii()));
|
||||
|
||||
assertThat(toCql(spec), is(equalTo("ALTER TABLE addamsfamily ALTER lastknownlocation TYPE list<ascii>;")));
|
||||
assertThat(toCql(spec)).isEqualTo("ALTER TABLE addamsfamily ALTER lastknownlocation TYPE list<ascii>;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,10 +67,10 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
@Test
|
||||
public void alterTableAddColumn() {
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.add("gravesite", DataType.varchar());
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").add("gravesite",
|
||||
DataType.varchar());
|
||||
|
||||
assertThat(toCql(spec), is(equalTo("ALTER TABLE addamsfamily ADD gravesite varchar;")));
|
||||
assertThat(toCql(spec)).isEqualTo("ALTER TABLE addamsfamily ADD gravesite varchar;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,10 +79,10 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
@Test
|
||||
public void alterTableAddListColumn() {
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("users")
|
||||
.add("top_places", DataType.list(DataType.ascii()));
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("users").add("top_places",
|
||||
DataType.list(DataType.ascii()));
|
||||
|
||||
assertThat(toCql(spec), is(equalTo("ALTER TABLE users ADD top_places list<ascii>;")));
|
||||
assertThat(toCql(spec)).isEqualTo("ALTER TABLE users ADD top_places list<ascii>;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +93,7 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").drop("gender");
|
||||
|
||||
assertThat(toCql(spec), is(equalTo("ALTER TABLE addamsfamily DROP gender;")));
|
||||
assertThat(toCql(spec)).isEqualTo("ALTER TABLE addamsfamily DROP gender;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,10 +102,9 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
@Test
|
||||
public void alterTableRenameColumn() {
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.rename("firstname", "lastname");
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").rename("firstname", "lastname");
|
||||
|
||||
assertThat(toCql(spec), is(equalTo("ALTER TABLE addamsfamily RENAME firstname TO lastname;")));
|
||||
assertThat(toCql(spec)).isEqualTo("ALTER TABLE addamsfamily RENAME firstname TO lastname;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,8 +116,8 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.with(TableOption.READ_REPAIR_CHANCE, 0.2f).with(TableOption.COMMENT, "A most excellent and useful table");
|
||||
|
||||
assertThat(toCql(spec), is(equalTo(
|
||||
"ALTER TABLE addamsfamily WITH read_repair_chance = 0.2 AND comment = 'A most excellent and useful table';")));
|
||||
assertThat(toCql(spec)).isEqualTo(
|
||||
"ALTER TABLE addamsfamily WITH read_repair_chance = 0.2 AND comment = 'A most excellent and useful table';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,8 +130,8 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
.add("top_places", DataType.list(DataType.ascii())).add("other", DataType.list(DataType.ascii()))
|
||||
.with(TableOption.COMMENT, "A most excellent and useful table");
|
||||
|
||||
assertThat(toCql(spec), is(equalTo(
|
||||
"ALTER TABLE addamsfamily ADD top_places list<ascii> ADD other list<ascii> WITH comment = 'A most excellent and useful table';")));
|
||||
assertThat(toCql(spec)).isEqualTo(
|
||||
"ALTER TABLE addamsfamily ADD top_places list<ascii> ADD other list<ascii> WITH comment = 'A most excellent and useful table';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,8 +146,8 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("users").with(TableOption.CACHING, cachingMap);
|
||||
|
||||
assertThat(toCql(spec),
|
||||
is(equalTo("ALTER TABLE users WITH caching = { 'keys' : 'none', 'rows_per_partition' : '15' };")));
|
||||
assertThat(toCql(spec))
|
||||
.isEqualTo("ALTER TABLE users WITH caching = { 'keys' : 'none', 'rows_per_partition' : '15' };");
|
||||
}
|
||||
|
||||
private String toCql(AlterTableSpecification spec) {
|
||||
|
||||
6
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateIndexCqlGeneratorUnitTests.java
Normal file → Executable file
6
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateIndexCqlGeneratorUnitTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.core.keyspace.CreateIndexSpecification;
|
||||
@@ -32,7 +32,7 @@ public class CreateIndexCqlGeneratorUnitTests {
|
||||
* Asserts that the preamble is first & correctly formatted in the given CQL string.
|
||||
*/
|
||||
public static void assertPreamble(String indexName, String tableName, String cql) {
|
||||
assertTrue(cql.startsWith("CREATE INDEX " + indexName + " ON " + tableName));
|
||||
assertThat(cql.startsWith("CREATE INDEX " + indexName + " ON " + tableName)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +41,7 @@ public class CreateIndexCqlGeneratorUnitTests {
|
||||
* @param columnName IE, "(foo)"
|
||||
*/
|
||||
public static void assertColumn(String columnName, String cql) {
|
||||
assertTrue(cql.contains("(" + columnName + ")"));
|
||||
assertThat(cql.contains("(" + columnName + ")")).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
10
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateKeyspaceCqlGeneratorUnitTests.java
Normal file → Executable file
10
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateKeyspaceCqlGeneratorUnitTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -40,21 +40,21 @@ public class CreateKeyspaceCqlGeneratorUnitTests {
|
||||
* Asserts that the preamble is first & correctly formatted in the given CQL string.
|
||||
*/
|
||||
public static void assertPreamble(String keyspaceName, String cql) {
|
||||
assertTrue(cql.startsWith("CREATE KEYSPACE " + keyspaceName + " "));
|
||||
assertThat(cql.startsWith("CREATE KEYSPACE " + keyspaceName + " ")).isTrue();
|
||||
}
|
||||
|
||||
private static void assertReplicationMap(Map<Option, Object> replicationMap, String cql) {
|
||||
assertTrue(cql.contains(" WITH replication = { "));
|
||||
assertThat(cql.contains(" WITH replication = { ")).isTrue();
|
||||
|
||||
for (Map.Entry<Option, Object> entry : replicationMap.entrySet()) {
|
||||
String keyValuePair = "'" + entry.getKey().getName() + "' : " + (entry.getKey().quotesValue() ? "'" : "")
|
||||
+ entry.getValue().toString() + (entry.getKey().quotesValue() ? "'" : "");
|
||||
assertTrue(cql.contains(keyValuePair));
|
||||
assertThat(cql.contains(keyValuePair)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertDurableWrites(Boolean durableWrites, String cql) {
|
||||
assertTrue(cql.contains(" AND durable_writes = " + durableWrites));
|
||||
assertThat(cql.contains(" AND durable_writes = " + durableWrites)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
16
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateTableCqlGeneratorUnitTests.java
Normal file → Executable file
16
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/CreateTableCqlGeneratorUnitTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.cassandra.core.cql.CqlIdentifier.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -54,7 +54,7 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
* Asserts that the preamble is first & correctly formatted in the given CQL string.
|
||||
*/
|
||||
public static void assertPreamble(CqlIdentifier tableName, String cql) {
|
||||
assertTrue(cql.startsWith("CREATE TABLE " + tableName + " "));
|
||||
assertThat(cql.startsWith("CREATE TABLE " + tableName + " ")).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
* @param primaryKeyString IE, "foo", "foo, bar, baz", "(foo, bar), baz", etc
|
||||
*/
|
||||
public static void assertPrimaryKey(String primaryKeyString, String cql) {
|
||||
assertTrue(cql.contains(", PRIMARY KEY (" + primaryKeyString + "))"));
|
||||
assertThat(cql.contains(", PRIMARY KEY (" + primaryKeyString + "))")).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
* @param columnSpec IE, "foo text, bar blob"
|
||||
*/
|
||||
public static void assertColumns(String columnSpec, String cql) {
|
||||
assertTrue(cql.contains("(" + columnSpec + ","));
|
||||
assertThat(cql.contains("(" + columnSpec + ",")).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +80,7 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
*/
|
||||
public static void assertStringOption(String name, String value, String cql) {
|
||||
log.info(name + " -> " + value);
|
||||
assertTrue(cql.contains(name + " = '" + value + "'"));
|
||||
assertThat(cql.contains(name + " = '" + value + "'")).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,12 +88,12 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
*/
|
||||
public static void assertDoubleOption(String name, Double value, String cql) {
|
||||
log.info(name + " -> " + value);
|
||||
assertTrue(cql.contains(name + " = " + value));
|
||||
assertThat(cql.contains(name + " = " + value)).isTrue();
|
||||
}
|
||||
|
||||
public static void assertLongOption(String name, Long value, String cql) {
|
||||
log.info(name + " -> " + value);
|
||||
assertTrue(cql.contains(name + " = " + value));
|
||||
assertThat(cql.contains(name + " = " + value)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +101,7 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
*/
|
||||
public static void assertNullOption(String name, String cql) {
|
||||
log.info(name);
|
||||
assertTrue(cql.contains(" " + name + " "));
|
||||
assertThat(cql.contains(" " + name + " ")).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
4
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropIndexCqlGeneratorUnitTests.java
Normal file → Executable file
4
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropIndexCqlGeneratorUnitTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.core.keyspace.DropIndexSpecification;
|
||||
@@ -32,7 +32,7 @@ public class DropIndexCqlGeneratorUnitTests {
|
||||
* Asserts that the preamble is first & correctly formatted in the given CQL string.
|
||||
*/
|
||||
public static void assertStatement(String indexName, boolean ifExists, String cql) {
|
||||
assertTrue(cql.equals("DROP INDEX " + (ifExists ? "IF EXISTS " : "") + indexName + ";"));
|
||||
assertThat(cql.equals("DROP INDEX " + (ifExists ? "IF EXISTS " : "") + indexName + ";")).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
4
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropKeyspaceCqlGeneratorUnitTests.java
Normal file → Executable file
4
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropKeyspaceCqlGeneratorUnitTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
|
||||
@@ -34,7 +34,7 @@ public class DropKeyspaceCqlGeneratorUnitTests {
|
||||
* Asserts that the preamble is first & correctly formatted in the given CQL string.
|
||||
*/
|
||||
public static void assertStatement(String tableName, String cql) {
|
||||
assertTrue(cql.equals("DROP KEYSPACE " + tableName + ";"));
|
||||
assertThat(cql.equals("DROP KEYSPACE " + tableName + ";")).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
4
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropTableCqlGeneratorUnitTests.java
Normal file → Executable file
4
spring-cql/src/test/java/org/springframework/cassandra/core/cql/generator/DropTableCqlGeneratorUnitTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.core.keyspace.DropTableSpecification;
|
||||
@@ -32,7 +32,7 @@ public class DropTableCqlGeneratorUnitTests {
|
||||
* Asserts that the preamble is first & correctly formatted in the given CQL string.
|
||||
*/
|
||||
public static void assertStatement(String tableName, boolean ifExists, String cql) {
|
||||
assertTrue(cql.equals("DROP TABLE " + (ifExists ? "IF EXISTS " : "") + tableName + ";"));
|
||||
assertThat(cql.equals("DROP TABLE " + (ifExists ? "IF EXISTS " : "") + tableName + ";")).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
48
spring-cql/src/test/java/org/springframework/cassandra/core/keyspace/OptionUnitTests.java
Normal file → Executable file
48
spring-cql/src/test/java/org/springframework/cassandra/core/keyspace/OptionUnitTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@@ -48,8 +48,8 @@ public class OptionUnitTests {
|
||||
@Test
|
||||
public void testOptionWithNullTypeIsCoerceable() {
|
||||
Option op = new DefaultOption("opt", null, true, true, true);
|
||||
assertTrue(op.isCoerceable(""));
|
||||
assertTrue(op.isCoerceable(null));
|
||||
assertThat(op.isCoerceable("")).isTrue();
|
||||
assertThat(op.isCoerceable(null)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,9 +62,9 @@ public class OptionUnitTests {
|
||||
|
||||
Option op = new DefaultOption(name, type, requires, escapes, quotes);
|
||||
|
||||
assertTrue(op.isCoerceable("opt"));
|
||||
assertEquals("'opt'", op.toString("opt"));
|
||||
assertEquals("'opt''n'", op.toString("opt'n"));
|
||||
assertThat(op.isCoerceable("opt")).isTrue();
|
||||
assertThat(op.toString("opt")).isEqualTo("'opt'");
|
||||
assertThat(op.toString("opt'n")).isEqualTo("'opt''n'");
|
||||
|
||||
type = Long.class;
|
||||
escapes = false;
|
||||
@@ -73,11 +73,11 @@ public class OptionUnitTests {
|
||||
|
||||
String expected = "1";
|
||||
for (Object value : new Object[] { 1, "1" }) {
|
||||
assertTrue(op.isCoerceable(value));
|
||||
assertEquals(expected, op.toString(value));
|
||||
assertThat(op.isCoerceable(value)).isTrue();
|
||||
assertThat(op.toString(value)).isEqualTo(expected);
|
||||
}
|
||||
assertFalse(op.isCoerceable("x"));
|
||||
assertTrue(op.isCoerceable(null));
|
||||
assertThat(op.isCoerceable("x")).isFalse();
|
||||
assertThat(op.isCoerceable(null)).isTrue();
|
||||
|
||||
type = Long.class;
|
||||
escapes = false;
|
||||
@@ -86,11 +86,11 @@ public class OptionUnitTests {
|
||||
|
||||
expected = "'1'";
|
||||
for (Object value : new Object[] { 1, "1" }) {
|
||||
assertTrue(op.isCoerceable(value));
|
||||
assertEquals(expected, op.toString(value));
|
||||
assertThat(op.isCoerceable(value)).isTrue();
|
||||
assertThat(op.toString(value)).isEqualTo(expected);
|
||||
}
|
||||
assertFalse(op.isCoerceable("x"));
|
||||
assertTrue(op.isCoerceable(null));
|
||||
assertThat(op.isCoerceable("x")).isFalse();
|
||||
assertThat(op.isCoerceable(null)).isTrue();
|
||||
|
||||
type = Double.class;
|
||||
escapes = false;
|
||||
@@ -100,22 +100,22 @@ public class OptionUnitTests {
|
||||
String[] expecteds = new String[] { "1", "1.0", "1.0", "1", "1.0", null };
|
||||
Object[] values = new Object[] { 1, 1.0F, 1.0D, "1", "1.0", null };
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
assertTrue(op.isCoerceable(values[i]));
|
||||
assertEquals(expecteds[i], op.toString(values[i]));
|
||||
assertThat(op.isCoerceable(values[i])).isTrue();
|
||||
assertThat(op.toString(values[i])).isEqualTo(expecteds[i]);
|
||||
}
|
||||
assertFalse(op.isCoerceable("x"));
|
||||
assertTrue(op.isCoerceable(null));
|
||||
assertThat(op.isCoerceable("x")).isFalse();
|
||||
assertThat(op.isCoerceable(null)).isTrue();
|
||||
|
||||
type = RetentionPolicy.class;
|
||||
escapes = false;
|
||||
quotes = false;
|
||||
op = new DefaultOption(name, type, requires, escapes, quotes);
|
||||
|
||||
assertTrue(op.isCoerceable(null));
|
||||
assertTrue(op.isCoerceable(RetentionPolicy.CLASS));
|
||||
assertTrue(op.isCoerceable("CLASS"));
|
||||
assertFalse(op.isCoerceable("x"));
|
||||
assertEquals("CLASS", op.toString("CLASS"));
|
||||
assertEquals("CLASS", op.toString(RetentionPolicy.CLASS));
|
||||
assertThat(op.isCoerceable(null)).isTrue();
|
||||
assertThat(op.isCoerceable(RetentionPolicy.CLASS)).isTrue();
|
||||
assertThat(op.isCoerceable("CLASS")).isTrue();
|
||||
assertThat(op.isCoerceable("x")).isFalse();
|
||||
assertThat(op.toString("CLASS")).isEqualTo("CLASS");
|
||||
assertThat(op.toString(RetentionPolicy.CLASS)).isEqualTo("CLASS");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,13 @@
|
||||
|
||||
package org.springframework.cassandra.core.support;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.datastax.driver.core.ExecutionInfo;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Row;
|
||||
|
||||
@@ -43,30 +40,29 @@ public class EmptyResultSetUnitTests {
|
||||
ResultSet mockResultSet = mock(ResultSet.class);
|
||||
ResultSet theResultSet = EmptyResultSet.nullSafeResultSet(mockResultSet);
|
||||
|
||||
assertThat(theResultSet, is(sameInstance(mockResultSet)));
|
||||
assertThat(theResultSet).isSameAs(mockResultSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullSAfeResultSetReturnsEmptyResultSetForNull() {
|
||||
ResultSet resultSet = EmptyResultSet.nullSafeResultSet(null);
|
||||
|
||||
assertThat(resultSet, is(instanceOf(EmptyResultSet.class)));
|
||||
assertThat(resultSet).isInstanceOf(EmptyResultSet.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isExhaustedForEmptyResultIsTrue() {
|
||||
assertThat(EmptyResultSet.nullSafeResultSet(null).isExhausted(), is(true));
|
||||
assertThat(EmptyResultSet.nullSafeResultSet(null).isExhausted()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFullyFetchedForEmptyResultSetIsTrue() {
|
||||
assertThat(EmptyResultSet.nullSafeResultSet(null).isFullyFetched(), is(true));
|
||||
assertThat(EmptyResultSet.nullSafeResultSet(null).isFullyFetched()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllExecutionInfoForEmptyResultSetIsEmptyList() {
|
||||
assertThat(EmptyResultSet.nullSafeResultSet(null).getAllExecutionInfo(),
|
||||
is(equalTo(Collections.<ExecutionInfo>emptyList())));
|
||||
assertThat(EmptyResultSet.nullSafeResultSet(null).getAllExecutionInfo()).isEmpty();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@@ -76,12 +72,12 @@ public class EmptyResultSetUnitTests {
|
||||
|
||||
@Test
|
||||
public void getExecutionInfoForEmptyResultSetIsNull() {
|
||||
assertThat(EmptyResultSet.nullSafeResultSet(null).getExecutionInfo(), is(nullValue(ExecutionInfo.class)));
|
||||
assertThat(EmptyResultSet.nullSafeResultSet(null).getExecutionInfo()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allForEmptyResultSetIsEmptyList() {
|
||||
assertThat(EmptyResultSet.nullSafeResultSet(null).all(), is(equalTo(Collections.<Row>emptyList())));
|
||||
assertThat(EmptyResultSet.nullSafeResultSet(null).all()).isEmpty();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@@ -93,13 +89,13 @@ public class EmptyResultSetUnitTests {
|
||||
public void iteratorForEmptyResultSetIsEmptyIterator() {
|
||||
Iterator<Row> iterator = EmptyResultSet.nullSafeResultSet(null).iterator();
|
||||
|
||||
assertThat(iterator, is(notNullValue(Iterator.class)));
|
||||
assertThat(iterator.hasNext(), is(false));
|
||||
assertThat(iterator).isNotNull();
|
||||
assertThat(iterator.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneForEmptyResultSetIsNull() {
|
||||
assertThat(EmptyResultSet.nullSafeResultSet(null).one(), is(nullValue(Row.class)));
|
||||
assertThat(EmptyResultSet.nullSafeResultSet(null).one()).isNull();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
|
||||
35
spring-cql/src/test/java/org/springframework/cassandra/core/util/CollectionUtilsUnitTests.java
Normal file → Executable file
35
spring-cql/src/test/java/org/springframework/cassandra/core/util/CollectionUtilsUnitTests.java
Normal file → Executable file
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.cassandra.core.util;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -27,8 +26,8 @@ import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* The CollectionUtilsUnitTests class is a test suite of test cases testing the contract and functionality
|
||||
* of the {@link CollectionUtils} class.
|
||||
* The CollectionUtilsUnitTests class is a test suite of test cases testing the contract and functionality of the
|
||||
* {@link CollectionUtils} class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.cassandra.core.util.CollectionUtils
|
||||
@@ -41,13 +40,13 @@ public class CollectionUtilsUnitTests {
|
||||
}
|
||||
|
||||
void assertNonNullEmptyArray(Object[] array) {
|
||||
assertThat(array, is(notNullValue()));
|
||||
assertThat(array.length, is(equalTo(0)));
|
||||
assertThat(array).isNotNull();
|
||||
assertThat(array.length).isEqualTo(0);
|
||||
}
|
||||
|
||||
void assertNonNullEmptyCollection(Collection<?> collection) {
|
||||
assertThat(collection, is(notNullValue()));
|
||||
assertThat(collection.isEmpty(), is(true));
|
||||
assertThat(collection).isNotNull();
|
||||
assertThat(collection.isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
<T> Iterable<T> newIterable(final T... elements) {
|
||||
@@ -75,12 +74,12 @@ public class CollectionUtilsUnitTests {
|
||||
public void toArrayWithIterable() {
|
||||
Object[] array = CollectionUtils.toArray(newIterable(1, 2, 3));
|
||||
|
||||
assertThat(array, is(notNullValue()));
|
||||
assertThat(array.length, is(equalTo(3)));
|
||||
assertThat(array).isNotNull();
|
||||
assertThat(array.length).isEqualTo(3);
|
||||
|
||||
for (int index = 0; index < array.length; index++) {
|
||||
Object valueAtIndex = (index + 1);
|
||||
assertThat(array[index], is(equalTo(valueAtIndex)));
|
||||
assertThat(array[index]).isEqualTo(valueAtIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,9 +97,9 @@ public class CollectionUtilsUnitTests {
|
||||
public void toListWithArray() {
|
||||
List<String> list = CollectionUtils.toList("test", "testing", "tested");
|
||||
|
||||
assertThat(list, is(notNullValue()));
|
||||
assertThat(list.size(), is(equalTo(3)));
|
||||
assertThat(list.containsAll(asList("test", "testing", "tested")), is(true));
|
||||
assertThat(list).isNotNull();
|
||||
assertThat(list).hasSize(3);
|
||||
assertThat(list.containsAll(asList("test", "testing", "tested"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,9 +117,9 @@ public class CollectionUtilsUnitTests {
|
||||
public void toListWithIterable() {
|
||||
List<Integer> list = CollectionUtils.toList(newIterable(1, 2, 3));
|
||||
|
||||
assertThat(list, is(notNullValue()));
|
||||
assertThat(list.size(), is(equalTo(3)));
|
||||
assertThat(list.containsAll(asList(1, 2, 3)), is(true));
|
||||
assertThat(list).isNotNull();
|
||||
assertThat(list).hasSize(3);
|
||||
assertThat(list.containsAll(asList(1, 2, 3))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,7 +127,7 @@ public class CollectionUtilsUnitTests {
|
||||
List<Integer> expected = asList(1, 2, 3);
|
||||
List<Integer> actual = CollectionUtils.toList(expected);
|
||||
|
||||
assertThat(actual, is(sameInstance(expected)));
|
||||
assertThat(actual).isSameAs(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -66,6 +66,6 @@ public abstract class BeanDefinitionTestUtils {
|
||||
Object value = getPropertyValue(beanDefinition, propertyName);
|
||||
|
||||
return (value instanceof RuntimeBeanReference ? ((RuntimeBeanReference) value).getBeanName()
|
||||
: (value != null ? String.valueOf(value) : null));
|
||||
: (value != null ? String.valueOf(value) : null));
|
||||
}
|
||||
}
|
||||
|
||||
53
spring-cql/src/test/java/org/springframework/cassandra/support/CassandraAccessorUnitTests.java
Normal file → Executable file
53
spring-cql/src/test/java/org/springframework/cassandra/support/CassandraAccessorUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.support;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -56,11 +55,12 @@ public class CassandraAccessorUnitTests {
|
||||
@Test
|
||||
public void afterPropertiesSetWithUnitializedSessionThrowsIllegalStateException() {
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("Session must not be null");
|
||||
|
||||
cassandraAccessor.afterPropertiesSet();
|
||||
try {
|
||||
cassandraAccessor.afterPropertiesSet();
|
||||
fail("Missing IllegalStateException");
|
||||
} catch (IllegalStateException e) {
|
||||
assertThat(e).hasMessageContaining("Session must not be null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ public class CassandraAccessorUnitTests {
|
||||
public void setAndGetExceptionTranslator() {
|
||||
|
||||
cassandraAccessor.setExceptionTranslator(mockExceptionTranslator);
|
||||
assertThat(cassandraAccessor.getExceptionTranslator(), is(sameInstance(mockExceptionTranslator)));
|
||||
assertThat(cassandraAccessor.getExceptionTranslator()).isSameAs(mockExceptionTranslator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,11 +79,12 @@ public class CassandraAccessorUnitTests {
|
||||
@Test
|
||||
public void setExceptionTranslatorToNullThrowsIllegalArgumentException() {
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(is(equalTo("CassandraExceptionTranslator must not be null")));
|
||||
|
||||
cassandraAccessor.setExceptionTranslator(null);
|
||||
try {
|
||||
cassandraAccessor.setExceptionTranslator(null);
|
||||
fail("Missing IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e).hasMessageContaining("CassandraExceptionTranslator must not be null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +92,7 @@ public class CassandraAccessorUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void getUninitializedExceptionTranslatorReturnsDefault() {
|
||||
assertThat(cassandraAccessor.getExceptionTranslator(), is(equalTo(cassandraAccessor.exceptionTranslator)));
|
||||
assertThat(cassandraAccessor.getExceptionTranslator()).isEqualTo(cassandraAccessor.exceptionTranslator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +102,7 @@ public class CassandraAccessorUnitTests {
|
||||
public void setAndGetSession() {
|
||||
|
||||
cassandraAccessor.setSession(mockSession);
|
||||
assertThat(cassandraAccessor.getSession(), is(sameInstance(mockSession)));
|
||||
assertThat(cassandraAccessor.getSession()).isSameAs(mockSession);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,11 +111,12 @@ public class CassandraAccessorUnitTests {
|
||||
@Test
|
||||
public void setSessionToNullThrowsIllegalArgumentException() {
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(is(equalTo("Session must not be null")));
|
||||
|
||||
cassandraAccessor.setSession(null);
|
||||
try {
|
||||
cassandraAccessor.setSession(null);
|
||||
fail("Missing IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e).hasMessageContaining("Session must not be null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,10 +125,11 @@ public class CassandraAccessorUnitTests {
|
||||
@Test
|
||||
public void getUninitializedSessionThrowsIllegalStateException() {
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(is(equalTo("Session was not properly initialized")));
|
||||
|
||||
cassandraAccessor.getSession();
|
||||
try {
|
||||
cassandraAccessor.getSession();
|
||||
fail("Missing IllegalStateException");
|
||||
} catch (IllegalStateException e) {
|
||||
assertThat(e).hasMessageContaining("Session was not properly initialized");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
38
spring-cql/src/test/java/org/springframework/cassandra/support/CassandraExceptionTranslatorTest.java
Normal file → Executable file
38
spring-cql/src/test/java/org/springframework/cassandra/support/CassandraExceptionTranslatorTest.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.support;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.support.exception.CassandraInvalidConfigurationInQueryException;
|
||||
@@ -44,14 +44,14 @@ public class CassandraExceptionTranslatorTest {
|
||||
String table = "tbl";
|
||||
AlreadyExistsException cx = new AlreadyExistsException(keyspace, table);
|
||||
DataAccessException dax = tx.translateExceptionIfPossible(cx);
|
||||
assertNotNull(dax);
|
||||
assertTrue(dax instanceof CassandraTableExistsException);
|
||||
assertThat(dax).isNotNull();
|
||||
assertThat(dax instanceof CassandraTableExistsException).isTrue();
|
||||
|
||||
CassandraTableExistsException x = (CassandraTableExistsException) dax;
|
||||
assertEquals(table, x.getTableName());
|
||||
assertEquals(x.getTableName(), x.getElementName());
|
||||
assertEquals(CassandraSchemaElementExistsException.ElementType.TABLE, x.getElementType());
|
||||
assertEquals(cx, x.getCause());
|
||||
assertThat(x.getTableName()).isEqualTo(table);
|
||||
assertThat(x.getElementName()).isEqualTo(x.getTableName());
|
||||
assertThat(x.getElementType()).isEqualTo(CassandraSchemaElementExistsException.ElementType.TABLE);
|
||||
assertThat(x.getCause()).isEqualTo(cx);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,14 +60,14 @@ public class CassandraExceptionTranslatorTest {
|
||||
String table = "";
|
||||
AlreadyExistsException cx = new AlreadyExistsException(keyspace, table);
|
||||
DataAccessException dax = tx.translateExceptionIfPossible(cx);
|
||||
assertNotNull(dax);
|
||||
assertTrue(dax instanceof CassandraKeyspaceExistsException);
|
||||
assertThat(dax).isNotNull();
|
||||
assertThat(dax instanceof CassandraKeyspaceExistsException).isTrue();
|
||||
|
||||
CassandraKeyspaceExistsException x = (CassandraKeyspaceExistsException) dax;
|
||||
assertEquals(keyspace, x.getKeyspaceName());
|
||||
assertEquals(x.getKeyspaceName(), x.getElementName());
|
||||
assertEquals(CassandraSchemaElementExistsException.ElementType.KEYSPACE, x.getElementType());
|
||||
assertEquals(cx, x.getCause());
|
||||
assertThat(x.getKeyspaceName()).isEqualTo(keyspace);
|
||||
assertThat(x.getElementName()).isEqualTo(x.getKeyspaceName());
|
||||
assertThat(x.getElementType()).isEqualTo(CassandraSchemaElementExistsException.ElementType.KEYSPACE);
|
||||
assertThat(x.getCause()).isEqualTo(cx);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,14 +75,14 @@ public class CassandraExceptionTranslatorTest {
|
||||
String msg = "msg";
|
||||
InvalidQueryException cx = new InvalidConfigurationInQueryException(null, msg);
|
||||
DataAccessException dax = tx.translateExceptionIfPossible(cx);
|
||||
assertNotNull(dax);
|
||||
assertTrue(dax instanceof CassandraInvalidConfigurationInQueryException);
|
||||
assertEquals(cx, dax.getCause());
|
||||
assertThat(dax).isNotNull();
|
||||
assertThat(dax instanceof CassandraInvalidConfigurationInQueryException).isTrue();
|
||||
assertThat(dax.getCause()).isEqualTo(cx);
|
||||
|
||||
cx = new InvalidQueryException(msg);
|
||||
dax = tx.translateExceptionIfPossible(cx);
|
||||
assertNotNull(dax);
|
||||
assertTrue(dax instanceof CassandraInvalidQueryException);
|
||||
assertEquals(cx, dax.getCause());
|
||||
assertThat(dax).isNotNull();
|
||||
assertThat(dax instanceof CassandraInvalidQueryException).isTrue();
|
||||
assertThat(dax.getCause()).isEqualTo(cx);
|
||||
}
|
||||
}
|
||||
|
||||
0
spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractEmbeddedCassandraIntegrationTest.java
Normal file → Executable file
0
spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractEmbeddedCassandraIntegrationTest.java
Normal file → Executable file
0
spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractKeyspaceCreatingIntegrationTest.java
Normal file → Executable file
0
spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractKeyspaceCreatingIntegrationTest.java
Normal file → Executable file
@@ -22,10 +22,13 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.cassandra.config.Config;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.db.commitlog.CommitLog;
|
||||
import org.apache.cassandra.io.util.FileUtils;
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.config;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -55,7 +53,7 @@ public class CassandraCqlClusterFactoryBeanIntegrationTests {
|
||||
cassandraCqlClusterFactoryBean.setProtocolVersion(ProtocolVersion.V2);
|
||||
cassandraCqlClusterFactoryBean.afterPropertiesSet();
|
||||
|
||||
assertEquals(ProtocolVersion.V2, getProtocolVersionEnum(cassandraCqlClusterFactoryBean));
|
||||
assertThat(getProtocolVersionEnum(cassandraCqlClusterFactoryBean)).isEqualTo(ProtocolVersion.V2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,7 +61,7 @@ public class CassandraCqlClusterFactoryBeanIntegrationTests {
|
||||
|
||||
cassandraCqlClusterFactoryBean.afterPropertiesSet();
|
||||
|
||||
assertThat(getProtocolVersionEnum(cassandraCqlClusterFactoryBean), is(nullValue()));
|
||||
assertThat(getProtocolVersionEnum(cassandraCqlClusterFactoryBean)).isNull();
|
||||
}
|
||||
|
||||
private ProtocolVersion getProtocolVersionEnum(CassandraCqlClusterFactoryBean cassandraCqlClusterFactoryBean)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.springframework.cassandra.core.CqlTemplate;
|
||||
|
||||
@@ -27,14 +27,14 @@ import com.datastax.driver.core.Session;
|
||||
public class IntegrationTestUtils {
|
||||
|
||||
public static void assertCqlTemplate(CqlTemplate cqlTemplate) {
|
||||
assertNotNull(cqlTemplate);
|
||||
assertThat(cqlTemplate).isNotNull();
|
||||
}
|
||||
|
||||
public static void assertSession(Session session) {
|
||||
assertNotNull(session);
|
||||
assertThat(session).isNotNull();
|
||||
}
|
||||
|
||||
public static void assertKeyspaceExists(String keyspace, Session session) {
|
||||
assertNotNull(session.getCluster().getMetadata().getKeyspace(keyspace));
|
||||
assertThat(session.getCluster().getMetadata().getKeyspace(keyspace)).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
0
spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/AbstractIntegrationTest.java
Normal file → Executable file
0
spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/AbstractIntegrationTest.java
Normal file → Executable file
0
spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/ConfigIntegrationTests.java
Normal file → Executable file
0
spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/ConfigIntegrationTests.java
Normal file → Executable file
5
spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/CqlTemplateConfigIntegrationTests.java
Normal file → Executable file
5
spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/java/CqlTemplateConfigIntegrationTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.config.java;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -79,6 +78,6 @@ public class CqlTemplateConfigIntegrationTests extends AbstractEmbeddedCassandra
|
||||
public void test() {
|
||||
|
||||
CqlTemplate cqlTemplate = context.getBean(CqlTemplate.class);
|
||||
assertThat(cqlTemplate.describeRing().size(), is(greaterThan(0)));
|
||||
assertThat(cqlTemplate.describeRing()).isNotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.config.java;
|
||||
|
||||
import org.junit.Assert;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.test.integration.config.IntegrationTestUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -28,7 +29,7 @@ public class KeyspaceCreatingJavaConfigIntegrationTests extends AbstractIntegrat
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Assert.assertNotNull(session);
|
||||
assertThat(session).isNotNull();
|
||||
IntegrationTestUtils.assertKeyspaceExists(KeyspaceCreatingJavaConfig.KEYSPACE_NAME, session);
|
||||
|
||||
session.execute("DROP KEYSPACE " + KeyspaceCreatingJavaConfig.KEYSPACE_NAME + ";");
|
||||
|
||||
5
spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigIntegrationTests.java
Normal file → Executable file
5
spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/MinimalXmlConfigIntegrationTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.config.xml;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -63,6 +62,6 @@ public class MinimalXmlConfigIntegrationTests extends AbstractEmbeddedCassandraI
|
||||
IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, session);
|
||||
|
||||
CqlOperations cqlOperations = context.getBean(CqlOperations.class);
|
||||
assertThat(cqlOperations.describeRing().size(), is(greaterThan(0)));
|
||||
assertThat(cqlOperations.describeRing()).isNotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.config.xml;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -55,7 +54,7 @@ public class PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests
|
||||
IntegrationTestUtils.assertSession(session);
|
||||
IntegrationTestUtils.assertKeyspaceExists("ppncxct", session);
|
||||
|
||||
assertNotNull(ops);
|
||||
assertThat(ops).isNotNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,17 +65,17 @@ public class PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests
|
||||
|
||||
PoolingOptions poolingOptions = cassandraCluster.getConfiguration().getPoolingOptions();
|
||||
|
||||
assertThat(poolingOptions, is(notNullValue(PoolingOptions.class)));
|
||||
assertThat(poolingOptions.getHeartbeatIntervalSeconds(), is(equalTo(60)));
|
||||
assertThat(poolingOptions.getIdleTimeoutSeconds(), is(equalTo(180)));
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL), is(equalTo(4)));
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL), is(equalTo(8)));
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.LOCAL), is(equalTo(20)));
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.LOCAL), is(equalTo(10)));
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.REMOTE), is(equalTo(2)));
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.REMOTE), is(equalTo(4)));
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE), is(equalTo(10)));
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.REMOTE), is(equalTo(5)));
|
||||
assertThat(poolingOptions).isNotNull();
|
||||
assertThat(poolingOptions.getHeartbeatIntervalSeconds()).isEqualTo(60);
|
||||
assertThat(poolingOptions.getIdleTimeoutSeconds()).isEqualTo(180);
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(4);
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(8);
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.LOCAL)).isEqualTo(20);
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.LOCAL)).isEqualTo(10);
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.REMOTE)).isEqualTo(2);
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.REMOTE)).isEqualTo(4);
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE)).isEqualTo(10);
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.REMOTE)).isEqualTo(5);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,14 +86,14 @@ public class PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests
|
||||
|
||||
SocketOptions socketOptions = cassandraCluster.getConfiguration().getSocketOptions();
|
||||
|
||||
assertThat(socketOptions, is(notNullValue(SocketOptions.class)));
|
||||
assertThat(socketOptions.getConnectTimeoutMillis(), is(equalTo(15000)));
|
||||
assertThat(socketOptions.getKeepAlive(), is(true));
|
||||
assertThat(socketOptions.getReadTimeoutMillis(), is(equalTo(60000)));
|
||||
assertThat(socketOptions.getReceiveBufferSize(), is(equalTo(1024)));
|
||||
assertThat(socketOptions.getReuseAddress(), is(true));
|
||||
assertThat(socketOptions.getSendBufferSize(), is(equalTo(2048)));
|
||||
assertThat(socketOptions.getSoLinger(), is(equalTo(5)));
|
||||
assertThat(socketOptions.getTcpNoDelay(), is(false));
|
||||
assertThat(socketOptions).isNotNull();
|
||||
assertThat(socketOptions.getConnectTimeoutMillis()).isEqualTo(15000);
|
||||
assertThat(socketOptions.getKeepAlive()).isTrue();
|
||||
assertThat(socketOptions.getReadTimeoutMillis()).isEqualTo(60000);
|
||||
assertThat(socketOptions.getReceiveBufferSize()).isEqualTo(1024);
|
||||
assertThat(socketOptions.getReuseAddress()).isTrue();
|
||||
assertThat(socketOptions.getSendBufferSize()).isEqualTo(2048);
|
||||
assertThat(socketOptions.getSoLinger()).isEqualTo(5);
|
||||
assertThat(socketOptions.getTcpNoDelay()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ import com.datastax.driver.core.LatencyTracker;
|
||||
import com.datastax.driver.core.Statement;
|
||||
|
||||
/**
|
||||
* {@link LatencyTracker} that logs latency events and their payload. This class can be considered a test dummy and is suitable for
|
||||
* mocking.
|
||||
* {@link LatencyTracker} that logs latency events and their payload. This class can be considered a test dummy and is
|
||||
* suitable for mocking.
|
||||
*
|
||||
* @author David Webb
|
||||
* @author Oliver Gierke
|
||||
|
||||
69
spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigIntegrationTests.java
Normal file → Executable file
69
spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigIntegrationTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.config.xml;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -54,8 +53,7 @@ public class XmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrat
|
||||
|
||||
public static final String KEYSPACE = "xmlconfigtest";
|
||||
|
||||
@Rule
|
||||
public KeyspaceRule keyspaceRule = new KeyspaceRule(cassandraEnvironment, KEYSPACE);
|
||||
@Rule public KeyspaceRule keyspaceRule = new KeyspaceRule(cassandraEnvironment, KEYSPACE);
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@@ -69,8 +67,7 @@ public class XmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrat
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.applicationContext = new ClassPathXmlApplicationContext(
|
||||
"XmlConfigIntegrationTests-context.xml", getClass());
|
||||
this.applicationContext = new ClassPathXmlApplicationContext("XmlConfigIntegrationTests-context.xml", getClass());
|
||||
|
||||
this.addressTranslator = applicationContext.getBean(AddressTranslator.class);
|
||||
this.cluster = applicationContext.getBean(Cluster.class);
|
||||
@@ -95,20 +92,20 @@ public class XmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrat
|
||||
|
||||
@Test
|
||||
public void clusterConfigurationIsCorrect() {
|
||||
assertThat(cluster.getConfiguration().getPolicies().getAddressTranslator(), is(equalTo(addressTranslator)));
|
||||
assertThat(cluster.getClusterName(), is(equalTo("skynet")));
|
||||
assertThat(cluster.getConfiguration().getProtocolOptions().getMaxSchemaAgreementWaitSeconds(), is(equalTo(2)));
|
||||
|
||||
assertThat(cluster.getConfiguration().getPolicies().getSpeculativeExecutionPolicy(),
|
||||
is(equalTo(speculativeExecutionPolicy)));
|
||||
|
||||
assertThat(cluster.getConfiguration().getPolicies().getTimestampGenerator(), is(equalTo(timestampGenerator)));
|
||||
assertThat(cluster.getConfiguration().getPolicies().getAddressTranslator()).isEqualTo(addressTranslator);
|
||||
assertThat(cluster.getClusterName()).isEqualTo("skynet");
|
||||
assertThat(cluster.getConfiguration().getProtocolOptions().getMaxSchemaAgreementWaitSeconds()).isEqualTo(2);
|
||||
assertThat(cluster.getConfiguration().getPolicies().getSpeculativeExecutionPolicy())
|
||||
.isEqualTo(speculativeExecutionPolicy);
|
||||
assertThat(cluster.getConfiguration().getPolicies().getTimestampGenerator()).isEqualTo(timestampGenerator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clusterBuilderConfigurerWasCalled() {
|
||||
assertThat(clusterBuilderConfigurer, is(instanceOf(TestClusterBuilderConfigurer.class)));
|
||||
assertThat(((TestClusterBuilderConfigurer) clusterBuilderConfigurer).configureCalled.get(), is(true));
|
||||
|
||||
assertThat(clusterBuilderConfigurer).isInstanceOf(TestClusterBuilderConfigurer.class);
|
||||
assertThat(((TestClusterBuilderConfigurer) clusterBuilderConfigurer).configureCalled.get()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,18 +116,18 @@ public class XmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrat
|
||||
|
||||
PoolingOptions poolingOptions = cluster.getConfiguration().getPoolingOptions();
|
||||
|
||||
assertThat(poolingOptions, is(notNullValue(PoolingOptions.class)));
|
||||
assertThat(poolingOptions.getHeartbeatIntervalSeconds(), is(equalTo(60)));
|
||||
assertThat(poolingOptions.getIdleTimeoutSeconds(), is(equalTo(300)));
|
||||
assertThat(poolingOptions.getInitializationExecutor(), is(equalTo(executor)));
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL), is(equalTo(2)));
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL), is(equalTo(8)));
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.LOCAL), is(equalTo(100)));
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.LOCAL), is(equalTo(25)));
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.REMOTE), is(equalTo(1)));
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.REMOTE), is(equalTo(2)));
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE), is(equalTo(100)));
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.REMOTE), is(equalTo(25)));
|
||||
assertThat(poolingOptions).isNotNull();
|
||||
assertThat(poolingOptions.getHeartbeatIntervalSeconds()).isEqualTo(60);
|
||||
assertThat(poolingOptions.getIdleTimeoutSeconds()).isEqualTo(300);
|
||||
assertThat(poolingOptions.getInitializationExecutor()).isEqualTo(executor);
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(2);
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(8);
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.LOCAL)).isEqualTo(100);
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.LOCAL)).isEqualTo(25);
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.REMOTE)).isEqualTo(1);
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.REMOTE)).isEqualTo(2);
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE)).isEqualTo(100);
|
||||
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.REMOTE)).isEqualTo(25);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,15 +138,15 @@ public class XmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrat
|
||||
|
||||
SocketOptions socketOptions = cluster.getConfiguration().getSocketOptions();
|
||||
|
||||
assertThat(socketOptions, is(notNullValue(SocketOptions.class)));
|
||||
assertThat(socketOptions.getConnectTimeoutMillis(), is(equalTo(5000)));
|
||||
assertThat(socketOptions.getKeepAlive(), is(true));
|
||||
assertThat(socketOptions.getReadTimeoutMillis(), is(equalTo(60000)));
|
||||
assertThat(socketOptions.getReceiveBufferSize(), is(equalTo(65536)));
|
||||
assertThat(socketOptions.getReuseAddress(), is(true));
|
||||
assertThat(socketOptions.getSendBufferSize(), is(equalTo(65536)));
|
||||
assertThat(socketOptions.getSoLinger(), is(equalTo(60)));
|
||||
assertThat(socketOptions.getTcpNoDelay(), is(true));
|
||||
assertThat(socketOptions).isNotNull();
|
||||
assertThat(socketOptions.getConnectTimeoutMillis()).isEqualTo(5000);
|
||||
assertThat(socketOptions.getKeepAlive()).isTrue();
|
||||
assertThat(socketOptions.getReadTimeoutMillis()).isEqualTo(60000);
|
||||
assertThat(socketOptions.getReceiveBufferSize()).isEqualTo(65536);
|
||||
assertThat(socketOptions.getReuseAddress()).isTrue();
|
||||
assertThat(socketOptions.getSendBufferSize()).isEqualTo(65536);
|
||||
assertThat(socketOptions.getSoLinger()).isEqualTo(60);
|
||||
assertThat(socketOptions.getTcpNoDelay()).isTrue();
|
||||
}
|
||||
|
||||
public static class TestClusterBuilderConfigurer implements ClusterBuilderConfigurer {
|
||||
|
||||
116
spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/CqlOperationsIntegrationTests.java
Normal file → Executable file
116
spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/CqlOperationsIntegrationTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.core;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
@@ -31,22 +30,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cassandra.core.ConsistencyLevel;
|
||||
import org.springframework.cassandra.core.CqlOperations;
|
||||
import org.springframework.cassandra.core.CqlTemplate;
|
||||
import org.springframework.cassandra.core.HostMapper;
|
||||
import org.springframework.cassandra.core.PreparedStatementBinder;
|
||||
import org.springframework.cassandra.core.PreparedStatementCallback;
|
||||
import org.springframework.cassandra.core.PreparedStatementCreator;
|
||||
import org.springframework.cassandra.core.QueryOptions;
|
||||
import org.springframework.cassandra.core.ResultSetExtractor;
|
||||
import org.springframework.cassandra.core.RetryPolicy;
|
||||
import org.springframework.cassandra.core.RingMember;
|
||||
import org.springframework.cassandra.core.RowCallbackHandler;
|
||||
import org.springframework.cassandra.core.RowIterator;
|
||||
import org.springframework.cassandra.core.RowMapper;
|
||||
import org.springframework.cassandra.core.SessionCallback;
|
||||
import org.springframework.cassandra.core.WriteOptions;
|
||||
import org.springframework.cassandra.core.*;
|
||||
import org.springframework.cassandra.core.keyspace.CreateTableSpecification;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@@ -106,7 +90,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
* There must be 1 node in the cluster if the embedded server is
|
||||
* running.
|
||||
*/
|
||||
assertNotNull(ring);
|
||||
assertThat(ring).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,8 +114,8 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
|
||||
});
|
||||
|
||||
assertNotNull(ring);
|
||||
assertTrue(ring.size() > 0);
|
||||
assertThat(ring).isNotNull();
|
||||
assertThat(ring.size() > 0).isTrue();
|
||||
|
||||
for (MyHost h : ring) {
|
||||
log.info("hostMapperTest Host -> " + h.someName);
|
||||
@@ -356,7 +340,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
@Override
|
||||
public Book extractData(ResultSet rs) throws DriverException, DataAccessException {
|
||||
Row r = rs.one();
|
||||
assertNotNull(r);
|
||||
assertThat(r).isNotNull();
|
||||
|
||||
Book b = rowToBook(r);
|
||||
|
||||
@@ -382,7 +366,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
@Override
|
||||
public Book extractData(ResultSet rs) throws DriverException, DataAccessException {
|
||||
Row r = rs.one();
|
||||
assertNotNull(r);
|
||||
assertThat(r).isNotNull();
|
||||
|
||||
Book b = rowToBook(r);
|
||||
|
||||
@@ -412,7 +396,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
@Override
|
||||
public Book extractData(ResultSet rs) throws DriverException, DataAccessException {
|
||||
Row r = rs.one();
|
||||
assertNotNull(r);
|
||||
assertThat(r).isNotNull();
|
||||
|
||||
Book b = rowToBook(r);
|
||||
|
||||
@@ -503,7 +487,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
@Override
|
||||
public void processRow(Row row) throws DriverException {
|
||||
|
||||
assertNotNull(row);
|
||||
assertThat(row).isNotNull();
|
||||
Book b = rowToBook(row);
|
||||
assertBook(b1, b);
|
||||
|
||||
@@ -526,14 +510,14 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
ResultSetFuture rsf = cqlTemplate.queryAsynchronously("select * from book where isbn='" + isbn + "'", options);
|
||||
ResultSet rs = rsf.getUninterruptibly();
|
||||
|
||||
assertNotNull(rs);
|
||||
assertThat(rs).isNotNull();
|
||||
|
||||
cqlTemplate.process(rs, new RowCallbackHandler() {
|
||||
|
||||
@Override
|
||||
public void processRow(Row row) throws DriverException {
|
||||
|
||||
assertNotNull(row);
|
||||
assertThat(row).isNotNull();
|
||||
Book b = rowToBook(row);
|
||||
assertBook(b1, b);
|
||||
}
|
||||
@@ -557,7 +541,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(books.size(), 3);
|
||||
assertThat(3).isEqualTo(books.size());
|
||||
assertBook(books.get(0), getBook(books.get(0).getIsbn()));
|
||||
assertBook(books.get(1), getBook(books.get(1).getIsbn()));
|
||||
assertBook(books.get(2), getBook(books.get(2).getIsbn()));
|
||||
@@ -572,7 +556,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
ResultSetFuture rsf = cqlTemplate.queryAsynchronously("select * from book where isbn in ('1234','2345','3456')");
|
||||
ResultSet rs = rsf.getUninterruptibly();
|
||||
|
||||
assertNotNull(rs);
|
||||
assertThat(rs).isNotNull();
|
||||
|
||||
List<Book> books = cqlTemplate.process(rs, new RowMapper<Book>() {
|
||||
|
||||
@@ -583,7 +567,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(books.size(), 3);
|
||||
assertThat(3).isEqualTo(books.size());
|
||||
assertBook(books.get(0), getBook(books.get(0).getIsbn()));
|
||||
assertBook(books.get(1), getBook(books.get(1).getIsbn()));
|
||||
assertBook(books.get(2), getBook(books.get(2).getIsbn()));
|
||||
@@ -602,7 +586,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(book);
|
||||
assertThat(book).isNotNull();
|
||||
assertBook(book, getBook(ISBN_NINES));
|
||||
}
|
||||
|
||||
@@ -634,7 +618,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
ResultSetFuture rsf = cqlTemplate.queryAsynchronously("select * from book where isbn in ('" + ISBN_NINES + "')");
|
||||
|
||||
ResultSet rs = rsf.getUninterruptibly();
|
||||
assertNotNull(rs);
|
||||
assertThat(rs).isNotNull();
|
||||
|
||||
Book book = cqlTemplate.processOne(rs, new RowMapper<Book>() {
|
||||
@Override
|
||||
@@ -644,7 +628,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(book);
|
||||
assertThat(book).isNotNull();
|
||||
assertBook(book, getBook(ISBN_NINES));
|
||||
}
|
||||
|
||||
@@ -654,7 +638,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
String title = cqlTemplate.queryForObject("select title from book where isbn in ('" + ISBN_NINES + "')",
|
||||
String.class);
|
||||
|
||||
assertEquals(title, TITLE_NINES);
|
||||
assertThat(TITLE_NINES).isEqualTo(title);
|
||||
|
||||
}
|
||||
|
||||
@@ -674,12 +658,12 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
.queryAsynchronously("select title from book where isbn in ('" + ISBN_NINES + "')");
|
||||
|
||||
ResultSet rs = rsf.getUninterruptibly();
|
||||
assertNotNull(rs);
|
||||
assertThat(rs).isNotNull();
|
||||
|
||||
String title = cqlTemplate.processOne(rs, String.class);
|
||||
|
||||
assertNotNull(title);
|
||||
assertEquals(title, TITLE_NINES);
|
||||
assertThat(title).isNotNull();
|
||||
assertThat(TITLE_NINES).isEqualTo(title);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -699,7 +683,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
ResultSetFuture rsf = cqlTemplate.queryAsynchronously("select * from book where isbn in ('" + ISBN_NINES + "')");
|
||||
|
||||
ResultSet rs = rsf.getUninterruptibly();
|
||||
assertNotNull(rs);
|
||||
assertThat(rs).isNotNull();
|
||||
|
||||
Map<String, Object> rsMap = cqlTemplate.processMap(rs);
|
||||
|
||||
@@ -718,8 +702,8 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
List<String> titles = cqlTemplate.queryForList("select title from book where isbn in ('1234','2345','3456')",
|
||||
String.class);
|
||||
|
||||
assertNotNull(titles);
|
||||
assertEquals(titles.size(), 3);
|
||||
assertThat(titles).isNotNull();
|
||||
assertThat(3).isEqualTo(titles.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -731,11 +715,11 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
ResultSetFuture rsf = cqlTemplate.queryAsynchronously("select * from book where isbn in ('1234','2345','3456')");
|
||||
ResultSet rs = rsf.getUninterruptibly();
|
||||
|
||||
assertNotNull(rs);
|
||||
assertThat(rs).isNotNull();
|
||||
|
||||
List<String> titles = cqlTemplate.processList(rs, String.class);
|
||||
assertNotNull(titles);
|
||||
assertEquals(titles.size(), 3);
|
||||
assertThat(titles).isNotNull();
|
||||
assertThat(3).isEqualTo(titles.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -747,7 +731,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
List<Map<String, Object>> results = cqlTemplate
|
||||
.queryForListOfMap("select * from book where isbn in ('1234','2345','3456')");
|
||||
|
||||
assertEquals(results.size(), 3);
|
||||
assertThat(3).isEqualTo(results.size());
|
||||
|
||||
}
|
||||
|
||||
@@ -761,11 +745,11 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
|
||||
ResultSet rs = rsf.getUninterruptibly();
|
||||
|
||||
assertNotNull(rs);
|
||||
assertThat(rs).isNotNull();
|
||||
|
||||
List<Map<String, Object>> results = cqlTemplate.processListOfMap(rs);
|
||||
|
||||
assertEquals(results.size(), 3);
|
||||
assertThat(3).isEqualTo(results.size());
|
||||
|
||||
}
|
||||
|
||||
@@ -783,7 +767,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(statement);
|
||||
assertThat(statement).isNotNull();
|
||||
|
||||
}
|
||||
|
||||
@@ -807,7 +791,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(statement);
|
||||
assertThat(statement).isNotNull();
|
||||
|
||||
}
|
||||
|
||||
@@ -828,7 +812,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
@Override
|
||||
public Book extractData(ResultSet rs) throws DriverException, DataAccessException {
|
||||
Row r = rs.one();
|
||||
assertNotNull(r);
|
||||
assertThat(r).isNotNull();
|
||||
|
||||
Book b = rowToBook(r);
|
||||
|
||||
@@ -891,7 +875,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
|
||||
Book b2 = getBook(isbn);
|
||||
|
||||
assertEquals(books.size(), 1);
|
||||
assertThat(1).isEqualTo(books.size());
|
||||
assertBook(books.get(0), b2);
|
||||
}
|
||||
|
||||
@@ -923,7 +907,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(books.size() > 0);
|
||||
assertThat(books.size() > 0).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -971,7 +955,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(books.size() > 0);
|
||||
assertThat(books.size() > 0).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1008,7 +992,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
|
||||
Book b2 = getBook(isbn);
|
||||
|
||||
assertEquals(books.size(), 1);
|
||||
assertThat(1).isEqualTo(books.size());
|
||||
assertBook(books.get(0), b2);
|
||||
}
|
||||
|
||||
@@ -1070,7 +1054,7 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
|
||||
Book b2 = getBook(isbn);
|
||||
|
||||
assertEquals(books.size(), 1);
|
||||
assertThat(1).isEqualTo(books.size());
|
||||
assertBook(books.get(0), b2);
|
||||
}
|
||||
|
||||
@@ -1102,13 +1086,13 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
|
||||
ResultSet oneByOneResultSet = cqlTemplate.query(cql, QueryOptions.builder().fetchSize(1).build());
|
||||
|
||||
assertThat(oneByOneResultSet.isFullyFetched(), is(false));
|
||||
assertThat(oneByOneResultSet.getAvailableWithoutFetching(), is(1));
|
||||
assertThat(oneByOneResultSet.isFullyFetched()).isFalse();
|
||||
assertThat(oneByOneResultSet.getAvailableWithoutFetching()).isEqualTo(1);
|
||||
|
||||
ResultSet fullResultSet = cqlTemplate.query(cql, QueryOptions.builder().fetchSize(10).build());
|
||||
|
||||
assertThat(fullResultSet.isFullyFetched(), is(true));
|
||||
assertThat(fullResultSet.getAvailableWithoutFetching(), is(4));
|
||||
assertThat(fullResultSet.isFullyFetched()).isTrue();
|
||||
assertThat(fullResultSet.getAvailableWithoutFetching()).isEqualTo(4);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1119,10 +1103,10 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
*/
|
||||
private void assertBook(Book b, Object... orderedElements) {
|
||||
|
||||
assertEquals(b.getIsbn(), orderedElements[0]);
|
||||
assertEquals(b.getTitle(), orderedElements[1]);
|
||||
assertEquals(b.getAuthor(), orderedElements[2]);
|
||||
assertEquals(b.getPages(), orderedElements[3]);
|
||||
assertThat(orderedElements[0]).isEqualTo(b.getIsbn());
|
||||
assertThat(orderedElements[1]).isEqualTo(b.getTitle());
|
||||
assertThat(orderedElements[2]).isEqualTo(b.getAuthor());
|
||||
assertThat(orderedElements[3]).isEqualTo(b.getPages());
|
||||
|
||||
}
|
||||
|
||||
@@ -1158,10 +1142,10 @@ public class CqlOperationsIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
*/
|
||||
public static void assertBook(Book b1, Book b2) {
|
||||
|
||||
assertEquals(b1.getIsbn(), b2.getIsbn());
|
||||
assertEquals(b1.getTitle(), b2.getTitle());
|
||||
assertEquals(b1.getAuthor(), b2.getAuthor());
|
||||
assertEquals(b1.getPages(), b2.getPages());
|
||||
assertThat(b2.getIsbn()).isEqualTo(b1.getIsbn());
|
||||
assertThat(b2.getTitle()).isEqualTo(b1.getTitle());
|
||||
assertThat(b2.getAuthor()).isEqualTo(b1.getAuthor());
|
||||
assertThat(b2.getPages()).isEqualTo(b1.getPages());
|
||||
|
||||
}
|
||||
|
||||
|
||||
28
spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/AsynchronousCqlOperationsIntegrationTests.java
Normal file → Executable file
28
spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/async/AsynchronousCqlOperationsIntegrationTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.core.async;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.cassandra.core.keyspace.CreateTableSpecification.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -29,22 +29,13 @@ import java.util.concurrent.CancellationException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.core.AsynchronousQueryListener;
|
||||
import org.springframework.cassandra.core.Cancellable;
|
||||
import org.springframework.cassandra.core.ConsistencyLevel;
|
||||
import org.springframework.cassandra.core.CqlOperations;
|
||||
import org.springframework.cassandra.core.CqlTemplate;
|
||||
import org.springframework.cassandra.core.QueryForListOfMapListener;
|
||||
import org.springframework.cassandra.core.QueryForMapListener;
|
||||
import org.springframework.cassandra.core.QueryForObjectListener;
|
||||
import org.springframework.cassandra.core.QueryOptions;
|
||||
import org.springframework.cassandra.core.RetryPolicy;
|
||||
import org.springframework.cassandra.core.*;
|
||||
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
import org.springframework.cassandra.test.integration.support.QueryListener;
|
||||
import org.springframework.cassandra.test.integration.support.ListOfMapListener;
|
||||
import org.springframework.cassandra.test.integration.support.MapListener;
|
||||
import org.springframework.cassandra.test.integration.support.ObjectListener;
|
||||
import org.springframework.cassandra.test.integration.support.QueryListener;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -113,8 +104,8 @@ public class AsynchronousCqlOperationsIntegrationTests extends AbstractKeyspaceC
|
||||
|
||||
public static void assertMapEquals(Map<?, ?> expected, Map<?, ?> actual) {
|
||||
for (Object key : expected.keySet()) {
|
||||
assertTrue(actual.containsKey(key));
|
||||
assertEquals(expected.get(key), actual.get(key));
|
||||
assertThat(actual.containsKey(key)).isTrue();
|
||||
assertThat(actual.get(key)).isEqualTo(expected.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,8 +124,8 @@ public class AsynchronousCqlOperationsIntegrationTests extends AbstractKeyspaceC
|
||||
}
|
||||
|
||||
void assertBook(Book expected, Book actual) {
|
||||
assertEquals(expected.isbn, actual.isbn);
|
||||
assertEquals(expected.title, actual.title);
|
||||
assertThat(actual.isbn).isEqualTo(expected.isbn);
|
||||
assertThat(actual.title).isEqualTo(expected.title);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,7 +173,7 @@ public class AsynchronousCqlOperationsIntegrationTests extends AbstractKeyspaceC
|
||||
if (listener.getException() != null) {
|
||||
throw listener.getException();
|
||||
}
|
||||
assertEquals(expected, listener.getResult());
|
||||
assertThat(listener.getResult()).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +204,8 @@ public class AsynchronousCqlOperationsIntegrationTests extends AbstractKeyspaceC
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that test {@link QueryForMapListener} should create an anonymous subclass of this class then call or {@link #test(int)}
|
||||
* Tests that test {@link QueryForMapListener} should create an anonymous subclass of this class then call or
|
||||
* {@link #test(int)}
|
||||
*/
|
||||
abstract class QueryForListListenerTestTemplate {
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.core.cql.generator;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.IndexDescriptor;
|
||||
|
||||
@@ -44,8 +43,8 @@ public class CqlIndexSpecificationAssertions {
|
||||
|
||||
IndexMetadata indexMetadata = tableMetadata.getIndex(expected.getName().toCql());
|
||||
|
||||
assertThat(indexMetadata, is(not(nullValue())));
|
||||
assertThat(indexMetadata.getName(), is(equalTo(expected.getName().toCql())));
|
||||
assertThat(indexMetadata).isNotNull();
|
||||
assertThat(indexMetadata.getName()).isEqualTo(expected.getName().toCql());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,6 +60,6 @@ public class CqlIndexSpecificationAssertions {
|
||||
|
||||
IndexMetadata indexMetadata = tableMetadata.getIndex(expected.getName().toCql());
|
||||
|
||||
assertThat(indexMetadata, is(nullValue()));
|
||||
assertThat(indexMetadata).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.core.cql.generator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -34,17 +34,17 @@ public class CqlKeyspaceSpecificationAssertions {
|
||||
public static void assertKeyspace(KeyspaceDescriptor expected, String keyspace, Session session) {
|
||||
KeyspaceMetadata kmd = session.getCluster().getMetadata().getKeyspace(keyspace.toLowerCase());
|
||||
|
||||
assertEquals(expected.getName(), kmd.getName());
|
||||
assertThat(expected.getName()).isEqualTo(kmd.getName());
|
||||
|
||||
Map<String, String> options = kmd.getReplication();
|
||||
Map<String, Object> expectedOptions = expected.getOptions();
|
||||
Map<Option, Object> replicationMap = (Map<Option, Object>) expectedOptions.get("replication");
|
||||
assertEquals(replicationMap.size(), options.size());
|
||||
assertThat(replicationMap).hasSameSizeAs(options);
|
||||
|
||||
for (Map.Entry<Option, Object> optionEntry : replicationMap.entrySet()) {
|
||||
String optionValue = options.get(optionEntry.getKey().getName());
|
||||
String repMapValue = "" + optionEntry.getValue();
|
||||
assertTrue(optionValue.endsWith(repMapValue));
|
||||
assertThat(optionValue).endsWith(repMapValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.core.cql.generator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -49,7 +49,7 @@ public class CqlTableSpecificationAssertions {
|
||||
TableMetadata tmd = session.getCluster().getMetadata().getKeyspace(keyspace.toLowerCase())
|
||||
.getTable(expected.getName().getUnquoted()); // TODO: talk to Datastax about unquoting
|
||||
|
||||
assertEquals(expected.getName().getUnquoted(), tmd.getName()); // TODO: talk to Datastax
|
||||
assertThat(expected.getName().getUnquoted()).isEqualTo(tmd.getName()); // TODO: talk to Datastax
|
||||
assertPartitionKeyColumns(expected, tmd);
|
||||
assertPrimaryKeyColumns(expected, tmd);
|
||||
assertColumns(expected.getColumns(), tmd.getColumns());
|
||||
@@ -60,7 +60,7 @@ public class CqlTableSpecificationAssertions {
|
||||
TableMetadata tmd = session.getCluster().getMetadata().getKeyspace(keyspace.toLowerCase())
|
||||
.getTable(expected.getName().toCql());
|
||||
|
||||
assertNull(tmd);
|
||||
assertThat(tmd).isNull();
|
||||
}
|
||||
|
||||
public static void assertPartitionKeyColumns(TableDescriptor expected, TableMetadata actual) {
|
||||
@@ -101,7 +101,7 @@ public class CqlTableSpecificationAssertions {
|
||||
case BLOOM_FILTER_FP_CHANCE:
|
||||
case READ_REPAIR_CHANCE:
|
||||
case DCLOCAL_READ_REPAIR_CHANCE:
|
||||
assertEquals((Double) expected, (Double) actual, DELTA);
|
||||
assertThat((Double) expected).isCloseTo((Double) actual, offset(DELTA));
|
||||
return;
|
||||
|
||||
case CACHING:
|
||||
@@ -119,8 +119,9 @@ public class CqlTableSpecificationAssertions {
|
||||
|
||||
log.info(actual.getClass().getName());
|
||||
|
||||
assertEquals(expected,
|
||||
tableOption.quotesValue() && !(actual instanceof CharSequence) ? CqlStringUtils.singleQuote(actual) : actual);
|
||||
assertThat(
|
||||
tableOption.quotesValue() && !(actual instanceof CharSequence) ? CqlStringUtils.singleQuote(actual) : actual)
|
||||
.isEqualTo(expected);
|
||||
}
|
||||
|
||||
public static void assertCaching(Map<String, Object> expected, Map<String, String> actual) {
|
||||
@@ -178,7 +179,7 @@ public class CqlTableSpecificationAssertions {
|
||||
}
|
||||
|
||||
public static void assertColumn(ColumnSpecification expected, ColumnMetadata actual) {
|
||||
assertEquals(expected.getName().toCql(), actual.getName()); // TODO: expected.getName().getUnquoted()?
|
||||
assertEquals(expected.getType(), actual.getType());
|
||||
assertThat(expected.getName().toCql()).isEqualTo(actual.getName()); // TODO: expected.getName().getUnquoted()?
|
||||
assertThat(expected.getType()).isEqualTo(actual.getType());
|
||||
}
|
||||
}
|
||||
|
||||
4
spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableLifecycleIntegrationTests.java
Normal file → Executable file
4
spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableLifecycleIntegrationTests.java
Normal file → Executable file
@@ -38,8 +38,7 @@ public class TableLifecycleIntegrationTests extends AbstractKeyspaceCreatingInte
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(TableLifecycleIntegrationTests.class);
|
||||
|
||||
CreateTableCqlGeneratorUnitTests.MultipleOptionsTest createTableTest =
|
||||
new CreateTableCqlGeneratorUnitTests.MultipleOptionsTest();
|
||||
CreateTableCqlGeneratorUnitTests.MultipleOptionsTest createTableTest = new CreateTableCqlGeneratorUnitTests.MultipleOptionsTest();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -67,7 +66,6 @@ public class TableLifecycleIntegrationTests extends AbstractKeyspaceCreatingInte
|
||||
assertNoTable(dropTest.specification, keyspace, session);
|
||||
}
|
||||
|
||||
|
||||
public class DropTableTest extends DropTableCqlGeneratorUnitTests.DropTableTest {
|
||||
|
||||
@Override
|
||||
|
||||
0
spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableOptionsIntegrationTests.java
Normal file → Executable file
0
spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableOptionsIntegrationTests.java
Normal file → Executable file
@@ -33,8 +33,7 @@ public class ListListener<T> extends CallbackSynchronizationSupport implements Q
|
||||
/**
|
||||
* Allow instances only using {@link #create()}
|
||||
*/
|
||||
private ListListener() {
|
||||
}
|
||||
private ListListener() {}
|
||||
|
||||
/**
|
||||
* @return a new {@link QueryForListListener}.
|
||||
|
||||
@@ -36,8 +36,7 @@ public class ListOfMapListener extends CallbackSynchronizationSupport implements
|
||||
/**
|
||||
* Allow instances only using {@link #create()}
|
||||
*/
|
||||
private ListOfMapListener() {
|
||||
}
|
||||
private ListOfMapListener() {}
|
||||
|
||||
/**
|
||||
* @return a new {@link QueryForListListener}.
|
||||
|
||||
@@ -33,8 +33,7 @@ public class MapListener extends CallbackSynchronizationSupport implements Query
|
||||
/**
|
||||
* Allow instances only using {@link #create()}
|
||||
*/
|
||||
private MapListener() {
|
||||
}
|
||||
private MapListener() {}
|
||||
|
||||
/**
|
||||
* @return a new {@link MapListener}.
|
||||
|
||||
@@ -32,8 +32,7 @@ public class ObjectListener<T> extends CallbackSynchronizationSupport implements
|
||||
/**
|
||||
* Allow instances only using {@link #create()}
|
||||
*/
|
||||
private ObjectListener() {
|
||||
}
|
||||
private ObjectListener() {}
|
||||
|
||||
/**
|
||||
* @return a new {@link ObjectListener}.
|
||||
|
||||
@@ -33,8 +33,7 @@ public class QueryListener extends CallbackSynchronizationSupport implements Asy
|
||||
/**
|
||||
* Allow instances only using {@link #create()}
|
||||
*/
|
||||
private QueryListener() {
|
||||
}
|
||||
private QueryListener() {}
|
||||
|
||||
/**
|
||||
* @return a new {@link QueryListener}.
|
||||
|
||||
Reference in New Issue
Block a user