diff --git a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/RabbitConnectionFactoryCloudConfigTestHelper.java b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/RabbitConnectionFactoryCloudConfigTestHelper.java index 9b66a6c..ffb2b6e 100644 --- a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/RabbitConnectionFactoryCloudConfigTestHelper.java +++ b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/RabbitConnectionFactoryCloudConfigTestHelper.java @@ -1,3 +1,15 @@ +/* + * Copyright 2015-2016 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.cloud.config; import static org.junit.Assert.assertEquals; @@ -7,23 +19,33 @@ import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.test.util.ReflectionTestUtils; /** - * + * * @author Ramnivas Laddad * @author Scott Frederick + * @author Gary Russell * */ public class RabbitConnectionFactoryCloudConfigTestHelper { public static final int DEFAULT_CHANNEL_CACHE_SIZE = 1; - + + private final static Integer DEFAULT_FACTORY_TIMEOUT = + (Integer) ReflectionTestUtils.getField(new com.rabbitmq.client.ConnectionFactory(), "connectionTimeout"); + + private final static Integer DEFAULT_FACTORY_HEARTBEAT = + (Integer) ReflectionTestUtils.getField(new com.rabbitmq.client.ConnectionFactory(), "requestedHeartbeat"); + public static void assertConfigProperties(ConnectionFactory connector, Integer channelCacheSize, Integer requestedHeartbeat, Integer connectionTimeout) { + Integer timeoutToTest = connectionTimeout < 0 ? DEFAULT_FACTORY_TIMEOUT : connectionTimeout; + Integer heartBeatToTest = requestedHeartbeat < 0 ? DEFAULT_FACTORY_HEARTBEAT : requestedHeartbeat; + assertNotNull(connector); assertEquals(channelCacheSize, ReflectionTestUtils.getField(connector, "channelCacheSize")); Object rabbitConnectionFactory = ReflectionTestUtils.getField(connector, "rabbitConnectionFactory"); assertNotNull(rabbitConnectionFactory); - assertEquals(requestedHeartbeat, ReflectionTestUtils.getField(rabbitConnectionFactory, "requestedHeartbeat")); - assertEquals(connectionTimeout, ReflectionTestUtils.getField(rabbitConnectionFactory, "connectionTimeout")); + assertEquals(heartBeatToTest, ReflectionTestUtils.getField(rabbitConnectionFactory, "requestedHeartbeat")); + assertEquals(timeoutToTest, ReflectionTestUtils.getField(rabbitConnectionFactory, "connectionTimeout")); } } diff --git a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/java/RabbitConnectionFactoryJavaConfigTest.java b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/java/RabbitConnectionFactoryJavaConfigTest.java index b14c8be..253aec6 100644 --- a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/java/RabbitConnectionFactoryJavaConfigTest.java +++ b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/java/RabbitConnectionFactoryJavaConfigTest.java @@ -1,6 +1,24 @@ +/* + * Copyright 2015-2016 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.cloud.config.java; +import static org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHelper.DEFAULT_CHANNEL_CACHE_SIZE; + +import java.util.HashMap; +import java.util.Map; + import org.junit.Test; + import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHelper; import org.springframework.cloud.service.ServiceInfo; @@ -8,37 +26,35 @@ import org.springframework.cloud.service.messaging.RabbitConnectionFactoryConfig import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; -import java.util.HashMap; -import java.util.Map; - -import static org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHelper.DEFAULT_CHANNEL_CACHE_SIZE; - /** - * + * * @author Ramnivas Laddad * @author Scott Frederick + * @author Gary Russell * */ public class RabbitConnectionFactoryJavaConfigTest extends AbstractServiceJavaConfigTest { public RabbitConnectionFactoryJavaConfigTest() { super(RabbitConnectionFactoryConfigWithId.class, RabbitConnectionFactoryConfigWithoutId.class); } - + + @Override protected ServiceInfo createService(String id) { return createRabbitService(id); } - + + @Override protected Class getConnectorType() { return ConnectionFactory.class; } - + @Test public void cloudRabbitConnectionFactoryWithConfig() { - ApplicationContext testContext = + ApplicationContext testContext = getTestApplicationContext(RabbitConnectionFactoryConfigWithServiceConfig.class, createService("my-service")); - + ConnectionFactory connector = testContext.getBean("connectionFactoryWithConfig", getConnectorType()); - RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, 0, 0); + RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, -1, -1); } @Test @@ -98,4 +114,4 @@ class RabbitConnectionFactoryConfigWithServiceConfig extends AbstractCloudConfig RabbitConnectionFactoryConfig serviceConfig = new RabbitConnectionFactoryConfig(properties, 300); return connectionFactory().rabbitConnectionFactory("my-service", serviceConfig); } -} \ No newline at end of file +} diff --git a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/xml/RabbitConnectionFactoryXmlConfigTest.java b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/xml/RabbitConnectionFactoryXmlConfigTest.java index ebb917f..62883be 100644 --- a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/xml/RabbitConnectionFactoryXmlConfigTest.java +++ b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/xml/RabbitConnectionFactoryXmlConfigTest.java @@ -1,44 +1,62 @@ +/* + * Copyright 2015-2016 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.cloud.config.xml; +import static org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHelper.DEFAULT_CHANNEL_CACHE_SIZE; + import org.junit.Test; + import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHelper; import org.springframework.cloud.service.ServiceInfo; import org.springframework.context.ApplicationContext; -import static org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHelper.DEFAULT_CHANNEL_CACHE_SIZE; - /** - * + * * @author Ramnivas Laddad + * @author Gary Russell * */ public class RabbitConnectionFactoryXmlConfigTest extends AbstractServiceXmlConfigTest { + @Override protected ServiceInfo createService(String id) { return createRabbitService(id); } - + + @Override protected String getWithServiceIdContextFileName() { return "cloud-rabbit-with-service-id.xml"; } - + + @Override protected String getWithoutServiceIdContextFileName() { return "cloud-rabbit-without-service-id.xml"; } + @Override protected Class getConnectorType() { return ConnectionFactory.class; } - + @Test public void cloudRabbitConnectionFactoryWithConfiguration() { ApplicationContext testContext = getTestApplicationContext("cloud-rabbit-with-config.xml", createService("my-service")); - + ConnectionFactory connector = testContext.getBean("service-channelCacheSize200", getConnectorType()); - RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, 0, 0); + RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, -1, -1); } - + @Test public void cloudRabbitConnectionFactoryWithProperties() { ApplicationContext testContext = getTestApplicationContext("cloud-rabbit-with-config.xml", createService("my-service"));