// Path: src/test/java/ru/shadam/tarantool/core/convert/ConversionTestEntities.java
// public static class Person {
//     @Id
//     @Tuple(index = ID)
//     long id;
//     @Tuple(index = FIRSTNAME)
//     String firstname;
//     @Tuple(index = GENDER)
//     Gender gender;
// 
//     @Tuple(index = NICKNAMES)
//     List<String> nicknames;
//     @Tuple(index = COWORKERS)
//     List<Person> coworkers;
//     @Tuple(index = AGE)
//     Integer age;
//     @Tuple(index = ALIVE)
//     Boolean alive;
//     @Tuple(index = BIRTHDAY)
//     Date birthday;
// 
//     @Tuple(index = ADDRESS)
//     Address address;
// 
// 
//     @Override
//     public String toString() {
//         return "Person{" +
//                 "id=" + id +
//                 ", firstname='" + firstname + '\'' +
//                 ", gender=" + gender +
//                 ", nicknames=" + nicknames +
//                 ", coworkers=" + coworkers +
//                 ", age=" + age +
//                 ", alive=" + alive +
//                 ", birthday=" + birthday +
//                 ", address=" + address +
//                 '}';
//     }
// }


import org.junit.Assert;
import org.junit.Test;
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.DefaultParameters;
import org.springframework.data.repository.query.ParametersParameterAccessor;
import org.springframework.data.repository.query.parser.PartTree;
import ru.shadam.tarantool.core.convert.ConversionTestEntities.Person;
import java.lang.reflect.Method;
package ru.shadam.tarantool.repository.query;



/**
 * @author sala
 */
public class TarantoolQueryCreatorTest {

    @Test
    public void findBySingleSimpleRepository() throws NoSuchMethodException {
        TarantoolQueryCreator creator = createQueryCreatorForMethodWithArgs(
            SampleRepository.class.getMethod("findByFirstname", String.class), new Object[]{ "eddard" }
        );

        final KeyValueQuery<TarantoolQuery> query = creator.createQuery();

        Assert.assertEquals(new TarantoolQuery("firstname", "eddard"), query.getCritieria());
    }

    private TarantoolQueryCreator createQueryCreatorForMethodWithArgs(Method method, Object[] args) {

        PartTree partTree = new PartTree(method.getName(), method.getReturnType());
        TarantoolQueryCreator creator = new TarantoolQueryCreator(partTree, new ParametersParameterAccessor(new DefaultParameters(
                method), args));

        return creator;
    }


// Path: src/test/java/ru/shadam/tarantool/core/convert/ConversionTestEntities.java
// public static class Person {
//     @Id
//     @Tuple(index = ID)
//     long id;
//     @Tuple(index = FIRSTNAME)
//     String firstname;
//     @Tuple(index = GENDER)
//     Gender gender;
// 
//     @Tuple(index = NICKNAMES)
//     List<String> nicknames;
//     @Tuple(index = COWORKERS)
//     List<Person> coworkers;
//     @Tuple(index = AGE)
//     Integer age;
//     @Tuple(index = ALIVE)
//     Boolean alive;
//     @Tuple(index = BIRTHDAY)
//     Date birthday;
// 
//     @Tuple(index = ADDRESS)
//     Address address;
// 
// 
//     @Override
//     public String toString() {
//         return "Person{" +
//                 "id=" + id +
//                 ", firstname='" + firstname + '\'' +
//                 ", gender=" + gender +
//                 ", nicknames=" + nicknames +
//                 ", coworkers=" + coworkers +
//                 ", age=" + age +
//                 ", alive=" + alive +
//                 ", birthday=" + birthday +
//                 ", address=" + address +
//                 '}';
//     }
// }


// Path: src/test/java/ru/shadam/tarantool/repository/query/TarantoolQueryCreatorTest.java
import org.junit.Assert;
import org.junit.Test;
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.DefaultParameters;
import org.springframework.data.repository.query.ParametersParameterAccessor;
import org.springframework.data.repository.query.parser.PartTree;
import ru.shadam.tarantool.core.convert.ConversionTestEntities.Person;
import java.lang.reflect.Method;

package ru.shadam.tarantool.repository.query;



/**
 * @author sala
 */
public class TarantoolQueryCreatorTest {

    @Test
    public void findBySingleSimpleRepository() throws NoSuchMethodException {
        TarantoolQueryCreator creator = createQueryCreatorForMethodWithArgs(
            SampleRepository.class.getMethod("findByFirstname", String.class), new Object[]{ "eddard" }
        );

        final KeyValueQuery<TarantoolQuery> query = creator.createQuery();

        Assert.assertEquals(new TarantoolQuery("firstname", "eddard"), query.getCritieria());
    }

    private TarantoolQueryCreator createQueryCreatorForMethodWithArgs(Method method, Object[] args) {

        PartTree partTree = new PartTree(method.getName(), method.getReturnType());
        TarantoolQueryCreator creator = new TarantoolQueryCreator(partTree, new ParametersParameterAccessor(new DefaultParameters(
                method), args));

        return creator;
    }


    private interface SampleRepository extends Repository<Person, Long> {