DATACASS-107 - added tests for external named queries
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.cassandra.test.integration.repositoryquery;
|
||||
package org.springframework.data.cassandra.test.integration.querymethods.declared;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.data.cassandra.test.integration.repositoryquery;
|
||||
package org.springframework.data.cassandra.test.integration.querymethods.declared;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -8,26 +8,20 @@ import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.cassandra.config.SchemaAction;
|
||||
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
|
||||
import org.springframework.data.cassandra.test.integration.querymethods.declared.base.PersonRepository;
|
||||
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class QueryAnnotationIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
|
||||
public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@Configuration
|
||||
@EnableCassandraRepositories(basePackageClasses = PersonRepository.class)
|
||||
public static class Config extends IntegrationTestConfig {
|
||||
|
||||
@Override
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.cassandra.test.integration.repositoryquery;
|
||||
package org.springframework.data.cassandra.test.integration.querymethods.declared;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -42,8 +42,6 @@ import com.datastax.driver.core.querybuilder.Select;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link StringBasedCassandraQuery}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class StringBasedCassandraQueryIntegrationTests {
|
||||
@@ -1,44 +1,54 @@
|
||||
package org.springframework.data.cassandra.test.integration.repositoryquery;
|
||||
package org.springframework.data.cassandra.test.integration.querymethods.declared.anno;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.data.cassandra.repository.CassandraRepository;
|
||||
import org.springframework.data.cassandra.repository.Query;
|
||||
import org.springframework.data.cassandra.test.integration.querymethods.declared.Person;
|
||||
import org.springframework.data.cassandra.test.integration.querymethods.declared.base.PersonRepository;
|
||||
import org.springframework.data.cassandra.test.integration.querymethods.declared.named.PersonRepositoryWithNamedQueries;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
|
||||
public interface PersonRepository extends CassandraRepository<Person> {
|
||||
/**
|
||||
* we extend {@link PersonRepositoryWithNamedQueries} here just to keep the test codebase in sync.
|
||||
*/
|
||||
public interface PersonRepositoryWithQueryAnnotations extends PersonRepository {
|
||||
|
||||
@Override
|
||||
@Query("select * from person where lastname = '?0'")
|
||||
List<Person> findFolksWithLastnameAsList(String lastname);
|
||||
|
||||
@Override
|
||||
@Query("select * from person where lastname = '?0'")
|
||||
ResultSet findFolksWithLastnameAsResultSet(String last);
|
||||
|
||||
@Override
|
||||
@Query("select * from person where lastname = '?0'")
|
||||
Person[] findFolksWithLastnameAsArray(String lastname);
|
||||
|
||||
@Override
|
||||
@Query("select * from person where lastname = '?0' and firstname = '?1'")
|
||||
Person findSingle(String last, String first);
|
||||
|
||||
@Override
|
||||
@Query("select * from person where lastname = '?0'")
|
||||
List<Map<String, Object>> findFolksWithLastnameAsListOfMapOfStringToObject(String last);
|
||||
|
||||
@Override
|
||||
@Query("select nickname from person where lastname = '?0' and firstname = '?1'")
|
||||
String findSingleNickname(String last, String first);
|
||||
|
||||
@Override
|
||||
@Query("select birthdate from person where lastname = '?0' and firstname = '?1'")
|
||||
Date findSingleBirthdate(String last, String first);
|
||||
|
||||
@Override
|
||||
@Query("select cool from person where lastname = '?0' and firstname = '?1'")
|
||||
boolean findSingleCool(String last, String first);
|
||||
|
||||
@Override
|
||||
@Query("select numberofchildren from person where lastname = '?0' and firstname = '?1'")
|
||||
int findSingleNumberOfChildren(String last, String first);
|
||||
|
||||
@Query("select uuid from person where lastname = '?0' and firstname = '?1'")
|
||||
UUID findSingleUuid(String last, String first);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.springframework.data.cassandra.test.integration.querymethods.declared.anno;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
|
||||
import org.springframework.data.cassandra.test.integration.querymethods.declared.QueryIntegrationTests;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@ContextConfiguration
|
||||
public class QueryAnnotationIntegrationTests extends QueryIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCassandraRepositories(basePackageClasses = PersonRepositoryWithQueryAnnotations.class)
|
||||
public static class Config extends QueryIntegrationTests.Config {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.springframework.data.cassandra.test.integration.querymethods.declared.base;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.cassandra.repository.CassandraRepository;
|
||||
import org.springframework.data.cassandra.test.integration.querymethods.declared.Person;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
|
||||
@NoRepositoryBean
|
||||
public interface PersonRepository extends CassandraRepository<Person> {
|
||||
|
||||
List<Person> findFolksWithLastnameAsList(String lastname);
|
||||
|
||||
ResultSet findFolksWithLastnameAsResultSet(String last);
|
||||
|
||||
Person[] findFolksWithLastnameAsArray(String lastname);
|
||||
|
||||
Person findSingle(String last, String first);
|
||||
|
||||
List<Map<String, Object>> findFolksWithLastnameAsListOfMapOfStringToObject(String last);
|
||||
|
||||
String findSingleNickname(String last, String first);
|
||||
|
||||
Date findSingleBirthdate(String last, String first);
|
||||
|
||||
boolean findSingleCool(String last, String first);
|
||||
|
||||
int findSingleNumberOfChildren(String last, String first);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.springframework.data.cassandra.test.integration.querymethods.declared.named;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
|
||||
import org.springframework.data.cassandra.test.integration.querymethods.declared.QueryIntegrationTests;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@ContextConfiguration
|
||||
public class NamedQueryIntegrationTests extends QueryIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCassandraRepositories(basePackageClasses = PersonRepositoryWithNamedQueries.class, namedQueriesLocation = "classpath:META-INF/PersonRepositoryWithNamedQueries.properties")
|
||||
public static class Config extends QueryIntegrationTests.Config {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.springframework.data.cassandra.test.integration.querymethods.declared.named;
|
||||
|
||||
import org.springframework.data.cassandra.test.integration.querymethods.declared.base.PersonRepository;
|
||||
|
||||
public interface PersonRepositoryWithNamedQueries extends PersonRepository {
|
||||
}
|
||||
@@ -21,7 +21,9 @@ import org.springframework.data.cassandra.repository.TypedIdCassandraRepository;
|
||||
* Sample repository managing {@link User} entities.
|
||||
*
|
||||
* @author Alex Shvid
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public interface UserRepository extends TypedIdCassandraRepository<User, String> {
|
||||
|
||||
String findByNamedQuery(String username);
|
||||
}
|
||||
|
||||
@@ -93,6 +93,12 @@ public class UserRepositoryIntegrationTests {
|
||||
setUp();
|
||||
}
|
||||
|
||||
public void findByNamedQuery() {
|
||||
String name = repository.findByNamedQuery("bob");
|
||||
Assert.assertNotNull(name);
|
||||
Assert.assertEquals("Bob", name);
|
||||
}
|
||||
|
||||
public void findsUserById() throws Exception {
|
||||
|
||||
User user = repository.findOne(bob.getUsername());
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.data.cassandra.test.integration.repository;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Base class for Java config tests for {@link UserRepository}.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class UserRepositoryIntegrationTestsDelegator extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
protected UserRepository repository;
|
||||
|
||||
@Autowired
|
||||
protected CassandraOperations template;
|
||||
|
||||
UserRepositoryIntegrationTests tests;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
tests = new UserRepositoryIntegrationTests(repository, template);
|
||||
tests.before();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByNamedQuery() {
|
||||
tests.findByNamedQuery();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsUserById() throws Exception {
|
||||
tests.findsUserById();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsAll() throws Exception {
|
||||
tests.findsAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsAllWithGivenIds() {
|
||||
tests.findsAllWithGivenIds();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletesUserCorrectly() throws Exception {
|
||||
tests.deletesUserCorrectly();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletesUserByIdCorrectly() {
|
||||
tests.deletesUserByIdCorrectly();
|
||||
}
|
||||
}
|
||||
@@ -15,26 +15,18 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.test.integration.repository;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
|
||||
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Base class for Java config tests for {@link UserRepository}.
|
||||
* Java config tests for {@link UserRepository}.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class UserRepositoryJavaConfigIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
|
||||
public class UserRepositoryJavaConfigIntegrationTests extends UserRepositoryIntegrationTestsDelegator {
|
||||
|
||||
@Configuration
|
||||
@EnableCassandraRepositories(basePackageClasses = UserRepository.class)
|
||||
@@ -51,42 +43,4 @@ public class UserRepositoryJavaConfigIntegrationTests extends AbstractSpringData
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
protected UserRepository repository;
|
||||
|
||||
@Autowired
|
||||
protected CassandraOperations template;
|
||||
|
||||
UserRepositoryIntegrationTests tests;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
tests = new UserRepositoryIntegrationTests(repository, template);
|
||||
tests.before();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsUserById() throws Exception {
|
||||
tests.findsUserById();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsAll() throws Exception {
|
||||
tests.findsAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsAllWithGivenIds() {
|
||||
tests.findsAllWithGivenIds();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletesUserCorrectly() throws Exception {
|
||||
tests.deletesUserCorrectly();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletesUserByIdCorrectly() {
|
||||
tests.deletesUserByIdCorrectly();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,60 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.test.integration.repository;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Base class for xml config tests for {@link UserRepository}.
|
||||
* xml config tests for {@link UserRepository}.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class UserRepositoryXmlConfigIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
protected UserRepository repository;
|
||||
|
||||
@Autowired
|
||||
protected CassandraOperations template;
|
||||
|
||||
UserRepositoryIntegrationTests tests;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
tests = new UserRepositoryIntegrationTests(repository, template);
|
||||
tests.before();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsUserById() throws Exception {
|
||||
tests.findsUserById();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsAll() throws Exception {
|
||||
tests.findsAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findsAllWithGivenIds() {
|
||||
tests.findsAllWithGivenIds();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletesUserCorrectly() throws Exception {
|
||||
tests.deletesUserCorrectly();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletesUserByIdCorrectly() {
|
||||
tests.deletesUserByIdCorrectly();
|
||||
}
|
||||
public class UserRepositoryXmlConfigIntegrationTests extends UserRepositoryIntegrationTestsDelegator {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
Person.findFolksWithLastnameAsList=select * from person where lastname = '?0'
|
||||
Person.findFolksWithLastnameAsResultSet=select * from person where lastname = '?0'
|
||||
Person.findFolksWithLastnameAsArray=select * from person where lastname = '?0'
|
||||
Person.findSingle=select * from person where lastname = '?0' and firstname = '?1'
|
||||
Person.findFolksWithLastnameAsListOfMapOfStringToObject=select * from person where lastname = '?0'
|
||||
Person.findSingleNickname=select nickname from person where lastname = '?0' and firstname = '?1'
|
||||
Person.findSingleBirthdate=select birthdate from person where lastname = '?0' and firstname = '?1'
|
||||
Person.findSingleCool=select cool from person where lastname = '?0' and firstname = '?1'
|
||||
Person.findSingleNumberOfChildren=select numberofchildren from person where lastname = '?0' and firstname = '?1'
|
||||
@@ -1 +1 @@
|
||||
User.findByNamedQuery=SELECT firstName FROM table WHERE firstName=?0
|
||||
User.findByNamedQuery=SELECT firstname FROM users WHERE username='?0'
|
||||
|
||||
Reference in New Issue
Block a user