Skip to content

Commit a9c4445

Browse files
committed
DATAJDBC-622 - Add test for negative case.
This demonstrates that the configured reference is actually used. Original pull request: #245.
1 parent 1ef97dd commit a9c4445

10 files changed

+85
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2017-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jdbc.repository.config;
17+
18+
import static org.assertj.core.api.Assertions.*;
19+
20+
import lombok.Data;
21+
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
25+
import org.springframework.beans.factory.annotation.Autowired;
26+
import org.springframework.context.annotation.Bean;
27+
import org.springframework.context.annotation.ComponentScan;
28+
import org.springframework.context.annotation.FilterType;
29+
import org.springframework.data.annotation.Id;
30+
import org.springframework.data.repository.CrudRepository;
31+
import org.springframework.test.context.ContextConfiguration;
32+
import org.springframework.test.context.junit.jupiter.SpringExtension;
33+
34+
/**
35+
* Tests the {@link EnableJdbcRepositories} annotation.
36+
*
37+
* @author Jens Schauder
38+
*/
39+
@ExtendWith(SpringExtension.class)
40+
@ContextConfiguration(
41+
classes = EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests.TestConfiguration.class)
42+
public class EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests {
43+
44+
@Autowired DummyRepository repository;
45+
46+
@Test // DATAJDBC-622
47+
public void missingTransactionManagerCausesException() {
48+
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> repository.findAll());
49+
}
50+
51+
interface DummyRepository extends CrudRepository<DummyEntity, Long> {
52+
53+
}
54+
55+
@Data
56+
static class DummyEntity {
57+
@Id private Long id;
58+
}
59+
60+
@ComponentScan("org.springframework.data.jdbc.testing")
61+
@EnableJdbcRepositories(considerNestedRepositories = true,
62+
includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = DummyRepository.class),
63+
transactionManagerRef = "no-such-transaction-manager")
64+
static class TestConfiguration {
65+
66+
@Bean
67+
Class<?> testClass() {
68+
return EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests.class;
69+
}
70+
}
71+
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesIntegrationTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
5252
import org.springframework.test.context.ContextConfiguration;
5353
import org.springframework.test.context.junit.jupiter.SpringExtension;
54-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
5554
import org.springframework.util.ReflectionUtils;
5655

5756
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DROP TABLE Dummy_entity;
2+
3+
CREATE TABLE Dummy_Entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE Dummy_Entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE Dummy_Entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE Dummy_Entity ( id BIGINT AUTO_INCREMENT PRIMARY KEY)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DROP TABLE IF EXISTS Dummy_Entity;
2+
CREATE TABLE Dummy_Entity ( id BIGINT IDENTITY PRIMARY KEY);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE Dummy_Entity ( id BIGINT AUTO_INCREMENT PRIMARY KEY)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DROP TABLE DUMMY_ENTITY;
2+
3+
CREATE TABLE DUMMY_ENTITY ( id NUMBER GENERATED by default on null as IDENTITY PRIMARY KEY);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DROP TABLE Dummy_Entity
2+
CREATE TABLE Dummy_Entity ( id SERIAL PRIMARY KEY)

0 commit comments

Comments
 (0)