DATACOUCH-519 - Apply formatting for changes
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
package org.springframework.data.couchbase.core;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.springframework.data.couchbase.config.BeanNames.COUCHBASE_TEMPLATE;
|
||||
import static org.springframework.data.couchbase.config.BeanNames.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
@@ -33,19 +33,14 @@ import org.springframework.dao.DataRetrievalFailureException;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.data.couchbase.CouchbaseClientFactory;
|
||||
import org.springframework.data.couchbase.SimpleCouchbaseClientFactory;
|
||||
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
|
||||
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
|
||||
import org.springframework.data.couchbase.domain.Config;
|
||||
import org.springframework.data.couchbase.domain.User;
|
||||
import org.springframework.data.couchbase.util.Capabilities;
|
||||
import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests;
|
||||
import org.springframework.data.couchbase.util.ClusterType;
|
||||
import org.springframework.data.couchbase.util.IgnoreWhen;
|
||||
|
||||
/**
|
||||
* KV tests
|
||||
*
|
||||
* Theses tests rely on a cb server running.
|
||||
* KV tests Theses tests rely on a cb server running.
|
||||
*
|
||||
* @author Michael Nitschinger
|
||||
* @author Michael Reiche
|
||||
@@ -70,7 +65,7 @@ class CouchbaseTemplateKeyValueIntegrationTests extends ClusterAwareIntegrationT
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
ApplicationContext ac = new AnnotationConfigApplicationContext(Config.class);
|
||||
couchbaseTemplate = (CouchbaseTemplate)ac.getBean(COUCHBASE_TEMPLATE);
|
||||
couchbaseTemplate = (CouchbaseTemplate) ac.getBean(COUCHBASE_TEMPLATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,8 +113,7 @@ class CouchbaseTemplateKeyValueIntegrationTests extends ClusterAwareIntegrationT
|
||||
assertTrue(removeResult.getCas() != 0);
|
||||
assertTrue(removeResult.getMutationToken().isPresent());
|
||||
|
||||
assertThrows(DataRetrievalFailureException.class,
|
||||
() -> couchbaseTemplate.findById(User.class).one(user.getId()));
|
||||
assertThrows(DataRetrievalFailureException.class, () -> couchbaseTemplate.findById(User.class).one(user.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -17,17 +17,15 @@
|
||||
package org.springframework.data.couchbase.core;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.springframework.data.couchbase.config.BeanNames.COUCHBASE_TEMPLATE;
|
||||
import static org.springframework.data.couchbase.config.BeanNames.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.data.couchbase.domain.Config;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -37,6 +35,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
import org.springframework.data.couchbase.CouchbaseClientFactory;
|
||||
import org.springframework.data.couchbase.SimpleCouchbaseClientFactory;
|
||||
import org.springframework.data.couchbase.domain.Config;
|
||||
import org.springframework.data.couchbase.domain.NaiveAuditorAware;
|
||||
import org.springframework.data.couchbase.domain.User;
|
||||
import org.springframework.data.couchbase.domain.time.AuditingDateTimeProvider;
|
||||
@@ -44,15 +43,12 @@ import org.springframework.data.couchbase.util.Capabilities;
|
||||
import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests;
|
||||
import org.springframework.data.couchbase.util.ClusterType;
|
||||
import org.springframework.data.couchbase.util.IgnoreWhen;
|
||||
import org.springframework.test.context.TestContext;
|
||||
|
||||
import com.couchbase.client.core.error.IndexExistsException;
|
||||
import com.couchbase.client.java.query.QueryScanConsistency;
|
||||
|
||||
/**
|
||||
* Query tests
|
||||
*
|
||||
* Theses tests rely on a cb server running
|
||||
* Query tests Theses tests rely on a cb server running
|
||||
*
|
||||
* @author Michael Nitschinger
|
||||
* @author Michael Reiche
|
||||
@@ -93,8 +89,8 @@ class CouchbaseTemplateQueryIntegrationTests extends ClusterAwareIntegrationTest
|
||||
|
||||
couchbaseTemplate.upsertById(User.class).all(Arrays.asList(user1, user2));
|
||||
|
||||
final List<User> foundUsers = couchbaseTemplate.findByQuery(User.class).consistentWith(
|
||||
QueryScanConsistency.REQUEST_PLUS).all();
|
||||
final List<User> foundUsers = couchbaseTemplate.findByQuery(User.class)
|
||||
.consistentWith(QueryScanConsistency.REQUEST_PLUS).all();
|
||||
|
||||
for (User u : foundUsers) {
|
||||
System.out.println(u);
|
||||
@@ -119,6 +115,7 @@ class CouchbaseTemplateQueryIntegrationTests extends ClusterAwareIntegrationTest
|
||||
couchbaseTemplate.removeByQuery(User.class).all();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeByQuery() {
|
||||
User user1 = new User(UUID.randomUUID().toString(), "user1", "user1");
|
||||
@@ -131,10 +128,8 @@ class CouchbaseTemplateQueryIntegrationTests extends ClusterAwareIntegrationTest
|
||||
|
||||
couchbaseTemplate.removeByQuery(User.class).consistentWith(QueryScanConsistency.REQUEST_PLUS).all();
|
||||
|
||||
assertThrows(DataRetrievalFailureException.class,
|
||||
() -> couchbaseTemplate.findById(User.class).one(user1.getId()));
|
||||
assertThrows(DataRetrievalFailureException.class,
|
||||
() -> couchbaseTemplate.findById(User.class).one(user2.getId()));
|
||||
assertThrows(DataRetrievalFailureException.class, () -> couchbaseTemplate.findById(User.class).one(user1.getId()));
|
||||
assertThrows(DataRetrievalFailureException.class, () -> couchbaseTemplate.findById(User.class).one(user2.getId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.springframework.data.couchbase.core.query;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.springframework.data.couchbase.core.query.QueryCriteria.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class QueryCriteriaTests {
|
||||
|
||||
@Test
|
||||
@@ -65,19 +65,14 @@ class QueryCriteriaTests {
|
||||
assertEquals("`name` = \"Bubba\" or (`age` > 12 or `country` = \"Austria\")", c.export());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testNestedNotIn() {
|
||||
QueryCriteria c =
|
||||
where("name").is("Bubba").or(
|
||||
where("age").gt(12).or("country").is("Austria")).and(
|
||||
where("state").notIn(new String[]{"Alabama", "Florida"}));
|
||||
assertEquals("`name` = \"Bubba\" or (`age` > 12 or `country` = \"Austria\") and " +
|
||||
"(not( (`state` in ( [ \"Alabama\", \"Florida\" ] )) ))",
|
||||
c.export());
|
||||
QueryCriteria c = where("name").is("Bubba").or(where("age").gt(12).or("country").is("Austria"))
|
||||
.and(where("state").notIn(new String[] { "Alabama", "Florida" }));
|
||||
assertEquals("`name` = \"Bubba\" or (`age` > 12 or `country` = \"Austria\") and "
|
||||
+ "(not( (`state` in ( [ \"Alabama\", \"Florida\" ] )) ))", c.export());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testLt() {
|
||||
QueryCriteria c = where("name").lt("Couch");
|
||||
@@ -156,7 +151,6 @@ class QueryCriteriaTests {
|
||||
assertEquals("not( (`name` like \"%Elvis%\") )", c.export());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testIsNull() {
|
||||
QueryCriteria c = where("name").isNull();
|
||||
@@ -201,13 +195,13 @@ class QueryCriteriaTests {
|
||||
|
||||
@Test
|
||||
void testIn() {
|
||||
QueryCriteria c = where("name").in(new String[]{"gump", "davis"});
|
||||
QueryCriteria c = where("name").in(new String[] { "gump", "davis" });
|
||||
assertEquals("`name` in ( [ \"gump\", \"davis\" ] )", c.export());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNotIn() {
|
||||
QueryCriteria c = where("name").notIn(new String[]{"gump", "davis"});
|
||||
QueryCriteria c = where("name").notIn(new String[] { "gump", "davis" });
|
||||
assertEquals("not( (`name` in ( [ \"gump\", \"davis\" ] )) )", c.export());
|
||||
}
|
||||
|
||||
@@ -222,4 +216,4 @@ class QueryCriteriaTests {
|
||||
QueryCriteria c = where("name").FALSE();
|
||||
assertEquals("not( (`name`) )", c.export());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +1,62 @@
|
||||
package org.springframework.data.couchbase.domain;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
import org.springframework.data.couchbase.core.mapping.id.GeneratedValue;
|
||||
import org.springframework.data.couchbase.core.mapping.id.GenerationStrategy;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Document
|
||||
public class AbstractEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
|
||||
private UUID id;
|
||||
@Id @GeneratedValue(strategy = GenerationStrategy.UNIQUE) private UUID id;
|
||||
|
||||
public AbstractEntity(){ }
|
||||
public AbstractEntity() {}
|
||||
|
||||
/**
|
||||
* set the id
|
||||
*/
|
||||
public void setId(UUID id) {
|
||||
this.id=id;
|
||||
}
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
/**
|
||||
* set the id
|
||||
*/
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this.id == null || obj == null || !(this.getClass().equals(obj.getClass()))) {
|
||||
return false;
|
||||
}
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
AbstractEntity that = (AbstractEntity) obj;
|
||||
if (this.id == null || obj == null || !(this.getClass().equals(obj.getClass()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.id.equals(that.getId());
|
||||
}
|
||||
AbstractEntity that = (AbstractEntity) obj;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id == null ? 0 : id.hashCode();
|
||||
}
|
||||
return this.id.equals(that.getId());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id == null ? 0 : id.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,11 @@ import org.springframework.data.couchbase.core.index.QueryIndexed;
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
@CompositeQueryIndex(fields = {"id", "name desc"})
|
||||
@CompositeQueryIndex(fields = { "id", "name desc" })
|
||||
public class Airline {
|
||||
@Id
|
||||
String id;
|
||||
@Id String id;
|
||||
|
||||
@QueryIndexed
|
||||
String name;
|
||||
@QueryIndexed String name;
|
||||
|
||||
@PersistenceConstructor
|
||||
public Airline(String id, String name) {
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.springframework.data.couchbase.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.couchbase.repository.ScanConsistency;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.couchbase.client.java.query.QueryScanConsistency;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface AirportRepository extends PagingAndSortingRepository<Airport, String> {
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package org.springframework.data.couchbase.domain;
|
||||
|
||||
import org.springframework.data.couchbase.domain.time.AuditingDateTimeProvider;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.auditing.DateTimeProvider;
|
||||
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
||||
import org.springframework.data.couchbase.domain.time.AuditingDateTimeProvider;
|
||||
import org.springframework.data.couchbase.repository.auditing.EnableCouchbaseAuditing;
|
||||
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
|
||||
|
||||
@Configuration
|
||||
@EnableCouchbaseRepositories
|
||||
@EnableCouchbaseAuditing //this activates auditing
|
||||
@EnableCouchbaseAuditing // this activates auditing
|
||||
public class Config extends AbstractCouchbaseConfiguration {
|
||||
String bucketname = "travel-sample";
|
||||
String username = "Administrator";
|
||||
@@ -46,4 +46,4 @@ public class Config extends AbstractCouchbaseConfiguration {
|
||||
public DateTimeProvider testDateTimeProvider() {
|
||||
return new AuditingDateTimeProvider();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.springframework.data.couchbase.domain;
|
||||
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
|
||||
// These are the classes that would be used for a real getCurrentAuditor() implementation
|
||||
//import org.springframework.security.core.Authentication;
|
||||
//import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@@ -27,4 +27,4 @@ public class NaiveAuditorAware implements AuditorAware<String> {
|
||||
public void setAuditor(String auditor) {
|
||||
this.auditor = Optional.of(auditor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,90 +1,92 @@
|
||||
package org.springframework.data.couchbase.domain;
|
||||
|
||||
import org.springframework.data.annotation.*;
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
import org.springframework.data.couchbase.core.mapping.event.AuditingEventListener;
|
||||
import org.springframework.data.couchbase.repository.auditing.EnableCouchbaseAuditing;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.data.annotation.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class Person extends AbstractEntity {
|
||||
Optional<String> firstname;
|
||||
Optional<String> lastname;
|
||||
Optional<String> firstname;
|
||||
Optional<String> lastname;
|
||||
|
||||
@CreatedBy
|
||||
private String creator;
|
||||
@CreatedBy private String creator;
|
||||
|
||||
@LastModifiedBy
|
||||
private String lastModifiedBy;
|
||||
@LastModifiedBy private String lastModifiedBy;
|
||||
|
||||
@LastModifiedDate
|
||||
private long lastModification;
|
||||
@LastModifiedDate private long lastModification;
|
||||
|
||||
@CreatedDate
|
||||
private long creationDate; // =System.currentTimeMillis();
|
||||
@CreatedDate private long creationDate; // =System.currentTimeMillis();
|
||||
|
||||
@Version
|
||||
private long version;
|
||||
@Version private long version;
|
||||
|
||||
public Person(){
|
||||
}
|
||||
public Person() {}
|
||||
|
||||
public Person(String firstname, String lastname){
|
||||
this();
|
||||
setFirstname(firstname);
|
||||
setLastname(lastname);
|
||||
}
|
||||
public Person(String firstname, String lastname) {
|
||||
this();
|
||||
setFirstname(firstname);
|
||||
setLastname(lastname);
|
||||
}
|
||||
|
||||
public Person(int id,String firstname, String lastname){
|
||||
this(firstname,lastname);
|
||||
setId(new UUID(id, id));
|
||||
}
|
||||
public Person(int id, String firstname, String lastname) {
|
||||
this(firstname, lastname);
|
||||
setId(new UUID(id, id));
|
||||
}
|
||||
|
||||
public Optional<String> getFirstname(){
|
||||
return firstname;
|
||||
}
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname == null ? null : ( Optional.ofNullable(firstname.equals("")?null:firstname) );
|
||||
}
|
||||
public void setFirstname(Optional<String> firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
static String optional(String name, Optional<String> obj) {
|
||||
if (obj != null)
|
||||
if (obj.isPresent())
|
||||
return (" " + name + ": '" + obj.get() + "'\n");
|
||||
else
|
||||
return " " + name + ": null\n";
|
||||
return "";
|
||||
}
|
||||
|
||||
public Optional<String> getLastname(){
|
||||
return lastname;
|
||||
}
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname == null ? null : ( Optional.ofNullable(lastname.equals("")?null:lastname) );
|
||||
}
|
||||
public void setLastname(Optional lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
public Optional<String> getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.append("Person : {\n");
|
||||
sb.append(" id : "+getId());
|
||||
sb.append(optional(", firstname",firstname));
|
||||
sb.append(optional( ", lastname", lastname));
|
||||
sb.append(", version : "+version);
|
||||
if(creator != null) sb.append(", creator : "+creator);
|
||||
if(creationDate != 0) sb.append(", creationDate : "+creationDate);
|
||||
if(lastModifiedBy != null) sb.append(", lastModifiedBy : "+lastModifiedBy);
|
||||
if(lastModification != 0) sb.append(", lastModification : "+lastModification);
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname == null ? null : (Optional.ofNullable(firstname.equals("") ? null : firstname));
|
||||
}
|
||||
|
||||
static String optional(String name, Optional<String> obj){
|
||||
if(obj != null)
|
||||
if(obj.isPresent())
|
||||
return(" "+name+ ": '"+obj.get()+"'\n");
|
||||
else
|
||||
return" "+name+": null\n" ;
|
||||
return "";
|
||||
}
|
||||
public void setFirstname(Optional<String> firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public Optional<String> getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname == null ? null : (Optional.ofNullable(lastname.equals("") ? null : lastname));
|
||||
}
|
||||
|
||||
public void setLastname(Optional lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Person : {\n");
|
||||
sb.append(" id : " + getId());
|
||||
sb.append(optional(", firstname", firstname));
|
||||
sb.append(optional(", lastname", lastname));
|
||||
sb.append(", version : " + version);
|
||||
if (creator != null)
|
||||
sb.append(", creator : " + creator);
|
||||
if (creationDate != 0)
|
||||
sb.append(", creationDate : " + creationDate);
|
||||
if (lastModifiedBy != null)
|
||||
sb.append(", lastModifiedBy : " + lastModifiedBy);
|
||||
if (lastModification != 0)
|
||||
sb.append(", lastModification : " + lastModification);
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
|
||||
package org.springframework.data.couchbase.domain;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.data.couchbase.repository.ScanConsistency;
|
||||
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.couchbase.client.java.query.QueryScanConsistency;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
@Repository
|
||||
public interface ReactiveAirportRepository extends ReactiveSortingRepository<Airport, String> {
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
|
||||
package org.springframework.data.couchbase.domain;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
@Repository
|
||||
public interface ReactiveUserRepository extends ReactiveSortingRepository<User, String> {
|
||||
|
||||
@@ -18,7 +18,13 @@ package org.springframework.data.couchbase.domain;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.data.annotation.*;
|
||||
import org.springframework.data.annotation.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
|
||||
/**
|
||||
@@ -31,20 +37,14 @@ import org.springframework.data.couchbase.core.mapping.Document;
|
||||
@Document
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@Version long version;
|
||||
@Id private String id;
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
@CreatedBy
|
||||
private String createdBy;
|
||||
@CreatedDate
|
||||
private long createdDate;
|
||||
@LastModifiedBy
|
||||
private String lastModifiedBy;
|
||||
@LastModifiedDate
|
||||
private long lastModifiedDate;
|
||||
@Version
|
||||
long version;
|
||||
@CreatedBy private String createdBy;
|
||||
@CreatedDate private long createdDate;
|
||||
@LastModifiedBy private String lastModifiedBy;
|
||||
@LastModifiedDate private long lastModifiedDate;
|
||||
|
||||
@PersistenceConstructor
|
||||
public User(final String id, final String firstname, final String lastname) {
|
||||
@@ -92,8 +92,8 @@ public class User {
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
User user = (User) o;
|
||||
return Objects.equals(id, user.id) && Objects.equals(firstname, user.firstname) && Objects.equals(lastname,
|
||||
user.lastname);
|
||||
return Objects.equals(id, user.id) && Objects.equals(firstname, user.firstname)
|
||||
&& Objects.equals(lastname, user.lastname);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.springframework.data.couchbase.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* User Repository for tests
|
||||
*
|
||||
* @author Michael Nitschinger
|
||||
* @author Michael Reiche
|
||||
*/
|
||||
@@ -34,5 +34,4 @@ public interface UserRepository extends PagingAndSortingRepository<User, String>
|
||||
|
||||
List<User> findByFirstnameAndLastname(String firstname, String lastname);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package org.springframework.data.couchbase.domain.time;
|
||||
|
||||
import org.springframework.data.auditing.DateTimeProvider;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.auditing.DateTimeProvider;
|
||||
|
||||
public class AuditingDateTimeProvider implements DateTimeProvider {
|
||||
|
||||
private DateTimeService dateTimeService = new FixedDateTimeService();
|
||||
|
||||
public AuditingDateTimeProvider() {
|
||||
}
|
||||
public AuditingDateTimeProvider() {}
|
||||
|
||||
public AuditingDateTimeProvider(DateTimeService dateTimeService) {
|
||||
this.dateTimeService = dateTimeService;
|
||||
@@ -21,4 +20,4 @@ public class AuditingDateTimeProvider implements DateTimeProvider {
|
||||
public Optional<TemporalAccessor> getNow() {
|
||||
return Optional.of(Instant.ofEpochSecond(dateTimeService.getCurrentDateAndTime().toEpochSecond()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,4 +4,4 @@ import java.time.ZonedDateTime;
|
||||
|
||||
public interface DateTimeService {
|
||||
ZonedDateTime getCurrentDateAndTime();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public class FixedDateTimeService implements DateTimeService {
|
||||
public static void main(String[] args) {
|
||||
System.out.println((new FixedDateTimeService()).getCurrentDateAndTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime getCurrentDateAndTime() {
|
||||
return ZonedDateTime.of(2020, 1, 1, 0, 0, 0, 0, ZoneId.of("GMT-8"));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println((new FixedDateTimeService()).getCurrentDateAndTime());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
|
||||
package org.springframework.data.couchbase.repository;
|
||||
|
||||
import com.couchbase.client.java.Cluster;
|
||||
import com.couchbase.client.java.manager.query.QueryIndex;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -29,29 +31,23 @@ import org.springframework.data.couchbase.util.ClusterType;
|
||||
import org.springframework.data.couchbase.util.IgnoreWhen;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import com.couchbase.client.java.Cluster;
|
||||
import com.couchbase.client.java.manager.query.QueryIndex;
|
||||
|
||||
@SpringJUnitConfig(CouchbaseRepositoryAutoQueryIndexIntegrationTests.Config.class)
|
||||
@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
|
||||
public class CouchbaseRepositoryAutoQueryIndexIntegrationTests extends ClusterAwareIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Cluster cluster;
|
||||
@Autowired private Cluster cluster;
|
||||
|
||||
/**
|
||||
* Since the index creation happens at startup, the only way to properly check is by querying the
|
||||
* index list and making sure it is present.
|
||||
* Since the index creation happens at startup, the only way to properly check is by querying the index list and
|
||||
* making sure it is present.
|
||||
*/
|
||||
@Test
|
||||
void createsSingleFieldIndex() {
|
||||
Optional<QueryIndex> foundIndex = cluster
|
||||
.queryIndexes()
|
||||
.getAllIndexes(bucketName())
|
||||
.stream()
|
||||
.filter(i -> i.name().equals("idx_airline_name"))
|
||||
.findFirst();
|
||||
Optional<QueryIndex> foundIndex = cluster.queryIndexes().getAllIndexes(bucketName()).stream()
|
||||
.filter(i -> i.name().equals("idx_airline_name")).findFirst();
|
||||
|
||||
assertTrue(foundIndex.isPresent());
|
||||
assertTrue(foundIndex.get().condition().get().contains("_class"));
|
||||
@@ -59,12 +55,8 @@ public class CouchbaseRepositoryAutoQueryIndexIntegrationTests extends ClusterAw
|
||||
|
||||
@Test
|
||||
void createsCompositeIndex() {
|
||||
Optional<QueryIndex> foundIndex = cluster
|
||||
.queryIndexes()
|
||||
.getAllIndexes(bucketName())
|
||||
.stream()
|
||||
.filter(i -> i.name().equals("idx_airline_id_name"))
|
||||
.findFirst();
|
||||
Optional<QueryIndex> foundIndex = cluster.queryIndexes().getAllIndexes(bucketName()).stream()
|
||||
.filter(i -> i.name().equals("idx_airline_id_name")).findFirst();
|
||||
|
||||
assertTrue(foundIndex.isPresent());
|
||||
assertTrue(foundIndex.get().condition().get().contains("_class"));
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
||||
import org.springframework.data.couchbase.domain.User;
|
||||
import org.springframework.data.couchbase.domain.UserRepository;
|
||||
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
|
||||
import org.springframework.data.couchbase.util.Capabilities;
|
||||
import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests;
|
||||
import org.springframework.data.couchbase.util.ClusterType;
|
||||
import org.springframework.data.couchbase.util.IgnoreWhen;
|
||||
@@ -44,8 +43,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
|
||||
public class CouchbaseRepositoryKeyValueIntegrationTests extends ClusterAwareIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
UserRepository userRepository;
|
||||
@Autowired UserRepository userRepository;
|
||||
|
||||
@Test
|
||||
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
|
||||
|
||||
@@ -37,8 +37,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
|
||||
public class ReactiveCouchbaseRepositoryKeyValueIntegrationTests extends ClusterAwareIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
ReactiveUserRepository userRepository;
|
||||
@Autowired ReactiveUserRepository userRepository;
|
||||
|
||||
@Test
|
||||
void saveAndFindById() {
|
||||
|
||||
@@ -20,7 +20,6 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -29,9 +28,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.couchbase.CouchbaseClientFactory;
|
||||
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
||||
import org.springframework.data.couchbase.domain.Airport;
|
||||
import org.springframework.data.couchbase.domain.AirportRepository;
|
||||
import org.springframework.data.couchbase.domain.ReactiveAirportRepository;
|
||||
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
|
||||
import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories;
|
||||
import org.springframework.data.couchbase.util.Capabilities;
|
||||
import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests;
|
||||
@@ -63,8 +60,7 @@ public class ReactiveCouchbaseRepositoryQueryIntegrationTests extends ClusterAwa
|
||||
Airport vie = new Airport("airports::vie", "vie", "loww");
|
||||
airportRepository.save(vie).block();
|
||||
|
||||
List<Airport> all = airportRepository.findAll().toStream()
|
||||
.collect(Collectors.toList());
|
||||
List<Airport> all = airportRepository.findAll().toStream().collect(Collectors.toList());
|
||||
|
||||
assertFalse(all.isEmpty());
|
||||
assertTrue(all.stream().anyMatch(a -> a.getId().equals("airports::vie")));
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
|
||||
package org.springframework.data.couchbase.repository.query;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.springframework.data.couchbase.core.query.QueryCriteria.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
|
||||
@@ -33,11 +38,6 @@ import org.springframework.data.repository.query.Parameters;
|
||||
import org.springframework.data.repository.query.ParametersParameterAccessor;
|
||||
import org.springframework.data.repository.query.parser.PartTree;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.springframework.data.couchbase.core.query.QueryCriteria.*;
|
||||
|
||||
class N1qlQueryCreatorTests {
|
||||
|
||||
MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> context;
|
||||
@@ -81,4 +81,4 @@ class N1qlQueryCreatorTests {
|
||||
return new DefaultParameters(method);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user