forked from snowdrop/narayana-spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNarayanaAutoConfigurationIT.java
More file actions
151 lines (127 loc) · 6.89 KB
/
Copy pathNarayanaAutoConfigurationIT.java
File metadata and controls
151 lines (127 loc) · 6.89 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Copyright 2020 Red Hat, Inc, and individual contributors.
*
* 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 dev.snowdrop.boot.narayana.autoconfigure;
import java.io.File;
import java.util.Properties;
import jakarta.transaction.TransactionManager;
import jakarta.transaction.TransactionSynchronizationRegistry;
import jakarta.transaction.UserTransaction;
import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule;
import com.arjuna.ats.jbossatx.jta.RecoveryManagerService;
import dev.snowdrop.boot.narayana.core.jdbc.GenericXADataSourceWrapper;
import dev.snowdrop.boot.narayana.core.jms.GenericXAConnectionFactoryWrapper;
import dev.snowdrop.boot.narayana.core.jms.PooledXAConnectionFactoryWrapper;
import dev.snowdrop.boot.narayana.core.properties.NarayanaProperties;
import dev.snowdrop.boot.narayana.core.properties.NarayanaPropertiesInitializer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.jdbc.XADataSourceWrapper;
import org.springframework.boot.jms.XAConnectionFactoryWrapper;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.transaction.jta.JtaTransactionManager;
import org.springframework.util.FileSystemUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author <a href="mailto:gytis@redhat.com">Gytis Trikleris</a>
*/
class NarayanaAutoConfigurationIT {
private AnnotationConfigApplicationContext context;
@AfterEach
void closeContext() {
if (this.context != null) {
this.context.close();
}
FileSystemUtils.deleteRecursively(new File("transaction-logs"));
}
@Test
void allDefaultBeansShouldBeLoaded() {
this.context = new AnnotationConfigApplicationContext(NarayanaAutoConfiguration.class);
this.context.getBean(NarayanaBeanFactoryPostProcessor.class);
this.context.getBean(XADataSourceWrapper.class);
this.context.getBean(XAConnectionFactoryWrapper.class);
this.context.getBean(NarayanaPropertiesInitializer.class);
this.context.getBean(UserTransaction.class);
this.context.getBean(TransactionManager.class);
this.context.getBean(TransactionSynchronizationRegistry.class);
this.context.getBean(JtaTransactionManager.class);
this.context.getBean(RecoveryManagerService.class);
this.context.getBean(XARecoveryModule.class);
}
@Test
void recoveryDbRecoveryPropertiesShouldBeLoaded() {
Properties properties = new Properties();
properties.put("narayana.dbRecoveryProperties.user", "userName");
properties.put("narayana.dbRecoveryProperties.password", "password");
PropertiesPropertySource propertySource = new PropertiesPropertySource("test", properties);
this.context = new AnnotationConfigApplicationContext();
this.context.register(NarayanaAutoConfiguration.class);
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.refresh();
NarayanaProperties narayanaProperties = this.context.getBean(NarayanaProperties.class);
assertThat(narayanaProperties.getDbRecoveryProperties().getUser()).isEqualTo("userName");
assertThat(narayanaProperties.getDbRecoveryProperties().getPassword()).isEqualTo("password");
}
@Test
void recoveryJmsRecoveryPropertiesShouldBeLoaded() {
Properties properties = new Properties();
properties.put("narayana.jmsRecoveryProperties.user", "userName");
properties.put("narayana.jmsRecoveryProperties.password", "password");
PropertiesPropertySource propertySource = new PropertiesPropertySource("test", properties);
this.context = new AnnotationConfigApplicationContext();
this.context.register(NarayanaAutoConfiguration.class);
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.refresh();
NarayanaProperties narayanaProperties = this.context.getBean(NarayanaProperties.class);
assertThat(narayanaProperties.getJmsRecoveryProperties().getUser()).isEqualTo("userName");
assertThat(narayanaProperties.getJmsRecoveryProperties().getPassword()).isEqualTo("password");
}
@Test
void genericXaDataSourceWrapperShouldBeLoaded() {
Properties properties = new Properties();
properties.put("narayana.dbcp.enabled", "false");
PropertiesPropertySource propertySource = new PropertiesPropertySource("test", properties);
this.context = new AnnotationConfigApplicationContext();
this.context.register(NarayanaAutoConfiguration.class);
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.refresh();
XADataSourceWrapper xaDataSourceWrapper = this.context.getBean(XADataSourceWrapper.class);
assertThat(xaDataSourceWrapper).isInstanceOf(GenericXADataSourceWrapper.class);
}
@Test
void genericXaConnectionFactoryWrapperShouldBeLoaded() {
Properties properties = new Properties();
PropertiesPropertySource propertySource = new PropertiesPropertySource("test", properties);
this.context = new AnnotationConfigApplicationContext();
this.context.register(NarayanaAutoConfiguration.class);
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.refresh();
XAConnectionFactoryWrapper xaConnectionFactoryWrapper = this.context.getBean(XAConnectionFactoryWrapper.class);
assertThat(xaConnectionFactoryWrapper).isInstanceOf(GenericXAConnectionFactoryWrapper.class);
}
@Test
void pooledXaConnectionFactoryWrapperShouldBeLoaded() {
Properties properties = new Properties();
properties.put("narayana.messaginghub.enabled", "true");
PropertiesPropertySource propertySource = new PropertiesPropertySource("test", properties);
this.context = new AnnotationConfigApplicationContext();
this.context.register(NarayanaAutoConfiguration.class);
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.refresh();
XAConnectionFactoryWrapper xaConnectionFactoryWrapper = this.context.getBean(XAConnectionFactoryWrapper.class);
assertThat(xaConnectionFactoryWrapper).isInstanceOf(PooledXAConnectionFactoryWrapper.class);
}
}