DATAJDBC-378 - Polishing
Move non integration tests to separate class. Original Pull Request: #155
This commit is contained in:
@@ -46,6 +46,7 @@ import org.springframework.util.Assert;
|
||||
* @author Jens Schauder
|
||||
* @author Mark Paluch
|
||||
* @author Thomas Lang
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
|
||||
@@ -165,8 +166,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <T> T findById(Object id, Class<T> domainType) {
|
||||
|
||||
Assert.notNull(id, "Id must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
Assert.notNull(id, "Id must not be null!");
|
||||
Assert.notNull(domainType, "Domain type must not be null!");
|
||||
|
||||
T entity = accessStrategy.findById(id, domainType);
|
||||
if (entity != null) {
|
||||
@@ -182,8 +183,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <T> boolean existsById(Object id, Class<T> domainType) {
|
||||
|
||||
Assert.notNull(id, "Id must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
Assert.notNull(id, "Id must not be null!");
|
||||
Assert.notNull(domainType, "Domain type must not be null!");
|
||||
|
||||
return accessStrategy.existsById(id, domainType);
|
||||
}
|
||||
@@ -195,7 +196,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <T> Iterable<T> findAll(Class<T> domainType) {
|
||||
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null!");
|
||||
|
||||
Iterable<T> all = accessStrategy.findAll(domainType);
|
||||
publishAfterLoad(all);
|
||||
@@ -209,8 +210,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <T> Iterable<T> findAllById(Iterable<?> ids, Class<T> domainType) {
|
||||
|
||||
Assert.notNull(ids, "Ids must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
Assert.notNull(ids, "Ids must not be null!");
|
||||
Assert.notNull(domainType, "Domain type must not be null!");
|
||||
|
||||
Iterable<T> allById = accessStrategy.findAllById(ids, domainType);
|
||||
publishAfterLoad(allById);
|
||||
@@ -224,8 +225,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <S> void delete(S aggregateRoot, Class<S> domainType) {
|
||||
|
||||
Assert.notNull(aggregateRoot, "Aggregate root must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
Assert.notNull(aggregateRoot, "Aggregate root must not be null!");
|
||||
Assert.notNull(domainType, "Domain type must not be null!");
|
||||
|
||||
IdentifierAccessor identifierAccessor = context.getRequiredPersistentEntity(domainType)
|
||||
.getIdentifierAccessor(aggregateRoot);
|
||||
@@ -240,8 +241,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <S> void deleteById(Object id, Class<S> domainType) {
|
||||
|
||||
Assert.notNull(id, "Id must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
Assert.notNull(id, "Id must not be null!");
|
||||
Assert.notNull(domainType, "Domain type must not be null!");
|
||||
|
||||
deleteTree(id, null, domainType);
|
||||
}
|
||||
@@ -253,7 +254,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public void deleteAll(Class<?> domainType) {
|
||||
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null!");
|
||||
|
||||
AggregateChange<?> change = createDeletingChange(domainType);
|
||||
change.executeWith(interpreter, context, converter);
|
||||
@@ -274,7 +275,7 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
|
||||
Object identifier = persistentEntity.getIdentifierAccessor(change.getEntity()).getIdentifier();
|
||||
|
||||
Assert.notNull(identifier, "After saving the identifier must not be null");
|
||||
Assert.notNull(identifier, "After saving the identifier must not be null!");
|
||||
|
||||
publisher.publishEvent(new AfterSaveEvent( //
|
||||
Identifier.of(identifier), //
|
||||
|
||||
@@ -596,24 +596,6 @@ public class JdbcAggregateTemplateIntegrationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-378
|
||||
public void findAllByIdMustNotAcceptNullArgumentForType() {
|
||||
|
||||
assertThatThrownBy(() -> template.findAllById(singleton(23L), null)).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-378
|
||||
public void findAllByIdMustNotAcceptNullArgumentForIds() {
|
||||
|
||||
assertThatThrownBy(() -> template.findAllById(null, LegoSet.class)).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-378
|
||||
public void findAllByIdWithEmpthListMustReturnEmptyResult() {
|
||||
|
||||
assertThat(template.findAllById(emptyList(), LegoSet.class)).isEmpty();
|
||||
}
|
||||
|
||||
private static NoIdMapChain4 createNoIdMapTree() {
|
||||
|
||||
NoIdMapChain4 chain4 = new NoIdMapChain4();
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.jdbc.core;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.core.convert.BasicJdbcConverter;
|
||||
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
|
||||
import org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy;
|
||||
import org.springframework.data.jdbc.core.convert.JdbcConverter;
|
||||
import org.springframework.data.jdbc.core.convert.RelationResolver;
|
||||
import org.springframework.data.jdbc.core.convert.SqlGeneratorSource;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
import org.springframework.data.relational.core.mapping.NamingStrategy;
|
||||
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class JdbcAggregateTemplateUnitTests {
|
||||
|
||||
JdbcAggregateOperations template;
|
||||
|
||||
@Mock ApplicationEventPublisher eventPublisher;
|
||||
@Mock RelationResolver relationResolver;
|
||||
@Mock DataSource dataSource;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
RelationalMappingContext mappingContext = new RelationalMappingContext(NamingStrategy.INSTANCE);
|
||||
JdbcConverter converter = new BasicJdbcConverter(mappingContext, relationResolver);
|
||||
NamedParameterJdbcOperations namedParameterJdbcOperations = new NamedParameterJdbcTemplate(dataSource);
|
||||
DataAccessStrategy dataAccessStrategy = new DefaultDataAccessStrategy(new SqlGeneratorSource(mappingContext),
|
||||
mappingContext, converter, namedParameterJdbcOperations);
|
||||
template = new JdbcAggregateTemplate(eventPublisher, mappingContext, converter, dataAccessStrategy);
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-378
|
||||
public void findAllByIdMustNotAcceptNullArgumentForType() {
|
||||
assertThatThrownBy(() -> template.findAllById(singleton(23L), null)).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-378
|
||||
public void findAllByIdMustNotAcceptNullArgumentForIds() {
|
||||
|
||||
assertThatThrownBy(() -> template.findAllById(null, SampleEntity.class))
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-378
|
||||
public void findAllByIdWithEmpthListMustReturnEmptyResult() {
|
||||
assertThat(template.findAllById(emptyList(), SampleEntity.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class SampleEntity {
|
||||
|
||||
@Column("id1") @Id private Long id;
|
||||
|
||||
private String name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user