Search in sources :

Example 16 with RelationalPersistentProperty

use of org.springframework.data.relational.core.mapping.RelationalPersistentProperty in project spring-data-jdbc by spring-projects.

the class MyBatisDataAccessStrategyUnitTests method findAllByPath.

@SuppressWarnings("unchecked")
// DATAJDBC-384
@Test
public void findAllByPath() {
    RelationalPersistentProperty property = mock(RelationalPersistentProperty.class, RETURNS_DEEP_STUBS);
    PersistentPropertyPath path = mock(PersistentPropertyPath.class, RETURNS_DEEP_STUBS);
    when(path.getBaseProperty()).thenReturn(property);
    when(property.getOwner().getType()).thenReturn((Class) String.class);
    when(path.getRequiredLeafProperty()).thenReturn(property);
    when(property.getType()).thenReturn((Class) Number.class);
    when(path.toDotPath()).thenReturn("dot.path");
    accessStrategy.findAllByPath(Identifier.empty(), path);
    verify(session).selectList(eq("java.lang.StringMapper.findAllByPath-dot.path"), captor.capture());
    // 
    assertThat(captor.getValue()).isNotNull().extracting(// 
    MyBatisContext::getInstance, // 
    MyBatisContext::getId, // 
    MyBatisContext::getIdentifier, // 
    MyBatisContext::getDomainType, // 
    c -> c.get("key")).containsExactly(// 
    null, // 
    null, // 
    Identifier.empty(), // 
    Number.class, // 
    null);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) BasicJdbcConverter(org.springframework.data.jdbc.core.convert.BasicJdbcConverter) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) RelationalMappingContext(org.springframework.data.relational.core.mapping.RelationalMappingContext) PageRequest(org.springframework.data.domain.PageRequest) PropertyPathTestingUtils(org.springframework.data.jdbc.core.PropertyPathTestingUtils) PersistentPropertyPath(org.springframework.data.mapping.PersistentPropertyPath) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ArgumentCaptor(org.mockito.ArgumentCaptor) IdentifierProcessing(org.springframework.data.relational.core.sql.IdentifierProcessing) Assertions(org.assertj.core.api.Assertions) Sort(org.springframework.data.domain.Sort) Collections(java.util.Collections) SqlSession(org.apache.ibatis.session.SqlSession) JdbcConverter(org.springframework.data.jdbc.core.convert.JdbcConverter) SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier) Identifier(org.springframework.data.jdbc.core.convert.Identifier) JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty) RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty) PersistentPropertyPath(org.springframework.data.mapping.PersistentPropertyPath) Test(org.junit.jupiter.api.Test)

Example 17 with RelationalPersistentProperty

use of org.springframework.data.relational.core.mapping.RelationalPersistentProperty in project spring-data-jdbc by spring-projects.

the class BasicJdbcConverterUnitTests method checkConversionToTimestampAndBack.

private void checkConversionToTimestampAndBack(SoftAssertions softly, RelationalPersistentEntity<?> persistentEntity, String propertyName, Object value) {
    RelationalPersistentProperty property = persistentEntity.getRequiredPersistentProperty(propertyName);
    Object converted = converter.writeValue(value, ClassTypeInformation.from(converter.getColumnType(property)));
    Object convertedBack = converter.readValue(converted, property.getTypeInformation());
    softly.assertThat(convertedBack).describedAs(propertyName).isEqualTo(value);
}
Also used : RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty)

Example 18 with RelationalPersistentProperty

use of org.springframework.data.relational.core.mapping.RelationalPersistentProperty in project spring-data-jdbc by spring-projects.

the class BasicRelationalConverterAggregateReferenceUnitTests method convertsToAggregateReference.

// DATAJDBC-221
@Test
public void convertsToAggregateReference() {
    final RelationalPersistentProperty property = entity.getRequiredPersistentProperty("reference");
    Object readValue = converter.readValue(23, property.getTypeInformation());
    Assertions.assertThat(readValue).isInstanceOf(AggregateReference.class);
    assertThat(((AggregateReference<DummyEntity, Long>) readValue).getId()).isEqualTo(23L);
}
Also used : AggregateReference(org.springframework.data.jdbc.core.mapping.AggregateReference) RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty) Test(org.junit.jupiter.api.Test)

Example 19 with RelationalPersistentProperty

use of org.springframework.data.relational.core.mapping.RelationalPersistentProperty in project spring-data-jdbc by spring-projects.

the class BasicJdbcPersistentPropertyUnitTests method detectsKeyColumnOverrideNameFromMappedCollectionAnnotation.

// DATAJDBC-331
@Test
public void detectsKeyColumnOverrideNameFromMappedCollectionAnnotation() {
    RelationalPersistentProperty listProperty = // 
    context.getRequiredPersistentEntity(// 
    WithCollections.class).getRequiredPersistentProperty("overrideList");
    PersistentPropertyPathExtension path = getPersistentPropertyPath(WithCollections.class, "overrideList");
    assertThat(listProperty.getKeyColumn()).isEqualTo(quoted("override_key"));
    assertThat(listProperty.getReverseColumnName(path)).isEqualTo(quoted("override_id"));
}
Also used : PersistentPropertyPathExtension(org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension) BasicRelationalPersistentProperty(org.springframework.data.relational.core.mapping.BasicRelationalPersistentProperty) RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty) Test(org.junit.jupiter.api.Test)

Example 20 with RelationalPersistentProperty

use of org.springframework.data.relational.core.mapping.RelationalPersistentProperty in project spring-data-jdbc by spring-projects.

the class BasicJdbcPersistentPropertyUnitTests method detectsAnnotatedColumnAndKeyName.

// DATAJDBC-218
@Test
public void detectsAnnotatedColumnAndKeyName() {
    String propertyName = "someList";
    RelationalPersistentProperty listProperty = entity.getRequiredPersistentProperty(propertyName);
    PersistentPropertyPathExtension path = getPersistentPropertyPath(DummyEntity.class, propertyName);
    assertThat(listProperty.getReverseColumnName(path)).isEqualTo(quoted("dummy_column_name"));
    assertThat(listProperty.getKeyColumn()).isEqualTo(quoted("dummy_key_column_name"));
}
Also used : PersistentPropertyPathExtension(org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension) BasicRelationalPersistentProperty(org.springframework.data.relational.core.mapping.BasicRelationalPersistentProperty) RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty) Test(org.junit.jupiter.api.Test)

Aggregations

RelationalPersistentProperty (org.springframework.data.relational.core.mapping.RelationalPersistentProperty)22 Test (org.junit.jupiter.api.Test)9 PersistentPropertyPathExtension (org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension)5 BasicRelationalPersistentProperty (org.springframework.data.relational.core.mapping.BasicRelationalPersistentProperty)3 SQLType (java.sql.SQLType)2 ArrayList (java.util.ArrayList)2 SoftAssertions (org.assertj.core.api.SoftAssertions)2 RelationalPersistentEntity (org.springframework.data.relational.core.mapping.RelationalPersistentEntity)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 SqlSession (org.apache.ibatis.session.SqlSession)1 Assertions (org.assertj.core.api.Assertions)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 ArgumentMatchers (org.mockito.ArgumentMatchers)1 Mockito (org.mockito.Mockito)1 Example (org.springframework.data.domain.Example)1 ExampleMatcher (org.springframework.data.domain.ExampleMatcher)1