DATACASS-678 - Polishing.
Add since tags and assertions. Simplify test. Original pull request: #163.
This commit is contained in:
@@ -42,6 +42,7 @@ import com.datastax.driver.core.TableMetadata;
|
||||
* @author Mark Paluch
|
||||
* @author Fabio J. Mendes
|
||||
* @author John Blum
|
||||
* @author Vagif Zeynalov
|
||||
*/
|
||||
public class CassandraAdminTemplate extends CassandraTemplate implements CassandraAdminOperations {
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ import com.datastax.driver.core.UDTValue;
|
||||
* @author Mark Paluch
|
||||
* @author John Blum
|
||||
* @author Jens Schauder
|
||||
* @author Vagif Zeynalov
|
||||
*/
|
||||
public class CassandraMappingContext
|
||||
extends AbstractMappingContext<BasicCassandraPersistentEntity<?>, CassandraPersistentProperty>
|
||||
@@ -433,21 +434,28 @@ public class CassandraMappingContext
|
||||
* @return
|
||||
*/
|
||||
public CreateTableSpecification getCreateTableSpecificationFor(CassandraPersistentEntity<?> entity) {
|
||||
return getCreateTableSpecificationFor(null, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link CreateTableSpecification} for the given entity, including all mapping information.
|
||||
*
|
||||
* @param tableName if {@literal null} then the table name will be derived from entity
|
||||
* @param entity must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public CreateTableSpecification getCreateTableSpecificationFor(CqlIdentifier tableName, CassandraPersistentEntity<?> entity) {
|
||||
|
||||
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
|
||||
|
||||
CreateTableSpecification specification = createTable(tableName != null ? tableName : entity.getTableName());
|
||||
return getCreateTableSpecificationFor(entity.getTableName(), entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link CreateTableSpecification} for the given entity using {@code tableName}, including all mapping
|
||||
* information.
|
||||
*
|
||||
* @param tableName must not be {@literal null}.
|
||||
* @param entity must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.2
|
||||
*/
|
||||
public CreateTableSpecification getCreateTableSpecificationFor(CqlIdentifier tableName,
|
||||
CassandraPersistentEntity<?> entity) {
|
||||
|
||||
Assert.notNull(tableName, "Table name must not be null");
|
||||
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
|
||||
|
||||
CreateTableSpecification specification = createTable(tableName);
|
||||
|
||||
for (CassandraPersistentProperty property : entity) {
|
||||
|
||||
|
||||
@@ -15,9 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -25,11 +28,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -57,6 +55,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
* Unit tests for {@link CassandraMappingContext} targeted on {@link CreateTableSpecification}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Vagif Zeynalov
|
||||
* @soundtrack Black Rose - Volbeat
|
||||
*/
|
||||
public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
@@ -335,25 +334,15 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACASS-678
|
||||
public void createTableSpecificationShouldHaveCustomTableName() {
|
||||
public void createTableSpecificationShouldConsiderCustomTableName() {
|
||||
|
||||
final CqlIdentifier customTableName = CqlIdentifier.of("employee_" + UUID.randomUUID().toString().replace("-","_"));
|
||||
CqlIdentifier customTableName = CqlIdentifier.of("my_custom_came");
|
||||
|
||||
final CassandraPersistentEntity<?> persistentEntity = ctx.getRequiredPersistentEntity(Employee.class);
|
||||
CassandraPersistentEntity<?> persistentEntity = ctx.getRequiredPersistentEntity(Employee.class);
|
||||
CreateTableSpecification specification = ctx.getCreateTableSpecificationFor(customTableName, persistentEntity);
|
||||
|
||||
assertThat(persistentEntity).isNotNull();
|
||||
|
||||
final CreateTableSpecification regularSpecification = ctx.getCreateTableSpecificationFor(persistentEntity);
|
||||
|
||||
assertThat(regularSpecification).isNotNull();
|
||||
assertThat(persistentEntity.getTableName()).isEqualTo(regularSpecification.getName());
|
||||
assertThat(customTableName).isNotEqualTo(regularSpecification.getName());
|
||||
|
||||
final CreateTableSpecification customSpecification = ctx.getCreateTableSpecificationFor(customTableName, persistentEntity);
|
||||
|
||||
assertThat(customSpecification).isNotNull();
|
||||
assertThat(customTableName).isEqualTo(customSpecification.getName());
|
||||
assertThat(customTableName).isNotEqualTo(persistentEntity.getTableName());
|
||||
assertThat(specification).isNotNull();
|
||||
assertThat(specification.getName()).isEqualTo(customTableName);
|
||||
}
|
||||
|
||||
private CreateTableSpecification getCreateTableSpecificationFor(Class<?> persistentEntityClass) {
|
||||
|
||||
Reference in New Issue
Block a user