DATACOUCH-144 - Detect N1QL dependency and fail fast if not available.
Detect N1QL is not available at configuration time for the repositories and at runtime for the template. This throws a UnsupportedCouchbaseFeatureException. The ClusterInfo is captured at bootstrap and used to determine if the feature is available. The xml configuration will need the ClusterInfo-related credentials to be provided explicitly.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.springframework.data.couchbase;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -7,6 +9,10 @@ import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.Cluster;
|
||||
import com.couchbase.client.java.CouchbaseBucket;
|
||||
import com.couchbase.client.java.CouchbaseCluster;
|
||||
import com.couchbase.client.java.cluster.ClusterInfo;
|
||||
import com.couchbase.client.java.cluster.DefaultClusterInfo;
|
||||
import com.couchbase.client.java.util.features.CouchbaseFeature;
|
||||
import com.couchbase.client.java.util.features.Version;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -18,45 +24,53 @@ import org.springframework.data.couchbase.core.WriteResultChecking;
|
||||
@Configuration
|
||||
public class UnitTestApplicationConfig extends AbstractCouchbaseConfiguration {
|
||||
|
||||
@Bean
|
||||
public String couchbaseAdminUser() {
|
||||
return "someLogin";
|
||||
}
|
||||
@Bean
|
||||
public String couchbaseAdminUser() {
|
||||
return "someLogin";
|
||||
}
|
||||
|
||||
@Bean
|
||||
public String couchbaseAdminPassword() {
|
||||
return "somePassword";
|
||||
}
|
||||
@Bean
|
||||
public String couchbaseAdminPassword() {
|
||||
return "somePassword";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getBootstrapHosts() {
|
||||
return Collections.singletonList("192.1.2.3");
|
||||
}
|
||||
@Override
|
||||
protected List<String> getBootstrapHosts() {
|
||||
return Collections.singletonList("192.1.2.3");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBucketName() {
|
||||
return "someBucket";
|
||||
}
|
||||
@Override
|
||||
protected String getBucketName() {
|
||||
return "someBucket";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBucketPassword() {
|
||||
return "someBucketPassword";
|
||||
}
|
||||
@Override
|
||||
protected String getBucketPassword() {
|
||||
return "someBucketPassword";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cluster couchbaseCluster() throws Exception {
|
||||
return Mockito.mock(CouchbaseCluster.class);
|
||||
}
|
||||
@Override
|
||||
public Cluster couchbaseCluster() throws Exception {
|
||||
return Mockito.mock(CouchbaseCluster.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bucket couchbaseClient() throws Exception {
|
||||
return Mockito.mock(CouchbaseBucket.class);
|
||||
}
|
||||
@Override
|
||||
public ClusterInfo couchbaseClusterInfo() {
|
||||
DefaultClusterInfo mock = Mockito.mock(DefaultClusterInfo.class);
|
||||
when(mock.checkAvailable(CouchbaseFeature.N1QL)).thenReturn(true);
|
||||
when(mock.getMinVersion()).thenReturn(new Version(4, 0, 0));
|
||||
return mock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CouchbaseTemplate couchbaseTemplate() throws Exception {
|
||||
CouchbaseTemplate template = super.couchbaseTemplate();
|
||||
template.setWriteResultChecking(WriteResultChecking.LOG);
|
||||
return template;
|
||||
}
|
||||
@Override
|
||||
public Bucket couchbaseClient() throws Exception {
|
||||
return Mockito.mock(CouchbaseBucket.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CouchbaseTemplate couchbaseTemplate() throws Exception {
|
||||
CouchbaseTemplate template = super.couchbaseTemplate();
|
||||
template.setWriteResultChecking(WriteResultChecking.LOG);
|
||||
return template;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user