DATACASS-333 - Switch tests to AssertJ.
This commit is contained in:
14
pom.xml
14
pom.xml
@@ -77,6 +77,7 @@
|
||||
<multithreadedtc.version>1.01</multithreadedtc.version>
|
||||
<project.type>multi</project.type>
|
||||
<springdata.commons>1.13.0.BUILD-SNAPSHOT</springdata.commons>
|
||||
<assertj>3.5.2</assertj>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
@@ -202,6 +203,13 @@
|
||||
<version>${multithreadedtc.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
@@ -210,6 +218,12 @@
|
||||
<groupId>com.datastax.cassandra</groupId>
|
||||
<artifactId>cassandra-driver-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
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}.
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra;
|
||||
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
|
||||
82
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/config/CassandraSessionFactoryBeanUnitTests.java
Normal file → Executable file
82
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/config/CassandraSessionFactoryBeanUnitTests.java
Normal file → Executable file
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.data.cassandra.config;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@@ -61,17 +60,13 @@ import com.datastax.driver.core.TableMetadata;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CassandraSessionFactoryBeanUnitTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
@Rule public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private CassandraConverter mockConverter;
|
||||
@Mock private CassandraConverter mockConverter;
|
||||
|
||||
@Mock
|
||||
private Cluster mockCluster;
|
||||
@Mock private Cluster mockCluster;
|
||||
|
||||
@Mock
|
||||
private Session mockSession;
|
||||
@Mock private Session mockSession;
|
||||
|
||||
private CassandraSessionFactoryBean factoryBean;
|
||||
|
||||
@@ -93,7 +88,7 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||
assertThat(factoryBean.getSchemaAction(), is(equalTo(SchemaAction.RECREATE)));
|
||||
assertThat(factoryBean.getSchemaAction()).isEqualTo(SchemaAction.RECREATE);
|
||||
return null;
|
||||
}
|
||||
}).when(factoryBean).performSchemaAction();
|
||||
@@ -101,13 +96,13 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
factoryBean.setConverter(mockConverter);
|
||||
factoryBean.setSchemaAction(SchemaAction.RECREATE);
|
||||
|
||||
assertThat(factoryBean.getConverter(), is(equalTo(mockConverter)));
|
||||
assertThat(factoryBean.getSchemaAction(), is(equalTo(SchemaAction.RECREATE)));
|
||||
assertThat(factoryBean.getConverter()).isEqualTo(mockConverter);
|
||||
assertThat(factoryBean.getSchemaAction()).isEqualTo(SchemaAction.RECREATE);
|
||||
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
assertThat(factoryBean.getCassandraAdminOperations(), is(notNullValue(CassandraAdminOperations.class)));
|
||||
assertThat(factoryBean.getObject(), is(equalTo(mockSession)));
|
||||
assertThat(factoryBean.getCassandraAdminOperations()).isNotNull();
|
||||
assertThat(factoryBean.getObject()).isEqualTo(mockSession);
|
||||
|
||||
verify(factoryBean, times(1)).performSchemaAction();
|
||||
}
|
||||
@@ -115,7 +110,6 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
@Test
|
||||
public void afterPropertiesSetThrowsIllegalStateExceptionWhenConverterIsNull() throws Exception {
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("Converter was not properly initialized");
|
||||
|
||||
factoryBean.setCluster(mockCluster);
|
||||
@@ -128,16 +122,16 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||
assertThat(invocationOnMock.getArgumentAt(0, Boolean.class), is(equalTo(dropTables)));
|
||||
assertThat(invocationOnMock.getArgumentAt(1, Boolean.class), is(equalTo(dropUnused)));
|
||||
assertThat(invocationOnMock.getArgumentAt(2, Boolean.class), is(equalTo(ifNotExists)));
|
||||
assertThat(invocationOnMock.getArgumentAt(0, Boolean.class)).isEqualTo(dropTables);
|
||||
assertThat(invocationOnMock.getArgumentAt(1, Boolean.class)).isEqualTo(dropUnused);
|
||||
assertThat(invocationOnMock.getArgumentAt(2, Boolean.class)).isEqualTo(ifNotExists);
|
||||
return null;
|
||||
}
|
||||
}).when(factoryBean).createTables(anyBoolean(), anyBoolean(), anyBoolean());
|
||||
|
||||
factoryBean.setSchemaAction(schemaAction);
|
||||
|
||||
assertThat(factoryBean.getSchemaAction(), is(equalTo(schemaAction)));
|
||||
assertThat(factoryBean.getSchemaAction()).isEqualTo(schemaAction);
|
||||
|
||||
factoryBean.performSchemaAction();
|
||||
|
||||
@@ -146,26 +140,26 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
|
||||
@Test
|
||||
public void performsSchemaActionCreatesTablesWithDefaults() {
|
||||
performSchemaActionCallsCreateTableWithArgumentsMatchingTheSchemaAction(SchemaAction.CREATE,
|
||||
DEFAULT_DROP_TABLES, DEFAULT_DROP_UNUSED_TABLES, DEFAULT_CREATE_IF_NOT_EXISTS);
|
||||
performSchemaActionCallsCreateTableWithArgumentsMatchingTheSchemaAction(SchemaAction.CREATE, DEFAULT_DROP_TABLES,
|
||||
DEFAULT_DROP_UNUSED_TABLES, DEFAULT_CREATE_IF_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performsSchemaActionCreatesTablesIfNotExists() {
|
||||
performSchemaActionCallsCreateTableWithArgumentsMatchingTheSchemaAction(SchemaAction.CREATE_IF_NOT_EXISTS,
|
||||
DEFAULT_DROP_TABLES, DEFAULT_DROP_UNUSED_TABLES, true);
|
||||
DEFAULT_DROP_TABLES, DEFAULT_DROP_UNUSED_TABLES, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performsSchemaActionRecreatesTables() {
|
||||
performSchemaActionCallsCreateTableWithArgumentsMatchingTheSchemaAction(SchemaAction.RECREATE, true,
|
||||
DEFAULT_DROP_UNUSED_TABLES, DEFAULT_CREATE_IF_NOT_EXISTS);
|
||||
DEFAULT_DROP_UNUSED_TABLES, DEFAULT_CREATE_IF_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performsSchemaActionRecreatesAndDropsUnusedTables() {
|
||||
performSchemaActionCallsCreateTableWithArgumentsMatchingTheSchemaAction(SchemaAction.RECREATE_DROP_UNUSED,
|
||||
true, true, DEFAULT_CREATE_IF_NOT_EXISTS);
|
||||
performSchemaActionCallsCreateTableWithArgumentsMatchingTheSchemaAction(SchemaAction.RECREATE_DROP_UNUSED, true,
|
||||
true, DEFAULT_CREATE_IF_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,7 +174,7 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
|
||||
factoryBean.setSchemaAction(SchemaAction.NONE);
|
||||
|
||||
assertThat(factoryBean.getSchemaAction(), is(equalTo(SchemaAction.NONE)));
|
||||
assertThat(factoryBean.getSchemaAction()).isEqualTo(SchemaAction.NONE);
|
||||
|
||||
factoryBean.performSchemaAction();
|
||||
|
||||
@@ -200,17 +194,17 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
doReturn(mockSession).when(factoryBean).getObject();
|
||||
when(mockCluster.getMetadata()).thenReturn(mockMetadata);
|
||||
when(mockMetadata.getKeyspace(eq("TestKeyspace"))).thenReturn(mockKeyspaceMetadata);
|
||||
when(mockKeyspaceMetadata.getTables()).thenReturn(Collections.<TableMetadata>emptyList());
|
||||
when(mockKeyspaceMetadata.getTables()).thenReturn(Collections.<TableMetadata> emptyList());
|
||||
when(mockConverter.getMappingContext()).thenReturn(mockMappingContext);
|
||||
when(mockMappingContext.getNonPrimaryKeyEntities()).thenReturn(
|
||||
Collections.<CassandraPersistentEntity<?>>singletonList(mockPersistentEntity));
|
||||
when(mockMappingContext.getNonPrimaryKeyEntities())
|
||||
.thenReturn(Collections.<CassandraPersistentEntity<?>> singletonList(mockPersistentEntity));
|
||||
when(mockPersistentEntity.getTableName()).thenReturn(newCqlIdentifier("TestTable"));
|
||||
when(mockPersistentEntity.getType()).thenReturn(Person.class);
|
||||
|
||||
factoryBean.setConverter(mockConverter);
|
||||
factoryBean.setKeyspaceName("TestKeyspace");
|
||||
|
||||
assertThat(factoryBean.getConverter(), is(equalTo(mockConverter)));
|
||||
assertThat(factoryBean.getConverter()).isEqualTo(mockConverter);
|
||||
|
||||
factoryBean.createTables(true, false, false);
|
||||
|
||||
@@ -223,7 +217,7 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
verify(mockPersistentEntity, times(1)).getTableName();
|
||||
verify(mockPersistentEntity, times(1)).getType();
|
||||
verify(mockCassandraAdminOperations, times(1)).createTable(eq(false), eq(newCqlIdentifier("TestTable")),
|
||||
eq(Person.class), isNull(Map.class));
|
||||
eq(Person.class), isNull(Map.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -236,15 +230,15 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
doReturn(mockCassandraAdminOperations).when(factoryBean).getCassandraAdminOperations();
|
||||
doReturn(mockSession).when(factoryBean).getObject();
|
||||
when(mockConverter.getMappingContext()).thenReturn(mockMappingContext);
|
||||
when(mockMappingContext.getNonPrimaryKeyEntities()).thenReturn(
|
||||
Collections.<CassandraPersistentEntity<?>>singletonList(mockPersistentEntity));
|
||||
when(mockMappingContext.getNonPrimaryKeyEntities())
|
||||
.thenReturn(Collections.<CassandraPersistentEntity<?>> singletonList(mockPersistentEntity));
|
||||
when(mockPersistentEntity.getTableName()).thenReturn(newCqlIdentifier("TestTable"));
|
||||
when(mockPersistentEntity.getType()).thenReturn(Person.class);
|
||||
|
||||
factoryBean.setConverter(mockConverter);
|
||||
factoryBean.setKeyspaceName("TestKeyspace");
|
||||
|
||||
assertThat(factoryBean.getConverter(), is(equalTo(mockConverter)));
|
||||
assertThat(factoryBean.getConverter()).isEqualTo(mockConverter);
|
||||
|
||||
factoryBean.createTables(false, false, true);
|
||||
|
||||
@@ -255,7 +249,7 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
verify(mockPersistentEntity, times(1)).getTableName();
|
||||
verify(mockPersistentEntity, times(1)).getType();
|
||||
verify(mockCassandraAdminOperations, times(1)).createTable(eq(true), eq(newCqlIdentifier("TestTable")),
|
||||
eq(Person.class), isNull(Map.class));
|
||||
eq(Person.class), isNull(Map.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -267,7 +261,6 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
when(mockMetadata.getKeyspace(anyString())).thenReturn(null);
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("keyspace [TestKeyspace] does not exist");
|
||||
|
||||
factoryBean.setKeyspaceName("TestKeyspace");
|
||||
@@ -283,16 +276,15 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
|
||||
@Test
|
||||
public void setAndGetConverter() {
|
||||
assertThat(factoryBean.getConverter(), is(nullValue()));
|
||||
assertThat(factoryBean.getConverter()).isNull();
|
||||
factoryBean.setConverter(mockConverter);
|
||||
assertThat(factoryBean.getConverter(), is(equalTo(mockConverter)));
|
||||
assertThat(factoryBean.getConverter()).isEqualTo(mockConverter);
|
||||
verifyZeroInteractions(mockConverter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setConverterToNull() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("CassandraConverter must not be null");
|
||||
|
||||
factoryBean.setConverter(null);
|
||||
@@ -300,23 +292,21 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
|
||||
@Test
|
||||
public void setAndGetSchemaAction() {
|
||||
assertThat(factoryBean.getSchemaAction(), is(equalTo(SchemaAction.NONE)));
|
||||
assertThat(factoryBean.getSchemaAction()).isEqualTo(SchemaAction.NONE);
|
||||
factoryBean.setSchemaAction(SchemaAction.CREATE);
|
||||
assertThat(factoryBean.getSchemaAction(), is(equalTo(SchemaAction.CREATE)));
|
||||
assertThat(factoryBean.getSchemaAction()).isEqualTo(SchemaAction.CREATE);
|
||||
factoryBean.setSchemaAction(SchemaAction.NONE);
|
||||
assertThat(factoryBean.getSchemaAction(), is(equalTo(SchemaAction.NONE)));
|
||||
assertThat(factoryBean.getSchemaAction()).isEqualTo(SchemaAction.NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSchemaActionToNullThrowsIllegalArgumentException() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("SchemaAction must not be null");
|
||||
|
||||
factoryBean.setSchemaAction(null);
|
||||
}
|
||||
|
||||
static class Person {
|
||||
}
|
||||
static class Person {}
|
||||
|
||||
}
|
||||
|
||||
32
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/config/xml/CassandraNamespaceIntegrationTests.java
Normal file → Executable file
32
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/config/xml/CassandraNamespaceIntegrationTests.java
Normal file → Executable file
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.config.xml;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -54,7 +52,7 @@ public class CassandraNamespaceIntegrationTests extends AbstractSpringDataEmbedd
|
||||
|
||||
Cluster cluster = applicationContext.getBean(Cluster.class);
|
||||
Configuration configuration = cluster.getConfiguration();
|
||||
assertThat(configuration.getProtocolOptions().getCompression(), is(Compression.SNAPPY));
|
||||
assertThat(configuration.getProtocolOptions().getCompression()).isEqualTo(Compression.SNAPPY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,14 +64,14 @@ public class CassandraNamespaceIntegrationTests extends AbstractSpringDataEmbedd
|
||||
Cluster cluster = applicationContext.getBean(Cluster.class);
|
||||
PoolingOptions poolingOptions = cluster.getConfiguration().getPoolingOptions();
|
||||
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.LOCAL), is(101));
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE), is(100));
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.LOCAL)).isEqualTo(101);
|
||||
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE)).isEqualTo(100);
|
||||
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL), is(3));
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.REMOTE), is(1));
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(3);
|
||||
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.REMOTE)).isEqualTo(1);
|
||||
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL), is(9));
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.REMOTE), is(2));
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(9);
|
||||
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.REMOTE)).isEqualTo(2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,12 +83,12 @@ public class CassandraNamespaceIntegrationTests extends AbstractSpringDataEmbedd
|
||||
Cluster cluster = applicationContext.getBean(Cluster.class);
|
||||
SocketOptions socketOptions = cluster.getConfiguration().getSocketOptions();
|
||||
|
||||
assertThat(socketOptions.getConnectTimeoutMillis(), is(5000));
|
||||
assertThat(socketOptions.getKeepAlive(), is(true));
|
||||
assertThat(socketOptions.getReuseAddress(), is(true));
|
||||
assertThat(socketOptions.getTcpNoDelay(), is(true));
|
||||
assertThat(socketOptions.getSoLinger(), is(equalTo(60)));
|
||||
assertThat(socketOptions.getReceiveBufferSize(), is(equalTo(65536)));
|
||||
assertThat(socketOptions.getSendBufferSize(), is(equalTo(65536)));
|
||||
assertThat(socketOptions.getConnectTimeoutMillis()).isEqualTo(5000);
|
||||
assertThat(socketOptions.getKeepAlive()).isTrue();
|
||||
assertThat(socketOptions.getReuseAddress()).isTrue();
|
||||
assertThat(socketOptions.getTcpNoDelay()).isTrue();
|
||||
assertThat(socketOptions.getSoLinger()).isEqualTo(60);
|
||||
assertThat(socketOptions.getReceiveBufferSize()).isEqualTo(65536);
|
||||
assertThat(socketOptions.getSendBufferSize()).isEqualTo(65536);
|
||||
}
|
||||
}
|
||||
|
||||
8
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/ColumnReaderUnitTests.java
Normal file → Executable file
8
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/ColumnReaderUnitTests.java
Normal file → Executable file
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.data.cassandra.convert;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -60,7 +60,7 @@ public class ColumnReaderUnitTests {
|
||||
underTest.get(NON_EXISTENT_COLUMN);
|
||||
fail("Expected illegal argument exception");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Column does not exist in Cassandra table: " + NON_EXISTENT_COLUMN, e.getMessage());
|
||||
assertThat(e.getMessage()).isEqualTo("Column does not exist in Cassandra table: " + NON_EXISTENT_COLUMN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ColumnReaderUnitTests {
|
||||
underTest.get(new CqlIdentifier(NON_EXISTENT_COLUMN));
|
||||
fail("Expected illegal argument exception");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Column does not exist in Cassandra table: " + NON_EXISTENT_COLUMN, e.getMessage());
|
||||
assertThat(e.getMessage()).isEqualTo("Column does not exist in Cassandra table: " + NON_EXISTENT_COLUMN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ColumnReaderUnitTests {
|
||||
underTest.get(new CqlIdentifier(NON_EXISTENT_COLUMN), String.class);
|
||||
fail("Expected illegal argument exception");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Column does not exist in Cassandra table: " + NON_EXISTENT_COLUMN, e.getMessage());
|
||||
assertThat(e.getMessage()).isEqualTo("Column does not exist in Cassandra table: " + NON_EXISTENT_COLUMN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
27
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/ConverterRegistrationUnitTests.java
Normal file → Executable file
27
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/ConverterRegistrationUnitTests.java
Normal file → Executable file
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.data.cassandra.convert;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.cassandra.domain.Person;
|
||||
@@ -36,16 +35,16 @@ public class ConverterRegistrationUnitTests {
|
||||
public void considersNotExplicitlyReadingDependingOnTypes() {
|
||||
|
||||
ConverterRegistration context = new ConverterRegistration(Person.class, String.class, false, false);
|
||||
assertThat(context.isWriting(), is(true));
|
||||
assertThat(context.isReading(), is(false));
|
||||
assertThat(context.isWriting()).isTrue();
|
||||
assertThat(context.isReading()).isFalse();
|
||||
|
||||
context = new ConverterRegistration(String.class, Person.class, false, false);
|
||||
assertThat(context.isWriting(), is(false));
|
||||
assertThat(context.isReading(), is(true));
|
||||
assertThat(context.isWriting()).isFalse();
|
||||
assertThat(context.isReading()).isTrue();
|
||||
|
||||
context = new ConverterRegistration(String.class, Class.class, false, false);
|
||||
assertThat(context.isWriting(), is(true));
|
||||
assertThat(context.isReading(), is(true));
|
||||
assertThat(context.isWriting()).isTrue();
|
||||
assertThat(context.isReading()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,12 +54,12 @@ public class ConverterRegistrationUnitTests {
|
||||
public void forcesReadWriteOnlyIfAnnotated() {
|
||||
|
||||
ConverterRegistration context = new ConverterRegistration(String.class, Class.class, false, true);
|
||||
assertThat(context.isWriting(), is(true));
|
||||
assertThat(context.isReading(), is(false));
|
||||
assertThat(context.isWriting()).isTrue();
|
||||
assertThat(context.isReading()).isFalse();
|
||||
|
||||
context = new ConverterRegistration(String.class, Class.class, true, false);
|
||||
assertThat(context.isWriting(), is(false));
|
||||
assertThat(context.isReading(), is(true));
|
||||
assertThat(context.isWriting()).isFalse();
|
||||
assertThat(context.isReading()).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +69,7 @@ public class ConverterRegistrationUnitTests {
|
||||
public void considersConverterForReadAndWriteIfBothAnnotated() {
|
||||
|
||||
ConverterRegistration context = new ConverterRegistration(String.class, Class.class, true, true);
|
||||
assertThat(context.isWriting(), is(true));
|
||||
assertThat(context.isReading(), is(true));
|
||||
assertThat(context.isWriting()).isTrue();
|
||||
assertThat(context.isReading()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
49
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/CustomConversionsUnitTests.java
Normal file → Executable file
49
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/CustomConversionsUnitTests.java
Normal file → Executable file
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.data.cassandra.convert;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.text.DateFormat;
|
||||
@@ -37,7 +36,6 @@ import org.springframework.core.convert.converter.ConverterFactory;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
import org.threeten.bp.LocalDateTime;
|
||||
|
||||
import com.datastax.driver.core.Row;
|
||||
|
||||
@@ -58,11 +56,11 @@ public class CustomConversionsUnitTests {
|
||||
CustomConversions conversions = new CustomConversions(
|
||||
Arrays.asList(FormatToStringConverter.INSTANCE, StringToFormatConverter.INSTANCE));
|
||||
|
||||
assertThat(conversions.getCustomWriteTarget(Format.class, null), is(typeCompatibleWith(String.class)));
|
||||
assertThat(conversions.getCustomWriteTarget(String.class, null), is(nullValue()));
|
||||
assertThat(conversions.getCustomWriteTarget(Format.class, null)).isAssignableFrom(String.class);
|
||||
assertThat(conversions.getCustomWriteTarget(String.class, null)).isNull();
|
||||
|
||||
assertThat(conversions.hasCustomReadTarget(String.class, Format.class), is(true));
|
||||
assertThat(conversions.hasCustomReadTarget(String.class, Locale.class), is(false));
|
||||
assertThat(conversions.hasCustomReadTarget(String.class, Format.class)).isTrue();
|
||||
assertThat(conversions.hasCustomReadTarget(String.class, Locale.class)).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,8 +72,8 @@ public class CustomConversionsUnitTests {
|
||||
CustomConversions conversions = new CustomConversions(
|
||||
Arrays.asList(NumberToStringConverter.INSTANCE, StringToNumberConverter.INSTANCE));
|
||||
|
||||
assertThat(conversions.getCustomWriteTarget(Long.class, null), is(typeCompatibleWith(String.class)));
|
||||
assertThat(conversions.hasCustomReadTarget(String.class, Long.class), is(true));
|
||||
assertThat(conversions.getCustomWriteTarget(Long.class, null)).isAssignableFrom(String.class);
|
||||
assertThat(conversions.hasCustomReadTarget(String.class, Long.class)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +83,7 @@ public class CustomConversionsUnitTests {
|
||||
public void considersTypesWeRegisteredConvertersForAsSimple() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(Arrays.asList(FormatToStringConverter.INSTANCE));
|
||||
assertThat(conversions.isSimpleType(UUID.class), is(true));
|
||||
assertThat(conversions.isSimpleType(UUID.class)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +97,7 @@ public class CustomConversionsUnitTests {
|
||||
CustomConversions conversions = new CustomConversions(Arrays.asList(StringToFormatConverter.INSTANCE));
|
||||
conversions.registerConvertersIn(conversionService);
|
||||
|
||||
assertThat(conversionService.canConvert(String.class, Format.class), is(true));
|
||||
assertThat(conversionService.canConvert(String.class, Format.class)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +107,7 @@ public class CustomConversionsUnitTests {
|
||||
public void doesNotConsiderTypeSimpleIfOnlyReadConverterIsRegistered() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(Arrays.asList(StringToFormatConverter.INSTANCE));
|
||||
assertThat(conversions.isSimpleType(Format.class), is(false));
|
||||
assertThat(conversions.isSimpleType(Format.class)).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,8 +117,8 @@ public class CustomConversionsUnitTests {
|
||||
public void discoversConvertersForSubtypesOfCassandraTypes() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(Arrays.asList(StringToIntegerConverter.INSTANCE));
|
||||
assertThat(conversions.hasCustomReadTarget(String.class, Integer.class), is(true));
|
||||
assertThat(conversions.hasCustomWriteTarget(String.class, Integer.class), is(true));
|
||||
assertThat(conversions.hasCustomReadTarget(String.class, Integer.class)).isTrue();
|
||||
assertThat(conversions.hasCustomWriteTarget(String.class, Integer.class)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,7 +128,7 @@ public class CustomConversionsUnitTests {
|
||||
public void considersUUIDASimpleType() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions();
|
||||
assertThat(conversions.isSimpleType(UUID.class), is(true));
|
||||
assertThat(conversions.isSimpleType(UUID.class)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,7 +138,7 @@ public class CustomConversionsUnitTests {
|
||||
public void considersInetAddressASimpleType() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions();
|
||||
assertThat(conversions.isSimpleType(InetAddress.class), is(true));
|
||||
assertThat(conversions.isSimpleType(InetAddress.class)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,7 +148,7 @@ public class CustomConversionsUnitTests {
|
||||
public void considersRowASimpleType() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions();
|
||||
assertThat(conversions.isSimpleType(Row.class), is(true));
|
||||
assertThat(conversions.isSimpleType(Row.class)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +159,7 @@ public class CustomConversionsUnitTests {
|
||||
public void favorsCustomConverterForIndeterminedTargetType() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(Arrays.asList(DateTimeToStringConverter.INSTANCE));
|
||||
assertThat(conversions.getCustomWriteTarget(DateTime.class, null), is(equalTo((Class) String.class)));
|
||||
assertThat(conversions.getCustomWriteTarget(DateTime.class, null)).isEqualTo((Class) String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +172,7 @@ public class CustomConversionsUnitTests {
|
||||
GenericConversionService conversionService = new DefaultConversionService();
|
||||
conversions.registerConvertersIn(conversionService);
|
||||
|
||||
assertThat(conversionService.convert(new DateTime(), Date.class), is(new Date(0)));
|
||||
assertThat(conversionService.convert(new DateTime(), Date.class)).isEqualTo(new Date(0));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,8 +182,7 @@ public class CustomConversionsUnitTests {
|
||||
public void shouldSelectPropertCustomWriteTargetForCglibProxiedType() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(Arrays.asList(FormatToStringConverter.INSTANCE));
|
||||
assertThat(conversions.getCustomWriteTarget(createProxyTypeFor(Format.class)),
|
||||
is(typeCompatibleWith(String.class)));
|
||||
assertThat(conversions.getCustomWriteTarget(createProxyTypeFor(Format.class))).isAssignableFrom(String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,7 +192,7 @@ public class CustomConversionsUnitTests {
|
||||
public void shouldSelectPropertyCustomReadTargetForCglibProxiedType() {
|
||||
|
||||
CustomConversions conversions = new CustomConversions(Arrays.asList(CustomObjectToStringConverter.INSTANCE));
|
||||
assertThat(conversions.hasCustomReadTarget(createProxyTypeFor(Object.class), String.class), is(true));
|
||||
assertThat(conversions.hasCustomReadTarget(createProxyTypeFor(Object.class), String.class)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +204,7 @@ public class CustomConversionsUnitTests {
|
||||
CustomConversions customConversions = new CustomConversions(
|
||||
Collections.singletonList(new FormatConverterFactory()));
|
||||
|
||||
assertThat(customConversions.getCustomWriteTarget(String.class, SimpleDateFormat.class), notNullValue());
|
||||
assertThat(customConversions.getCustomWriteTarget(String.class, SimpleDateFormat.class)).isNotNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +215,7 @@ public class CustomConversionsUnitTests {
|
||||
|
||||
CustomConversions customConversions = new CustomConversions();
|
||||
|
||||
assertThat(customConversions.hasCustomWriteTarget(java.time.LocalDateTime.class), is(true));
|
||||
assertThat(customConversions.hasCustomWriteTarget(java.time.LocalDateTime.class)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,7 +226,7 @@ public class CustomConversionsUnitTests {
|
||||
|
||||
CustomConversions customConversions = new CustomConversions();
|
||||
|
||||
assertThat(customConversions.hasCustomWriteTarget(org.threeten.bp.LocalDateTime.class), is(true));
|
||||
assertThat(customConversions.hasCustomWriteTarget(org.threeten.bp.LocalDateTime.class)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,7 +237,7 @@ public class CustomConversionsUnitTests {
|
||||
|
||||
CustomConversions customConversions = new CustomConversions();
|
||||
|
||||
assertThat(customConversions.hasCustomWriteTarget(org.joda.time.LocalDate.class), is(true));
|
||||
assertThat(customConversions.hasCustomWriteTarget(org.joda.time.LocalDate.class)).isTrue();
|
||||
}
|
||||
|
||||
private static Class<?> createProxyTypeFor(Class<?> type) {
|
||||
|
||||
231
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/MappingCassandraConverterUnitTests.java
Normal file → Executable file
231
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/convert/MappingCassandraConverterUnitTests.java
Normal file → Executable file
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.data.cassandra.convert;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.cassandra.RowMockUtil.*;
|
||||
@@ -98,14 +95,11 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
private static final Version VERSION_4_3 = Version.parse("4.3");
|
||||
|
||||
@Rule
|
||||
public final ExpectedException expectedException = ExpectedException.none();
|
||||
@Rule public final ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private ColumnDefinitions columnDefinitionsMock;
|
||||
@Mock private ColumnDefinitions columnDefinitionsMock;
|
||||
|
||||
@Mock
|
||||
private Row rowMock;
|
||||
@Mock private Row rowMock;
|
||||
|
||||
private CassandraMappingContext mappingContext;
|
||||
private MappingCassandraConverter mappingCassandraConverter;
|
||||
@@ -133,7 +127,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(withEnumColumns, insert);
|
||||
|
||||
assertThat(getValues(insert), hasItem((Object) "MINT"));
|
||||
assertThat(getValues(insert)).contains("MINT");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +139,6 @@ public class MappingCassandraConverterUnitTests {
|
||||
assumeTrue(Version.parse(SpringVersion.getVersion()).isLessThan(VERSION_4_3));
|
||||
|
||||
expectedException.expect(ConverterNotFoundException.class);
|
||||
expectedException.expectMessage(allOf(containsString("No converter found"), containsString("java.lang.Integer")));
|
||||
|
||||
UnsupportedEnumToOrdinalMapping unsupportedEnumToOrdinalMapping = new UnsupportedEnumToOrdinalMapping();
|
||||
unsupportedEnumToOrdinalMapping.setAsOrdinal(Condition.MINT);
|
||||
@@ -170,7 +163,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(unsupportedEnumToOrdinalMapping, insert);
|
||||
|
||||
assertThat(getValues(insert), hasItem((Object) Integer.valueOf(Condition.USED.ordinal())));
|
||||
assertThat(getValues(insert)).contains((Object) Integer.valueOf(Condition.USED.ordinal()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,7 +179,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(key, insert);
|
||||
|
||||
assertThat(getValues(insert), hasItem((Object) "MINT"));
|
||||
assertThat(getValues(insert)).contains((Object) "MINT");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,7 +198,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(composite, insert);
|
||||
|
||||
assertThat(getValues(insert), hasItem((Object) "MINT"));
|
||||
assertThat(getValues(insert)).contains((Object) "MINT");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,7 +214,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(withEnumColumns, update);
|
||||
|
||||
assertThat(getAssignmentValues(update), hasItem((Object) "MINT"));
|
||||
assertThat(getAssignmentValues(update)).contains((Object) "MINT");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,7 +230,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(key, update);
|
||||
|
||||
assertThat(getWhereValues(update), hasItem((Object) "MINT"));
|
||||
assertThat(getWhereValues(update)).contains((Object) "MINT");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +249,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(composite, update);
|
||||
|
||||
assertThat(getWhereValues(update), hasItem((Object) "MINT"));
|
||||
assertThat(getWhereValues(update)).contains((Object) "MINT");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,7 +265,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(key, where);
|
||||
|
||||
assertThat(getWhereValues(where), hasItem((Object) "MINT"));
|
||||
assertThat(getWhereValues(where)).contains((Object) "MINT");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -291,7 +284,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(composite, where);
|
||||
|
||||
assertThat(getWhereValues(where), hasItem((Object) "MINT"));
|
||||
assertThat(getWhereValues(where)).contains((Object) "MINT");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,7 +297,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
String result = mappingCassandraConverter.readRow(String.class, rowMock);
|
||||
|
||||
assertThat(result, is(equalTo("foo")));
|
||||
assertThat(result).isEqualTo("foo");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,7 +310,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
Integer result = mappingCassandraConverter.readRow(Integer.class, rowMock);
|
||||
|
||||
assertThat(result, is(equalTo(2)));
|
||||
assertThat(result).isEqualTo(2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,7 +323,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
Long result = mappingCassandraConverter.readRow(Long.class, rowMock);
|
||||
|
||||
assertThat(result, is(equalTo(2L)));
|
||||
assertThat(result).isEqualTo(2L);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -343,7 +336,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
Double result = mappingCassandraConverter.readRow(Double.class, rowMock);
|
||||
|
||||
assertThat(result, is(equalTo(2D)));
|
||||
assertThat(result).isEqualTo(2D);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -356,7 +349,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
Float result = mappingCassandraConverter.readRow(Float.class, rowMock);
|
||||
|
||||
assertThat(result, is(equalTo(2F)));
|
||||
assertThat(result).isEqualTo(2F);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -369,7 +362,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
BigInteger result = mappingCassandraConverter.readRow(BigInteger.class, rowMock);
|
||||
|
||||
assertThat(result, is(equalTo(BigInteger.valueOf(2))));
|
||||
assertThat(result).isEqualTo(BigInteger.valueOf(2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,7 +375,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
BigDecimal result = mappingCassandraConverter.readRow(BigDecimal.class, rowMock);
|
||||
|
||||
assertThat(result, is(equalTo(BigDecimal.valueOf(2))));
|
||||
assertThat(result).isEqualTo(BigDecimal.valueOf(2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -397,7 +390,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
UUID result = mappingCassandraConverter.readRow(UUID.class, rowMock);
|
||||
|
||||
assertThat(result, is(equalTo(uuid)));
|
||||
assertThat(result).isEqualTo(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -412,7 +405,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
InetAddress result = mappingCassandraConverter.readRow(InetAddress.class, rowMock);
|
||||
|
||||
assertThat(result, is(equalTo(localHost)));
|
||||
assertThat(result).isEqualTo(localHost);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -428,7 +421,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
Date result = mappingCassandraConverter.readRow(Date.class, rowMock);
|
||||
|
||||
assertThat(result, is(equalTo(date)));
|
||||
assertThat(result).isEqualTo(date);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -443,7 +436,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
LocalDate result = mappingCassandraConverter.readRow(LocalDate.class, rowMock);
|
||||
|
||||
assertThat(result, is(equalTo(date)));
|
||||
assertThat(result).isEqualTo(date);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -456,7 +449,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
Boolean result = mappingCassandraConverter.readRow(Boolean.class, rowMock);
|
||||
|
||||
assertThat(result, is(equalTo(true)));
|
||||
assertThat(result).isEqualTo(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -473,9 +466,9 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
TypeWithLocalDate result = mappingCassandraConverter.readRow(TypeWithLocalDate.class, rowMock);
|
||||
|
||||
assertThat(result.localDate, is(notNullValue()));
|
||||
assertThat(result.localDate.getYear(), is(now.getYear()));
|
||||
assertThat(result.localDate.getMonthValue(), is(now.getMonthValue()));
|
||||
assertThat(result.localDate).isNotNull();
|
||||
assertThat(result.localDate.getYear()).isEqualTo(now.getYear());
|
||||
assertThat(result.localDate.getMonthValue()).isEqualTo(now.getMonthValue());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,8 +486,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(typeWithLocalDate, insert);
|
||||
|
||||
assertThat(getValues(insert).contains(LocalDate.fromYearMonthDay(now.getYear(), now.getMonthValue(), now.getDayOfMonth())),
|
||||
is(true));
|
||||
assertThat(getValues(insert))
|
||||
.contains(LocalDate.fromYearMonthDay(now.getYear(), now.getMonthValue(), now.getDayOfMonth()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -512,8 +505,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(typeWithLocalDate, update);
|
||||
|
||||
assertThat(getAssignmentValues(update).contains(LocalDate.fromYearMonthDay(now.getYear(), now.getMonthValue(), now.getDayOfMonth())),
|
||||
is(true));
|
||||
assertThat(getAssignmentValues(update))
|
||||
.contains(LocalDate.fromYearMonthDay(now.getYear(), now.getMonthValue(), now.getDayOfMonth()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -534,9 +527,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
List<LocalDate> dates = getListValue(insert);
|
||||
|
||||
assertThat(dates, is(notNullValue(List.class)));
|
||||
assertThat(dates, hasItem(LocalDate.fromYearMonthDay(now.getYear(), now.getMonthValue(), now.getDayOfMonth())));
|
||||
assertThat(dates, hasItem(LocalDate.fromYearMonthDay(2010, 7, 4)));
|
||||
assertThat(dates).contains(LocalDate.fromYearMonthDay(now.getYear(), now.getMonthValue(), now.getDayOfMonth()));
|
||||
assertThat(dates).contains(LocalDate.fromYearMonthDay(2010, 7, 4));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -557,9 +549,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
Set<LocalDate> dates = getSetValue(insert);
|
||||
|
||||
assertThat(dates, is(notNullValue(Set.class)));
|
||||
assertThat(dates, hasItem(LocalDate.fromYearMonthDay(now.getYear(), now.getMonthValue(), now.getDayOfMonth())));
|
||||
assertThat(dates, hasItem(LocalDate.fromYearMonthDay(2010, 7, 4)));
|
||||
assertThat(dates).contains(LocalDate.fromYearMonthDay(now.getYear(), now.getMonthValue(), now.getDayOfMonth()));
|
||||
assertThat(dates).contains(LocalDate.fromYearMonthDay(2010, 7, 4));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -574,10 +565,10 @@ public class MappingCassandraConverterUnitTests {
|
||||
TypeWithLocalDateMappedToDate result = mappingCassandraConverter.readRow(TypeWithLocalDateMappedToDate.class,
|
||||
rowMock);
|
||||
|
||||
assertThat(result.localDate, is(notNullValue()));
|
||||
assertThat(result.localDate.getYear(), is(2010));
|
||||
assertThat(result.localDate.getMonthValue(), is(7));
|
||||
assertThat(result.localDate.getDayOfMonth(), is(4));
|
||||
assertThat(result.localDate).isNotNull();
|
||||
assertThat(result.localDate.getYear()).isEqualTo(2010);
|
||||
assertThat(result.localDate.getMonthValue()).isEqualTo(7);
|
||||
assertThat(result.localDate.getDayOfMonth()).isEqualTo(4);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -593,7 +584,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(typeWithLocalDate, insert);
|
||||
|
||||
assertThat(getValues(insert).contains(LocalDate.fromYearMonthDay(2010, 7, 4)), is(true));
|
||||
assertThat(getValues(insert).contains(LocalDate.fromYearMonthDay(2010, 7, 4))).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -609,7 +600,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(typeWithLocalDate, update);
|
||||
|
||||
assertThat(getAssignmentValues(update), contains((Object) LocalDate.fromYearMonthDay(2010, 7, 4)));
|
||||
assertThat(getAssignmentValues(update)).contains(LocalDate.fromYearMonthDay(2010, 7, 4));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -626,9 +617,9 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
TypeWithLocalDate result = mappingCassandraConverter.readRow(TypeWithLocalDate.class, rowMock);
|
||||
|
||||
assertThat(result.localDateTime, is(notNullValue()));
|
||||
assertThat(result.localDateTime.getYear(), is(now.getYear()));
|
||||
assertThat(result.localDateTime.getMinute(), is(now.getMinute()));
|
||||
assertThat(result.localDateTime).isNotNull();
|
||||
assertThat(result.localDateTime.getYear()).isEqualTo(now.getYear());
|
||||
assertThat(result.localDateTime.getMinute()).isEqualTo(now.getMinute());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -645,8 +636,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
TypeWithInstant result = mappingCassandraConverter.readRow(TypeWithInstant.class, rowMock);
|
||||
|
||||
assertThat(result.instant, is(notNullValue()));
|
||||
assertThat(result.instant.getEpochSecond(), is(instant.getEpochSecond()));
|
||||
assertThat(result.instant).isNotNull();
|
||||
assertThat(result.instant.getEpochSecond()).isEqualTo(instant.getEpochSecond());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -660,8 +651,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
TypeWithZoneId result = mappingCassandraConverter.readRow(TypeWithZoneId.class, rowMock);
|
||||
|
||||
assertThat(result.zoneId, is(notNullValue()));
|
||||
assertThat(result.zoneId.getId(), is(equalTo("Europe/Paris")));
|
||||
assertThat(result.zoneId).isNotNull();
|
||||
assertThat(result.zoneId.getId()).isEqualTo("Europe/Paris");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -673,13 +664,13 @@ public class MappingCassandraConverterUnitTests {
|
||||
Row rowMock = RowMockUtil.newRowMock(column("id", "my-id", DataType.ascii()),
|
||||
column("localDate", LocalDate.fromYearMonthDay(2010, 7, 4), DataType.date()));
|
||||
|
||||
TypeWithJodaLocalDateMappedToDate result =
|
||||
mappingCassandraConverter.readRow(TypeWithJodaLocalDateMappedToDate.class, rowMock);
|
||||
TypeWithJodaLocalDateMappedToDate result = mappingCassandraConverter
|
||||
.readRow(TypeWithJodaLocalDateMappedToDate.class, rowMock);
|
||||
|
||||
assertThat(result.localDate, is(notNullValue()));
|
||||
assertThat(result.localDate.getYear(), is(2010));
|
||||
assertThat(result.localDate.getMonthOfYear(), is(7));
|
||||
assertThat(result.localDate.getDayOfMonth(), is(4));
|
||||
assertThat(result.localDate).isNotNull();
|
||||
assertThat(result.localDate.getYear()).isEqualTo(2010);
|
||||
assertThat(result.localDate.getMonthOfYear()).isEqualTo(7);
|
||||
assertThat(result.localDate.getDayOfMonth()).isEqualTo(4);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -695,7 +686,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(typeWithLocalDate, insert);
|
||||
|
||||
assertThat(getValues(insert).contains(LocalDate.fromYearMonthDay(2010, 7, 4)), is(true));
|
||||
assertThat(getValues(insert).contains(LocalDate.fromYearMonthDay(2010, 7, 4))).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -711,7 +702,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(typeWithLocalDate, update);
|
||||
|
||||
assertThat(getAssignmentValues(update), contains((Object) LocalDate.fromYearMonthDay(2010, 7, 4)));
|
||||
assertThat(getAssignmentValues(update)).contains(LocalDate.fromYearMonthDay(2010, 7, 4));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -723,13 +714,13 @@ public class MappingCassandraConverterUnitTests {
|
||||
Row rowMock = RowMockUtil.newRowMock(column("id", "my-id", DataType.ascii()),
|
||||
column("localDate", LocalDate.fromYearMonthDay(2010, 7, 4), DataType.date()));
|
||||
|
||||
TypeWithThreeTenBpLocalDateMappedToDate result =
|
||||
mappingCassandraConverter.readRow(TypeWithThreeTenBpLocalDateMappedToDate.class, rowMock);
|
||||
TypeWithThreeTenBpLocalDateMappedToDate result = mappingCassandraConverter
|
||||
.readRow(TypeWithThreeTenBpLocalDateMappedToDate.class, rowMock);
|
||||
|
||||
assertThat(result.localDate, is(notNullValue()));
|
||||
assertThat(result.localDate.getYear(), is(2010));
|
||||
assertThat(result.localDate.getMonthValue(), is(7));
|
||||
assertThat(result.localDate.getDayOfMonth(), is(4));
|
||||
assertThat(result.localDate).isNotNull();
|
||||
assertThat(result.localDate.getYear()).isEqualTo(2010);
|
||||
assertThat(result.localDate.getMonthValue()).isEqualTo(7);
|
||||
assertThat(result.localDate.getDayOfMonth()).isEqualTo(4);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -745,7 +736,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(typeWithLocalDate, insert);
|
||||
|
||||
assertThat(getValues(insert).contains(LocalDate.fromYearMonthDay(2010, 7, 4)), is(true));
|
||||
assertThat(getValues(insert).contains(LocalDate.fromYearMonthDay(2010, 7, 4))).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -761,7 +752,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(typeWithLocalDate, update);
|
||||
|
||||
assertThat(getAssignmentValues(update), contains((Object) LocalDate.fromYearMonthDay(2010, 7, 4)));
|
||||
assertThat(getAssignmentValues(update)).contains(LocalDate.fromYearMonthDay(2010, 7, 4));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -780,9 +771,9 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(userToken, update);
|
||||
|
||||
assertThat(getAssignments(update), hasEntry("admincomment", (Object) "admin comment"));
|
||||
assertThat(getAssignments(update), hasEntry("user_comment", (Object) "user comment"));
|
||||
assertThat(getWherePredicates(update), hasEntry("user_id", (Object) userToken.getUserId()));
|
||||
assertThat(getAssignments(update)).containsEntry("admincomment", "admin comment");
|
||||
assertThat(getAssignments(update)).containsEntry("user_comment", "user comment");
|
||||
assertThat(getWherePredicates(update)).containsEntry("user_id", userToken.getUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -801,7 +792,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(userToken, delete.where());
|
||||
|
||||
assertThat(getWherePredicates(delete), hasEntry("user_id", (Object) userToken.getUserId()));
|
||||
assertThat(getWherePredicates(delete)).containsEntry("user_id", userToken.getUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -814,7 +805,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write("42", delete.where(), mappingContext.getPersistentEntity(Person.class));
|
||||
|
||||
assertThat(getWherePredicates(delete), hasEntry("id", (Object) "42"));
|
||||
assertThat(getWherePredicates(delete)).containsEntry("id", "42");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -830,7 +821,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(person, delete.where(), mappingContext.getPersistentEntity(Person.class));
|
||||
|
||||
assertThat(getWherePredicates(delete), hasEntry("id", (Object) "42"));
|
||||
assertThat(getWherePredicates(delete)).containsEntry("id", "42");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -854,7 +845,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(id("id", "42"), delete.where(), mappingContext.getPersistentEntity(Person.class));
|
||||
|
||||
assertThat(getWherePredicates(delete), hasEntry("id", (Object) "42"));
|
||||
assertThat(getWherePredicates(delete)).containsEntry("id", "42");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -872,8 +863,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
mappingCassandraConverter.write(entity, delete.where(),
|
||||
mappingContext.getPersistentEntity(TypeWithCompositeKey.class));
|
||||
|
||||
assertThat(getWherePredicates(delete), hasEntry("firstname", (Object) "Walter"));
|
||||
assertThat(getWherePredicates(delete), hasEntry("lastname", (Object) "White"));
|
||||
assertThat(getWherePredicates(delete)).containsEntry("firstname", "Walter");
|
||||
assertThat(getWherePredicates(delete)).containsEntry("lastname", "White");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -887,8 +878,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
mappingCassandraConverter.write(id("firstname", "Walter").with("lastname", "White"), delete.where(),
|
||||
mappingContext.getPersistentEntity(TypeWithCompositeKey.class));
|
||||
|
||||
assertThat(getWherePredicates(delete), hasEntry("firstname", (Object) "Walter"));
|
||||
assertThat(getWherePredicates(delete), hasEntry("lastname", (Object) "White"));
|
||||
assertThat(getWherePredicates(delete)).containsEntry("firstname", "Walter");
|
||||
assertThat(getWherePredicates(delete)).containsEntry("lastname", "White");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -905,8 +896,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(entity, delete.where(), mappingContext.getPersistentEntity(TypeWithMapId.class));
|
||||
|
||||
assertThat(getWherePredicates(delete), hasEntry("firstname", (Object) "Walter"));
|
||||
assertThat(getWherePredicates(delete), hasEntry("lastname", (Object) "White"));
|
||||
assertThat(getWherePredicates(delete)).containsEntry("firstname", "Walter");
|
||||
assertThat(getWherePredicates(delete)).containsEntry("lastname", "White");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -917,9 +908,10 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
Delete delete = QueryBuilder.delete().from("table");
|
||||
|
||||
mappingCassandraConverter.write(Condition.MINT, delete.where(), mappingContext.getPersistentEntity(EnumPrimaryKey.class));
|
||||
mappingCassandraConverter.write(Condition.MINT, delete.where(),
|
||||
mappingContext.getPersistentEntity(EnumPrimaryKey.class));
|
||||
|
||||
assertThat(getWherePredicates(delete), hasEntry("condition", (Object) "MINT"));
|
||||
assertThat(getWherePredicates(delete)).containsEntry("condition", "MINT");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -933,8 +925,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
mappingCassandraConverter.write(id("firstname", "Walter").with("lastname", "White"), delete.where(),
|
||||
mappingContext.getPersistentEntity(TypeWithMapId.class));
|
||||
|
||||
assertThat(getWherePredicates(delete), hasEntry("firstname", (Object) "Walter"));
|
||||
assertThat(getWherePredicates(delete), hasEntry("lastname", (Object) "White"));
|
||||
assertThat(getWherePredicates(delete)).containsEntry("firstname", "Walter");
|
||||
assertThat(getWherePredicates(delete)).containsEntry("lastname", "White");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -954,8 +946,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(entity, delete.where(), mappingContext.getPersistentEntity(TypeWithKeyClass.class));
|
||||
|
||||
assertThat(getWherePredicates(delete), hasEntry("firstname", (Object) "Walter"));
|
||||
assertThat(getWherePredicates(delete), hasEntry("lastname", (Object) "White"));
|
||||
assertThat(getWherePredicates(delete)).containsEntry("firstname", "Walter");
|
||||
assertThat(getWherePredicates(delete)).containsEntry("lastname", "White");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -984,8 +976,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
mappingCassandraConverter.write(key, delete.where(), mappingContext.getPersistentEntity(TypeWithKeyClass.class));
|
||||
|
||||
assertThat(getWherePredicates(delete), hasEntry("firstname", (Object) "Walter"));
|
||||
assertThat(getWherePredicates(delete), hasEntry("lastname", (Object) "White"));
|
||||
assertThat(getWherePredicates(delete)).containsEntry("firstname", "Walter");
|
||||
assertThat(getWherePredicates(delete)).containsEntry("lastname", "White");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -999,8 +991,8 @@ public class MappingCassandraConverterUnitTests {
|
||||
mappingCassandraConverter.write(id("firstname", "Walter").with("lastname", "White"), delete.where(),
|
||||
mappingContext.getPersistentEntity(TypeWithKeyClass.class));
|
||||
|
||||
assertThat(getWherePredicates(delete), hasEntry("firstname", (Object) "Walter"));
|
||||
assertThat(getWherePredicates(delete), hasEntry("lastname", (Object) "White"));
|
||||
assertThat(getWherePredicates(delete)).containsEntry("firstname", "Walter");
|
||||
assertThat(getWherePredicates(delete)).containsEntry("lastname", "White");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1101,11 +1093,9 @@ public class MappingCassandraConverterUnitTests {
|
||||
@Table
|
||||
public static class UnsupportedEnumToOrdinalMapping {
|
||||
|
||||
@PrimaryKey
|
||||
private String id;
|
||||
@PrimaryKey private String id;
|
||||
|
||||
@CassandraType(type = Name.INT)
|
||||
private Condition asOrdinal;
|
||||
@CassandraType(type = Name.INT) private Condition asOrdinal;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
@@ -1127,8 +1117,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
@Table
|
||||
public static class WithEnumColumns {
|
||||
|
||||
@PrimaryKey
|
||||
private String id;
|
||||
@PrimaryKey private String id;
|
||||
|
||||
private Condition condition;
|
||||
|
||||
@@ -1152,8 +1141,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
@PrimaryKeyClass
|
||||
public static class EnumCompositePrimaryKey implements Serializable {
|
||||
|
||||
@PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.PARTITIONED)
|
||||
private Condition condition;
|
||||
@PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.PARTITIONED) private Condition condition;
|
||||
|
||||
public EnumCompositePrimaryKey() {}
|
||||
|
||||
@@ -1173,8 +1161,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
@Table
|
||||
public static class EnumPrimaryKey {
|
||||
|
||||
@PrimaryKey
|
||||
private Condition condition;
|
||||
@PrimaryKey private Condition condition;
|
||||
|
||||
public Condition getCondition() {
|
||||
return condition;
|
||||
@@ -1188,8 +1175,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
@Table
|
||||
public static class CompositeKeyThing {
|
||||
|
||||
@PrimaryKey
|
||||
private EnumCompositePrimaryKey key;
|
||||
@PrimaryKey private EnumCompositePrimaryKey key;
|
||||
|
||||
public CompositeKeyThing() {}
|
||||
|
||||
@@ -1213,8 +1199,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
@Table
|
||||
public static class TypeWithLocalDate {
|
||||
|
||||
@PrimaryKey
|
||||
private String id;
|
||||
@PrimaryKey private String id;
|
||||
|
||||
java.time.LocalDate localDate;
|
||||
java.time.LocalDateTime localDateTime;
|
||||
@@ -1229,11 +1214,9 @@ public class MappingCassandraConverterUnitTests {
|
||||
@Table
|
||||
public static class TypeWithLocalDateMappedToDate {
|
||||
|
||||
@PrimaryKey
|
||||
private String id;
|
||||
@PrimaryKey private String id;
|
||||
|
||||
@CassandraType(type = Name.DATE)
|
||||
java.time.LocalDate localDate;
|
||||
@CassandraType(type = Name.DATE) java.time.LocalDate localDate;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1242,11 +1225,9 @@ public class MappingCassandraConverterUnitTests {
|
||||
@Table
|
||||
public static class TypeWithJodaLocalDateMappedToDate {
|
||||
|
||||
@PrimaryKey
|
||||
private String id;
|
||||
@PrimaryKey private String id;
|
||||
|
||||
@CassandraType(type = Name.DATE)
|
||||
org.joda.time.LocalDate localDate;
|
||||
@CassandraType(type = Name.DATE) org.joda.time.LocalDate localDate;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1255,18 +1236,15 @@ public class MappingCassandraConverterUnitTests {
|
||||
@Table
|
||||
public static class TypeWithThreeTenBpLocalDateMappedToDate {
|
||||
|
||||
@PrimaryKey
|
||||
private String id;
|
||||
@PrimaryKey private String id;
|
||||
|
||||
@CassandraType(type = Name.DATE)
|
||||
org.threeten.bp.LocalDate localDate;
|
||||
@CassandraType(type = Name.DATE) org.threeten.bp.LocalDate localDate;
|
||||
}
|
||||
|
||||
@Table
|
||||
public static class TypeWithInstant {
|
||||
|
||||
@PrimaryKey
|
||||
private String id;
|
||||
@PrimaryKey private String id;
|
||||
|
||||
Instant instant;
|
||||
}
|
||||
@@ -1274,8 +1252,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
@Table
|
||||
public static class TypeWithZoneId {
|
||||
|
||||
@PrimaryKey
|
||||
private String id;
|
||||
@PrimaryKey private String id;
|
||||
|
||||
ZoneId zoneId;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -67,7 +67,7 @@ public class CassandraBatchTemplateIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
Group loaded = template.selectOneById(Group.class, walter.getId());
|
||||
|
||||
assertThat(loaded.getId().getUsername(), is(equalTo(walter.getId().getUsername())));
|
||||
assertThat(loaded.getId().getUsername()).isEqualTo(walter.getId().getUsername());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +84,7 @@ public class CassandraBatchTemplateIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
Group loaded = template.selectOneById(Group.class, walter.getId());
|
||||
|
||||
assertThat(loaded.getId().getUsername(), is(equalTo(walter.getId().getUsername())));
|
||||
assertThat(loaded.getId().getUsername()).isEqualTo(walter.getId().getUsername());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +104,7 @@ public class CassandraBatchTemplateIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
Group loaded = template.selectOneById(Group.class, walter.getId());
|
||||
|
||||
assertThat(loaded.getEmail(), is(equalTo(walter.getEmail())));
|
||||
assertThat(loaded.getEmail()).isEqualTo(walter.getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +124,7 @@ public class CassandraBatchTemplateIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
Group loaded = template.selectOneById(Group.class, walter.getId());
|
||||
|
||||
assertThat(loaded.getEmail(), is(equalTo(walter.getEmail())));
|
||||
assertThat(loaded.getEmail()).isEqualTo(walter.getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +144,7 @@ public class CassandraBatchTemplateIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
FlatGroup loaded = template.selectOneById(FlatGroup.class, walter);
|
||||
|
||||
assertThat(loaded.getEmail(), is(equalTo(walter.getEmail())));
|
||||
assertThat(loaded.getEmail()).isEqualTo(walter.getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +162,7 @@ public class CassandraBatchTemplateIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
Group loaded = template.selectOneById(Group.class, walter.getId());
|
||||
|
||||
assertThat(loaded, is(nullValue()));
|
||||
assertThat(loaded).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +180,7 @@ public class CassandraBatchTemplateIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
Group loaded = template.selectOneById(Group.class, walter.getId());
|
||||
|
||||
assertThat(loaded, is(nullValue()));
|
||||
assertThat(loaded).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,10 +202,10 @@ public class CassandraBatchTemplateIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
ResultSet resultSet = template.query("SELECT writetime(email) FROM group;");
|
||||
|
||||
assertThat(resultSet.getAvailableWithoutFetching(), is(2));
|
||||
assertThat(resultSet.getAvailableWithoutFetching()).isEqualTo(2);
|
||||
|
||||
for (Row row : resultSet) {
|
||||
assertThat(row.getLong(0), is(timestamp));
|
||||
assertThat(row.getLong(0)).isEqualTo(timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.data.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.Arrays;
|
||||
@@ -52,8 +51,7 @@ public class CassandraTemplateUnitTests {
|
||||
|
||||
private CassandraTemplate template;
|
||||
|
||||
@Mock
|
||||
private Session mockSession;
|
||||
@Mock private Session mockSession;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -67,6 +65,7 @@ public class CassandraTemplateUnitTests {
|
||||
protected Row mockRow(String name) {
|
||||
return mock(Row.class, name);
|
||||
}
|
||||
|
||||
protected <T> CassandraConverterRowCallback<T> newRollCallback(CassandraConverter converter, Class<T> type) {
|
||||
return new CassandraConverterRowCallback<T>(converter, type);
|
||||
}
|
||||
@@ -91,11 +90,9 @@ public class CassandraTemplateUnitTests {
|
||||
when(mockCassandraConverter.read(eq(Integer.class), eq(mockRowThree))).thenReturn(3);
|
||||
|
||||
List<Integer> results = template.select("SELECT * FROM Test",
|
||||
newRollCallback(mockCassandraConverter, Integer.class));
|
||||
newRollCallback(mockCassandraConverter, Integer.class));
|
||||
|
||||
assertThat(results, is(notNullValue(List.class)));
|
||||
assertThat(results.size(), is(equalTo(3)));
|
||||
assertThat(results.containsAll(Arrays.asList(1, 2, 3)), is(true));
|
||||
assertThat(results).isNotNull().hasSize(3).contains(1, 2, 3);
|
||||
|
||||
verify(mockSession, times(1)).execute(eq("SELECT * FROM Test"));
|
||||
verify(mockResultSet, times(1)).iterator();
|
||||
@@ -118,12 +115,9 @@ public class CassandraTemplateUnitTests {
|
||||
when(mockResultSet.iterator()).thenReturn(iterator(mockRow));
|
||||
when(mockCassandraConverter.read(eq(String.class), eq(mockRow))).thenReturn("test");
|
||||
|
||||
List<String> results = template.select(mockSelect,
|
||||
newRollCallback(mockCassandraConverter, String.class));
|
||||
List<String> results = template.select(mockSelect, newRollCallback(mockCassandraConverter, String.class));
|
||||
|
||||
assertThat(results, is(notNullValue(List.class)));
|
||||
assertThat(results.size(), is(equalTo(1)));
|
||||
assertThat(results, hasItem("test"));
|
||||
assertThat(results).hasSize(1).contains("test");
|
||||
|
||||
verify(mockSession, times(1)).execute(eq(mockSelect));
|
||||
verify(mockResultSet, times(1)).iterator();
|
||||
@@ -139,13 +133,12 @@ public class CassandraTemplateUnitTests {
|
||||
ResultSet mockResultSet = mock(ResultSet.class);
|
||||
|
||||
when(mockSession.execute(eq("SELECT * FROM Test"))).thenReturn(mockResultSet);
|
||||
when(mockResultSet.iterator()).thenReturn(this.<Row>iterator());
|
||||
when(mockResultSet.iterator()).thenReturn(this.<Row> iterator());
|
||||
|
||||
List<Object> results = template.select("SELECT * FROM Test",
|
||||
newRollCallback(mockCassandraConverter, Object.class));
|
||||
List<Object> results = template.select("SELECT * FROM Test", newRollCallback(mockCassandraConverter, Object.class));
|
||||
|
||||
assertThat(results, is(notNullValue(List.class)));
|
||||
assertThat(results.isEmpty(), is(true));
|
||||
assertThat(results).isNotNull();
|
||||
assertThat(results.isEmpty()).isTrue();
|
||||
|
||||
verify(mockSession, times(1)).execute(eq("SELECT * FROM Test"));
|
||||
verify(mockResultSet, times(1)).iterator();
|
||||
@@ -161,11 +154,10 @@ public class CassandraTemplateUnitTests {
|
||||
|
||||
when(mockSession.execute(anyString())).thenReturn(null);
|
||||
|
||||
List<Object> results = template.select("SELECT * FROM Test",
|
||||
newRollCallback(mockCassandraConverter, Object.class));
|
||||
List<Object> results = template.select("SELECT * FROM Test", newRollCallback(mockCassandraConverter, Object.class));
|
||||
|
||||
assertThat(results, is(notNullValue(List.class)));
|
||||
assertThat(results.isEmpty(), is(true));
|
||||
assertThat(results).isNotNull();
|
||||
assertThat(results.isEmpty()).isTrue();
|
||||
|
||||
verify(mockSession, times(1)).execute(eq("SELECT * FROM Test"));
|
||||
verifyZeroInteractions(mockCassandraConverter);
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.cassandra.core.PrimaryKeyType;
|
||||
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
* @see http://www.datastax.com/dev/blog/basic-rules-of-cassandra-data-modeling
|
||||
|
||||
103
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraMappingContextUnitTests.java
Normal file → Executable file
103
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraMappingContextUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
@@ -62,9 +61,9 @@ public class BasicCassandraMappingContextUnitTests {
|
||||
|
||||
mappingContext.getPersistentEntity(X.class);
|
||||
|
||||
assertTrue(mappingContext.contains(X.class));
|
||||
assertNotNull(mappingContext.getExistingPersistentEntity(X.class));
|
||||
assertFalse(mappingContext.contains(Y.class));
|
||||
assertThat(mappingContext.contains(X.class)).isTrue();
|
||||
assertThat(mappingContext.getExistingPersistentEntity(X.class)).isNotNull();
|
||||
assertThat(mappingContext.contains(Y.class)).isFalse();
|
||||
}
|
||||
|
||||
@Table
|
||||
@@ -87,12 +86,12 @@ public class BasicCassandraMappingContextUnitTests {
|
||||
|
||||
CassandraPersistentProperty idProperty = persistentEntity.getIdProperty();
|
||||
|
||||
assertThat(idProperty.getColumnName().toCql(), is(equalTo("foo")));
|
||||
assertThat(idProperty.getColumnName().toCql()).isEqualTo("foo");
|
||||
|
||||
List<CqlIdentifier> columnNames = idProperty.getColumnNames();
|
||||
|
||||
assertThat(columnNames, hasSize(1));
|
||||
assertThat(columnNames.get(0).toCql(), is(equalTo("foo")));
|
||||
assertThat(columnNames).hasSize(1);
|
||||
assertThat(columnNames.get(0).toCql()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Table
|
||||
@@ -119,20 +118,20 @@ public class BasicCassandraMappingContextUnitTests {
|
||||
CassandraPersistentEntity<?> persistentEntity = mappingContext
|
||||
.getPersistentEntity(PrimaryKeyColumnsOnProperty.class);
|
||||
|
||||
assertThat(persistentEntity.isCompositePrimaryKey(), is(false));
|
||||
assertThat(persistentEntity.isCompositePrimaryKey()).isFalse();
|
||||
|
||||
CassandraPersistentProperty firstname = persistentEntity.getPersistentProperty("firstname");
|
||||
|
||||
assertThat(firstname.isCompositePrimaryKey(), is(false));
|
||||
assertThat(firstname.isPrimaryKeyColumn(), is(true));
|
||||
assertThat(firstname.isPartitionKeyColumn(), is(true));
|
||||
assertThat(firstname.getColumnName().toCql(), is(equalTo("firstname")));
|
||||
assertThat(firstname.isCompositePrimaryKey()).isFalse();
|
||||
assertThat(firstname.isPrimaryKeyColumn()).isTrue();
|
||||
assertThat(firstname.isPartitionKeyColumn()).isTrue();
|
||||
assertThat(firstname.getColumnName().toCql()).isEqualTo("firstname");
|
||||
|
||||
CassandraPersistentProperty lastname = persistentEntity.getPersistentProperty("lastname");
|
||||
|
||||
assertThat(lastname.isPrimaryKeyColumn(), is(true));
|
||||
assertThat(lastname.isClusterKeyColumn(), is(true));
|
||||
assertThat(lastname.getColumnName().toCql(), is(equalTo("mylastname")));
|
||||
assertThat(lastname.isPrimaryKeyColumn()).isTrue();
|
||||
assertThat(lastname.isClusterKeyColumn()).isTrue();
|
||||
assertThat(lastname.getColumnName().toCql()).isEqualTo("mylastname");
|
||||
}
|
||||
|
||||
@Table
|
||||
@@ -172,25 +171,25 @@ public class BasicCassandraMappingContextUnitTests {
|
||||
CassandraPersistentEntity<?> primaryKeyClass = mappingContext
|
||||
.getPersistentEntity(CompositePrimaryKeyClassWithProperties.class);
|
||||
|
||||
assertThat(persistentEntity.isCompositePrimaryKey(), is(false));
|
||||
assertThat(persistentEntity.getPersistentProperty("key").isCompositePrimaryKey(), is(true));
|
||||
assertThat(persistentEntity.isCompositePrimaryKey()).isFalse();
|
||||
assertThat(persistentEntity.getPersistentProperty("key").isCompositePrimaryKey()).isTrue();
|
||||
|
||||
assertThat(primaryKeyClass.isCompositePrimaryKey(), is(true));
|
||||
assertThat(primaryKeyClass.getCompositePrimaryKeyProperties(), hasSize(2));
|
||||
assertThat(primaryKeyClass.isCompositePrimaryKey()).isTrue();
|
||||
assertThat(primaryKeyClass.getCompositePrimaryKeyProperties()).hasSize(2);
|
||||
|
||||
CassandraPersistentProperty firstname = primaryKeyClass.getPersistentProperty("firstname");
|
||||
|
||||
assertThat(firstname.isPrimaryKeyColumn(), is(true));
|
||||
assertThat(firstname.isPartitionKeyColumn(), is(true));
|
||||
assertThat(firstname.isClusterKeyColumn(), is(false));
|
||||
assertThat(firstname.getColumnName().toCql(), is(equalTo("firstname")));
|
||||
assertThat(firstname.isPrimaryKeyColumn()).isTrue();
|
||||
assertThat(firstname.isPartitionKeyColumn()).isTrue();
|
||||
assertThat(firstname.isClusterKeyColumn()).isFalse();
|
||||
assertThat(firstname.getColumnName().toCql()).isEqualTo("firstname");
|
||||
|
||||
CassandraPersistentProperty lastname = primaryKeyClass.getPersistentProperty("lastname");
|
||||
|
||||
assertThat(lastname.isPrimaryKeyColumn(), is(true));
|
||||
assertThat(lastname.isPartitionKeyColumn(), is(false));
|
||||
assertThat(lastname.isClusterKeyColumn(), is(true));
|
||||
assertThat(lastname.getColumnName().toCql(), is(equalTo("mylastname")));
|
||||
assertThat(lastname.isPrimaryKeyColumn()).isTrue();
|
||||
assertThat(lastname.isPartitionKeyColumn()).isFalse();
|
||||
assertThat(lastname.isClusterKeyColumn()).isTrue();
|
||||
assertThat(lastname.getColumnName().toCql()).isEqualTo("mylastname");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,20 +203,20 @@ public class BasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification tableSpecification = mappingContext.getCreateTableSpecificationFor(persistentEntity);
|
||||
|
||||
assertThat(tableSpecification.getPartitionKeyColumns(), hasSize(1));
|
||||
assertThat(tableSpecification.getClusteredKeyColumns(), hasSize(3));
|
||||
assertThat(tableSpecification.getPartitionKeyColumns()).hasSize(1);
|
||||
assertThat(tableSpecification.getClusteredKeyColumns()).hasSize(3);
|
||||
|
||||
ColumnSpecification breed = tableSpecification.getClusteredKeyColumns().get(0);
|
||||
assertThat(breed.getName().toCql(), is(equalTo("breed")));
|
||||
assertThat(breed.getOrdering(), is(Ordering.ASCENDING));
|
||||
assertThat(breed.getName().toCql()).isEqualTo("breed");
|
||||
assertThat(breed.getOrdering()).isEqualTo(Ordering.ASCENDING);
|
||||
|
||||
ColumnSpecification color = tableSpecification.getClusteredKeyColumns().get(1);
|
||||
assertThat(color.getName().toCql(), is(equalTo("color")));
|
||||
assertThat(color.getOrdering(), is(Ordering.DESCENDING));
|
||||
assertThat(color.getName().toCql()).isEqualTo("color");
|
||||
assertThat(color.getOrdering()).isEqualTo(Ordering.DESCENDING);
|
||||
|
||||
ColumnSpecification kind = tableSpecification.getClusteredKeyColumns().get(2);
|
||||
assertThat(kind.getName().toCql(), is(equalTo("kind")));
|
||||
assertThat(kind.getOrdering(), is(Ordering.ASCENDING));
|
||||
assertThat(kind.getName().toCql()).isEqualTo("kind");
|
||||
assertThat(kind.getOrdering()).isEqualTo(Ordering.ASCENDING);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,20 +230,20 @@ public class BasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification tableSpecification = mappingContext.getCreateTableSpecificationFor(persistentEntity);
|
||||
|
||||
assertThat(tableSpecification.getPartitionKeyColumns(), hasSize(1));
|
||||
assertThat(tableSpecification.getClusteredKeyColumns(), hasSize(3));
|
||||
assertThat(tableSpecification.getPartitionKeyColumns()).hasSize(1);
|
||||
assertThat(tableSpecification.getClusteredKeyColumns()).hasSize(3);
|
||||
|
||||
ColumnSpecification breed = tableSpecification.getClusteredKeyColumns().get(0);
|
||||
assertThat(breed.getName().toCql(), is(equalTo("breed")));
|
||||
assertThat(breed.getOrdering(), is(Ordering.ASCENDING));
|
||||
assertThat(breed.getName().toCql()).isEqualTo("breed");
|
||||
assertThat(breed.getOrdering()).isEqualTo(Ordering.ASCENDING);
|
||||
|
||||
ColumnSpecification color = tableSpecification.getClusteredKeyColumns().get(1);
|
||||
assertThat(color.getName().toCql(), is(equalTo("color")));
|
||||
assertThat(color.getOrdering(), is(Ordering.DESCENDING));
|
||||
assertThat(color.getName().toCql()).isEqualTo("color");
|
||||
assertThat(color.getOrdering()).isEqualTo(Ordering.DESCENDING);
|
||||
|
||||
ColumnSpecification kind = tableSpecification.getClusteredKeyColumns().get(2);
|
||||
assertThat(kind.getName().toCql(), is(equalTo("kind")));
|
||||
assertThat(kind.getOrdering(), is(Ordering.ASCENDING));
|
||||
assertThat(kind.getName().toCql()).isEqualTo("kind");
|
||||
assertThat(kind.getOrdering()).isEqualTo(Ordering.ASCENDING);
|
||||
}
|
||||
|
||||
@Table
|
||||
@@ -318,7 +317,7 @@ public class BasicCassandraMappingContextUnitTests {
|
||||
public void shouldCreatePersistentEntityIfNoConversionRegistered() {
|
||||
|
||||
mappingContext.setCustomConversions(new CustomConversions(Collections.EMPTY_LIST));
|
||||
assertThat(mappingContext.shouldCreatePersistentEntityFor(ClassTypeInformation.from(Human.class)), is(true));
|
||||
assertThat(mappingContext.shouldCreatePersistentEntityFor(ClassTypeInformation.from(Human.class))).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,7 +329,7 @@ public class BasicCassandraMappingContextUnitTests {
|
||||
mappingContext
|
||||
.setCustomConversions(new CustomConversions(Collections.singletonList(HumanToStringConverter.INSTANCE)));
|
||||
|
||||
assertThat(mappingContext.shouldCreatePersistentEntityFor(ClassTypeInformation.from(Human.class)), is(false));
|
||||
assertThat(mappingContext.shouldCreatePersistentEntityFor(ClassTypeInformation.from(Human.class))).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -345,11 +344,11 @@ public class BasicCassandraMappingContextUnitTests {
|
||||
CassandraPersistentEntity<?> persistentEntity = mappingContext
|
||||
.getPersistentEntity(TypeWithCustomConvertedMap.class);
|
||||
|
||||
assertThat(mappingContext.getDataType(persistentEntity.getPersistentProperty("stringMap")),
|
||||
is(equalTo(DataType.varchar())));
|
||||
assertThat(mappingContext.getDataType(persistentEntity.getPersistentProperty("stringMap")))
|
||||
.isEqualTo(DataType.varchar());
|
||||
|
||||
assertThat(mappingContext.getDataType(persistentEntity.getPersistentProperty("blobMap")),
|
||||
is(equalTo(DataType.ascii())));
|
||||
assertThat(mappingContext.getDataType(persistentEntity.getPersistentProperty("blobMap")))
|
||||
.isEqualTo(DataType.ascii());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,8 +362,8 @@ public class BasicCassandraMappingContextUnitTests {
|
||||
|
||||
CassandraPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(TypeWithListOfHumans.class);
|
||||
|
||||
assertThat(mappingContext.getDataType(persistentEntity.getPersistentProperty("humans")),
|
||||
is(equalTo((DataType) DataType.list(DataType.varchar()))));
|
||||
assertThat(mappingContext.getDataType(persistentEntity.getPersistentProperty("humans")))
|
||||
.isEqualTo(DataType.list(DataType.varchar()));
|
||||
}
|
||||
|
||||
private static class Human {}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -84,7 +83,7 @@ public class BasicCassandraPersistentEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(TooManyAnnotations.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(), containsString("Entity cannot be of type @Table and @PrimaryKeyClass"));
|
||||
assertThat(e).hasMessageContaining("Entity cannot be of type @Table and @PrimaryKeyClass");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,8 +97,8 @@ public class BasicCassandraPersistentEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(EntityWithComplexTypePrimaryKey.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(),
|
||||
containsString("Property [species] annotated with @PrimaryKeyColumn must be a simple CassandraType"));
|
||||
assertThat(e)
|
||||
.hasMessageContaining("Property [species] annotated with @PrimaryKeyColumn must be a simple CassandraType");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +112,7 @@ public class BasicCassandraPersistentEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(EntityWithComplexTypeId.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(), containsString("Property [species] annotated with @Id must be a simple CassandraType"));
|
||||
assertThat(e).hasMessageContaining("Property [species] annotated with @Id must be a simple CassandraType");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,8 +126,8 @@ public class BasicCassandraPersistentEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(NoPartitionKey.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(),
|
||||
containsString("At least one of the @PrimaryKeyColumn annotations must have a type of PARTITIONED"));
|
||||
assertThat(e)
|
||||
.hasMessageContaining("At least one of the @PrimaryKeyColumn annotations must have a type of PARTITIONED");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +141,7 @@ public class BasicCassandraPersistentEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(NoPrimaryKey.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(), containsString("@Table types must have only one primary attribute, if any; Found 0"));
|
||||
assertThat(e).hasMessageContaining("@Table types must have only one primary attribute, if any; Found 0");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,8 +155,7 @@ public class BasicCassandraPersistentEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(PrimaryKeyAndPrimaryKeyColumn.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(),
|
||||
containsString("@Table types must not define both @Id and @PrimaryKeyColumn properties"));
|
||||
assertThat(e).hasMessageContaining("@Table types must not define both @Id and @PrimaryKeyColumn properties");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedList;
|
||||
@@ -60,7 +60,7 @@ public class BasicCassandraPersistentEntityOrderPropertiesUnitTests {
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(expected, actual);
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class BasicCassandraPersistentEntityOrderPropertiesUnitTests {
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(expected, actual);
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
|
||||
}
|
||||
|
||||
|
||||
32
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntityUnitTests.java
Normal file → Executable file
32
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntityUnitTests.java
Normal file → Executable file
@@ -15,16 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.isA;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -51,7 +43,7 @@ public class BasicCassandraPersistentEntityUnitTests {
|
||||
|
||||
BasicCassandraPersistentEntity<Notification> entity = new BasicCassandraPersistentEntity<Notification>(
|
||||
ClassTypeInformation.from(Notification.class));
|
||||
assertThat(entity.getTableName().toCql(), is("messages"));
|
||||
assertThat(entity.getTableName().toCql()).isEqualTo("messages");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,7 +52,7 @@ public class BasicCassandraPersistentEntityUnitTests {
|
||||
BasicCassandraPersistentEntity<Area> entity = new BasicCassandraPersistentEntity<Area>(
|
||||
ClassTypeInformation.from(Area.class));
|
||||
entity.setApplicationContext(context);
|
||||
assertThat(entity.getTableName().toCql(), is("a123"));
|
||||
assertThat(entity.getTableName().toCql()).isEqualTo("a123");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,34 +68,34 @@ public class BasicCassandraPersistentEntityUnitTests {
|
||||
ClassTypeInformation.from(UserLine.class));
|
||||
entity.setApplicationContext(context);
|
||||
|
||||
assertThat(entity.getTableName().toCql(), is(bean.tableName));
|
||||
assertThat(entity.getTableName().toCql()).isEqualTo(bean.tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setForceQuoteCallsSetTableName() {
|
||||
BasicCassandraPersistentEntity<Message> entitySpy =
|
||||
spy(new BasicCassandraPersistentEntity<Message>(ClassTypeInformation.from(Message.class)));
|
||||
BasicCassandraPersistentEntity<Message> entitySpy = spy(
|
||||
new BasicCassandraPersistentEntity<Message>(ClassTypeInformation.from(Message.class)));
|
||||
|
||||
entitySpy.tableName = CqlIdentifier.cqlId("Messages", false);
|
||||
|
||||
assertThat(entitySpy.forceQuote, is(nullValue(Boolean.class)));
|
||||
assertThat(entitySpy.forceQuote).isNull();
|
||||
|
||||
entitySpy.setForceQuote(true);
|
||||
|
||||
assertThat(entitySpy.forceQuote, is(true));
|
||||
assertThat(entitySpy.forceQuote).isTrue();
|
||||
|
||||
verify(entitySpy, times(1)).setTableName(isA(CqlIdentifier.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setForceQuoteDoesNothing() {
|
||||
BasicCassandraPersistentEntity<Message> entitySpy =
|
||||
spy(new BasicCassandraPersistentEntity<Message>(ClassTypeInformation.from(Message.class)));
|
||||
BasicCassandraPersistentEntity<Message> entitySpy = spy(
|
||||
new BasicCassandraPersistentEntity<Message>(ClassTypeInformation.from(Message.class)));
|
||||
|
||||
entitySpy.forceQuote = true;
|
||||
entitySpy.setForceQuote(true);
|
||||
|
||||
assertThat(entitySpy.forceQuote, is(true));
|
||||
assertThat(entitySpy.forceQuote).isTrue();
|
||||
|
||||
verify(entitySpy, never()).setTableName(isA(CqlIdentifier.class));
|
||||
}
|
||||
|
||||
9
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentPropertyUnitTests.java
Normal file → Executable file
9
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentPropertyUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Date;
|
||||
@@ -54,20 +53,20 @@ public class BasicCassandraPersistentPropertyUnitTests {
|
||||
public void usesAnnotatedColumnName() {
|
||||
|
||||
Field field = ReflectionUtils.findField(Timeline.class, "text");
|
||||
assertThat(getPropertyFor(field).getColumnName().toCql(), is("message"));
|
||||
assertThat(getPropertyFor(field).getColumnName().toCql()).isEqualTo("message");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checksIdProperty() {
|
||||
Field field = ReflectionUtils.findField(Timeline.class, "id");
|
||||
CassandraPersistentProperty property = getPropertyFor(field);
|
||||
assertTrue(property.isIdProperty());
|
||||
assertThat(property.isIdProperty()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsPropertyNameForUnannotatedProperty() {
|
||||
Field field = ReflectionUtils.findField(Timeline.class, "time");
|
||||
assertThat(getPropertyFor(field).getColumnName().toCql(), is("time"));
|
||||
assertThat(getPropertyFor(field).getColumnName().toCql()).isEqualTo("time");
|
||||
}
|
||||
|
||||
private CassandraPersistentProperty getPropertyFor(Field field) {
|
||||
|
||||
26
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CassandraCompositePrimaryKeyUnitTests.java
Normal file → Executable file
26
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CassandraCompositePrimaryKeyUnitTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.cassandra.core.cql.CqlIdentifier.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -113,33 +113,33 @@ public class CassandraCompositePrimaryKeyUnitTests {
|
||||
|
||||
Field field = ReflectionUtils.findField(Thing.class, "id");
|
||||
CassandraPersistentProperty property = new BasicCassandraPersistentProperty(field, null, thing, SIMPLE_TYPE_HOLDER);
|
||||
assertTrue(property.isIdProperty());
|
||||
assertTrue(property.isCompositePrimaryKey());
|
||||
assertThat(property.isIdProperty()).isTrue();
|
||||
assertThat(property.isCompositePrimaryKey()).isTrue();
|
||||
|
||||
List<CqlIdentifier> expectedColumnNames = Arrays.asList(new CqlIdentifier[] { cqlId("z"), cqlId("a") });
|
||||
assertTrue(expectedColumnNames.equals(property.getColumnNames()));
|
||||
assertThat(expectedColumnNames.equals(property.getColumnNames())).isTrue();
|
||||
|
||||
List<CqlIdentifier> actualColumnNames = new ArrayList<CqlIdentifier>();
|
||||
List<CassandraPersistentProperty> properties = property.getCompositePrimaryKeyProperties();
|
||||
for (CassandraPersistentProperty p : properties) {
|
||||
actualColumnNames.addAll(p.getColumnNames());
|
||||
}
|
||||
assertTrue(expectedColumnNames.equals(actualColumnNames));
|
||||
assertThat(expectedColumnNames.equals(actualColumnNames)).isTrue();
|
||||
|
||||
CreateTableSpecification spec = context.getCreateTableSpecificationFor(thing);
|
||||
|
||||
List<ColumnSpecification> partitionKeyColumns = spec.getPartitionKeyColumns();
|
||||
assertEquals(1, partitionKeyColumns.size());
|
||||
assertThat(partitionKeyColumns).hasSize(1);
|
||||
ColumnSpecification partitionKeyColumn = partitionKeyColumns.get(0);
|
||||
assertEquals("z", partitionKeyColumn.getName().toCql());
|
||||
assertEquals(PrimaryKeyType.PARTITIONED, partitionKeyColumn.getKeyType());
|
||||
assertEquals(DataType.text(), partitionKeyColumn.getType());
|
||||
assertThat(partitionKeyColumn.getName().toCql()).isEqualTo("z");
|
||||
assertThat(partitionKeyColumn.getKeyType()).isEqualTo(PrimaryKeyType.PARTITIONED);
|
||||
assertThat(partitionKeyColumn.getType()).isEqualTo(DataType.text());
|
||||
|
||||
List<ColumnSpecification> clusteredKeyColumns = spec.getClusteredKeyColumns();
|
||||
assertEquals(1, clusteredKeyColumns.size());
|
||||
assertThat(clusteredKeyColumns).hasSize(1);
|
||||
ColumnSpecification clusteredKeyColumn = clusteredKeyColumns.get(0);
|
||||
assertEquals("a", clusteredKeyColumn.getName().toCql());
|
||||
assertEquals(PrimaryKeyType.CLUSTERED, clusteredKeyColumn.getKeyType());
|
||||
assertEquals(DataType.text(), partitionKeyColumn.getType());
|
||||
assertThat(clusteredKeyColumn.getName().toCql()).isEqualTo("a");
|
||||
assertThat(clusteredKeyColumn.getKeyType()).isEqualTo(PrimaryKeyType.CLUSTERED);
|
||||
assertThat(partitionKeyColumn.getType()).isEqualTo(DataType.text());
|
||||
}
|
||||
}
|
||||
|
||||
35
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CassandraPersistentPropertyComparatorUnitTests.java
Normal file → Executable file
35
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CassandraPersistentPropertyComparatorUnitTests.java
Normal file → Executable file
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -26,8 +25,8 @@ import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
* The CassandraPersistentPropertyComparatorUnitTests class is a test suite of test cases testing the contract
|
||||
* and functionality of the {@link CassandraPersistentPropertyComparator} class.
|
||||
* The CassandraPersistentPropertyComparatorUnitTests class is a test suite of test cases testing the contract and
|
||||
* functionality of the {@link CassandraPersistentPropertyComparator} class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.cassandra.mapping.CassandraPersistentPropertyComparator
|
||||
@@ -36,37 +35,35 @@ import org.mockito.runners.MockitoJUnitRunner;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
|
||||
@Mock
|
||||
private CassandraPersistentProperty left;
|
||||
@Mock private CassandraPersistentProperty left;
|
||||
|
||||
@Mock
|
||||
private CassandraPersistentProperty right;
|
||||
@Mock private CassandraPersistentProperty right;
|
||||
|
||||
@Test
|
||||
public void leftAndRightAreNullReturnsZero() {
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(null, null), is(equalTo(0)));
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(null, null)).isEqualTo(0);
|
||||
verifyZeroInteractions(left);
|
||||
verifyZeroInteractions(right);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leftIsNotNullAndRightIsNullReturnsOne() {
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, null), is(equalTo(1)));
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, null)).isEqualTo(1);
|
||||
verifyZeroInteractions(left);
|
||||
verifyZeroInteractions(right);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leftIsNullAndRightIsNotNullReturnsMinusOne() {
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(null, right), is(equalTo(-1)));
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(null, right)).isEqualTo(-1);
|
||||
verifyZeroInteractions(left);
|
||||
verifyZeroInteractions(right);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leftAndRightAreEqualReturnsZero() {
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, left), is(equalTo(0)));
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(right, right), is(equalTo(0)));
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, left)).isEqualTo(0);
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(right, right)).isEqualTo(0);
|
||||
verifyZeroInteractions(left);
|
||||
verifyZeroInteractions(right);
|
||||
}
|
||||
@@ -76,7 +73,7 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
when(left.isCompositePrimaryKey()).thenReturn(true);
|
||||
when(right.isCompositePrimaryKey()).thenReturn(true);
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right), is(equalTo(0)));
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right)).isEqualTo(0);
|
||||
|
||||
verify(left, times(1)).isCompositePrimaryKey();
|
||||
verify(right, times(1)).isCompositePrimaryKey();
|
||||
@@ -89,7 +86,7 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
when(right.isCompositePrimaryKey()).thenReturn(false);
|
||||
when(right.isPrimaryKeyColumn()).thenReturn(false);
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right), is(equalTo(-1)));
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right)).isEqualTo(-1);
|
||||
|
||||
verify(left, times(1)).isCompositePrimaryKey();
|
||||
verify(left, times(1)).isPrimaryKeyColumn();
|
||||
@@ -104,7 +101,7 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
when(right.isCompositePrimaryKey()).thenReturn(false);
|
||||
when(right.isPrimaryKeyColumn()).thenReturn(false);
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right), is(equalTo(-1)));
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right)).isEqualTo(-1);
|
||||
|
||||
verify(left, times(1)).isCompositePrimaryKey();
|
||||
verify(left, times(1)).isPrimaryKeyColumn();
|
||||
@@ -119,7 +116,7 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
when(right.isCompositePrimaryKey()).thenReturn(true);
|
||||
when(right.isPrimaryKeyColumn()).thenReturn(false);
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right), is(equalTo(1)));
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right)).isEqualTo(1);
|
||||
|
||||
verify(left, times(1)).isCompositePrimaryKey();
|
||||
verify(left, times(1)).isPrimaryKeyColumn();
|
||||
@@ -134,7 +131,7 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
when(right.isCompositePrimaryKey()).thenReturn(false);
|
||||
when(right.isPrimaryKeyColumn()).thenReturn(true);
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right), is(equalTo(1)));
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right)).isEqualTo(1);
|
||||
|
||||
verify(left, times(1)).isCompositePrimaryKey();
|
||||
verify(left, times(1)).isPrimaryKeyColumn();
|
||||
@@ -153,7 +150,7 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
when(left.getName()).thenReturn("left");
|
||||
when(right.getName()).thenReturn("right");
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right), is(lessThan(0)));
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right)).isLessThan(0);
|
||||
|
||||
verify(left, times(1)).isCompositePrimaryKey();
|
||||
verify(left, times(1)).isPrimaryKeyColumn();
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.UUID;
|
||||
@@ -54,54 +53,53 @@ public class CassandraPrimaryKeyColumnAnnotationComparatorUnitTests {
|
||||
|
||||
@Test
|
||||
public void compareTypes() {
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityOne, entityTwo), is(equalTo(1)));
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityTwo, entityTwo), is(equalTo(0)));
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityTwo, entityOne), is(equalTo(-1)));
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityOne, entityTwo)).isEqualTo(1);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityTwo, entityTwo)).isEqualTo(0);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityTwo, entityOne)).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareOrdinals() {
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityOne, entityThree), is(equalTo(-1)));
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityThree, entityThree), is(equalTo(0)));
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityThree, entityOne), is(equalTo(1)));
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityOne, entityThree)).isEqualTo(-1);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityThree, entityThree)).isEqualTo(0);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityThree, entityOne)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareName() {
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityOne, entityFour), is(equalTo(-1)));
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityFour, entityFour), is(equalTo(0)));
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityFour, entityOne), is(equalTo(1)));
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityOne, entityFour)).isEqualTo(-1);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityFour, entityFour)).isEqualTo(0);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityFour, entityOne)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareOrdering() {
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityOne, entityFive), is(equalTo(-1)));
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityFive, entityFive), is(equalTo(0)));
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityFive, entityOne), is(equalTo(1)));
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityOne, entityFive)).isEqualTo(-1);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityFive, entityFive)).isEqualTo(0);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityFive, entityOne)).isEqualTo(1);
|
||||
}
|
||||
|
||||
static class EntityOne {
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 1, name = "A", ordering = Ordering.ASCENDING)
|
||||
Integer id;
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 1, name = "A",
|
||||
ordering = Ordering.ASCENDING) Integer id;
|
||||
}
|
||||
|
||||
static class EntityTwo {
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED, ordinal = 1, name = "A", ordering = Ordering.ASCENDING)
|
||||
Long id;
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED, ordinal = 1, name = "A",
|
||||
ordering = Ordering.ASCENDING) Long id;
|
||||
}
|
||||
|
||||
static class EntityThree {
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 2, name = "A", ordering = Ordering.ASCENDING)
|
||||
String id;
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 2, name = "A",
|
||||
ordering = Ordering.ASCENDING) String id;
|
||||
}
|
||||
|
||||
static class EntityFour {
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 1, name = "B", ordering = Ordering.ASCENDING)
|
||||
Timestamp id;
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 1, name = "B",
|
||||
ordering = Ordering.ASCENDING) Timestamp id;
|
||||
}
|
||||
|
||||
static class EntityFive {
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 1, name = "A", ordering = Ordering.DESCENDING)
|
||||
UUID id;
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 1, name = "A", ordering = Ordering.DESCENDING) UUID id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Fail.fail;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -74,7 +74,8 @@ public class CompositeCassandraPersistentEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(NonPersistentClass.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(), containsString("Cassandra entities must be annotated with either @Persistent, @Table, or @PrimaryKeyClass"));
|
||||
assertThat(e).hasMessageContaining(
|
||||
"Cassandra entities must be annotated with either @Persistent, @Table, or @PrimaryKeyClass");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +89,7 @@ public class CompositeCassandraPersistentEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(TooManyAnnotations.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(), containsString("Entity cannot be of type @Table and @PrimaryKeyClass"));
|
||||
assertThat(e).hasMessageContaining("Entity cannot be of type @Table and @PrimaryKeyClass");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
6
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CompoundPrimaryKeyUnitTests.java
Normal file → Executable file
6
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CompoundPrimaryKeyUnitTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Date;
|
||||
@@ -62,8 +62,8 @@ public class CompoundPrimaryKeyUnitTests {
|
||||
public void checkIdProperty() {
|
||||
Field id = ReflectionUtils.findField(Timeline.class, "id");
|
||||
CassandraPersistentProperty property = getPropertyFor(id);
|
||||
assertTrue(property.isIdProperty());
|
||||
assertTrue(property.isCompositePrimaryKey());
|
||||
assertThat(property.isIdProperty()).isTrue();
|
||||
assertThat(property.isCompositePrimaryKey()).isTrue();
|
||||
}
|
||||
|
||||
private CassandraPersistentProperty getPropertyFor(Field field) {
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -34,7 +33,6 @@ import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.cassandra.convert.CustomConversions;
|
||||
import org.springframework.data.cassandra.domain.AllPossibleTypes;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.datastax.driver.core.DataType;
|
||||
@@ -76,23 +74,23 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = ctx.getCreateTableSpecificationFor(persistentEntity);
|
||||
|
||||
assertThat(getColumn("human", specification).getType(), is(DataType.varchar()));
|
||||
assertThat(getColumn("human", specification).getType()).isEqualTo(DataType.varchar());
|
||||
|
||||
ColumnSpecification friends = getColumn("friends", specification);
|
||||
assertThat(friends.getType().isCollection(), is(true));
|
||||
assertThat(friends.getType().isCollection()).isTrue();
|
||||
|
||||
CollectionType friendsCollection = (CollectionType) friends.getType();
|
||||
assertThat(friendsCollection.getName(), is(Name.LIST));
|
||||
assertThat(friendsCollection.getTypeArguments().size(), is(1));
|
||||
assertThat(friendsCollection.getTypeArguments().get(0), is(DataType.varchar()));
|
||||
assertThat(friendsCollection.getName()).isEqualTo(Name.LIST);
|
||||
assertThat(friendsCollection.getTypeArguments()).hasSize(1);
|
||||
assertThat(friendsCollection.getTypeArguments().get(0)).isEqualTo(DataType.varchar());
|
||||
|
||||
ColumnSpecification people = getColumn("people", specification);
|
||||
assertThat(people.getType().isCollection(), is(true));
|
||||
assertThat(people.getType().isCollection()).isTrue();
|
||||
|
||||
CollectionType peopleCollection = (CollectionType) people.getType();
|
||||
assertThat(peopleCollection.getName(), is(Name.SET));
|
||||
assertThat(peopleCollection.getTypeArguments().size(), is(1));
|
||||
assertThat(peopleCollection.getTypeArguments().get(0), is(DataType.varchar()));
|
||||
assertThat(peopleCollection.getName()).isEqualTo(Name.SET);
|
||||
assertThat(peopleCollection.getTypeArguments()).hasSize(1);
|
||||
assertThat(peopleCollection.getTypeArguments().get(0)).isEqualTo(DataType.varchar());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,15 +103,15 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = ctx.getCreateTableSpecificationFor(persistentEntity);
|
||||
|
||||
assertThat(getColumn("floater", specification).getType(), is(DataType.cfloat()));
|
||||
assertThat(getColumn("floater", specification).getType()).isEqualTo(DataType.cfloat());
|
||||
|
||||
ColumnSpecification enemies = getColumn("enemies", specification);
|
||||
assertThat(enemies.getType().isCollection(), is(true));
|
||||
assertThat(enemies.getType().isCollection()).isTrue();
|
||||
|
||||
CollectionType enemiesCollection = (CollectionType) enemies.getType();
|
||||
assertThat(enemiesCollection.getName(), is(Name.SET));
|
||||
assertThat(enemiesCollection.getTypeArguments().size(), is(1));
|
||||
assertThat(enemiesCollection.getTypeArguments().get(0), is(DataType.bigint()));
|
||||
assertThat(enemiesCollection.getName()).isEqualTo(Name.SET);
|
||||
assertThat(enemiesCollection.getTypeArguments()).hasSize(1);
|
||||
assertThat(enemiesCollection.getTypeArguments().get(0)).isEqualTo(DataType.bigint());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,10 +122,10 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("id", specification).getType(), is(DataType.varchar()));
|
||||
assertThat(getColumn("zoneId", specification).getType(), is(DataType.varchar()));
|
||||
assertThat(getColumn("bpZoneId", specification).getType(), is(DataType.varchar()));
|
||||
assertThat(getColumn("anEnum", specification).getType(), is(DataType.varchar()));
|
||||
assertThat(getColumn("id", specification).getType()).isEqualTo(DataType.varchar());
|
||||
assertThat(getColumn("zoneId", specification).getType()).isEqualTo(DataType.varchar());
|
||||
assertThat(getColumn("bpZoneId", specification).getType()).isEqualTo(DataType.varchar());
|
||||
assertThat(getColumn("anEnum", specification).getType()).isEqualTo(DataType.varchar());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,8 +136,8 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("boxedByte", specification).getType(), is(DataType.tinyint()));
|
||||
assertThat(getColumn("primitiveByte", specification).getType(), is(DataType.tinyint()));
|
||||
assertThat(getColumn("boxedByte", specification).getType()).isEqualTo(DataType.tinyint());
|
||||
assertThat(getColumn("primitiveByte", specification).getType()).isEqualTo(DataType.tinyint());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,8 +148,8 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("boxedShort", specification).getType(), is(DataType.smallint()));
|
||||
assertThat(getColumn("primitiveShort", specification).getType(), is(DataType.smallint()));
|
||||
assertThat(getColumn("boxedShort", specification).getType()).isEqualTo(DataType.smallint());
|
||||
assertThat(getColumn("primitiveShort", specification).getType()).isEqualTo(DataType.smallint());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,8 +160,8 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("boxedLong", specification).getType(), is(DataType.bigint()));
|
||||
assertThat(getColumn("primitiveLong", specification).getType(), is(DataType.bigint()));
|
||||
assertThat(getColumn("boxedLong", specification).getType()).isEqualTo(DataType.bigint());
|
||||
assertThat(getColumn("primitiveLong", specification).getType()).isEqualTo(DataType.bigint());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +172,7 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("bigInteger", specification).getType(), is(DataType.varint()));
|
||||
assertThat(getColumn("bigInteger", specification).getType()).isEqualTo(DataType.varint());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,7 +183,7 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("bigDecimal", specification).getType(), is(DataType.decimal()));
|
||||
assertThat(getColumn("bigDecimal", specification).getType()).isEqualTo(DataType.decimal());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,8 +194,8 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("boxedInteger", specification).getType(), is(DataType.cint()));
|
||||
assertThat(getColumn("primitiveInteger", specification).getType(), is(DataType.cint()));
|
||||
assertThat(getColumn("boxedInteger", specification).getType()).isEqualTo(DataType.cint());
|
||||
assertThat(getColumn("primitiveInteger", specification).getType()).isEqualTo(DataType.cint());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,8 +206,8 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("boxedFloat", specification).getType(), is(DataType.cfloat()));
|
||||
assertThat(getColumn("primitiveFloat", specification).getType(), is(DataType.cfloat()));
|
||||
assertThat(getColumn("boxedFloat", specification).getType()).isEqualTo(DataType.cfloat());
|
||||
assertThat(getColumn("primitiveFloat", specification).getType()).isEqualTo(DataType.cfloat());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,8 +218,8 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("boxedDouble", specification).getType(), is(DataType.cdouble()));
|
||||
assertThat(getColumn("primitiveDouble", specification).getType(), is(DataType.cdouble()));
|
||||
assertThat(getColumn("boxedDouble", specification).getType()).isEqualTo(DataType.cdouble());
|
||||
assertThat(getColumn("primitiveDouble", specification).getType()).isEqualTo(DataType.cdouble());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,8 +230,8 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("boxedBoolean", specification).getType(), is(DataType.cboolean()));
|
||||
assertThat(getColumn("primitiveBoolean", specification).getType(), is(DataType.cboolean()));
|
||||
assertThat(getColumn("boxedBoolean", specification).getType()).isEqualTo(DataType.cboolean());
|
||||
assertThat(getColumn("primitiveBoolean", specification).getType()).isEqualTo(DataType.cboolean());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,11 +242,11 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("date", specification).getType(), is(DataType.date()));
|
||||
assertThat(getColumn("localDate", specification).getType(), is(DataType.date()));
|
||||
assertThat(getColumn("jodaLocalDate", specification).getType(), is(DataType.date()));
|
||||
assertThat(getColumn("jodaDateMidnight", specification).getType(), is(DataType.date()));
|
||||
assertThat(getColumn("bpLocalDate", specification).getType(), is(DataType.date()));
|
||||
assertThat(getColumn("date", specification).getType()).isEqualTo(DataType.date());
|
||||
assertThat(getColumn("localDate", specification).getType()).isEqualTo(DataType.date());
|
||||
assertThat(getColumn("jodaLocalDate", specification).getType()).isEqualTo(DataType.date());
|
||||
assertThat(getColumn("jodaDateMidnight", specification).getType()).isEqualTo(DataType.date());
|
||||
assertThat(getColumn("bpLocalDate", specification).getType()).isEqualTo(DataType.date());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,13 +257,13 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("timestamp", specification).getType(), is(DataType.timestamp()));
|
||||
assertThat(getColumn("localDateTime", specification).getType(), is(DataType.timestamp()));
|
||||
assertThat(getColumn("instant", specification).getType(), is(DataType.timestamp()));
|
||||
assertThat(getColumn("jodaLocalDateTime", specification).getType(), is(DataType.timestamp()));
|
||||
assertThat(getColumn("jodaDateTime", specification).getType(), is(DataType.timestamp()));
|
||||
assertThat(getColumn("bpLocalDateTime", specification).getType(), is(DataType.timestamp()));
|
||||
assertThat(getColumn("bpInstant", specification).getType(), is(DataType.timestamp()));
|
||||
assertThat(getColumn("timestamp", specification).getType()).isEqualTo(DataType.timestamp());
|
||||
assertThat(getColumn("localDateTime", specification).getType()).isEqualTo(DataType.timestamp());
|
||||
assertThat(getColumn("instant", specification).getType()).isEqualTo(DataType.timestamp());
|
||||
assertThat(getColumn("jodaLocalDateTime", specification).getType()).isEqualTo(DataType.timestamp());
|
||||
assertThat(getColumn("jodaDateTime", specification).getType()).isEqualTo(DataType.timestamp());
|
||||
assertThat(getColumn("bpLocalDateTime", specification).getType()).isEqualTo(DataType.timestamp());
|
||||
assertThat(getColumn("bpInstant", specification).getType()).isEqualTo(DataType.timestamp());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,8 +274,8 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(TypeWithOverrides.class);
|
||||
|
||||
assertThat(getColumn("localDate", specification).getType(), is(DataType.timestamp()));
|
||||
assertThat(getColumn("jodaLocalDate", specification).getType(), is(DataType.timestamp()));
|
||||
assertThat(getColumn("localDate", specification).getType()).isEqualTo(DataType.timestamp());
|
||||
assertThat(getColumn("jodaLocalDate", specification).getType()).isEqualTo(DataType.timestamp());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,7 +286,7 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
|
||||
CreateTableSpecification specification = getCreateTableSpecificationFor(AllPossibleTypes.class);
|
||||
|
||||
assertThat(getColumn("blob", specification).getType(), is(DataType.blob()));
|
||||
assertThat(getColumn("blob", specification).getType()).isEqualTo(DataType.blob());
|
||||
}
|
||||
|
||||
public CreateTableSpecification getCreateTableSpecificationFor(Class<?> persistentEntityClass) {
|
||||
|
||||
17
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/ForceQuotedEntitiesSimpleUnitTests.java
Normal file → Executable file
17
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/ForceQuotedEntitiesSimpleUnitTests.java
Normal file → Executable file
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
@@ -33,8 +33,9 @@ public class ForceQuotedEntitiesSimpleUnitTests {
|
||||
BasicCassandraPersistentEntity<ImplicitTableNameForceQuoted> entity = new BasicCassandraPersistentEntity<ImplicitTableNameForceQuoted>(
|
||||
ClassTypeInformation.from(ImplicitTableNameForceQuoted.class));
|
||||
|
||||
assertEquals("\"" + ImplicitTableNameForceQuoted.class.getSimpleName() + "\"", entity.getTableName().toCql());
|
||||
assertEquals(ImplicitTableNameForceQuoted.class.getSimpleName(), entity.getTableName().getUnquoted());
|
||||
assertThat(entity.getTableName().toCql())
|
||||
.isEqualTo("\"" + ImplicitTableNameForceQuoted.class.getSimpleName() + "\"");
|
||||
assertThat(entity.getTableName().getUnquoted()).isEqualTo(ImplicitTableNameForceQuoted.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Table(forceQuote = true)
|
||||
@@ -47,8 +48,8 @@ public class ForceQuotedEntitiesSimpleUnitTests {
|
||||
BasicCassandraPersistentEntity<ExplicitTableNameForceQuoted> entity = new BasicCassandraPersistentEntity<ExplicitTableNameForceQuoted>(
|
||||
ClassTypeInformation.from(ExplicitTableNameForceQuoted.class));
|
||||
|
||||
assertEquals("\"" + EXPLICIT_TABLE_NAME + "\"", entity.getTableName().toCql());
|
||||
assertEquals(EXPLICIT_TABLE_NAME, entity.getTableName().getUnquoted());
|
||||
assertThat(entity.getTableName().toCql()).isEqualTo("\"" + EXPLICIT_TABLE_NAME + "\"");
|
||||
assertThat(entity.getTableName().getUnquoted()).isEqualTo(EXPLICIT_TABLE_NAME);
|
||||
}
|
||||
|
||||
@Table(value = EXPLICIT_TABLE_NAME, forceQuote = true)
|
||||
@@ -59,8 +60,10 @@ public class ForceQuotedEntitiesSimpleUnitTests {
|
||||
BasicCassandraPersistentEntity<DefaultTableNameForceQuoted> entity = new BasicCassandraPersistentEntity<DefaultTableNameForceQuoted>(
|
||||
ClassTypeInformation.from(DefaultTableNameForceQuoted.class));
|
||||
|
||||
assertEquals(DefaultTableNameForceQuoted.class.getSimpleName().toLowerCase(), entity.getTableName().toCql());
|
||||
assertEquals(DefaultTableNameForceQuoted.class.getSimpleName().toLowerCase(), entity.getTableName().getUnquoted());
|
||||
assertThat(entity.getTableName().toCql())
|
||||
.isEqualTo(DefaultTableNameForceQuoted.class.getSimpleName().toLowerCase());
|
||||
assertThat(entity.getTableName().getUnquoted())
|
||||
.isEqualTo(DefaultTableNameForceQuoted.class.getSimpleName().toLowerCase());
|
||||
}
|
||||
|
||||
@Table
|
||||
|
||||
36
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/ForceQuotedPropertiesSimpleUnitTests.java
Normal file → Executable file
36
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/ForceQuotedPropertiesSimpleUnitTests.java
Normal file → Executable file
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.cassandra.core.cql.CqlIdentifier.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -48,8 +48,8 @@ public class ForceQuotedPropertiesSimpleUnitTests {
|
||||
CassandraPersistentProperty primaryKey = entity.getPersistentProperty("primaryKey");
|
||||
CassandraPersistentProperty aString = entity.getPersistentProperty("aString");
|
||||
|
||||
assertEquals("\"primaryKey\"", primaryKey.getColumnName().toCql());
|
||||
assertEquals("\"aString\"", aString.getColumnName().toCql());
|
||||
assertThat(primaryKey.getColumnName().toCql()).isEqualTo("\"primaryKey\"");
|
||||
assertThat(aString.getColumnName().toCql()).isEqualTo("\"aString\"");
|
||||
}
|
||||
|
||||
@Table
|
||||
@@ -67,8 +67,8 @@ public class ForceQuotedPropertiesSimpleUnitTests {
|
||||
CassandraPersistentProperty primaryKey = entity.getPersistentProperty("primaryKey");
|
||||
CassandraPersistentProperty aString = entity.getPersistentProperty("aString");
|
||||
|
||||
assertEquals("primarykey", primaryKey.getColumnName().toCql());
|
||||
assertEquals("astring", aString.getColumnName().toCql());
|
||||
assertThat(primaryKey.getColumnName().toCql()).isEqualTo("primarykey");
|
||||
assertThat(aString.getColumnName().toCql()).isEqualTo("astring");
|
||||
}
|
||||
|
||||
@Table
|
||||
@@ -86,8 +86,8 @@ public class ForceQuotedPropertiesSimpleUnitTests {
|
||||
CassandraPersistentProperty primaryKey = entity.getPersistentProperty("primaryKey");
|
||||
CassandraPersistentProperty aString = entity.getPersistentProperty("aString");
|
||||
|
||||
assertEquals("\"" + EXPLICIT_PRIMARY_KEY_NAME + "\"", primaryKey.getColumnName().toCql());
|
||||
assertEquals("\"" + EXPLICIT_COLUMN_NAME + "\"", aString.getColumnName().toCql());
|
||||
assertThat(primaryKey.getColumnName().toCql()).isEqualTo("\"" + EXPLICIT_PRIMARY_KEY_NAME + "\"");
|
||||
assertThat(aString.getColumnName().toCql()).isEqualTo("\"" + EXPLICIT_COLUMN_NAME + "\"");
|
||||
}
|
||||
|
||||
@Table
|
||||
@@ -105,14 +105,14 @@ public class ForceQuotedPropertiesSimpleUnitTests {
|
||||
CassandraPersistentProperty stringZero = key.getPersistentProperty("stringZero");
|
||||
CassandraPersistentProperty stringOne = key.getPersistentProperty("stringOne");
|
||||
|
||||
assertEquals("\"stringZero\"", stringZero.getColumnName().toCql());
|
||||
assertEquals("\"stringOne\"", stringOne.getColumnName().toCql());
|
||||
assertThat(stringZero.getColumnName().toCql()).isEqualTo("\"stringZero\"");
|
||||
assertThat(stringOne.getColumnName().toCql()).isEqualTo("\"stringOne\"");
|
||||
|
||||
List<CqlIdentifier> names = Arrays
|
||||
.asList(new CqlIdentifier[] { quotedCqlId("stringZero"), quotedCqlId("stringOne") });
|
||||
CassandraPersistentEntity<?> entity = context.getPersistentEntity(ImplicitComposite.class);
|
||||
|
||||
assertEquals(names, entity.getPersistentProperty("primaryKey").getColumnNames());
|
||||
assertThat(entity.getPersistentProperty("primaryKey").getColumnNames()).isEqualTo(names);
|
||||
}
|
||||
|
||||
@PrimaryKeyClass
|
||||
@@ -140,15 +140,15 @@ public class ForceQuotedPropertiesSimpleUnitTests {
|
||||
CassandraPersistentProperty stringZero = key.getPersistentProperty("stringZero");
|
||||
CassandraPersistentProperty stringOne = key.getPersistentProperty("stringOne");
|
||||
|
||||
assertTrue(stringZero.getColumnName().equals("stringZero"));
|
||||
assertTrue(stringOne.getColumnName().equals("stringOne"));
|
||||
assertEquals("stringzero", stringZero.getColumnName().toCql());
|
||||
assertEquals("stringone", stringOne.getColumnName().toCql());
|
||||
assertThat(stringZero.getColumnName().equals("stringZero")).isTrue();
|
||||
assertThat(stringOne.getColumnName().equals("stringOne")).isTrue();
|
||||
assertThat(stringZero.getColumnName().toCql()).isEqualTo("stringzero");
|
||||
assertThat(stringOne.getColumnName().toCql()).isEqualTo("stringone");
|
||||
|
||||
List<CqlIdentifier> names = Arrays.asList(new CqlIdentifier[] { cqlId("stringZero"), cqlId("stringOne") });
|
||||
CassandraPersistentEntity<?> entity = context.getPersistentEntity(DefaultComposite.class);
|
||||
|
||||
assertEquals(names, entity.getPersistentProperty("primaryKey").getColumnNames());
|
||||
assertThat(entity.getPersistentProperty("primaryKey").getColumnNames()).isEqualTo(names);
|
||||
}
|
||||
|
||||
@PrimaryKeyClass
|
||||
@@ -176,14 +176,14 @@ public class ForceQuotedPropertiesSimpleUnitTests {
|
||||
CassandraPersistentProperty stringZero = key.getPersistentProperty("stringZero");
|
||||
CassandraPersistentProperty stringOne = key.getPersistentProperty("stringOne");
|
||||
|
||||
assertEquals("\"" + EXPLICIT_KEY_0 + "\"", stringZero.getColumnName().toCql());
|
||||
assertEquals("\"" + EXPLICIT_KEY_1 + "\"", stringOne.getColumnName().toCql());
|
||||
assertThat(stringZero.getColumnName().toCql()).isEqualTo("\"" + EXPLICIT_KEY_0 + "\"");
|
||||
assertThat(stringOne.getColumnName().toCql()).isEqualTo("\"" + EXPLICIT_KEY_1 + "\"");
|
||||
|
||||
List<CqlIdentifier> names = Arrays
|
||||
.asList(new CqlIdentifier[] { quotedCqlId(EXPLICIT_KEY_0), quotedCqlId(EXPLICIT_KEY_1) });
|
||||
CassandraPersistentEntity<?> entity = context.getPersistentEntity(ExplicitComposite.class);
|
||||
|
||||
assertEquals(names, entity.getPersistentProperty("primaryKey").getColumnNames());
|
||||
assertThat(entity.getPersistentProperty("primaryKey").getColumnNames()).isEqualTo(names);
|
||||
}
|
||||
|
||||
@PrimaryKeyClass
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Fail.fail;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -83,7 +82,7 @@ public class PrimaryKeyClassEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(TooManyAnnotations.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(), containsString("Entity cannot be of type @Table and @PrimaryKeyClass"));
|
||||
assertThat(e).hasMessageContaining("Entity cannot be of type @Table and @PrimaryKeyClass");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,8 +96,7 @@ public class PrimaryKeyClassEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(NoPartitionKey.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(),
|
||||
containsString("At least one of the @PrimaryKeyColumn annotations must have a type of PARTITIONED"));
|
||||
assertThat(e).hasMessageContaining("At least one of the @PrimaryKeyColumn annotations must have a type of PARTITIONED");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,8 +110,7 @@ public class PrimaryKeyClassEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(NoPrimaryKey.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(),
|
||||
containsString("At least one of the @PrimaryKeyColumn annotations must have a type of PARTITIONED"));
|
||||
assertThat(e).hasMessageContaining("At least one of the @PrimaryKeyColumn annotations must have a type of PARTITIONED");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,8 +124,7 @@ public class PrimaryKeyClassEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(TypeCycle.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(),
|
||||
containsString("Composite primary keys are not allowed inside of composite primary key classes"));
|
||||
assertThat(e).hasMessageContaining("Composite primary keys are not allowed inside of composite primary key classes");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,8 +138,7 @@ public class PrimaryKeyClassEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(PKClassWithNestedCompositeKey.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(),
|
||||
containsString("Composite primary keys are not allowed inside of composite primary key classes"));
|
||||
assertThat(e).hasMessageContaining("Composite primary keys are not allowed inside of composite primary key classes");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,8 +152,7 @@ public class PrimaryKeyClassEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(PKWithComplexType.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(),
|
||||
containsString("Property [species] annotated with @PrimaryKeyColumn must be a simple CassandraType"));
|
||||
assertThat(e).hasMessageContaining("Property [species] annotated with @PrimaryKeyColumn must be a simple CassandraType");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,8 +166,7 @@ public class PrimaryKeyClassEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(PrimaryKeyAndPrimaryKeyColumn.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(),
|
||||
containsString("Annotations @Id and @PrimaryKey are invalid for type annotated with @PrimaryKeyClass"));
|
||||
assertThat(e).hasMessageContaining("Annotations @Id and @PrimaryKey are invalid for type annotated with @PrimaryKeyClass");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +180,7 @@ public class PrimaryKeyClassEntityMetadataVerifierUnitTests {
|
||||
verifier.verify(getEntity(SubclassPK.class));
|
||||
fail("Missing MappingException");
|
||||
} catch (MappingException e) {
|
||||
assertThat(e.toString(), containsString("@PrimaryKeyClass must only extend Object"));
|
||||
assertThat(e).hasMessageContaining("@PrimaryKeyClass must only extend Object");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +188,9 @@ public class PrimaryKeyClassEntityMetadataVerifierUnitTests {
|
||||
return context.getPersistentEntity(entityClass);
|
||||
}
|
||||
|
||||
interface MyInterface {}
|
||||
interface MyInterface {
|
||||
|
||||
}
|
||||
|
||||
static class NonPersistentClass {
|
||||
|
||||
@@ -237,7 +232,9 @@ public class PrimaryKeyClassEntityMetadataVerifierUnitTests {
|
||||
|
||||
@Table
|
||||
@PrimaryKeyClass
|
||||
static class TooManyAnnotations {}
|
||||
static class TooManyAnnotations {
|
||||
|
||||
}
|
||||
|
||||
@PrimaryKeyClass
|
||||
static class NoPartitionKey {
|
||||
@@ -290,6 +287,7 @@ public class PrimaryKeyClassEntityMetadataVerifierUnitTests {
|
||||
private static class NoOpVerifier implements CassandraPersistentEntityMetadataVerifier {
|
||||
|
||||
@Override
|
||||
public void verify(CassandraPersistentEntity<?> entity) throws MappingException {}
|
||||
public void verify(CassandraPersistentEntity<?> entity) throws MappingException {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -53,6 +52,6 @@ public class VerifierMappingExceptionsUnitTests {
|
||||
VerifierMappingExceptions exceptions = new VerifierMappingExceptions(entityMock, "err");
|
||||
exceptions.add(new MappingException("my error"));
|
||||
|
||||
assertThat(exceptions.toString(), containsString("my error"));
|
||||
assertThat(exceptions.toString()).contains("my error");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping.multipackagescanning;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -58,9 +58,9 @@ public class MultipackageScanningUnitTests {
|
||||
types.add(entity.getType());
|
||||
}
|
||||
|
||||
assertTrue(types.contains(First.class));
|
||||
assertTrue(types.contains(Second.class));
|
||||
assertFalse(types.contains(Third.class));
|
||||
assertFalse(types.contains(Top.class));
|
||||
assertThat(types.contains(First.class)).isTrue();
|
||||
assertThat(types.contains(Second.class)).isTrue();
|
||||
assertThat(types.contains(Third.class)).isFalse();
|
||||
assertThat(types.contains(Top.class)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.data.cassandra.repository.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.isolated;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
@@ -51,7 +50,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.datastax.driver.core.DataType.Name;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.exceptions.InvalidQueryException;
|
||||
|
||||
/**
|
||||
* Integration tests for various query method parameter types.
|
||||
@@ -108,8 +106,8 @@ public class RepositoryQueryMethodParameterTypesIntegrationTests
|
||||
|
||||
List<AllPossibleTypes> result = allPossibleTypesRepository.findWithCreatedDate(allPossibleTypes.getLocalDate());
|
||||
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result, contains(allPossibleTypes));
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(result).contains(allPossibleTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +117,7 @@ public class RepositoryQueryMethodParameterTypesIntegrationTests
|
||||
public void shouldFindByAnnotatedDateParameter() {
|
||||
|
||||
CustomConversions customConversions = new CustomConversions(
|
||||
Collections.singletonList(new DateToLocalDateConverter()));
|
||||
Collections.singletonList(new DateToLocalDateConverter()));
|
||||
|
||||
mappingContext.setCustomConversions(customConversions);
|
||||
converter.setCustomConversions(customConversions);
|
||||
@@ -140,8 +138,8 @@ public class RepositoryQueryMethodParameterTypesIntegrationTests
|
||||
|
||||
List<AllPossibleTypes> result = allPossibleTypesRepository.findWithAnnotatedDateParameter(Date.from(instant));
|
||||
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result, contains(allPossibleTypes));
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(result).contains(allPossibleTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,8 +170,8 @@ public class RepositoryQueryMethodParameterTypesIntegrationTests
|
||||
|
||||
List<AllPossibleTypes> result = allPossibleTypesRepository.findWithZoneId(zoneId);
|
||||
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result, contains(allPossibleTypes));
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(result).contains(allPossibleTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,8 +192,8 @@ public class RepositoryQueryMethodParameterTypesIntegrationTests
|
||||
|
||||
List<AllPossibleTypes> result = allPossibleTypesRepository.findWithZoneId(Optional.of(zoneId));
|
||||
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result, contains(allPossibleTypes));
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(result).contains(allPossibleTypes);
|
||||
}
|
||||
|
||||
private interface AllPossibleTypesRepository extends CrudRepository<AllPossibleTypes, String> {
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.isolated;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
@@ -88,8 +87,8 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
Optional<AllPossibleTypes> result = allPossibleTypesRepository.findOptionalById(entity.getId());
|
||||
assertThat(result.isPresent(), is(true));
|
||||
assertThat(result.get(), is(instanceOf(AllPossibleTypes.class)));
|
||||
assertThat(result.isPresent()).isTrue();
|
||||
assertThat(result.get()).isInstanceOf(AllPossibleTypes.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,8 +101,8 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
List<AllPossibleTypes> result = allPossibleTypesRepository.findManyById(entity.getId());
|
||||
assertThat(result.isEmpty(), is(false));
|
||||
assertThat(result, hasItem(entity));
|
||||
assertThat(result.isEmpty()).isFalse();
|
||||
assertThat(result).contains(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +116,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
InetAddress result = allPossibleTypesRepository.findInetAddressById(entity.getId());
|
||||
assertThat(result, is(equalTo(entity.getInet())));
|
||||
assertThat(result).isEqualTo(entity.getInet());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,8 +130,8 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
Optional<InetAddress> result = allPossibleTypesRepository.findOptionalInetById(entity.getId());
|
||||
assertThat(result.isPresent(), is(true));
|
||||
assertThat(result.get(), is(equalTo(entity.getInet())));
|
||||
assertThat(result.isPresent()).isTrue();
|
||||
assertThat(result.get()).isEqualTo(entity.getInet());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +145,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
Byte result = allPossibleTypesRepository.findBoxedByteById(entity.getId());
|
||||
assertThat(result, is(equalTo(entity.getBoxedByte())));
|
||||
assertThat(result).isEqualTo(entity.getBoxedByte());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +159,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
byte result = allPossibleTypesRepository.findPrimitiveByteById(entity.getId());
|
||||
assertThat(result, is(equalTo(entity.getPrimitiveByte())));
|
||||
assertThat(result).isEqualTo(entity.getPrimitiveByte());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +173,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
Short result = allPossibleTypesRepository.findBoxedShortById(entity.getId());
|
||||
assertThat(result, is(equalTo(entity.getBoxedShort())));
|
||||
assertThat(result).isEqualTo(entity.getBoxedShort());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,7 +187,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
Long result = allPossibleTypesRepository.findBoxedLongById(entity.getId());
|
||||
assertThat(result, is(equalTo(entity.getBoxedLong())));
|
||||
assertThat(result).isEqualTo(entity.getBoxedLong());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,7 +201,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
Integer result = allPossibleTypesRepository.findBoxedIntegerById(entity.getId());
|
||||
assertThat(result, is(equalTo(entity.getBoxedInteger())));
|
||||
assertThat(result).isEqualTo(entity.getBoxedInteger());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +215,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
Double result = allPossibleTypesRepository.findBoxedDoubleById(entity.getId());
|
||||
assertThat(result, is(equalTo(entity.getBoxedDouble())));
|
||||
assertThat(result).isEqualTo(entity.getBoxedDouble());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,7 +229,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
Double result = allPossibleTypesRepository.findDoubleFromIntegerById(entity.getId());
|
||||
assertThat(result, is(closeTo(entity.getBoxedInteger(), 0.01d)));
|
||||
assertThat(result).isCloseTo(entity.getBoxedInteger(), offset(0.01d));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,7 +243,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
Boolean result = allPossibleTypesRepository.findBoxedBooleanById(entity.getId());
|
||||
assertThat(result, is(equalTo(entity.getBoxedBoolean())));
|
||||
assertThat(result).isEqualTo(entity.getBoxedBoolean());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,7 +257,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
LocalDate result = allPossibleTypesRepository.findLocalDateById(entity.getId());
|
||||
assertThat(result, is(equalTo(entity.getDate())));
|
||||
assertThat(result).isEqualTo(entity.getDate());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,7 +271,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
Date result = allPossibleTypesRepository.findTimestampById(entity.getId());
|
||||
assertThat(result, is(equalTo(entity.getTimestamp())));
|
||||
assertThat(result).isEqualTo(entity.getTimestamp());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,7 +285,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
BigDecimal result = allPossibleTypesRepository.findBigDecimalById(entity.getId());
|
||||
assertThat(result, is(equalTo(entity.getBigDecimal())));
|
||||
assertThat(result).isEqualTo(entity.getBigDecimal());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,7 +299,7 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
BigInteger result = allPossibleTypesRepository.findBigIntegerById(entity.getId());
|
||||
assertThat(result, is(equalTo(entity.getBigInteger())));
|
||||
assertThat(result).isEqualTo(entity.getBigInteger());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,9 +314,9 @@ public class RepositoryReturnTypesIntegrationTests extends AbstractSpringDataEmb
|
||||
allPossibleTypesRepository.save(entity);
|
||||
|
||||
Map<String, Object> result = allPossibleTypesRepository.findEntityAsMapById(entity.getId());
|
||||
assertThat(result.size(), is(41));
|
||||
assertThat(result.get("primitiveinteger"), is(equalTo((Object) Integer.valueOf(123))));
|
||||
assertThat(result.get("biginteger"), is(equalTo((Object) BigInteger.ONE)));
|
||||
assertThat(result).hasSize(41);
|
||||
assertThat(result.get("primitiveinteger")).isEqualTo((Object) Integer.valueOf(123));
|
||||
assertThat(result.get("biginteger")).isEqualTo((Object) BigInteger.ONE);
|
||||
}
|
||||
|
||||
public interface AllPossibleTypesRepository extends CrudRepository<AllPossibleTypes, String> {
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
@@ -61,7 +60,7 @@ public class CassandraParametersParameterAccessorUnitTests {
|
||||
CassandraParameterAccessor accessor = new CassandraParametersParameterAccessor(getCassandraQueryMethod(method),
|
||||
new Object[] { "firstname" });
|
||||
|
||||
assertThat(accessor.getDataType(0), is(equalTo(DataType.varchar())));
|
||||
assertThat(accessor.getDataType(0)).isEqualTo(DataType.varchar());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +73,7 @@ public class CassandraParametersParameterAccessorUnitTests {
|
||||
CassandraParameterAccessor accessor = new CassandraParametersParameterAccessor(getCassandraQueryMethod(method),
|
||||
new Object[] { LocalDateTime.of(2000, 10, 11, 12, 13, 14) });
|
||||
|
||||
assertThat(accessor.getDataType(0), is(nullValue()));
|
||||
assertThat(accessor.getDataType(0)).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +86,7 @@ public class CassandraParametersParameterAccessorUnitTests {
|
||||
CassandraParameterAccessor accessor = new CassandraParametersParameterAccessor(getCassandraQueryMethod(method),
|
||||
new Object[] { LocalDateTime.of(2000, 10, 11, 12, 13, 14) });
|
||||
|
||||
assertThat(accessor.getDataType(0), is(DataType.date()));
|
||||
assertThat(accessor.getDataType(0)).isEqualTo(DataType.date());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +99,7 @@ public class CassandraParametersParameterAccessorUnitTests {
|
||||
CassandraParameterAccessor accessor = new CassandraParametersParameterAccessor(getCassandraQueryMethod(method),
|
||||
new Object[] { "" });
|
||||
|
||||
assertThat(accessor.getDataType(0), is(DataType.date()));
|
||||
assertThat(accessor.getDataType(0)).isEqualTo(DataType.date());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +112,7 @@ public class CassandraParametersParameterAccessorUnitTests {
|
||||
CassandraParameterAccessor accessor = new CassandraParametersParameterAccessor(getCassandraQueryMethod(method),
|
||||
new Object[] { "" });
|
||||
|
||||
assertThat(accessor.getDataType(0), is(DataType.date()));
|
||||
assertThat(accessor.getDataType(0)).isEqualTo(DataType.date());
|
||||
}
|
||||
|
||||
private CassandraQueryMethod getCassandraQueryMethod(Method method) {
|
||||
|
||||
13
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/query/CassandraParametersUnitTests.java
Normal file → Executable file
13
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/query/CassandraParametersUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -48,7 +47,7 @@ public class CassandraParametersUnitTests {
|
||||
Method method = PersonRepository.class.getMethod("findByFirstname", String.class);
|
||||
CassandraParameters cassandraParameters = new CassandraParameters(method);
|
||||
|
||||
assertThat(cassandraParameters.getParameter(0).getCassandraType(), is(nullValue()));
|
||||
assertThat(cassandraParameters.getParameter(0).getCassandraType()).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,8 +59,7 @@ public class CassandraParametersUnitTests {
|
||||
Method method = PersonRepository.class.getMethod("findByFirstTime", String.class);
|
||||
CassandraParameters cassandraParameters = new CassandraParameters(method);
|
||||
|
||||
assertThat(cassandraParameters.getParameter(0).getCassandraType(), is(notNullValue()));
|
||||
assertThat(cassandraParameters.getParameter(0).getCassandraType().type(), is(Name.TIME));
|
||||
assertThat(cassandraParameters.getParameter(0).getCassandraType().type()).isEqualTo(Name.TIME);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +71,7 @@ public class CassandraParametersUnitTests {
|
||||
Method method = PersonRepository.class.getMethod("findByObject", Object.class);
|
||||
CassandraParameters cassandraParameters = new CassandraParameters(method);
|
||||
|
||||
assertThat(cassandraParameters.getParameter(0).getCassandraType(), is(nullValue()));
|
||||
assertThat(cassandraParameters.getParameter(0).getCassandraType()).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,8 +83,7 @@ public class CassandraParametersUnitTests {
|
||||
Method method = PersonRepository.class.getMethod("findByAnnotatedObject", Object.class);
|
||||
CassandraParameters cassandraParameters = new CassandraParameters(method);
|
||||
|
||||
assertThat(cassandraParameters.getParameter(0).getCassandraType(), is(notNullValue()));
|
||||
assertThat(cassandraParameters.getParameter(0).getCassandraType().type(), is(Name.TIME));
|
||||
assertThat(cassandraParameters.getParameter(0).getCassandraType().type()).isEqualTo(Name.TIME);
|
||||
}
|
||||
|
||||
interface PersonRepository {
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.cassandra.repository.query.StubParameterAccessor.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -55,8 +54,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
CassandraMappingContext context;
|
||||
CassandraConverter converter;
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
@Rule public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() throws SecurityException, NoSuchMethodException {
|
||||
@@ -72,7 +70,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstname", Person.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname='Walter';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname='Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +81,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameOrderByLastname", Person.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname='Walter' ORDER BY lastname ASC;")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname='Walter' ORDER BY lastname ASC;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +92,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameAndLastname", Person.class, "Walter", "White");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname='Walter' AND lastname='White';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname='Walter' AND lastname='White';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,7 +119,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameGreaterThan", Person.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname>'Walter';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname>'Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +130,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameGreaterThanEqual", Person.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname>='Walter';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname>='Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,7 +141,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameLessThan", Person.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname<'Walter';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname<'Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +152,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameLessThanEqual", Person.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname<='Walter';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname<='Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,7 +163,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameIn", Person.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname IN ('Walter');")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname IN ('Walter');");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,7 +174,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameIn", Person.class, Arrays.asList("Walter", "Gus"));
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname IN ('Walter','Gus');")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname IN ('Walter','Gus');");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,10 +183,9 @@ public class CassandraQueryCreatorUnitTests {
|
||||
@Test
|
||||
public void createsInQueryWithArrayCorrectly() {
|
||||
|
||||
String query = createQuery("findByFirstnameInAndLastname", Person.class,
|
||||
new String[] { "Walter", "Gus" }, "Fring");
|
||||
String query = createQuery("findByFirstnameInAndLastname", Person.class, new String[] { "Walter", "Gus" }, "Fring");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname IN ('Walter','Gus') AND lastname='Fring';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname IN ('Walter','Gus') AND lastname='Fring';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,11 +194,11 @@ public class CassandraQueryCreatorUnitTests {
|
||||
@Test
|
||||
public void createsLikeQueryCorrectly() {
|
||||
|
||||
assertThat(createQuery("findByFirstnameLike", Person.class, "Wal%ter"),
|
||||
is(equalTo("SELECT * FROM person WHERE firstname LIKE 'Wal%ter';")));
|
||||
assertThat(createQuery("findByFirstnameLike", Person.class, "Wal%ter"))
|
||||
.isEqualTo("SELECT * FROM person WHERE firstname LIKE 'Wal%ter';");
|
||||
|
||||
assertThat(createQuery("findByFirstnameLike", Person.class, "Walter"),
|
||||
is(equalTo("SELECT * FROM person WHERE firstname LIKE 'Walter';")));
|
||||
assertThat(createQuery("findByFirstnameLike", Person.class, "Walter"))
|
||||
.isEqualTo("SELECT * FROM person WHERE firstname LIKE 'Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,7 +209,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameStartsWith", Person.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname LIKE 'Walter%';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname LIKE 'Walter%';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,7 +220,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameEndsWith", Person.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname LIKE '%Walter';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname LIKE '%Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,7 +231,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameContains", Person.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname LIKE '%Walter%';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname LIKE '%Walter%';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,7 +242,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByMysetContains", TypeWithSet.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM typewithset WHERE myset CONTAINS 'Walter';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM typewithset WHERE myset CONTAINS 'Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +253,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByMylistContains", TypeWithList.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM typewithlist WHERE mylist CONTAINS 'Walter';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM typewithlist WHERE mylist CONTAINS 'Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,7 +264,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByMymapContains", TypeWithMap.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM typewithmap WHERE mymap CONTAINS 'Walter';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM typewithmap WHERE mymap CONTAINS 'Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,7 +275,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameIsTrue", Person.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname=true;")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname=true;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -289,7 +286,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByFirstnameIsFalse", Person.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname=false;")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname=false;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,7 +297,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByIdAndSet", QuotedType.class, "Walter", "White");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM \"myTable\" WHERE \"my_id\"='Walter' AND \"set\"='White';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM \"myTable\" WHERE \"my_id\"='Walter' AND \"set\"='White';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,7 +308,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByKeyFirstname", TypeWithCompositeId.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM typewithcompositeid WHERE firstname='Walter';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM typewithcompositeid WHERE firstname='Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,7 +319,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
|
||||
String query = createQuery("findByKeyFirstnameOrderByKeyLastnameAsc", TypeWithCompositeId.class, "Walter");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM typewithcompositeid WHERE firstname='Walter' ORDER BY lastname ASC;")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM typewithcompositeid WHERE firstname='Walter' ORDER BY lastname ASC;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,7 +331,7 @@ public class CassandraQueryCreatorUnitTests {
|
||||
String query = createQuery("findByFirstname", Key.class, "Walter");
|
||||
|
||||
// ⊙_ʘ rly? ヾ( •́д•̀ ;)ノ
|
||||
assertThat(query, is(equalTo("SELECT * FROM key WHERE firstname='Walter';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM key WHERE firstname='Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
@@ -54,8 +53,8 @@ public class CassandraQueryMethodUnitTests {
|
||||
CassandraQueryMethod queryMethod = queryMethod(SampleRepository.class, "method");
|
||||
CassandraEntityMetadata<?> metadata = queryMethod.getEntityInformation();
|
||||
|
||||
assertThat(metadata.getJavaType(), is(typeCompatibleWith(Person.class)));
|
||||
assertThat(metadata.getTableName().toCql(), is("person"));
|
||||
assertThat(metadata.getJavaType()).isAssignableFrom(Person.class);
|
||||
assertThat(metadata.getTableName().toCql()).isEqualTo("person");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +77,7 @@ public class CassandraQueryMethodUnitTests {
|
||||
|
||||
CassandraQueryMethod queryMethod = queryMethod(SampleRepository.class, "method");
|
||||
|
||||
assertThat(queryMethod.isCollectionQuery(), is(true));
|
||||
assertThat(queryMethod.isCollectionQuery()).isTrue();
|
||||
}
|
||||
|
||||
private CassandraQueryMethod queryMethod(Class<?> repository, String name, Class<?>... parameters) throws Exception {
|
||||
|
||||
47
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/query/ConvertingParameterAccessorUnitTests.java
Normal file → Executable file
47
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/query/ConvertingParameterAccessorUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
@@ -46,11 +45,9 @@ import com.datastax.driver.core.DataType;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ConvertingParameterAccessorUnitTests {
|
||||
|
||||
@Mock
|
||||
private CassandraParameterAccessor mockParameterAccessor;
|
||||
@Mock private CassandraParameterAccessor mockParameterAccessor;
|
||||
|
||||
@Mock
|
||||
private CassandraPersistentProperty mockProperty;
|
||||
@Mock private CassandraPersistentProperty mockProperty;
|
||||
|
||||
ConvertingParameterAccessor convertingParameterAccessor;
|
||||
|
||||
@@ -68,35 +65,43 @@ public class ConvertingParameterAccessorUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnNullBindableValue() {
|
||||
assertThat(convertingParameterAccessor.getBindableValue(0), is(nullValue()));
|
||||
|
||||
ConvertingParameterAccessor accessor = new ConvertingParameterAccessor(converter, mockParameterAccessor);
|
||||
|
||||
assertThat(accessor.getBindableValue(0)).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-296">DATACASS-296</a>
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void shouldReturnNativeBindableValue() {
|
||||
when(mockParameterAccessor.getBindableValue(0)).thenReturn("hello");
|
||||
when(mockParameterAccessor.getDataType(0)).thenReturn(DataType.varchar());
|
||||
when(mockParameterAccessor.getParameterType(0)).thenReturn((Class) String.class);
|
||||
|
||||
assertThat(convertingParameterAccessor.getBindableValue(0), is(equalTo((Object) "hello")));
|
||||
ConvertingParameterAccessor accessor = new ConvertingParameterAccessor(converter, mockParameterAccessor);
|
||||
|
||||
when(mockParameterAccessor.getBindableValue(0)).thenReturn("hello");
|
||||
when(mockParameterAccessor.getDataType(0)).thenReturn(DataType.varchar());
|
||||
|
||||
assertThat(accessor.getBindableValue(0)).isEqualTo((Object) "hello");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-296">DATACASS-296</a>
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void shouldReturnConvertedBindableValue() {
|
||||
LocalDate localDate = LocalDate.of(2010, 7, 4);
|
||||
|
||||
when(mockParameterAccessor.getBindableValue(0)).thenReturn(localDate);
|
||||
when(mockParameterAccessor.getParameterType(0)).thenReturn((Class) LocalDate.class);
|
||||
|
||||
assertThat(convertingParameterAccessor.getBindableValue(0),
|
||||
is(equalTo((Object) com.datastax.driver.core.LocalDate.fromYearMonthDay(2010, 7, 4))));
|
||||
assertThat(convertingParameterAccessor.getBindableValue(0))
|
||||
.isEqualTo(com.datastax.driver.core.LocalDate.fromYearMonthDay(2010, 7, 4));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +112,7 @@ public class ConvertingParameterAccessorUnitTests {
|
||||
public void shouldReturnDataTypeProvidedByDelegate() {
|
||||
when(mockParameterAccessor.getDataType(0)).thenReturn(DataType.varchar());
|
||||
|
||||
assertThat(convertingParameterAccessor.getDataType(0), is(equalTo(DataType.varchar())));
|
||||
assertThat(convertingParameterAccessor.getDataType(0)).isEqualTo(DataType.varchar());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,12 +120,12 @@ public class ConvertingParameterAccessorUnitTests {
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-7">DATACASS-7</a>
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void shouldConvertCollections() {
|
||||
LocalDate localDate = LocalDate.of(2010, 7, 4);
|
||||
|
||||
when(mockParameterAccessor.iterator()).thenReturn((Iterator)
|
||||
Collections.singletonList(Collections.singletonList(localDate)).iterator());
|
||||
when(mockParameterAccessor.iterator())
|
||||
.thenReturn((Iterator) Collections.singletonList(Collections.singletonList(localDate)).iterator());
|
||||
when(mockParameterAccessor.getDataType(0)).thenReturn(DataType.list(DataType.date()));
|
||||
when(mockParameterAccessor.getParameterType(0)).thenReturn((Class) List.class);
|
||||
when(mockProperty.getType()).thenReturn((Class) List.class);
|
||||
@@ -130,23 +135,23 @@ public class ConvertingParameterAccessorUnitTests {
|
||||
PotentiallyConvertingIterator iterator = (PotentiallyConvertingIterator) convertingParameterAccessor.iterator();
|
||||
Object converted = iterator.nextConverted(mockProperty);
|
||||
|
||||
assertThat(converted, is(instanceOf(List.class)));
|
||||
assertThat(converted).isInstanceOf(List.class);
|
||||
|
||||
List<?> list = (List<?>) converted;
|
||||
|
||||
assertThat(list.get(0), is(instanceOf(com.datastax.driver.core.LocalDate.class)));
|
||||
assertThat(list.get(0)).isInstanceOf(com.datastax.driver.core.LocalDate.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-7">DATACASS-7</a>
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void shouldProvideTypeBasedOnValue() {
|
||||
when(mockParameterAccessor.getDataType(0)).thenReturn(null);
|
||||
when(mockParameterAccessor.getParameterType(0)).thenReturn((Class) LocalDate.class);
|
||||
|
||||
assertThat(convertingParameterAccessor.getDataType(0), is(equalTo(DataType.date())));
|
||||
assertThat(convertingParameterAccessor.getDataType(0)).isEqualTo(DataType.date());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,6 +165,6 @@ public class ConvertingParameterAccessorUnitTests {
|
||||
when(mockParameterAccessor.getParameterType(0)).thenReturn((Class) String.class);
|
||||
when(mockParameterAccessor.getDataType(0)).thenReturn(null);
|
||||
|
||||
assertThat(convertingParameterAccessor.getDataType(0, mockProperty), is(equalTo(DataType.varchar())));
|
||||
assertThat(convertingParameterAccessor.getDataType(0, mockProperty)).isEqualTo(DataType.varchar());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.cassandra.repository.query.StringBasedCassandraQuery.ParameterBindingParser.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -44,8 +43,8 @@ public class ParameterBindingParserUnitTests {
|
||||
|
||||
String transformed = INSTANCE.parseAndCollectParameterBindingsFromQueryIntoBindings(query, bindings);
|
||||
|
||||
assertThat(transformed, is(equalTo(query)));
|
||||
assertThat(bindings, is(empty()));
|
||||
assertThat(transformed).isEqualTo(query);
|
||||
assertThat(bindings).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,8 +58,8 @@ public class ParameterBindingParserUnitTests {
|
||||
|
||||
String transformed = INSTANCE.parseAndCollectParameterBindingsFromQueryIntoBindings(query, bindings);
|
||||
|
||||
assertThat(transformed, is(equalTo(query)));
|
||||
assertThat(bindings, is(empty()));
|
||||
assertThat(transformed).isEqualTo(query);
|
||||
assertThat(bindings).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,11 +73,11 @@ public class ParameterBindingParserUnitTests {
|
||||
|
||||
String transformed = INSTANCE.parseAndCollectParameterBindingsFromQueryIntoBindings(query, bindings);
|
||||
|
||||
assertThat(transformed, is(equalTo("SELECT * FROM hello_world WHERE a = ?_param_? and b = ?_param_?")));
|
||||
assertThat(bindings, hasSize(2));
|
||||
assertThat(transformed).isEqualTo("SELECT * FROM hello_world WHERE a = ?_param_? and b = ?_param_?");
|
||||
assertThat(bindings).hasSize(2);
|
||||
|
||||
assertThat(bindings.get(0).getParameterIndex(), is(equalTo(0)));
|
||||
assertThat(bindings.get(1).getParameterIndex(), is(equalTo(13)));
|
||||
assertThat(bindings.get(0).getParameterIndex()).isEqualTo(0);
|
||||
assertThat(bindings.get(1).getParameterIndex()).isEqualTo(13);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,8 +91,8 @@ public class ParameterBindingParserUnitTests {
|
||||
|
||||
String transformed = INSTANCE.parseAndCollectParameterBindingsFromQueryIntoBindings(query, bindings);
|
||||
|
||||
assertThat(transformed, is(equalTo("SELECT * FROM hello_world WHERE a = ?_param_? and b = ?_param_?")));
|
||||
assertThat(bindings, hasSize(2));
|
||||
assertThat(transformed).isEqualTo("SELECT * FROM hello_world WHERE a = ?_param_? and b = ?_param_?");
|
||||
assertThat(bindings).hasSize(2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,8 +106,8 @@ public class ParameterBindingParserUnitTests {
|
||||
|
||||
String transformed = INSTANCE.parseAndCollectParameterBindingsFromQueryIntoBindings(query, bindings);
|
||||
|
||||
assertThat(transformed, is(equalTo("SELECT * FROM hello_world WHERE a = ?_param_? and b = ?_param_?")));
|
||||
assertThat(bindings, hasSize(2));
|
||||
assertThat(transformed).isEqualTo("SELECT * FROM hello_world WHERE a = ?_param_? and b = ?_param_?");
|
||||
assertThat(bindings).hasSize(2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,8 +121,8 @@ public class ParameterBindingParserUnitTests {
|
||||
|
||||
String transformed = INSTANCE.parseAndCollectParameterBindingsFromQueryIntoBindings(query, bindings);
|
||||
|
||||
assertThat(transformed, is(equalTo("SELECT * FROM hello_world WHERE a = ?_param_? and b = ?_param_?")));
|
||||
assertThat(bindings, hasSize(2));
|
||||
assertThat(transformed).isEqualTo("SELECT * FROM hello_world WHERE a = ?_param_? and b = ?_param_?");
|
||||
assertThat(bindings).hasSize(2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,8 +136,8 @@ public class ParameterBindingParserUnitTests {
|
||||
|
||||
String transformed = INSTANCE.parseAndCollectParameterBindingsFromQueryIntoBindings(query, bindings);
|
||||
|
||||
assertThat(transformed, is(equalTo(
|
||||
"SELECT * FROM hello_world WHERE (a = ?_param_? and b = ?_param_?) and c = (?_param_?) and (d = ?_param_?)")));
|
||||
assertThat(bindings, hasSize(4));
|
||||
assertThat(transformed).isEqualTo(
|
||||
"SELECT * FROM hello_world WHERE (a = ?_param_? and b = ?_param_?) and c = (?_param_?) and (d = ?_param_?)");
|
||||
assertThat(bindings).hasSize(4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -48,11 +47,9 @@ import org.springframework.data.repository.core.support.DefaultRepositoryMetadat
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PartTreeCassandraQueryUnitTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
@Rule public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private CassandraOperations mockCassandraOperations;
|
||||
@Mock private CassandraOperations mockCassandraOperations;
|
||||
|
||||
private CassandraMappingContext mappingContext;
|
||||
private CassandraConverter converter;
|
||||
@@ -72,7 +69,7 @@ public class PartTreeCassandraQueryUnitTests {
|
||||
public void shouldDeriveSimpleQuery() {
|
||||
String query = deriveQueryFromMethod("findByLastname", "foo");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE lastname='foo';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE lastname='foo';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +79,7 @@ public class PartTreeCassandraQueryUnitTests {
|
||||
public void shouldDeriveSimpleQueryWithoutNames() {
|
||||
String query = deriveQueryFromMethod("findPersonBy");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person;")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,9 +87,9 @@ public class PartTreeCassandraQueryUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldDeriveAndQuery() {
|
||||
String query = deriveQueryFromMethod("findByFirstnameAndLastname", "foo", "bar" );
|
||||
String query = deriveQueryFromMethod("findByFirstnameAndLastname", "foo", "bar");
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person WHERE firstname='foo' AND lastname='bar';")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE firstname='foo' AND lastname='bar';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,10 +99,9 @@ public class PartTreeCassandraQueryUnitTests {
|
||||
public void usesDynamicProjection() {
|
||||
String query = deriveQueryFromMethod("findDynamicallyProjectedBy", PersonProjection.class);
|
||||
|
||||
assertThat(query, is(equalTo("SELECT * FROM person;")));
|
||||
assertThat(query).isEqualTo("SELECT * FROM person;");
|
||||
}
|
||||
|
||||
|
||||
private String deriveQueryFromMethod(String method, Object... args) {
|
||||
Class<?>[] types = new Class<?>[args.length];
|
||||
|
||||
@@ -115,7 +111,8 @@ public class PartTreeCassandraQueryUnitTests {
|
||||
|
||||
PartTreeCassandraQuery partTreeQuery = createQueryForMethod(method, types);
|
||||
|
||||
CassandraParameterAccessor accessor = new CassandraParametersParameterAccessor(partTreeQuery.getQueryMethod(), args);
|
||||
CassandraParameterAccessor accessor = new CassandraParametersParameterAccessor(partTreeQuery.getQueryMethod(),
|
||||
args);
|
||||
|
||||
return partTreeQuery.createQuery(new ConvertingParameterAccessor(mockCassandraOperations.getConverter(), accessor));
|
||||
}
|
||||
@@ -124,8 +121,8 @@ public class PartTreeCassandraQueryUnitTests {
|
||||
try {
|
||||
Method method = Repo.class.getMethod(methodName, paramTypes);
|
||||
ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
|
||||
CassandraQueryMethod queryMethod = new CassandraQueryMethod(method,
|
||||
new DefaultRepositoryMetadata(Repo.class), factory, mappingContext);
|
||||
CassandraQueryMethod queryMethod = new CassandraQueryMethod(method, new DefaultRepositoryMetadata(Repo.class),
|
||||
factory, mappingContext);
|
||||
|
||||
return new PartTreeCassandraQuery(queryMethod, mockCassandraOperations);
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -103,7 +102,7 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
|
||||
String actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE lastname = 'Matthews';")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE lastname = 'Matthews';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +117,7 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
|
||||
String actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE lastname = 'Mat\th''ew\"s';")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE lastname = 'Mat\th''ew\"s';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +132,7 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
|
||||
String actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE lastname = 0x01020304;")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE lastname = 0x01020304;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,7 +147,7 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
|
||||
String actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE lastname IN ('White','Heisenberg');")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE lastname IN ('White','Heisenberg');");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,7 +162,7 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
|
||||
String actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE lastnames = ['White','Heisenberg'] AND age = 42;")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE lastnames = ['White','Heisenberg'] AND age = 42;");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,7 +203,7 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
|
||||
String actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE lastname IN ('White','Heisenberg');")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE lastname IN ('White','Heisenberg');");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +218,7 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
|
||||
String actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE lastname = 'Matthews';")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE lastname = 'Matthews';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,7 +233,7 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
|
||||
String actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE lastname = 'Matthews';")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE lastname = 'Matthews';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,7 +248,7 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
|
||||
String actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE lastname = 'Matthews';")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE lastname = 'Matthews';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,13 +263,13 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
|
||||
String actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE lastname = 'Woohoo';")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE lastname = 'Woohoo';");
|
||||
|
||||
accessor = new CassandraParametersParameterAccessor(cassandraQuery.getQueryMethod(), "Walter");
|
||||
|
||||
actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE lastname = 'Walter';")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE lastname = 'Walter';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -285,7 +284,7 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
|
||||
String actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE lastname='Matthews' or firstname = 'Matthews';")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE lastname='Matthews' or firstname = 'Matthews';");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,7 +304,7 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
expected.setForceNoValues(true);
|
||||
expected.where(QueryBuilder.eq("lastname", "Matthews")).and(QueryBuilder.eq("firstname", "John"));
|
||||
|
||||
assertThat(actual, is(expected.toString()));
|
||||
assertThat(actual).isEqualTo(expected.getQueryString());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -320,12 +319,7 @@ public class StringBasedCassandraQueryIntegrationUnitTests {
|
||||
|
||||
String actual = cassandraQuery.createQuery(accessor);
|
||||
|
||||
String table = Person.class.getSimpleName().toLowerCase();
|
||||
Select expected = QueryBuilder.select().all().from(table);
|
||||
expected.setForceNoValues(true);
|
||||
expected.where(QueryBuilder.eq("createdDate", com.datastax.driver.core.LocalDate.fromYearMonthDay(2010, 7, 4)));
|
||||
|
||||
assertThat(actual, is(equalTo("SELECT * FROM person WHERE createdDate='2010-07-04';")));
|
||||
assertThat(actual).isEqualTo("SELECT * FROM person WHERE createdDate='2010-07-04';");
|
||||
}
|
||||
|
||||
private StringBasedCassandraQuery getQueryMethod(String name, Class<?>... args) {
|
||||
|
||||
6
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/BasicMapIdUnitTests.java
Normal file → Executable file
6
spring-data-cassandra/src/test/java/org/springframework/data/cassandra/repository/support/BasicMapIdUnitTests.java
Normal file → Executable file
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.data.cassandra.repository.support;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
@@ -38,7 +38,7 @@ public class BasicMapIdUnitTests {
|
||||
|
||||
BasicMapId basicMapId = new BasicMapId(map);
|
||||
|
||||
assertEquals(basicMapId.get("field1"), map.get("field1"));
|
||||
assertEquals(basicMapId.get("field2"), map.get("field2"));
|
||||
assertThat(map.get("field1")).isEqualTo(basicMapId.get("field1"));
|
||||
assertThat(map.get("field2")).isEqualTo(basicMapId.get("field2"));
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user