Browse Source
Move non integration tests to separate class. Original Pull Request: #155pull/157/head
3 changed files with 105 additions and 31 deletions
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue