DATACOUCH-265 - Verify entity filter is not added, if n1ql.filter is not in query

Original pull request: #128.
This commit is contained in:
Subhashni Balakrishnan
2017-01-10 17:26:37 -08:00
parent 5d36ecc12b
commit c26053868c
2 changed files with 12 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mapping.model.MappingInstantiationException;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
@@ -177,4 +178,11 @@ public class N1qlCouchbaseRepositoryTests {
previousAttendees = party.getAttendees();
}
}
//Fails on deserialization as a different entity item is also present
@Test(expected = MappingInstantiationException.class)
public void shouldFailWithMissingFilterStringBasedQuery() {
Sort sort = new Sort(Sort.Direction.DESC, "attendees");
List<Party> parties = partyRepository.findParties(sort);
}
}

View File

@@ -9,6 +9,7 @@ import org.springframework.data.couchbase.core.query.View;
import org.springframework.data.couchbase.core.query.ViewIndexed;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.query.Param;
/**
@@ -47,6 +48,9 @@ public interface PartyRepository extends CouchbaseRepository<Party, String> {
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND `attendees` >= $1")
Page<Party> findPartiesWithAttendee(int count, Pageable pageable);
@Query("#{#n1ql.selectEntity}")
List<Party> findParties(Sort sort);
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND `desc` LIKE '%' || $included || '%' AND attendees >= $min" +
" AND `desc` NOT LIKE '%' || $excluded || '%'")
List<Party> findAllWithNamedParams(@Param("excluded") String ex, @Param("included") String inc, @Param("min") long minimumAttendees);