Remove references to ClassTypeInformation from TypeInformation.

Closes #1314
This commit is contained in:
Mark Paluch
2022-10-06 16:29:29 +02:00
parent b8bd4f1e4b
commit f8e560775a
16 changed files with 66 additions and 69 deletions

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.cassandra.core.convert;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
@@ -42,7 +41,7 @@ public interface ColumnType {
* @return
*/
static ColumnType create(Class<?> type) {
return create(ClassTypeInformation.from(type));
return create(TypeInformation.of(type));
}
/**
@@ -63,7 +62,7 @@ public interface ColumnType {
* @return
*/
static CassandraColumnType create(Class<?> type, DataType dataType) {
return new DefaultCassandraColumnType(ClassTypeInformation.from(type), dataType);
return new DefaultCassandraColumnType(TypeInformation.of(type), dataType);
}
/**
@@ -78,7 +77,7 @@ public interface ColumnType {
return listOf((CassandraColumnType) componentType);
}
return new DefaultColumnType(ClassTypeInformation.LIST, componentType);
return new DefaultColumnType(TypeInformation.LIST, componentType);
}
/**
@@ -99,7 +98,7 @@ public interface ColumnType {
* @return
*/
static CassandraColumnType listOf(CassandraColumnType componentType, boolean frozen) {
return new DefaultCassandraColumnType(ClassTypeInformation.LIST,
return new DefaultCassandraColumnType(TypeInformation.LIST,
() -> DataTypes.listOf(componentType.getDataType(), frozen), componentType);
}
@@ -115,7 +114,7 @@ public interface ColumnType {
return setOf((CassandraColumnType) componentType);
}
return new DefaultColumnType(ClassTypeInformation.SET, componentType);
return new DefaultColumnType(TypeInformation.SET, componentType);
}
/**
@@ -136,7 +135,7 @@ public interface ColumnType {
* @return
*/
static CassandraColumnType setOf(CassandraColumnType componentType, boolean frozen) {
return new DefaultCassandraColumnType(ClassTypeInformation.SET,
return new DefaultCassandraColumnType(TypeInformation.SET,
() -> DataTypes.setOf(componentType.getDataType(), frozen), componentType);
}
@@ -148,7 +147,7 @@ public interface ColumnType {
* @return
*/
static ColumnType mapOf(ColumnType keyType, ColumnType valueType) {
return new DefaultColumnType(ClassTypeInformation.MAP, keyType, valueType);
return new DefaultColumnType(TypeInformation.MAP, keyType, valueType);
}
/**
@@ -172,7 +171,7 @@ public interface ColumnType {
* @since 3.2.4
*/
static CassandraColumnType mapOf(CassandraColumnType keyType, CassandraColumnType valueType, boolean frozen) {
return new DefaultCassandraColumnType(ClassTypeInformation.MAP,
return new DefaultCassandraColumnType(TypeInformation.MAP,
() -> DataTypes.mapOf(keyType.getDataType(), valueType.getDataType(), frozen), keyType, valueType);
}

View File

@@ -18,7 +18,6 @@ package org.springframework.data.cassandra.core.convert;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.Lazy;
import org.springframework.data.util.TypeInformation;
@@ -36,7 +35,7 @@ class DefaultCassandraColumnType extends DefaultColumnType implements CassandraC
private final Lazy<DataType> dataType;
DefaultCassandraColumnType(Class<?> type, DataType dataType, ColumnType... parameters) {
this(ClassTypeInformation.from(type), dataType, parameters);
this(TypeInformation.of(type), dataType, parameters);
}
DefaultCassandraColumnType(TypeInformation<?> typeInformation, Supplier<DataType> dataType,

View File

@@ -20,7 +20,6 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
@@ -32,7 +31,7 @@ import org.springframework.lang.Nullable;
*/
class DefaultColumnType implements ColumnType {
public static final DefaultColumnType OBJECT = new DefaultColumnType(ClassTypeInformation.OBJECT);
public static final DefaultColumnType OBJECT = new DefaultColumnType(TypeInformation.OBJECT);
private final TypeInformation<?> typeInformation;
private final List<ColumnType> parameters;

View File

@@ -41,7 +41,6 @@ import org.springframework.data.cassandra.core.mapping.UserTypeResolver;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.Lazy;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
@@ -196,7 +195,7 @@ class DefaultColumnTypeResolver implements ColumnTypeResolver {
private CassandraColumnType resolve(TypeInformation<?> typeInformation, FrozenIndicator frozen) {
return getCustomWriteTarget(typeInformation)
.map(it -> createCassandraTypeDescriptor(tryResolve(it), ClassTypeInformation.from(it)))
.map(it -> createCassandraTypeDescriptor(tryResolve(it), TypeInformation.of(it)))
.orElseGet(() -> typeInformation.getType().isEnum()
? ColumnType.create(String.class, DataTypes.TEXT)
: createCassandraTypeDescriptor(typeInformation, frozen));
@@ -279,7 +278,7 @@ class DefaultColumnTypeResolver implements ColumnTypeResolver {
if (value != null) {
ClassTypeInformation<?> typeInformation = ClassTypeInformation.from(value.getClass());
TypeInformation<?> typeInformation = TypeInformation.of(value.getClass());
return getCustomWriteTarget(typeInformation).map(it -> {
return (ColumnType) createCassandraTypeDescriptor(tryResolve(it), typeInformation);

View File

@@ -60,7 +60,6 @@ import org.springframework.data.mapping.model.SpELExpressionParameterValueProvid
import org.springframework.data.projection.EntityProjection;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.Predicates;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
@@ -420,7 +419,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
public <R> R readRow(Class<R> type, Row row) {
Class<R> beanClassLoaderClass = transformClassToBeanClassLoaderClass(type);
TypeInformation<? extends R> typeInfo = ClassTypeInformation.from(beanClassLoaderClass);
TypeInformation<? extends R> typeInfo = TypeInformation.of(beanClassLoaderClass);
return doReadRow(getConversionContext(), row, typeInfo);
}
@@ -553,7 +552,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
@Override
public Object convertToColumnType(Object obj) {
return convertToColumnType(obj, ClassTypeInformation.from(obj.getClass()));
return convertToColumnType(obj, TypeInformation.of(obj.getClass()));
}
@Override
@@ -924,7 +923,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
return writeMapInternal((Map<Object, Object>) value, columnType);
}
TypeInformation<?> type = ClassTypeInformation.from((Class) value.getClass());
TypeInformation<?> type = TypeInformation.of((Class) value.getClass());
TypeInformation<?> actualType = type.getRequiredActualType();
BasicCassandraPersistentEntity<?> entity = getMappingContext().getPersistentEntity(actualType.getType());
@@ -1144,7 +1143,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
}
TypeInformation<?> componentType = targetType.getComponentType();
componentType = componentType == null ? ClassTypeInformation.from(elementType) : componentType;
componentType = componentType == null ? TypeInformation.of(elementType) : componentType;
for (Object element : source) {
collection.add(context.convert(element, componentType));
@@ -1200,7 +1199,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
Object value = entry.getValue();
map.put(key, context.convert(value, valueType == null ? ClassTypeInformation.OBJECT : valueType));
map.put(key, context.convert(value, valueType == null ? TypeInformation.OBJECT : valueType));
}
return map;

View File

@@ -30,7 +30,6 @@ import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -201,7 +200,7 @@ public class CassandraQueryMethod extends QueryMethod {
* @return the return type for this {@link QueryMethod}.
*/
public TypeInformation<?> getReturnType() {
return ClassTypeInformation.fromReturnTypeOf(this.method);
return TypeInformation.fromReturnTypeOf(this.method);
}
/**

View File

@@ -25,6 +25,7 @@ import java.util.UUID;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty;
@@ -32,7 +33,7 @@ import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.core.mapping.Frozen;
import org.springframework.data.cassandra.core.mapping.UserDefinedType;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import com.datastax.oss.driver.api.core.data.TupleValue;
import com.datastax.oss.driver.api.core.type.DataType;
@@ -59,8 +60,8 @@ public class ColumnTypeResolverUnitTests {
void shouldResolveSimpleType() {
assertThat(resolver.resolve("foo").getType()).isEqualTo(String.class);
assertThat(resolver.resolve(ClassTypeInformation.from(String.class)).getType()).isEqualTo(String.class);
assertThat(resolver.resolve(ClassTypeInformation.from(String.class)).getDataType()).isEqualTo(DataTypes.TEXT);
assertThat(resolver.resolve(TypeInformation.of(String.class)).getType()).isEqualTo(String.class);
assertThat(resolver.resolve(TypeInformation.of(String.class)).getDataType()).isEqualTo(DataTypes.TEXT);
BasicCassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(Person.class);
@@ -72,8 +73,8 @@ public class ColumnTypeResolverUnitTests {
void shouldResolveEnumType() {
assertThat(resolver.resolve(MyEnum.INSTANCE).getType()).isEqualTo(String.class);
assertThat(resolver.resolve(ClassTypeInformation.from(MyEnum.class)).getType()).isEqualTo(String.class);
assertThat(resolver.resolve(ClassTypeInformation.from(MyEnum.class)).getDataType()).isEqualTo(DataTypes.TEXT);
assertThat(resolver.resolve(TypeInformation.of(MyEnum.class)).getType()).isEqualTo(String.class);
assertThat(resolver.resolve(TypeInformation.of(MyEnum.class)).getDataType()).isEqualTo(DataTypes.TEXT);
BasicCassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(Person.class);

View File

@@ -34,7 +34,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AliasFor;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.AssociationHandler;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import com.datastax.oss.driver.api.core.CqlIdentifier;
@@ -55,7 +55,7 @@ class BasicCassandraPersistentEntityUnitTests {
void subclassInheritsAtTableAnnotation() {
BasicCassandraPersistentEntity<Notification> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(Notification.class));
TypeInformation.of(Notification.class));
assertThat(entity.getTableName().asCql(true)).isEqualTo("messages");
}
@@ -64,7 +64,7 @@ class BasicCassandraPersistentEntityUnitTests {
void evaluatesSpELExpression() {
BasicCassandraPersistentEntity<Area> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(Area.class));
TypeInformation.of(Area.class));
entity.setApplicationContext(this.context);
@@ -81,7 +81,7 @@ class BasicCassandraPersistentEntityUnitTests {
when(this.context.containsBean("tableNameHolderThingy")).thenReturn(true);
BasicCassandraPersistentEntity<UserLine> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(UserLine.class));
TypeInformation.of(UserLine.class));
entity.setApplicationContext(context);
assertThat(entity.getTableName()).hasToString(bean.tableName);
@@ -91,7 +91,7 @@ class BasicCassandraPersistentEntityUnitTests {
void setForceQuoteCallsSetTableName() {
BasicCassandraPersistentEntity<Message> entitySpy = spy(
new BasicCassandraPersistentEntity<>(ClassTypeInformation.from(Message.class)));
new BasicCassandraPersistentEntity<>(TypeInformation.of(Message.class)));
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(entitySpy);
@@ -110,7 +110,7 @@ class BasicCassandraPersistentEntityUnitTests {
void setForceQuoteDoesNothing() {
BasicCassandraPersistentEntity<Message> entitySpy = spy(
new BasicCassandraPersistentEntity<>(ClassTypeInformation.from(Message.class)));
new BasicCassandraPersistentEntity<>(TypeInformation.of(Message.class)));
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(entitySpy);
@@ -126,7 +126,7 @@ class BasicCassandraPersistentEntityUnitTests {
void isUserDefinedTypeShouldReturnFalse() {
BasicCassandraPersistentEntity<UserLine> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(UserLine.class));
TypeInformation.of(UserLine.class));
assertThat(entity.isUserDefinedType()).isFalse();
}
@@ -135,7 +135,7 @@ class BasicCassandraPersistentEntityUnitTests {
void shouldConsiderComposedTableAnnotation() {
BasicCassandraPersistentEntity<TableWithComposedAnnotation> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(TableWithComposedAnnotation.class));
TypeInformation.of(TableWithComposedAnnotation.class));
assertThat(entity.getTableName()).isEqualTo(CqlIdentifier.fromCql("mytable"));
}
@@ -144,7 +144,7 @@ class BasicCassandraPersistentEntityUnitTests {
void shouldConsiderComposedPrimaryKeyClassAnnotation() {
BasicCassandraPersistentEntity<PrimaryKeyClassWithComposedAnnotation> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(PrimaryKeyClassWithComposedAnnotation.class));
TypeInformation.of(PrimaryKeyClassWithComposedAnnotation.class));
assertThat(entity.isCompositePrimaryKey()).isTrue();
}
@@ -154,7 +154,7 @@ class BasicCassandraPersistentEntityUnitTests {
void shouldRejectAssociationCreation() {
BasicCassandraPersistentEntity<PrimaryKeyClassWithComposedAnnotation> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(PrimaryKeyClassWithComposedAnnotation.class));
TypeInformation.of(PrimaryKeyClassWithComposedAnnotation.class));
assertThatThrownBy(() -> entity.addAssociation(mock(Association.class)))
.isInstanceOf(UnsupportedCassandraOperationException.class);
@@ -165,7 +165,7 @@ class BasicCassandraPersistentEntityUnitTests {
void shouldNoOpOnDoWithAssociations() {
BasicCassandraPersistentEntity<PrimaryKeyClassWithComposedAnnotation> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(PrimaryKeyClassWithComposedAnnotation.class));
TypeInformation.of(PrimaryKeyClassWithComposedAnnotation.class));
AssociationHandler<CassandraPersistentProperty> handlerMock = mock(AssociationHandler.class);
entity.doWithAssociations(handlerMock);

View File

@@ -33,7 +33,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AliasFor;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.ReflectionUtils;
import com.datastax.oss.driver.api.core.CqlIdentifier;
@@ -162,12 +162,12 @@ class BasicCassandraPersistentPropertyUnitTests {
Field field = ReflectionUtils.findField(type, fieldName);
return new BasicCassandraPersistentProperty(Property.of(ClassTypeInformation.from(type), field), getEntity(type),
return new BasicCassandraPersistentProperty(Property.of(TypeInformation.of(type), field), getEntity(type),
CassandraSimpleTypeHolder.HOLDER);
}
private <T> BasicCassandraPersistentEntity<T> getEntity(Class<T> type) {
return new BasicCassandraPersistentEntity<>(ClassTypeInformation.from(type));
return new BasicCassandraPersistentEntity<>(TypeInformation.of(type));
}
private static class Timeline {

View File

@@ -25,7 +25,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.ReflectionUtils;
/**
@@ -56,12 +56,12 @@ class BasicCassandraPersistentTuplePropertyUnitTests {
Field field = ReflectionUtils.findField(type, fieldName);
return new BasicCassandraPersistentTupleProperty(Property.of(ClassTypeInformation.from(type), field),
return new BasicCassandraPersistentTupleProperty(Property.of(TypeInformation.of(type), field),
getEntity(type), CassandraSimpleTypeHolder.HOLDER);
}
private <T> BasicCassandraPersistentEntity<T> getEntity(Class<T> type) {
return new BasicCassandraPersistentTupleEntity<>(ClassTypeInformation.from(type));
return new BasicCassandraPersistentTupleEntity<>(TypeInformation.of(type));
}
@Tuple

View File

@@ -32,7 +32,7 @@ import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.cassandra.core.cql.keyspace.ColumnSpecification;
import org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.ReflectionUtils;
import com.datastax.oss.driver.api.core.type.DataTypes;
@@ -58,8 +58,8 @@ class CassandraCompositePrimaryKeyUnitTests {
context = new CassandraMappingContext();
schemaFactory = new SchemaFactory(context, context.getCustomConversions(), context.getCodecRegistry());
entity = context.getRequiredPersistentEntity(ClassTypeInformation.from(TypeWithCompositeKey.class));
key = context.getRequiredPersistentEntity(ClassTypeInformation.from(CompositeKey.class));
entity = context.getRequiredPersistentEntity(TypeInformation.of(TypeWithCompositeKey.class));
key = context.getRequiredPersistentEntity(TypeInformation.of(CompositeKey.class));
}
@Test // DATACASS-507
@@ -67,7 +67,7 @@ class CassandraCompositePrimaryKeyUnitTests {
Field field = ReflectionUtils.findField(TypeWithCompositeKey.class, "id");
CassandraPersistentProperty property = new BasicCassandraPersistentProperty(
Property.of(ClassTypeInformation.from(TypeWithCompositeKey.class), field), entity,
Property.of(TypeInformation.of(TypeWithCompositeKey.class), field), entity,
CassandraSimpleTypeHolder.HOLDER);
assertThat(property.isIdProperty()).isTrue();
assertThat(property.isCompositePrimaryKey()).isTrue();

View File

@@ -35,7 +35,7 @@ import org.springframework.data.cassandra.core.cql.Ordering;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.cassandra.core.cql.keyspace.CreateIndexSpecification;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.data.UdtValue;
@@ -283,7 +283,7 @@ public class CassandraMappingContextUnitTests {
void shouldCreatePersistentEntityIfNoConversionRegistered() {
mappingContext.setCustomConversions(new CassandraCustomConversions(Collections.emptyList()));
assertThat(mappingContext.shouldCreatePersistentEntityFor(ClassTypeInformation.from(Human.class))).isTrue();
assertThat(mappingContext.shouldCreatePersistentEntityFor(TypeInformation.of(Human.class))).isTrue();
}
@Test // DATACASS-296
@@ -292,7 +292,7 @@ public class CassandraMappingContextUnitTests {
mappingContext.setCustomConversions(
new CassandraCustomConversions(Collections.singletonList(HumanToStringConverter.INSTANCE)));
assertThat(mappingContext.shouldCreatePersistentEntityFor(ClassTypeInformation.from(Human.class))).isFalse();
assertThat(mappingContext.shouldCreatePersistentEntityFor(TypeInformation.of(Human.class))).isFalse();
}
@Test // DATACASS-172, DATACASS-455

View File

@@ -27,7 +27,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.core.annotation.AliasFor;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import com.datastax.oss.driver.api.core.CqlIdentifier;
@@ -80,7 +80,7 @@ class CassandraUserTypePersistentEntityUnitTests {
}
private <T> CassandraUserTypePersistentEntity<T> getEntity(Class<T> entityClass) {
return new CassandraUserTypePersistentEntity<>(ClassTypeInformation.from(entityClass), null);
return new CassandraUserTypePersistentEntity<>(TypeInformation.of(entityClass), null);
}
@UserDefinedType

View File

@@ -22,9 +22,10 @@ import java.util.Date;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.mapping.model.Property;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.ReflectionUtils;
/**
@@ -56,14 +57,14 @@ class CompoundPrimaryKeyUnitTests {
@BeforeEach
void setup() {
cpk = new BasicCassandraPersistentEntity<>(ClassTypeInformation.from(TimelineKey.class));
entity = new BasicCassandraPersistentEntity<>(ClassTypeInformation.from(Timeline.class));
cpk = new BasicCassandraPersistentEntity<>(TypeInformation.of(TimelineKey.class));
entity = new BasicCassandraPersistentEntity<>(TypeInformation.of(Timeline.class));
}
@Test // DATACASS-507
void checkIdProperty() {
Field id = ReflectionUtils.findField(Timeline.class, "id");
CassandraPersistentProperty property = getPropertyFor(Property.of(ClassTypeInformation.from(Timeline.class), id));
CassandraPersistentProperty property = getPropertyFor(Property.of(TypeInformation.of(Timeline.class), id));
assertThat(property.isIdProperty()).isTrue();
assertThat(property.isCompositePrimaryKey()).isTrue();
}

View File

@@ -19,7 +19,8 @@ package org.springframework.data.cassandra.core.mapping;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
/**
* Unit tests for {@link BasicCassandraPersistentEntity}.
@@ -31,7 +32,7 @@ class ForceQuotedEntitiesSimpleUnitTests {
@Test
void testImplicitTableNameForceQuoted() {
BasicCassandraPersistentEntity<ImplicitTableNameForceQuoted> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(ImplicitTableNameForceQuoted.class));
TypeInformation.of(ImplicitTableNameForceQuoted.class));
assertThat(entity.getTableName().asCql(false))
.isEqualTo("\"" + ImplicitTableNameForceQuoted.class.getSimpleName() + "\"");
@@ -46,7 +47,7 @@ class ForceQuotedEntitiesSimpleUnitTests {
@Test
void testExplicitTableNameForceQuoted() {
BasicCassandraPersistentEntity<ExplicitTableNameForceQuoted> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(ExplicitTableNameForceQuoted.class));
TypeInformation.of(ExplicitTableNameForceQuoted.class));
assertThat(entity.getTableName().asCql(true)).isEqualTo("\"" + EXPLICIT_TABLE_NAME + "\"");
assertThat(entity.getTableName().asInternal()).isEqualTo(EXPLICIT_TABLE_NAME);
@@ -58,7 +59,7 @@ class ForceQuotedEntitiesSimpleUnitTests {
@Test
void testDefaultTableNameForceQuoted() {
BasicCassandraPersistentEntity<DefaultTableNameForceQuoted> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(DefaultTableNameForceQuoted.class));
TypeInformation.of(DefaultTableNameForceQuoted.class));
assertThat(entity.getTableName().asCql(true))
.isEqualTo(DefaultTableNameForceQuoted.class.getSimpleName().toLowerCase());

View File

@@ -21,7 +21,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.StringUtils;
import com.datastax.oss.driver.api.core.CqlIdentifier;
@@ -46,7 +46,7 @@ class NamingStrategyUnitTests {
void getTableNameGeneratesTableName() {
BasicCassandraPersistentEntity<TableNameHolderThingy> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(TableNameHolderThingy.class));
TypeInformation.of(TableNameHolderThingy.class));
assertThat(entity.getTableName().asCql(true)).isEqualTo("tablenameholderthingy");
}
@@ -55,12 +55,12 @@ class NamingStrategyUnitTests {
void getTableNameGeneratesQuotedTableName() {
BasicCassandraPersistentEntity<TableNameHolderThingy> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(TableNameHolderThingy.class));
TypeInformation.of(TableNameHolderThingy.class));
entity.setNamingStrategy(NamingStrategy.SNAKE_CASE.transform(it -> "\"" + StringUtils.capitalize(it) + "\""));
assertThat(entity.getTableName().asCql(true)).isEqualTo("\"Table_name_holder_thingy\"");
entity = new BasicCassandraPersistentEntity<>(ClassTypeInformation.from(TableNameHolderThingy.class));
entity = new BasicCassandraPersistentEntity<>(TypeInformation.of(TableNameHolderThingy.class));
entity.setNamingStrategy(NamingStrategy.SNAKE_CASE.transform(String::toUpperCase));
assertThat(entity.getTableName().asCql(true)).isEqualTo("\"TABLE_NAME_HOLDER_THINGY\"");
@@ -70,7 +70,7 @@ class NamingStrategyUnitTests {
void atTableIsCaseSensitive() {
BasicCassandraPersistentEntity<ProvidedTableName> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(ProvidedTableName.class));
TypeInformation.of(ProvidedTableName.class));
assertThat(entity.getTableName().asCql(true)).isEqualTo("\"iAmProvided\"");
}
@@ -79,7 +79,7 @@ class NamingStrategyUnitTests {
void atTableWithQuotedNameShouldRetainQuotes() {
BasicCassandraPersistentEntity<QuotedTableName> entity = new BasicCassandraPersistentEntity<>(
ClassTypeInformation.from(QuotedTableName.class));
TypeInformation.of(QuotedTableName.class));
assertThat(entity.getTableName().asCql(true)).isEqualTo("\"IAmQuoted\"");
}