Browse Source

DATAJDBC-622 - Add test for negative case.

This demonstrates that the configured reference is actually used.

Original pull request: #245.
pull/252/head
Jens Schauder 5 years ago
parent
commit
a9c4445501
No known key found for this signature in database
GPG Key ID: 996B1389BA0721C3
  1. 71
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests.java
  2. 1
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositoriesIntegrationTests.java
  3. 3
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-db2.sql
  4. 1
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-h2.sql
  5. 1
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-hsql.sql
  6. 1
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-mariadb.sql
  7. 2
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-mssql.sql
  8. 1
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-mysql.sql
  9. 3
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-oracle.sql
  10. 2
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-postgres.sql

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

@ -0,0 +1,71 @@ @@ -0,0 +1,71 @@
/*
* Copyright 2017-2020 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.repository.config;
import static org.assertj.core.api.Assertions.*;
import lombok.Data;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.annotation.Id;
import org.springframework.data.repository.CrudRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Tests the {@link EnableJdbcRepositories} annotation.
*
* @author Jens Schauder
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration(
classes = EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests.TestConfiguration.class)
public class EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests {
@Autowired DummyRepository repository;
@Test // DATAJDBC-622
public void missingTransactionManagerCausesException() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> repository.findAll());
}
interface DummyRepository extends CrudRepository<DummyEntity, Long> {
}
@Data
static class DummyEntity {
@Id private Long id;
}
@ComponentScan("org.springframework.data.jdbc.testing")
@EnableJdbcRepositories(considerNestedRepositories = true,
includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = DummyRepository.class),
transactionManagerRef = "no-such-transaction-manager")
static class TestConfiguration {
@Bean
Class<?> testClass() {
return EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests.class;
}
}
}

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

@ -51,7 +51,6 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; @@ -51,7 +51,6 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ReflectionUtils;
/**

3
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-db2.sql

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
DROP TABLE Dummy_entity;
CREATE TABLE Dummy_Entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY)

1
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-h2.sql

@ -0,0 +1 @@ @@ -0,0 +1 @@
CREATE TABLE Dummy_Entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY)

1
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-hsql.sql

@ -0,0 +1 @@ @@ -0,0 +1 @@
CREATE TABLE Dummy_Entity ( id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY)

1
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-mariadb.sql

@ -0,0 +1 @@ @@ -0,0 +1 @@
CREATE TABLE Dummy_Entity ( id BIGINT AUTO_INCREMENT PRIMARY KEY)

2
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-mssql.sql

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
DROP TABLE IF EXISTS Dummy_Entity;
CREATE TABLE Dummy_Entity ( id BIGINT IDENTITY PRIMARY KEY);

1
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-mysql.sql

@ -0,0 +1 @@ @@ -0,0 +1 @@
CREATE TABLE Dummy_Entity ( id BIGINT AUTO_INCREMENT PRIMARY KEY)

3
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-oracle.sql

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
DROP TABLE DUMMY_ENTITY;
CREATE TABLE DUMMY_ENTITY ( id NUMBER GENERATED by default on null as IDENTITY PRIMARY KEY);

2
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesBrokenTransactionManagerRefIntegrationTests-postgres.sql

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
DROP TABLE Dummy_Entity
CREATE TABLE Dummy_Entity ( id SERIAL PRIMARY KEY)
Loading…
Cancel
Save