DATACOUCH-384 - Apply converters to string based query parameters

Apply the converters registered to serialize the positional and named
parameters to match the database representation

Original Pull Request: #172.
This commit is contained in:
Subhashni Balakrishnan
2018-09-18 21:57:19 -07:00
parent f2d77aea8b
commit 841803f77c
8 changed files with 67 additions and 17 deletions

View File

@@ -40,6 +40,8 @@ import org.springframework.data.repository.core.support.RepositoryFactorySupport
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
@@ -127,7 +129,7 @@ public class N1qlCouchbaseRepositoryTests {
Pageable pageable = new PageRequest(0, 8);
Page<Party> page1 = repository.findAll(pageable);
assertEquals(16, page1.getTotalElements()); //12 generated parties + 4 specifically crafted party
assertEquals(17, page1.getTotalElements()); //12 generated parties + 5 specifically crafted party
assertEquals(8, page1.getNumberOfElements());
}
@@ -136,7 +138,7 @@ public class N1qlCouchbaseRepositoryTests {
Pageable pageable = new PageRequest(0, 8, Sort.Direction.DESC, "attendees");
Page<Party> page1 = repository.findAll(pageable);
assertEquals(16, page1.getTotalElements()); //12 generated parties + 4 specifically crafted party
assertEquals(17, page1.getTotalElements()); //12 generated parties + 5 specifically crafted party
assertEquals(8, page1.getNumberOfElements());
List<Party> parties = page1.getContent();
@@ -195,4 +197,16 @@ public class N1qlCouchbaseRepositoryTests {
assertTrue(partyList.size() == 1);
}
@Test
public void testSpelDateConvertion() {
final String key = "testSpelDateConvertion";
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2018, Calendar.SEPTEMBER, 10);
Date date = cal.getTime();
partyRepository.save(new Party(key, "", "", date, 0, null));
List<Party> partyList = partyRepository.getByEventDate(date);
assertTrue(partyList.size() == 1);
assertEquals("Key mismatch", partyList.get(0).getKey(), key);
}
}

View File

@@ -89,4 +89,7 @@ public interface PartyRepository extends CouchbaseRepository<Party, String> {
List<Party> findByDescriptionOrName(String description, String name);
List<Party> removeByDescriptionOrName(String description, String name);
@Query("#{#n1ql.selectEntity} where #{#n1ql.filter} and eventDate = $1")
List<Party> getByEventDate(Date eventDate);
}

View File

@@ -18,6 +18,10 @@ package org.springframework.data.couchbase.repository;
import static org.junit.Assert.*;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -115,12 +119,25 @@ public class ReactiveN1qlCouchbaseRepositoryTests {
@Test
public void testCustomSpelCountQuery() {
long count = partyRepository.countCustom().block();
assertEquals("Test N1QL Spel based query", 15, count);
assertEquals("Test N1QL Spel based query", 17, count);
}
@Test
public void testPartTreeQuery() {
long count = partyRepository.countAllByDescriptionNotNull().block();
assertEquals("Test N1QL part tree based query", 15, count);
assertEquals("Test N1QL part tree based query", 17, count);
}
@Test
public void testSpelDateConvertion() {
final String key = "testReactiveSpelDateConvertion";
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2018, Calendar.SEPTEMBER, 15);
Date date = cal.getTime();
partyRepository.save(new Party(key, "", "", date, 0, null)).block();
List<Party> partyList = partyRepository.getByEventDate(date).collectList().block();
assertTrue(partyList.size() == 1);
assertEquals("Key mismatch", partyList.get(0).getKey(), key);
}
}

View File

@@ -57,4 +57,6 @@ public interface ReactivePartyRepository extends ReactiveCouchbaseRepository<Par
Flux<Party> findByDescriptionOrName(String description, String name);
@Query("#{#n1ql.selectEntity} where #{#n1ql.filter} and eventDate = $1")
Flux<Party> getByEventDate(Date eventDate);
}