DATACASS-389 - Adapt to API changes after Mockito 2.7 upgrade.
This commit is contained in:
committed by
Mark Paluch
parent
c9bb49fad4
commit
01e0372905
@@ -16,14 +16,26 @@
|
||||
package org.springframework.cassandra.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.datastax.driver.core.*;
|
||||
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.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;
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
package org.springframework.cassandra.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -34,7 +33,7 @@ import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.CqlOperations;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
|
||||
@@ -17,11 +17,8 @@ package org.springframework.cassandra.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
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.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -32,9 +29,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import com.datastax.driver.core.HostDistance;
|
||||
@@ -315,12 +310,7 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
final PoolingOptionsFactoryBean.HostDistancePoolingOptions mockHostDistancePoolingOptions = mock(
|
||||
PoolingOptionsFactoryBean.HostDistancePoolingOptions.class);
|
||||
|
||||
when(mockHostDistancePoolingOptions.configure(any(PoolingOptions.class))).thenAnswer(new Answer<PoolingOptions>() {
|
||||
@Override
|
||||
public PoolingOptions answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||
return invocationOnMock.getArgumentAt(0, PoolingOptions.class);
|
||||
}
|
||||
});
|
||||
when(mockHostDistancePoolingOptions.configure(any(PoolingOptions.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0));
|
||||
|
||||
poolingOptionsFactoryBean = new PoolingOptionsFactoryBean() {
|
||||
@Override
|
||||
@@ -341,12 +331,7 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
final PoolingOptionsFactoryBean.HostDistancePoolingOptions mockHostDistancePoolingOptions = mock(
|
||||
PoolingOptionsFactoryBean.HostDistancePoolingOptions.class);
|
||||
|
||||
when(mockHostDistancePoolingOptions.configure(any(PoolingOptions.class))).thenAnswer(new Answer<PoolingOptions>() {
|
||||
@Override
|
||||
public PoolingOptions answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||
return invocationOnMock.getArgumentAt(0, PoolingOptions.class);
|
||||
}
|
||||
});
|
||||
when(mockHostDistancePoolingOptions.configure(any(PoolingOptions.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0));
|
||||
|
||||
poolingOptionsFactoryBean = new PoolingOptionsFactoryBean() {
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cassandra.config.java;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -29,8 +30,17 @@ import org.springframework.cassandra.config.CompressionType;
|
||||
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
|
||||
|
||||
import com.datastax.driver.core.*;
|
||||
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.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;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.cassandra.config.xml;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.cassandra.support.BeanDefinitionTestUtils.*;
|
||||
|
||||
@@ -24,7 +25,7 @@ import java.util.List;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.parsing.PassThroughSourceExtractor;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -33,7 +35,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
|
||||
import org.springframework.cassandra.support.exception.CassandraInvalidQueryException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
@@ -57,14 +59,14 @@ import com.google.common.util.concurrent.SettableFuture;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AsyncCqlTemplateUnitTests {
|
||||
|
||||
@Mock private Session session;
|
||||
@Mock private ResultSet resultSet;
|
||||
@Mock private Row row;
|
||||
@Mock private PreparedStatement preparedStatement;
|
||||
@Mock private BoundStatement boundStatement;
|
||||
@Mock private ColumnDefinitions columnDefinitions;
|
||||
@Mock Session session;
|
||||
@Mock ResultSet resultSet;
|
||||
@Mock Row row;
|
||||
@Mock PreparedStatement preparedStatement;
|
||||
@Mock BoundStatement boundStatement;
|
||||
@Mock ColumnDefinitions columnDefinitions;
|
||||
|
||||
private AsyncCqlTemplate template;
|
||||
AsyncCqlTemplate template;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
@@ -508,9 +510,6 @@ public class AsyncCqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void executePreparedStatementCreatorShouldTranslateStatementCreationExceptions() throws Exception {
|
||||
|
||||
when(session.executeAsync(boundStatement)).thenReturn(new TestResultSetFuture(resultSet));
|
||||
when(resultSet.wasApplied()).thenReturn(true);
|
||||
|
||||
try {
|
||||
template.execute(session -> {
|
||||
throw new NoHostAvailableException(Collections.emptyMap());
|
||||
@@ -537,9 +536,6 @@ public class AsyncCqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void executePreparedStatementCreatorShouldTranslateStatementCallbackExceptions() throws Exception {
|
||||
|
||||
when(session.executeAsync(boundStatement)).thenReturn(new TestResultSetFuture(resultSet));
|
||||
when(resultSet.wasApplied()).thenReturn(true);
|
||||
|
||||
ListenableFuture<ResultSetFuture> future = template.execute(session -> new AsyncResult<>(preparedStatement),
|
||||
(session, ps) -> {
|
||||
throw new NoHostAvailableException(Collections.emptyMap());
|
||||
@@ -558,7 +554,6 @@ public class AsyncCqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void queryPreparedStatementCreatorShouldReturnResult() {
|
||||
|
||||
when(session.prepareAsync(anyString())).thenReturn(new TestPreparedStatementFuture(preparedStatement));
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
when(session.executeAsync(boundStatement)).thenReturn(new TestResultSetFuture(resultSet));
|
||||
when(resultSet.iterator()).thenReturn(Collections.singleton(row).iterator());
|
||||
@@ -573,14 +568,14 @@ public class AsyncCqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void queryPreparedStatementCreatorAndBinderShouldReturnResult() {
|
||||
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
when(session.executeAsync(boundStatement)).thenReturn(new TestResultSetFuture(resultSet));
|
||||
when(resultSet.iterator()).thenReturn(Collections.singleton(row).iterator());
|
||||
|
||||
ListenableFuture<ResultSet> future = template.query(session -> new AsyncResult<PreparedStatement>(preparedStatement), ps -> {
|
||||
ps.bind("a", "b");
|
||||
return boundStatement;
|
||||
}, rs -> rs);
|
||||
ListenableFuture<ResultSet> future = template
|
||||
.query(session -> new AsyncResult<PreparedStatement>(preparedStatement), ps -> {
|
||||
ps.bind("a", "b");
|
||||
return boundStatement;
|
||||
}, rs -> rs);
|
||||
|
||||
assertThat(getUninterruptibly(future)).contains(row);
|
||||
verify(preparedStatement).bind("a", "b");
|
||||
@@ -589,8 +584,6 @@ public class AsyncCqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void queryPreparedStatementCreatorAndBinderShouldTranslatePrepareStatementExceptions() throws Exception {
|
||||
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
|
||||
ListenableFuture<ResultSet> future = template.query(
|
||||
session -> AsyncResult.forExecutionException(new NoHostAvailableException(Collections.emptyMap())), ps -> {
|
||||
ps.bind("a", "b");
|
||||
@@ -609,11 +602,10 @@ public class AsyncCqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void queryPreparedStatementCreatorAndBinderShouldTranslateBindExceptions() throws Exception {
|
||||
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
|
||||
ListenableFuture<ResultSet> future = template.query(session -> new AsyncResult<PreparedStatement>(preparedStatement), ps -> {
|
||||
throw new NoHostAvailableException(Collections.emptyMap());
|
||||
}, rs -> rs);
|
||||
ListenableFuture<ResultSet> future = template
|
||||
.query(session -> new AsyncResult<PreparedStatement>(preparedStatement), ps -> {
|
||||
throw new NoHostAvailableException(Collections.emptyMap());
|
||||
}, rs -> rs);
|
||||
|
||||
try {
|
||||
future.get();
|
||||
@@ -626,17 +618,16 @@ public class AsyncCqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void queryPreparedStatementCreatorAndBinderShouldTranslateExecutionExceptions() throws Exception {
|
||||
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
|
||||
TestResultSetFuture resultSetFuture = TestResultSetFuture
|
||||
.failed(new NoHostAvailableException(Collections.emptyMap()));
|
||||
|
||||
when(session.executeAsync(boundStatement)).thenReturn(resultSetFuture);
|
||||
|
||||
ListenableFuture<ResultSet> future = template.query(session -> new AsyncResult<PreparedStatement>(preparedStatement), ps -> {
|
||||
ps.bind("a", "b");
|
||||
return boundStatement;
|
||||
}, rs -> rs);
|
||||
ListenableFuture<ResultSet> future = template
|
||||
.query(session -> new AsyncResult<PreparedStatement>(preparedStatement), ps -> {
|
||||
ps.bind("a", "b");
|
||||
return boundStatement;
|
||||
}, rs -> rs);
|
||||
|
||||
try {
|
||||
future.get();
|
||||
@@ -649,7 +640,6 @@ public class AsyncCqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void queryPreparedStatementCreatorAndBinderAndMapperShouldReturnResult() {
|
||||
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
when(session.executeAsync(boundStatement)).thenReturn(new TestResultSetFuture(resultSet));
|
||||
when(resultSet.iterator()).thenReturn(Collections.singleton(row).iterator());
|
||||
|
||||
@@ -773,7 +763,7 @@ public class AsyncCqlTemplateUnitTests {
|
||||
|
||||
String[] results = { "Walter", "Hank", " Jesse" };
|
||||
|
||||
when(this.session.executeAsync(any(Statement.class))).thenReturn(new TestResultSetFuture(resultSet));
|
||||
when(this.session.executeAsync((Statement) any())).thenReturn(new TestResultSetFuture(resultSet));
|
||||
when(this.resultSet.iterator()).thenReturn(Arrays.asList(row, row, row).iterator());
|
||||
|
||||
when(this.row.getString(0)).thenReturn(results[0], results[1], results[2]);
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.cassandra.core;
|
||||
|
||||
import static edu.umd.cs.mtc.TestFramework.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import edu.umd.cs.mtc.MultithreadedTestCase;
|
||||
@@ -31,7 +31,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -29,7 +31,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
|
||||
import org.springframework.cassandra.support.exception.CassandraInvalidQueryException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
@@ -50,7 +52,7 @@ import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CqlTemplate}.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -469,9 +471,6 @@ public class CqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void executePreparedStatementCreatorShouldTranslateStatementCreationExceptions() {
|
||||
|
||||
when(session.execute(boundStatement)).thenReturn(resultSet);
|
||||
when(resultSet.wasApplied()).thenReturn(true);
|
||||
|
||||
try {
|
||||
template.execute(session -> {
|
||||
throw new NoHostAvailableException(Collections.emptyMap());
|
||||
@@ -486,9 +485,6 @@ public class CqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void executePreparedStatementCreatorShouldTranslateStatementCallbackExceptions() {
|
||||
|
||||
when(session.execute(boundStatement)).thenReturn(resultSet);
|
||||
when(resultSet.wasApplied()).thenReturn(true);
|
||||
|
||||
try {
|
||||
template.execute(session -> preparedStatement, (session, ps) -> {
|
||||
throw new NoHostAvailableException(Collections.emptyMap());
|
||||
@@ -503,7 +499,6 @@ public class CqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void queryPreparedStatementCreatorShouldReturnResult() {
|
||||
|
||||
when(session.prepare(anyString())).thenReturn(preparedStatement);
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
when(session.execute(boundStatement)).thenReturn(resultSet);
|
||||
when(resultSet.iterator()).thenReturn(Collections.singleton(row).iterator());
|
||||
@@ -517,7 +512,6 @@ public class CqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void queryPreparedStatementCreatorAndBinderShouldReturnResult() {
|
||||
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
when(session.execute(boundStatement)).thenReturn(resultSet);
|
||||
when(resultSet.iterator()).thenReturn(Collections.singleton(row).iterator());
|
||||
|
||||
@@ -533,8 +527,6 @@ public class CqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void queryPreparedStatementCreatorAndBinderShouldTranslatePrepareStatementExceptions() {
|
||||
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
|
||||
try {
|
||||
template.query(session -> {
|
||||
throw new NoHostAvailableException(Collections.emptyMap());
|
||||
@@ -552,8 +544,6 @@ public class CqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void queryPreparedStatementCreatorAndBinderShouldTranslateBindExceptions() {
|
||||
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
|
||||
try {
|
||||
template.query(session -> preparedStatement, ps -> {
|
||||
throw new NoHostAvailableException(Collections.emptyMap());
|
||||
@@ -568,7 +558,6 @@ public class CqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void queryPreparedStatementCreatorAndBinderShouldTranslateExecutionExceptions() {
|
||||
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
when(session.execute(boundStatement)).thenThrow(new NoHostAvailableException(Collections.emptyMap()));
|
||||
|
||||
try {
|
||||
@@ -586,7 +575,6 @@ public class CqlTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void queryPreparedStatementCreatorAndBinderAndMapperShouldReturnResult() {
|
||||
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
when(session.execute(boundStatement)).thenReturn(resultSet);
|
||||
when(resultSet.iterator()).thenReturn(Collections.singleton(row).iterator());
|
||||
|
||||
@@ -695,7 +683,7 @@ public class CqlTemplateUnitTests {
|
||||
|
||||
String[] results = { "Walter", "Hank", " Jesse" };
|
||||
|
||||
when(this.session.execute(any(Statement.class))).thenReturn(resultSet);
|
||||
when(this.session.execute((Statement) any())).thenReturn(resultSet);
|
||||
when(this.resultSet.iterator()).thenReturn(Arrays.asList(row, row, row).iterator());
|
||||
|
||||
when(this.row.getString(0)).thenReturn(results[0], results[1], results[2]);
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -23,9 +26,6 @@ import org.springframework.cassandra.core.session.DefaultBridgedReactiveSession;
|
||||
import org.springframework.cassandra.core.session.ReactiveResultSet;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import com.datastax.driver.core.KeyspaceMetadata;
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.Row;
|
||||
|
||||
@@ -15,24 +15,21 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
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 reactor.core.scheduler.Schedulers;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.hamcrest.core.IsEqual;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.session.DefaultBridgedReactiveSession;
|
||||
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.SimpleStatement;
|
||||
@@ -139,17 +136,8 @@ public class DefaultBridgedReactiveSessionUnitTests {
|
||||
|
||||
private static <T extends Statement> T eq(T value) {
|
||||
|
||||
return Matchers.argThat(new IsEqual<T>(value) {
|
||||
|
||||
@Override
|
||||
public boolean matches(Object actualValue) {
|
||||
|
||||
if (actualValue instanceof Statement) {
|
||||
return value.toString().equals(actualValue.toString());
|
||||
}
|
||||
|
||||
return super.matches(actualValue);
|
||||
}
|
||||
});
|
||||
return ArgumentMatchers.argThat(argument -> argument instanceof Statement //
|
||||
? value.toString().equals(argument.toString()) //
|
||||
: value.equals(argument));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import com.datastax.driver.core.ConsistencyLevel;
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -27,8 +29,6 @@ import org.springframework.cassandra.core.session.DefaultReactiveSessionFactory;
|
||||
import org.springframework.cassandra.core.session.ReactiveSession;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,16 +15,13 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyString;
|
||||
import static org.mockito.Mockito.atMost;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -35,7 +32,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.session.DefaultReactiveSessionFactory;
|
||||
import org.springframework.cassandra.core.session.ReactiveResultSet;
|
||||
import org.springframework.cassandra.core.session.ReactiveSession;
|
||||
@@ -44,9 +41,6 @@ import org.springframework.cassandra.support.exception.CassandraConnectionFailur
|
||||
import org.springframework.cassandra.support.exception.CassandraInvalidQueryException;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import com.datastax.driver.core.BoundStatement;
|
||||
import com.datastax.driver.core.ColumnDefinitions;
|
||||
import com.datastax.driver.core.ConsistencyLevel;
|
||||
@@ -66,15 +60,15 @@ import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ReactiveCqlTemplateUnitTests {
|
||||
|
||||
@Mock private ReactiveSession session;
|
||||
@Mock private ReactiveResultSet reactiveResultSet;
|
||||
@Mock private Row row;
|
||||
@Mock private PreparedStatement preparedStatement;
|
||||
@Mock private BoundStatement boundStatement;
|
||||
@Mock private ColumnDefinitions columnDefinitions;
|
||||
@Mock ReactiveSession session;
|
||||
@Mock ReactiveResultSet reactiveResultSet;
|
||||
@Mock Row row;
|
||||
@Mock PreparedStatement preparedStatement;
|
||||
@Mock BoundStatement boundStatement;
|
||||
@Mock ColumnDefinitions columnDefinitions;
|
||||
|
||||
private ReactiveCqlTemplate template;
|
||||
private ReactiveSessionFactory sessionFactory;
|
||||
ReactiveCqlTemplate template;
|
||||
ReactiveSessionFactory sessionFactory;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
@@ -588,7 +582,6 @@ public class ReactiveCqlTemplateUnitTests {
|
||||
when(session.prepare(anyString())).thenReturn(Mono.just(preparedStatement));
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
when(session.execute(boundStatement)).thenReturn(Mono.just(reactiveResultSet));
|
||||
when(reactiveResultSet.wasApplied()).thenReturn(true);
|
||||
|
||||
Flux<ReactiveResultSet> flux = template.execute("UPDATE user SET a = 'b';",
|
||||
(session, ps) -> session.execute(ps.bind()));
|
||||
@@ -603,7 +596,6 @@ public class ReactiveCqlTemplateUnitTests {
|
||||
public void executePreparedStatementCreatorShouldExecuteDeferred() {
|
||||
|
||||
when(session.execute(boundStatement)).thenReturn(Mono.just(reactiveResultSet));
|
||||
when(reactiveResultSet.wasApplied()).thenReturn(true);
|
||||
|
||||
Flux<ReactiveResultSet> flux = template.execute(session -> Mono.just(preparedStatement),
|
||||
(session, ps) -> session.execute(boundStatement));
|
||||
@@ -616,9 +608,6 @@ public class ReactiveCqlTemplateUnitTests {
|
||||
@Test // DATACASS-335
|
||||
public void executePreparedStatementCreatorShouldTranslateStatementCreationExceptions() {
|
||||
|
||||
when(session.execute(boundStatement)).thenReturn(Mono.just(reactiveResultSet));
|
||||
when(reactiveResultSet.wasApplied()).thenReturn(true);
|
||||
|
||||
Flux<ReactiveResultSet> flux = template.execute(session -> {
|
||||
throw new NoHostAvailableException(Collections.emptyMap());
|
||||
}, (session, ps) -> session.execute(boundStatement));
|
||||
@@ -635,9 +624,6 @@ public class ReactiveCqlTemplateUnitTests {
|
||||
@Test // DATACASS-335
|
||||
public void executePreparedStatementCreatorShouldTranslateStatementCallbackExceptions() {
|
||||
|
||||
when(session.execute(boundStatement)).thenReturn(Mono.just(reactiveResultSet));
|
||||
when(reactiveResultSet.wasApplied()).thenReturn(true);
|
||||
|
||||
Flux<ReactiveResultSet> flux = template.execute(session -> Mono.just(preparedStatement), (session, ps) -> {
|
||||
throw new NoHostAvailableException(Collections.emptyMap());
|
||||
});
|
||||
@@ -654,7 +640,6 @@ public class ReactiveCqlTemplateUnitTests {
|
||||
@Test // DATACASS-335
|
||||
public void queryPreparedStatementCreatorShouldReturnResult() {
|
||||
|
||||
when(session.prepare(anyString())).thenReturn(Mono.just(preparedStatement));
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
when(session.execute(boundStatement)).thenReturn(Mono.just(reactiveResultSet));
|
||||
when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
|
||||
@@ -669,8 +654,6 @@ public class ReactiveCqlTemplateUnitTests {
|
||||
@Test // DATACASS-335
|
||||
public void queryPreparedStatementCreatorAndBinderShouldReturnResult() {
|
||||
|
||||
when(session.prepare(anyString())).thenReturn(Mono.just(preparedStatement));
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
when(session.execute(boundStatement)).thenReturn(Mono.just(reactiveResultSet));
|
||||
when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
|
||||
|
||||
@@ -687,8 +670,6 @@ public class ReactiveCqlTemplateUnitTests {
|
||||
@Test // DATACASS-335
|
||||
public void queryPreparedStatementCreatorAndBinderAndMapperShouldReturnResult() {
|
||||
|
||||
when(session.prepare(anyString())).thenReturn(Mono.just(preparedStatement));
|
||||
when(preparedStatement.bind()).thenReturn(boundStatement);
|
||||
when(session.execute(boundStatement)).thenReturn(Mono.just(reactiveResultSet));
|
||||
when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
|
||||
|
||||
@@ -827,7 +808,7 @@ public class ReactiveCqlTemplateUnitTests {
|
||||
|
||||
String[] results = { "Walter", "Hank", " Jesse" };
|
||||
|
||||
when(this.session.execute(any(Statement.class))).thenReturn(Mono.just(reactiveResultSet));
|
||||
when(this.session.execute((Statement) any())).thenReturn(Mono.just(reactiveResultSet));
|
||||
when(this.reactiveResultSet.rows()).thenReturn(Flux.just(row, row, row));
|
||||
|
||||
when(this.row.getString(0)).thenReturn(results[0], results[1], results[2]);
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.support.exception.IncorrectResultSetColumnCountException;
|
||||
import org.springframework.dao.TypeMismatchDataAccessException;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.session.DefaultSessionFactory;
|
||||
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
@@ -21,7 +21,7 @@ import static org.mockito.Mockito.*;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.cassandra.core.session.SessionFactory;
|
||||
|
||||
@@ -15,15 +15,14 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.session.lookup;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.session.SessionFactory;
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
|
||||
@@ -23,8 +23,24 @@ import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.support.exception.*;
|
||||
import org.springframework.cassandra.support.exception.CassandraAuthenticationException;
|
||||
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
|
||||
import org.springframework.cassandra.support.exception.CassandraInsufficientReplicasAvailableException;
|
||||
import org.springframework.cassandra.support.exception.CassandraInternalException;
|
||||
import org.springframework.cassandra.support.exception.CassandraInvalidConfigurationInQueryException;
|
||||
import org.springframework.cassandra.support.exception.CassandraInvalidQueryException;
|
||||
import org.springframework.cassandra.support.exception.CassandraKeyspaceExistsException;
|
||||
import org.springframework.cassandra.support.exception.CassandraQuerySyntaxException;
|
||||
import org.springframework.cassandra.support.exception.CassandraReadTimeoutException;
|
||||
import org.springframework.cassandra.support.exception.CassandraSchemaElementExistsException;
|
||||
import org.springframework.cassandra.support.exception.CassandraSchemaElementExistsException.ElementType;
|
||||
import org.springframework.cassandra.support.exception.CassandraTableExistsException;
|
||||
import org.springframework.cassandra.support.exception.CassandraTraceRetrievalException;
|
||||
import org.springframework.cassandra.support.exception.CassandraTruncateException;
|
||||
import org.springframework.cassandra.support.exception.CassandraTypeMismatchException;
|
||||
import org.springframework.cassandra.support.exception.CassandraUnauthorizedException;
|
||||
import org.springframework.cassandra.support.exception.CassandraUncategorizedException;
|
||||
import org.springframework.cassandra.support.exception.CassandraWriteTimeoutException;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
@@ -34,7 +50,34 @@ import com.datastax.driver.core.ConsistencyLevel;
|
||||
import com.datastax.driver.core.DataType;
|
||||
import com.datastax.driver.core.ProtocolVersion;
|
||||
import com.datastax.driver.core.WriteType;
|
||||
import com.datastax.driver.core.exceptions.*;
|
||||
import com.datastax.driver.core.exceptions.AlreadyExistsException;
|
||||
import com.datastax.driver.core.exceptions.AuthenticationException;
|
||||
import com.datastax.driver.core.exceptions.BootstrappingException;
|
||||
import com.datastax.driver.core.exceptions.BusyConnectionException;
|
||||
import com.datastax.driver.core.exceptions.CodecNotFoundException;
|
||||
import com.datastax.driver.core.exceptions.ConnectionException;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
import com.datastax.driver.core.exceptions.DriverInternalError;
|
||||
import com.datastax.driver.core.exceptions.FunctionExecutionException;
|
||||
import com.datastax.driver.core.exceptions.InvalidConfigurationInQueryException;
|
||||
import com.datastax.driver.core.exceptions.InvalidQueryException;
|
||||
import com.datastax.driver.core.exceptions.InvalidTypeException;
|
||||
import com.datastax.driver.core.exceptions.NoHostAvailableException;
|
||||
import com.datastax.driver.core.exceptions.OverloadedException;
|
||||
import com.datastax.driver.core.exceptions.PagingStateException;
|
||||
import com.datastax.driver.core.exceptions.ReadFailureException;
|
||||
import com.datastax.driver.core.exceptions.ReadTimeoutException;
|
||||
import com.datastax.driver.core.exceptions.SyntaxError;
|
||||
import com.datastax.driver.core.exceptions.TraceRetrievalException;
|
||||
import com.datastax.driver.core.exceptions.TruncateException;
|
||||
import com.datastax.driver.core.exceptions.UnauthorizedException;
|
||||
import com.datastax.driver.core.exceptions.UnavailableException;
|
||||
import com.datastax.driver.core.exceptions.UnpreparedException;
|
||||
import com.datastax.driver.core.exceptions.UnresolvedUserTypeException;
|
||||
import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
|
||||
import com.datastax.driver.core.exceptions.UnsupportedProtocolVersionException;
|
||||
import com.datastax.driver.core.exceptions.WriteFailureException;
|
||||
import com.datastax.driver.core.exceptions.WriteTimeoutException;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.core.cql.generator;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.*;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra;
|
||||
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -66,30 +66,11 @@ public class RowMockUtil {
|
||||
return -1;
|
||||
});
|
||||
|
||||
when(columnDefinitionsMock.getType(anyString())).thenAnswer(new Answer<DataType>() {
|
||||
@Override
|
||||
public DataType answer(InvocationOnMock invocation) throws Throwable {
|
||||
|
||||
return Arrays.stream(columns)
|
||||
.filter(column -> column.name.equalsIgnoreCase((String) invocation.getArguments()[0])).findFirst()
|
||||
.map(column -> column.type).orElse(null);
|
||||
}
|
||||
});
|
||||
|
||||
when(columnDefinitionsMock.getType(anyInt()))
|
||||
.thenAnswer(invocation -> columns[(Integer) invocation.getArguments()[0]].type);
|
||||
|
||||
when(rowMock.getObject(anyInt())).thenAnswer(invocation -> columns[(Integer) invocation.getArguments()[0]].value);
|
||||
|
||||
when(rowMock.getObject(anyString())).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return Arrays.stream(columns)
|
||||
.filter(column -> column.name.equalsIgnoreCase((String) invocation.getArguments()[0])).findFirst()
|
||||
.map(column -> column.value).orElse(null);
|
||||
}
|
||||
});
|
||||
|
||||
return rowMock;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package org.springframework.data.cassandra.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.cassandra.config.CassandraSessionFactoryBean.*;
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
|
||||
@@ -57,7 +57,6 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
public void setup() {
|
||||
|
||||
when(mockCluster.connect()).thenReturn(mockSession);
|
||||
when(mockSession.getCluster()).thenReturn(mockCluster);
|
||||
|
||||
factoryBean = spy(new CassandraSessionFactoryBean());
|
||||
factoryBean.setCluster(mockCluster);
|
||||
@@ -103,9 +102,9 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
final boolean dropTables, final boolean dropUnused, final boolean ifNotExists) {
|
||||
|
||||
doAnswer(invocationOnMock -> {
|
||||
assertThat(invocationOnMock.getArgumentAt(0, Boolean.class)).isEqualTo(dropTables);
|
||||
assertThat(invocationOnMock.getArgumentAt(1, Boolean.class)).isEqualTo(dropUnused);
|
||||
assertThat(invocationOnMock.getArgumentAt(2, Boolean.class)).isEqualTo(ifNotExists);
|
||||
assertThat(invocationOnMock.<Boolean> getArgument(0)).isEqualTo(dropTables);
|
||||
assertThat(invocationOnMock.<Boolean> getArgument(1)).isEqualTo(dropUnused);
|
||||
assertThat(invocationOnMock.<Boolean> getArgument(2)).isEqualTo(ifNotExists);
|
||||
return null;
|
||||
}).when(factoryBean).createTables(anyBoolean(), anyBoolean(), anyBoolean());
|
||||
|
||||
@@ -143,14 +142,6 @@ public class CassandraSessionFactoryBeanUnitTests {
|
||||
@Test // DATACASS-219
|
||||
public void performsSchemaActionDoesNotCallCreateTablesWhenSchemaActionIsNone() {
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||
fail("'createTables(..)' should not have been called");
|
||||
return null;
|
||||
}
|
||||
}).when(factoryBean).createTables(anyBoolean(), anyBoolean(), anyBoolean());
|
||||
|
||||
factoryBean.setSchemaAction(SchemaAction.NONE);
|
||||
|
||||
assertThat(factoryBean.getSchemaAction()).isEqualTo(SchemaAction.NONE);
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.cassandra.convert;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
@@ -23,7 +22,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
|
||||
import com.datastax.driver.core.ColumnDefinitions;
|
||||
@@ -33,6 +32,7 @@ import com.datastax.driver.core.Row;
|
||||
* Unit tests for {@link ColumnReader}.
|
||||
*
|
||||
* @author Christopher Batey
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ColumnReaderUnitTests {
|
||||
@@ -47,14 +47,15 @@ public class ColumnReaderUnitTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
given(row.getColumnDefinitions()).willReturn(columnDefinitions);
|
||||
|
||||
when(row.getColumnDefinitions()).thenReturn(columnDefinitions);
|
||||
underTest = new ColumnReader(row);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void throwsIllegalArgumentExceptionIfColumnDoesNotExistByName() throws Exception {
|
||||
given(columnDefinitions.contains(NON_EXISTENT_COLUMN)).willReturn(false);
|
||||
given(columnDefinitions.getIndexOf(NON_EXISTENT_COLUMN)).willReturn(-1);
|
||||
|
||||
when(columnDefinitions.getIndexOf(NON_EXISTENT_COLUMN)).thenReturn(-1);
|
||||
|
||||
try {
|
||||
underTest.get(NON_EXISTENT_COLUMN);
|
||||
@@ -66,8 +67,8 @@ public class ColumnReaderUnitTests {
|
||||
|
||||
@Test
|
||||
public void throwsIllegalArgumentExceptionIfColumnDoesNotExistByCqlIdentifier() throws Exception {
|
||||
given(columnDefinitions.contains(NON_EXISTENT_COLUMN)).willReturn(false);
|
||||
given(columnDefinitions.getIndexOf(NON_EXISTENT_COLUMN)).willReturn(-1);
|
||||
|
||||
when(columnDefinitions.getIndexOf(NON_EXISTENT_COLUMN)).thenReturn(-1);
|
||||
|
||||
try {
|
||||
underTest.get(new CqlIdentifier(NON_EXISTENT_COLUMN));
|
||||
@@ -79,8 +80,8 @@ public class ColumnReaderUnitTests {
|
||||
|
||||
@Test
|
||||
public void throwsIllegalArgumentExceptionIfColumnDoesNotExistByCqlIdentifierAndType() throws Exception {
|
||||
given(columnDefinitions.contains(NON_EXISTENT_COLUMN)).willReturn(false);
|
||||
given(columnDefinitions.getIndexOf(NON_EXISTENT_COLUMN)).willReturn(-1);
|
||||
|
||||
when(columnDefinitions.getIndexOf(NON_EXISTENT_COLUMN)).thenReturn(-1);
|
||||
|
||||
try {
|
||||
underTest.get(new CqlIdentifier(NON_EXISTENT_COLUMN), String.class);
|
||||
|
||||
@@ -48,7 +48,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.PrimaryKeyType;
|
||||
import org.springframework.core.SpringVersion;
|
||||
import org.springframework.core.convert.ConverterNotFoundException;
|
||||
@@ -97,10 +97,10 @@ public class MappingCassandraConverterUnitTests {
|
||||
|
||||
@Rule public final ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Mock private Row rowMock;
|
||||
@Mock Row rowMock;
|
||||
|
||||
private CassandraMappingContext mappingContext;
|
||||
private MappingCassandraConverter mappingCassandraConverter;
|
||||
CassandraMappingContext mappingContext;
|
||||
MappingCassandraConverter mappingCassandraConverter;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -908,8 +908,7 @@ public class MappingCassandraConverterUnitTests {
|
||||
List<Clause> clauses = (List<Clause>) ReflectionTestUtils.getField(where, "clauses");
|
||||
|
||||
for (Clause clause : clauses) {
|
||||
result.put(ReflectionTestUtils.invokeMethod(clause, "name"),
|
||||
ReflectionTestUtils.getField(clause, "value"));
|
||||
result.put(ReflectionTestUtils.invokeMethod(clause, "name"), ReflectionTestUtils.getField(clause, "value"));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -16,13 +16,12 @@
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -36,7 +35,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
|
||||
import org.springframework.data.cassandra.domain.Person;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
@@ -63,17 +62,16 @@ public class AsyncCassandraTemplateUnitTests {
|
||||
@Mock ResultSet resultSet;
|
||||
@Mock Row row;
|
||||
@Mock ColumnDefinitions columnDefinitions;
|
||||
|
||||
@Captor ArgumentCaptor<Statement> statementCaptor;
|
||||
|
||||
private AsyncCassandraTemplate template;
|
||||
AsyncCassandraTemplate template;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
template = new AsyncCassandraTemplate(session);
|
||||
when(session.executeAsync(anyString())).thenReturn(new TestResultSetFuture(resultSet));
|
||||
when(session.executeAsync(any(Statement.class))).thenReturn(new TestResultSetFuture(resultSet));
|
||||
when(resultSet.getColumnDefinitions()).thenReturn(columnDefinitions);
|
||||
when(row.getColumnDefinitions()).thenReturn(columnDefinitions);
|
||||
}
|
||||
|
||||
@@ -102,8 +100,7 @@ public class AsyncCassandraTemplateUnitTests {
|
||||
@Test // DATACASS-292
|
||||
public void selectUsingCqlShouldInvokeCallbackWithMappedResults() {
|
||||
|
||||
when(resultSet.iterator()).thenReturn(Collections.singleton(row).iterator());
|
||||
when(resultSet.spliterator()).thenReturn(Arrays.asList(row).spliterator());
|
||||
when(resultSet.spliterator()).thenReturn(Collections.singletonList(row).spliterator());
|
||||
when(columnDefinitions.contains(anyString())).thenReturn(true);
|
||||
when(columnDefinitions.getType(anyInt())).thenReturn(DataType.ascii());
|
||||
|
||||
@@ -157,8 +154,7 @@ public class AsyncCassandraTemplateUnitTests {
|
||||
when(row.getObject(1)).thenReturn("Walter");
|
||||
when(row.getObject(2)).thenReturn("White");
|
||||
|
||||
ListenableFuture<Person> future = template.selectOne("SELECT * FROM person WHERE id='myid';",
|
||||
Person.class);
|
||||
ListenableFuture<Person> future = template.selectOne("SELECT * FROM person WHERE id='myid';", Person.class);
|
||||
|
||||
assertThat(getUninterruptibly(future)).isEqualTo(new Person("myid", "Walter", "White"));
|
||||
verify(session).executeAsync(statementCaptor.capture());
|
||||
@@ -191,8 +187,6 @@ public class AsyncCassandraTemplateUnitTests {
|
||||
public void existsShouldReturnExistingElement() {
|
||||
|
||||
when(resultSet.iterator()).thenReturn(Collections.singleton(row).iterator());
|
||||
when(columnDefinitions.contains(anyString())).thenReturn(true);
|
||||
when(columnDefinitions.getType(anyInt())).thenReturn(DataType.ascii());
|
||||
|
||||
ListenableFuture<Boolean> future = template.exists("myid", Person.class);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.CqlOperations;
|
||||
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
|
||||
import org.springframework.data.cassandra.mapping.UserDefinedType;
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -32,7 +32,7 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
|
||||
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
|
||||
import org.springframework.data.cassandra.domain.Person;
|
||||
@@ -59,17 +59,16 @@ public class CassandraTemplateUnitTests {
|
||||
@Mock ResultSet resultSet;
|
||||
@Mock Row row;
|
||||
@Mock ColumnDefinitions columnDefinitions;
|
||||
|
||||
@Captor ArgumentCaptor<Statement> statementCaptor;
|
||||
|
||||
private CassandraTemplate template;
|
||||
CassandraTemplate template;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
template = new CassandraTemplate(session, new MappingCassandraConverter());
|
||||
when(session.execute(anyString())).thenReturn(resultSet);
|
||||
when(session.execute(any(Statement.class))).thenReturn(resultSet);
|
||||
when(resultSet.getColumnDefinitions()).thenReturn(columnDefinitions);
|
||||
when(row.getColumnDefinitions()).thenReturn(columnDefinitions);
|
||||
}
|
||||
|
||||
@@ -157,8 +156,6 @@ public class CassandraTemplateUnitTests {
|
||||
public void existsShouldReturnExistingElement() {
|
||||
|
||||
when(resultSet.iterator()).thenReturn(Collections.singleton(row).iterator());
|
||||
when(columnDefinitions.contains(anyString())).thenReturn(true);
|
||||
when(columnDefinitions.getType(anyInt())).thenReturn(DataType.ascii());
|
||||
|
||||
boolean exists = template.exists("myid", Person.class);
|
||||
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -26,9 +29,6 @@ import org.springframework.data.cassandra.convert.MappingCassandraConverter;
|
||||
import org.springframework.data.cassandra.domain.Person;
|
||||
import org.springframework.data.cassandra.test.integration.support.SchemaTestUtils;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ReactiveCassandraTemplate}.
|
||||
*
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -32,15 +32,12 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.session.ReactiveResultSet;
|
||||
import org.springframework.cassandra.core.session.ReactiveSession;
|
||||
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
|
||||
import org.springframework.data.cassandra.domain.Person;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import com.datastax.driver.core.ColumnDefinitions;
|
||||
import com.datastax.driver.core.DataType;
|
||||
import com.datastax.driver.core.Row;
|
||||
@@ -59,18 +56,17 @@ public class ReactiveCassandraTemplateUnitTests {
|
||||
@Mock ReactiveResultSet reactiveResultSet;
|
||||
@Mock Row row;
|
||||
@Mock ColumnDefinitions columnDefinitions;
|
||||
|
||||
@Captor ArgumentCaptor<Statement> statementCaptor;
|
||||
|
||||
private ReactiveCassandraTemplate template;
|
||||
ReactiveCassandraTemplate template;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
template = new ReactiveCassandraTemplate(session);
|
||||
|
||||
when(session.execute(anyString())).thenReturn(Mono.just(reactiveResultSet));
|
||||
when(session.execute(any(Statement.class))).thenReturn(Mono.just(reactiveResultSet));
|
||||
when(reactiveResultSet.getColumnDefinitions()).thenReturn(columnDefinitions);
|
||||
when(row.getColumnDefinitions()).thenReturn(columnDefinitions);
|
||||
}
|
||||
|
||||
@@ -138,8 +134,6 @@ public class ReactiveCassandraTemplateUnitTests {
|
||||
public void existsShouldReturnExistingElement() {
|
||||
|
||||
when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
|
||||
when(columnDefinitions.contains(anyString())).thenReturn(true);
|
||||
when(columnDefinitions.getType(anyInt())).thenReturn(DataType.ascii());
|
||||
|
||||
Mono<Boolean> mono = template.exists("myid", Person.class);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -27,7 +28,7 @@ import java.util.Optional;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
@@ -22,7 +22,7 @@ import static org.springframework.data.cassandra.mapping.CassandraPersistentProp
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.lang.annotation.Target;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.mapping.model.MappingException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.cassandra.mapping.multipackagescanning;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.config;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.cassandra.domain.AllPossibleTypes;
|
||||
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
|
||||
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.lang.reflect.Method;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.cassandra.domain.Person;
|
||||
import org.springframework.data.cassandra.mapping.CassandraType;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
|
||||
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
|
||||
import org.springframework.data.cassandra.mapping.CassandraPersistentProperty;
|
||||
@@ -49,11 +49,9 @@ import com.datastax.driver.core.DataType;
|
||||
public class ConvertingParameterAccessorUnitTests {
|
||||
|
||||
@Mock CassandraParameterAccessor mockParameterAccessor;
|
||||
|
||||
@Mock CassandraPersistentProperty mockProperty;
|
||||
|
||||
ConvertingParameterAccessor convertingParameterAccessor;
|
||||
|
||||
MappingCassandraConverter converter;
|
||||
|
||||
@Before
|
||||
@@ -77,25 +75,18 @@ public class ConvertingParameterAccessorUnitTests {
|
||||
public void shouldReturnNativeBindableValue() {
|
||||
|
||||
when(mockParameterAccessor.getBindableValue(0)).thenReturn("hello");
|
||||
when(mockParameterAccessor.getDataType(0)).thenReturn(DataType.varchar());
|
||||
when(mockParameterAccessor.getParameterType(0)).thenReturn((Class) String.class);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
@Test // DATACASS-296
|
||||
@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))
|
||||
.isEqualTo(com.datastax.driver.core.LocalDate.fromYearMonthDay(2010, 7, 4));
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
|
||||
@@ -129,9 +129,6 @@ public class PartTreeCassandraQueryUnitTests {
|
||||
@Test // DATACASS-172
|
||||
public void shouldDeriveSimpleQueryWithUDTValue() {
|
||||
|
||||
when(userTypeResolverMock.resolveType(CqlIdentifier.cqlId("address"))).thenReturn(userTypeMock);
|
||||
when(userTypeMock.newValue()).thenReturn(udtValueMock);
|
||||
|
||||
String query = deriveQueryFromMethod("findByMainAddress", udtValueMock);
|
||||
|
||||
assertThat(query).isEqualTo("SELECT * FROM person WHERE mainaddress={};");
|
||||
@@ -140,9 +137,6 @@ public class PartTreeCassandraQueryUnitTests {
|
||||
@Test // DATACASS-357
|
||||
public void shouldDeriveUdtInCollectionQuery() {
|
||||
|
||||
when(userTypeResolverMock.resolveType(CqlIdentifier.cqlId("address"))).thenReturn(userTypeMock);
|
||||
when(userTypeMock.newValue()).thenReturn(udtValueMock);
|
||||
|
||||
String query = deriveQueryFromMethod("findByMainAddressIn", new Class[] { Collection.class },
|
||||
Collections.singleton(udtValueMock));
|
||||
|
||||
@@ -171,8 +165,13 @@ public class PartTreeCassandraQueryUnitTests {
|
||||
}
|
||||
|
||||
private PartTreeCassandraQuery createQueryForMethod(String methodName, Class<?>... paramTypes) {
|
||||
|
||||
Class<?>[] userTypes = Arrays.stream(paramTypes)//
|
||||
.map(it -> it.getName().contains("Mockito") ? it.getSuperclass() : it)//
|
||||
.toArray(size -> new Class<?>[size]);
|
||||
|
||||
try {
|
||||
Method method = Repo.class.getMethod(methodName, paramTypes);
|
||||
Method method = Repo.class.getMethod(methodName, userTypes);
|
||||
ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
|
||||
CassandraQueryMethod queryMethod = new CassandraQueryMethod(method, new DefaultRepositoryMetadata(Repo.class),
|
||||
factory, mappingContext);
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.lang.reflect.Method;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.data.cassandra.domain.AllPossibleTypes;
|
||||
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
|
||||
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.ReactiveCqlOperations;
|
||||
import org.springframework.cassandra.core.ReactiveSessionCallback;
|
||||
import org.springframework.cassandra.core.session.ReactiveSession;
|
||||
@@ -71,9 +71,9 @@ public class ReactiveStringBasedCassandraQueryUnitTests {
|
||||
ProjectionFactory factory;
|
||||
|
||||
@Before
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
|
||||
when(operations.getConverter()).thenReturn(converter);
|
||||
when(operations.getReactiveCqlOperations()).thenReturn(cqlOperations);
|
||||
when(cqlOperations.execute(any(ReactiveSessionCallback.class))).thenAnswer(
|
||||
invocation -> ((ReactiveSessionCallback) invocation.getArguments()[0]).doInSession(reactiveSession));
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -32,7 +33,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cassandra.core.CqlOperations;
|
||||
import org.springframework.cassandra.core.SessionCallback;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
@@ -91,12 +92,12 @@ public class StringBasedCassandraQueryUnitTests {
|
||||
ProjectionFactory factory;
|
||||
|
||||
@Before
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
|
||||
BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
|
||||
mappingContext.setUserTypeResolver(userTypeResolver);
|
||||
|
||||
when(operations.getConverter()).thenReturn(converter);
|
||||
when(operations.getCqlOperations()).thenReturn(cqlOperations);
|
||||
when(cqlOperations.execute(any(SessionCallback.class)))
|
||||
.thenAnswer(invocation -> ((SessionCallback) invocation.getArguments()[0]).doInSession(session));
|
||||
@@ -318,7 +319,6 @@ public class StringBasedCassandraQueryUnitTests {
|
||||
UserType addressType = createUserType("address", Arrays.asList(city, country));
|
||||
|
||||
when(userTypeResolver.resolveType(CqlIdentifier.cqlId("address"))).thenReturn(addressType);
|
||||
when(udtValue.getType()).thenReturn(addressType);
|
||||
|
||||
StringBasedCassandraQuery cassandraQuery = getQueryMethod("findByMainAddress", Address.class);
|
||||
CassandraParameterAccessor accessor = new ConvertingParameterAccessor(converter,
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.core.CassandraTemplate;
|
||||
import org.springframework.data.cassandra.domain.Person;
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
|
||||
import org.springframework.data.cassandra.domain.Person;
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -307,6 +306,8 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa
|
||||
|
||||
@Test // DATACASS-297
|
||||
public void streamShouldReturnEntities() {
|
||||
|
||||
long before = personRepository.count();
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
Person person = new Person();
|
||||
@@ -320,13 +321,8 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa
|
||||
|
||||
Stream<Person> allPeople = personRepository.findAllPeople();
|
||||
|
||||
long count = allPeople.peek(new Consumer<Person>() {
|
||||
@Override
|
||||
public void accept(Person person) {
|
||||
assertThat(person).isInstanceOf(Person.class);
|
||||
}
|
||||
}).count();
|
||||
long count = allPeople.peek(person -> assertThat(person).isInstanceOf(Person.class)).count();
|
||||
|
||||
assertThat(count).isEqualTo(100L);
|
||||
assertThat(count).isEqualTo(before + 100L);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user