Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Use shorter field names.

See #1449
  • Loading branch information
mp911de committed Nov 13, 2023
1 parent 75cb544 commit ee7def1
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,31 @@ class MappingCassandraConverterMappedTupleUnitTests {

private CassandraMappingContext mappingContext;

private MappingCassandraConverter mappingCassandraConverter;
private MappingCassandraConverter converter;

private Row rowMock;

@BeforeEach
void setUp() {

this.mappingContext = new CassandraMappingContext();
this.mappingCassandraConverter = new MappingCassandraConverter(mappingContext);
this.mappingCassandraConverter.afterPropertiesSet();
this.converter = new MappingCassandraConverter(mappingContext);
this.converter.afterPropertiesSet();
}

@Test // DATACASS-523
void shouldReadMappedTupleValue() {

BasicCassandraPersistentEntity<?> entity = this.mappingContext.getRequiredPersistentEntity(MappedTuple.class);

CassandraColumnType type = mappingCassandraConverter.getColumnTypeResolver().resolve(entity.getTypeInformation());
CassandraColumnType type = converter.getColumnTypeResolver().resolve(entity.getTypeInformation());

TupleValue value = ((TupleType) type.getDataType()).newValue("hello", 1);

this.rowMock = RowMockUtil.newRowMock(column("name", "Jon Doe", DataTypes.TEXT),
column("tuple", value, type.getDataType()));

Person person = this.mappingCassandraConverter.read(Person.class, rowMock);
Person person = this.converter.read(Person.class, rowMock);

assertThat(person).isNotNull();
assertThat(person.name()).isEqualTo("Jon Doe");
Expand All @@ -93,7 +93,7 @@ void shouldWriteMappedTuple() {

Map<CqlIdentifier, Object> insert = new LinkedHashMap<>();

this.mappingCassandraConverter.write(person, insert);
this.converter.write(person, insert);

TupleValue tupleValue = (TupleValue) insert.get(CqlIdentifier.fromCql("tuple"));
assertThat(tupleValue.getFormattedContents()).contains("('hello',1)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
@MockitoSettings(strictness = Strictness.LENIENT)
class MappingCassandraConverterUDTUnitTests {

@Mock UserTypeResolver userTypeResolver;
@Mock UserTypeResolver typeResolver;

private com.datastax.oss.driver.api.core.type.UserDefinedType manufacturer = UserDefinedTypeBuilder
.forName("manufacturer").withField("name", DataTypes.TEXT).withField("displayname", DataTypes.TEXT).build();
Expand Down Expand Up @@ -93,23 +93,23 @@ class MappingCassandraConverterUDTUnitTests {
void setUp() {

mappingContext = new CassandraMappingContext();
mappingContext.setUserTypeResolver(userTypeResolver);
mappingContext.setUserTypeResolver(typeResolver);

CassandraCustomConversions cassandraCustomConversions = new CassandraCustomConversions(
Arrays.asList(new UDTToCurrencyConverter(), new CurrencyToUDTConverter(userTypeResolver)));
Arrays.asList(new UDTToCurrencyConverter(), new CurrencyToUDTConverter(typeResolver)));
mappingContext.setSimpleTypeHolder(cassandraCustomConversions.getSimpleTypeHolder());

converter = new MappingCassandraConverter(mappingContext);
converter.setCustomConversions(cassandraCustomConversions);
converter.afterPropertiesSet();

when(userTypeResolver.resolveType(CqlIdentifier.fromCql("address"))).thenReturn(address);
when(userTypeResolver.resolveType(CqlIdentifier.fromCql("engine"))).thenReturn(engine);
when(userTypeResolver.resolveType(CqlIdentifier.fromCql("manufacturer"))).thenReturn(manufacturer);
when(userTypeResolver.resolveType(CqlIdentifier.fromCql("currency"))).thenReturn(currency);
when(userTypeResolver.resolveType(CqlIdentifier.fromCql("withnullableembeddedtype")))
when(typeResolver.resolveType(CqlIdentifier.fromCql("address"))).thenReturn(address);
when(typeResolver.resolveType(CqlIdentifier.fromCql("engine"))).thenReturn(engine);
when(typeResolver.resolveType(CqlIdentifier.fromCql("manufacturer"))).thenReturn(manufacturer);
when(typeResolver.resolveType(CqlIdentifier.fromCql("currency"))).thenReturn(currency);
when(typeResolver.resolveType(CqlIdentifier.fromCql("withnullableembeddedtype")))
.thenReturn(withnullableembeddedtype);
when(userTypeResolver.resolveType(CqlIdentifier.fromCql("withprefixednullableembeddedtype")))
when(typeResolver.resolveType(CqlIdentifier.fromCql("withprefixednullableembeddedtype")))
.thenReturn(withprefixednullableembeddedtype);
}

Expand Down Expand Up @@ -476,7 +476,7 @@ void shouldWriteNestedUdt() {
@Test // #1098
void shouldWriteMapWithTypeHintToUdtValue() {

when(userTypeResolver.resolveType(CqlIdentifier.fromCql("udt"))).thenReturn(manufacturer);
when(typeResolver.resolveType(CqlIdentifier.fromCql("udt"))).thenReturn(manufacturer);

MapWithUdt mapWithUdt = new MapWithUdt();
mapWithUdt.map = Collections.singletonMap("key", new Manufacturer("name", "display"));
Expand Down
Loading

0 comments on commit ee7def1

Please sign in to comment.