Search in sources :

Example 1 with MyBatisContext

use of org.springframework.data.jdbc.mybatis.MyBatisContext in project spring-data-jdbc by spring-projects.

the class MyBatisDataAccessStrategyUnitTests method findAllByProperty.

@SuppressWarnings("unchecked")
// DATAJDBC-123
@Test
public void findAllByProperty() {
    JdbcPersistentProperty property = mock(JdbcPersistentProperty.class, Mockito.RETURNS_DEEP_STUBS);
    when(property.getOwner().getType()).thenReturn((Class) String.class);
    doReturn(Number.class).when(property).getType();
    doReturn("propertyName").when(property).getName();
    accessStrategy.findAllByProperty("id", property);
    verify(session).selectList(eq("java.lang.StringMapper.findAllByProperty-propertyName"), captor.capture());
    // 
    assertThat(captor.getValue()).isNotNull().extracting(// 
    MyBatisContext::getInstance, // 
    MyBatisContext::getId, // 
    MyBatisContext::getDomainType, // 
    c -> c.get("key")).containsExactly(// 
    null, // 
    "id", // 
    Number.class, // 
    null);
}
Also used : Arrays(java.util.Arrays) Test(org.junit.Test) MyBatisDataAccessStrategy(org.springframework.data.jdbc.mybatis.MyBatisDataAccessStrategy) Mockito(org.mockito.Mockito) ArgumentCaptor(org.mockito.ArgumentCaptor) MyBatisContext(org.springframework.data.jdbc.mybatis.MyBatisContext) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Assertions(org.assertj.core.api.Assertions) JdbcPersistentProperty(org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty) PropertyPath(org.springframework.data.mapping.PropertyPath) Collections(java.util.Collections) SqlSession(org.apache.ibatis.session.SqlSession) Before(org.junit.Before) JdbcPersistentProperty(org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty) Test(org.junit.Test)

Aggregations

Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 SqlSession (org.apache.ibatis.session.SqlSession)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 Assertions (org.assertj.core.api.Assertions)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 Mockito (org.mockito.Mockito)1 JdbcPersistentProperty (org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty)1 MyBatisContext (org.springframework.data.jdbc.mybatis.MyBatisContext)1 MyBatisDataAccessStrategy (org.springframework.data.jdbc.mybatis.MyBatisDataAccessStrategy)1 PropertyPath (org.springframework.data.mapping.PropertyPath)1