15 changed files with 320 additions and 162 deletions
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
/* |
||||
* Copyright 2012-2016 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.autoconfigure.couchbase; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
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 org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration; |
||||
|
||||
import static org.mockito.Mockito.mock; |
||||
|
||||
/** |
||||
* Test configuration for couchbase that mocks access. |
||||
* |
||||
* @author Stephane Nicoll |
||||
*/ |
||||
@Configuration |
||||
public class CouchbaseTestConfiguration extends AbstractCouchbaseConfiguration { |
||||
|
||||
@Override |
||||
protected List<String> getBootstrapHosts() { |
||||
return Collections.singletonList("localhost"); |
||||
} |
||||
|
||||
@Override |
||||
protected String getBucketName() { |
||||
return "my-bucket"; |
||||
} |
||||
|
||||
@Override |
||||
protected String getBucketPassword() { |
||||
return "my-password"; |
||||
} |
||||
|
||||
@Override |
||||
public Cluster couchbaseCluster() throws Exception { |
||||
return mock(CouchbaseCluster.class); |
||||
} |
||||
|
||||
@Bean |
||||
public ClusterInfo couchbaseClusterInfo() { |
||||
return mock(ClusterInfo.class); |
||||
} |
||||
|
||||
@Override |
||||
public Bucket couchbaseClient() throws Exception { |
||||
return mock(CouchbaseBucket.class); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
= Spring Boot Couchbase Sample |
||||
|
||||
This sample demonstrates how you can store a simple document using Spring Data Couchbase. |
||||
|
||||
The sample expects couchbase to run on your machine with a bucket named `mybucket` and |
||||
`couchbase` for the password. You can customize these settings in `application.properties`. |
||||
|
||||
Before you use the sample, you need _at least_ to create an `all` view for the `User`: go |
||||
to the Couchbase server’s admin console and visit the Views screen, then click `Create |
||||
Development View` and name it `all` with `user` as document name. On that view, you need |
||||
to change the code to: |
||||
|
||||
```java |
||||
function (doc, meta) { |
||||
if (doc._class == "sample.data.couchbase.User") { |
||||
emit(meta.id, null); |
||||
} |
||||
} |
||||
``` |
||||
|
||||
and the _reduce_ function to `_count`. After you've saved your changes go back to `Views` |
||||
and click on `Publish` so that the `all` view move to the `Production Views` tab. |
||||
@ -1,3 +1,2 @@
@@ -1,3 +1,2 @@
|
||||
spring.data.couchbase.bucket-name=mybucket |
||||
spring.data.couchbase.bucket-password=couchbase |
||||
spring.data.couchbase.hosts[0]=127.0.0.1 |
||||
spring.data.couchbase.bucket.name=mybucket |
||||
spring.data.couchbase.bucket.password=couchbase |
||||
Loading…
Reference in new issue