Skip to content

Commit cf22e28

Browse files
committed
Add tests to verify that ActiveMQAutoConfiguration backs off
See gh-1599
1 parent 38d8a5c commit cf22e28

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright 2012-2014 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+
* http://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+
17+
package org.springframework.boot.autoconfigure.jms.activemq;
18+
19+
import javax.jms.ConnectionFactory;
20+
21+
import org.apache.activemq.ActiveMQConnectionFactory;
22+
import org.junit.Test;
23+
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
24+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
25+
import org.springframework.context.annotation.Bean;
26+
import org.springframework.context.annotation.Configuration;
27+
28+
import static org.hamcrest.Matchers.instanceOf;
29+
import static org.junit.Assert.assertEquals;
30+
import static org.junit.Assert.assertThat;
31+
import static org.junit.Assert.assertTrue;
32+
import static org.mockito.Mockito.mock;
33+
import static org.mockito.Mockito.mockingDetails;
34+
35+
/**
36+
* Tests for {@link ActiveMQAutoConfiguration}
37+
*
38+
* @author Andy Wilkinson
39+
*/
40+
public class ActiveMQAutoConfigurationTests {
41+
42+
private AnnotationConfigApplicationContext context;
43+
44+
@Test
45+
public void brokerIsEmbeddedByDefault() {
46+
load(EmptyConfiguration.class);
47+
ConnectionFactory connectionFactory = this.context
48+
.getBean(ConnectionFactory.class);
49+
assertThat(connectionFactory, instanceOf(ActiveMQConnectionFactory.class));
50+
String brokerUrl = ((ActiveMQConnectionFactory) connectionFactory).getBrokerURL();
51+
assertEquals(ActiveMQProperties.DEFAULT_EMBEDDED_BROKER_URL, brokerUrl);
52+
}
53+
54+
@Test
55+
public void configurationBacksOffWhenCustomConnectionFactoryExists() {
56+
load(CustomConnectionFactoryConfiguration.class);
57+
assertTrue(mockingDetails(this.context.getBean(ConnectionFactory.class)).isMock());
58+
}
59+
60+
private void load(Class<?> config) {
61+
this.context = doLoad(config);
62+
}
63+
64+
private AnnotationConfigApplicationContext doLoad(Class<?> config) {
65+
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
66+
applicationContext.register(config);
67+
applicationContext.register(ActiveMQAutoConfiguration.class,
68+
JmsAutoConfiguration.class);
69+
applicationContext.refresh();
70+
return applicationContext;
71+
}
72+
73+
@Configuration
74+
static class EmptyConfiguration {
75+
76+
}
77+
78+
@Configuration
79+
static class CustomConnectionFactoryConfiguration {
80+
81+
@Bean
82+
public ConnectionFactory connectionFactory() {
83+
return mock(ConnectionFactory.class);
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)