Search in sources :

Example 1 with CassandraCustomConversions

use of org.springframework.data.cassandra.core.convert.CassandraCustomConversions in project spring-data-cassandra by spring-projects.

the class CassandraMappingContextUnitTests method shouldCreatePersistentEntityIfNoConversionRegistered.

// DATACASS-296
@Test
void shouldCreatePersistentEntityIfNoConversionRegistered() {
    mappingContext.setCustomConversions(new CassandraCustomConversions(Collections.emptyList()));
    assertThat(mappingContext.shouldCreatePersistentEntityFor(ClassTypeInformation.from(Human.class))).isTrue();
}
Also used : CassandraCustomConversions(org.springframework.data.cassandra.core.convert.CassandraCustomConversions) Test(org.junit.jupiter.api.Test)

Example 2 with CassandraCustomConversions

use of org.springframework.data.cassandra.core.convert.CassandraCustomConversions in project spring-data-cassandra by spring-projects.

the class CassandraMappingContextUnitTests method shouldNotCreateEntitiesForCustomConvertedTypes.

// DATACASS-296
@Test
void shouldNotCreateEntitiesForCustomConvertedTypes() {
    mappingContext.setCustomConversions(new CassandraCustomConversions(Collections.singletonList(HumanToStringConverter.INSTANCE)));
    assertThat(mappingContext.shouldCreatePersistentEntityFor(ClassTypeInformation.from(Human.class))).isFalse();
}
Also used : CassandraCustomConversions(org.springframework.data.cassandra.core.convert.CassandraCustomConversions) Test(org.junit.jupiter.api.Test)

Example 3 with CassandraCustomConversions

use of org.springframework.data.cassandra.core.convert.CassandraCustomConversions in project spring-data-cassandra by spring-projects.

the class RepositoryQueryMethodParameterTypesIntegrationTests method shouldFindByAnnotatedDateParameter.

// DATACASS-296
@Test
void shouldFindByAnnotatedDateParameter() {
    CustomConversions customConversions = new CassandraCustomConversions(Collections.singletonList(new DateToLocalDateConverter()));
    mappingContext.setCustomConversions(customConversions);
    converter.setCustomConversions(customConversions);
    converter.afterPropertiesSet();
    session.execute("CREATE INDEX IF NOT EXISTS allpossibletypes_date ON allpossibletypes ( date )");
    AllPossibleTypes allPossibleTypes = new AllPossibleTypes();
    LocalDate localDate = LocalDate.now();
    Instant instant = localDate.atStartOfDay().toInstant(ZoneOffset.UTC);
    allPossibleTypes.setId("id");
    allPossibleTypes.setDate(LocalDate.of(localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth()));
    allPossibleTypesRepository.save(allPossibleTypes);
    List<AllPossibleTypes> result = allPossibleTypesRepository.findWithAnnotatedDateParameter(Date.from(instant));
    assertThat(result).hasSize(1).contains(allPossibleTypes);
}
Also used : AllPossibleTypes(org.springframework.data.cassandra.domain.AllPossibleTypes) CassandraCustomConversions(org.springframework.data.cassandra.core.convert.CassandraCustomConversions) CustomConversions(org.springframework.data.convert.CustomConversions) CassandraCustomConversions(org.springframework.data.cassandra.core.convert.CassandraCustomConversions) Instant(java.time.Instant) LocalDate(java.time.LocalDate) AbstractSpringDataEmbeddedCassandraIntegrationTest(org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 CassandraCustomConversions (org.springframework.data.cassandra.core.convert.CassandraCustomConversions)3 Instant (java.time.Instant)1 LocalDate (java.time.LocalDate)1 AllPossibleTypes (org.springframework.data.cassandra.domain.AllPossibleTypes)1 AbstractSpringDataEmbeddedCassandraIntegrationTest (org.springframework.data.cassandra.repository.support.AbstractSpringDataEmbeddedCassandraIntegrationTest)1 CustomConversions (org.springframework.data.convert.CustomConversions)1