/
TransactionalAnnotatedConfigClassWithAtConfigurationTests.java
83 lines (70 loc) · 2.55 KB
/
TransactionalAnnotatedConfigClassWithAtConfigurationTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Copyright 2002-2012 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
*
* http://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.test.context.junit4.spr9051;
import static org.junit.Assert.assertSame;
import javax.sql.DataSource;
import org.junit.Before;
import org.springframework.beans.Employee;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.PlatformTransactionManager;
/**
* Concrete implementation of {@link AbstractTransactionalAnnotatedConfigClassTests}
* that uses a true {@link Configuration @Configuration class}.
*
* @author Sam Brannen
* @since 3.2
* @see TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests
*/
@ContextConfiguration
public class TransactionalAnnotatedConfigClassWithAtConfigurationTests extends
AbstractTransactionalAnnotatedConfigClassTests {
/**
* This is <b>intentionally</b> annotated with {@code @Configuration}.
*
* <p>Consequently, this class contains standard singleton bean methods
* instead of <i>annotated factory bean methods</i>.
*/
@Configuration
static class Config {
@Bean
public Employee employee() {
Employee employee = new Employee();
employee.setName("John Smith");
employee.setAge(42);
employee.setCompany("Acme Widgets, Inc.");
return employee;
}
@Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()//
.addScript("classpath:/org/springframework/test/context/junit4/spr9051/schema.sql")//
.build();
}
}
@Before
public void compareDataSources() throws Exception {
// NOTE: the two DataSource instances are the same!
assertSame(dataSourceFromTxManager, dataSourceViaInjection);
}
}