PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/qpid-0.16/java/common/src/test/java/org/apache/qpid/transport/ConnectionSettingsTest.java

#
Java | 174 lines | 125 code | 29 blank | 20 comment | 1 complexity | f0ef9d04b8f40b2603baca860c384024 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. package org.apache.qpid.transport;
  22. import javax.net.ssl.KeyManagerFactory;
  23. import javax.net.ssl.TrustManagerFactory;
  24. import org.apache.qpid.configuration.ClientProperties;
  25. import org.apache.qpid.test.utils.QpidTestCase;
  26. public class ConnectionSettingsTest extends QpidTestCase
  27. {
  28. private static final String TEST_ALGORITHM_NAME = "algorithmName";
  29. private ConnectionSettings _conConnectionSettings;
  30. protected void setUp() throws Exception
  31. {
  32. super.setUp();
  33. _conConnectionSettings = new ConnectionSettings();
  34. }
  35. public void testTcpNoDelayDefault()
  36. {
  37. assertTrue("Default for isTcpNodelay() should be true", _conConnectionSettings.isTcpNodelay());
  38. }
  39. public void testTcpNoDelayOverrideTrue()
  40. {
  41. systemPropertyOverrideForTcpDelay(ClientProperties.QPID_TCP_NODELAY_PROP_NAME, true);
  42. }
  43. public void testTcpNoDelayOverrideFalse()
  44. {
  45. systemPropertyOverrideForTcpDelay(ClientProperties.QPID_TCP_NODELAY_PROP_NAME, false);
  46. }
  47. @SuppressWarnings("deprecation")
  48. public void testTcpNoDelayLegacyOverrideTrue()
  49. {
  50. systemPropertyOverrideForTcpDelay(ClientProperties.AMQJ_TCP_NODELAY_PROP_NAME, true);
  51. }
  52. @SuppressWarnings("deprecation")
  53. public void testTcpNoDelayLegacyOverrideFalse()
  54. {
  55. systemPropertyOverrideForTcpDelay(ClientProperties.AMQJ_TCP_NODELAY_PROP_NAME, false);
  56. }
  57. public void testKeyManagerFactoryAlgorithmDefault()
  58. {
  59. assertEquals(KeyManagerFactory.getDefaultAlgorithm(), _conConnectionSettings.getKeyManagerFactoryAlgorithm());
  60. }
  61. public void testKeyManagerFactoryAlgorithmOverridden()
  62. {
  63. String algorithmName = TEST_ALGORITHM_NAME;
  64. systemPropertyOverrideForKeyFactoryAlgorithm(ClientProperties.QPID_SSL_KEY_MANAGER_FACTORY_ALGORITHM_PROP_NAME, algorithmName);
  65. }
  66. @SuppressWarnings("deprecation")
  67. public void testKeyManagerFactoryAlgorithmLegacyOverridden()
  68. {
  69. String algorithmName = TEST_ALGORITHM_NAME;
  70. systemPropertyOverrideForKeyFactoryAlgorithm(ClientProperties.QPID_SSL_KEY_STORE_CERT_TYPE_PROP_NAME, algorithmName);
  71. }
  72. public void testTrustManagerFactoryAlgorithmDefault()
  73. {
  74. assertEquals(TrustManagerFactory.getDefaultAlgorithm(), _conConnectionSettings.getTrustManagerFactoryAlgorithm());
  75. }
  76. public void testTrustManagerFactoryAlgorithmOverridden()
  77. {
  78. String algorithmName = TEST_ALGORITHM_NAME;
  79. systemPropertyOverrideForTrustFactoryAlgorithm(ClientProperties.QPID_SSL_TRUST_MANAGER_FACTORY_ALGORITHM_PROP_NAME, algorithmName);
  80. }
  81. @SuppressWarnings("deprecation")
  82. public void testTrustManagerFactoryAlgorithmLegacyOverridden()
  83. {
  84. String algorithmName = TEST_ALGORITHM_NAME;
  85. systemPropertyOverrideForTrustFactoryAlgorithm(ClientProperties.QPID_SSL_TRUST_STORE_CERT_TYPE_PROP_NAME, algorithmName);
  86. }
  87. public void testSendBufferSizeDefault()
  88. {
  89. assertEquals("unexpected default for buffer size", 65535, _conConnectionSettings.getWriteBufferSize());
  90. }
  91. public void testSendBufferSizeOverridden()
  92. {
  93. systemPropertyOverrideForSocketBufferSize(ClientProperties.SEND_BUFFER_SIZE_PROP_NAME, 1024, false);
  94. }
  95. @SuppressWarnings("deprecation")
  96. public void testtestSendBufferSizeOverriddenLegacyOverridden()
  97. {
  98. systemPropertyOverrideForSocketBufferSize(ClientProperties.LEGACY_SEND_BUFFER_SIZE_PROP_NAME, 1024, false);
  99. }
  100. public void testReceiveBufferSizeDefault()
  101. {
  102. assertEquals("unexpected default for buffer size", 65535, _conConnectionSettings.getReadBufferSize());
  103. }
  104. public void testReceiveBufferSizeOverridden()
  105. {
  106. systemPropertyOverrideForSocketBufferSize(ClientProperties.RECEIVE_BUFFER_SIZE_PROP_NAME, 1024, true);
  107. }
  108. @SuppressWarnings("deprecation")
  109. public void testtestReceiveBufferSizeOverriddenLegacyOverridden()
  110. {
  111. systemPropertyOverrideForSocketBufferSize(ClientProperties.LEGACY_RECEIVE_BUFFER_SIZE_PROP_NAME, 1024, true);
  112. }
  113. private void systemPropertyOverrideForTcpDelay(String propertyName, boolean value)
  114. {
  115. resetSystemProperty(propertyName, String.valueOf(value));
  116. assertEquals("Value for isTcpNodelay() is incorrect", value, _conConnectionSettings.isTcpNodelay());
  117. }
  118. private void systemPropertyOverrideForKeyFactoryAlgorithm(String propertyName, String value)
  119. {
  120. resetSystemProperty(propertyName, value);
  121. assertEquals(value, _conConnectionSettings.getKeyManagerFactoryAlgorithm());
  122. }
  123. private void systemPropertyOverrideForTrustFactoryAlgorithm(String propertyName, String value)
  124. {
  125. resetSystemProperty(propertyName, value);
  126. assertEquals(value, _conConnectionSettings.getTrustManagerFactoryAlgorithm());
  127. }
  128. private void systemPropertyOverrideForSocketBufferSize(String propertyName, int value, boolean read)
  129. {
  130. resetSystemProperty(propertyName, String.valueOf(value));
  131. if(read)
  132. {
  133. assertEquals("unexpected value for receive buffer", value, _conConnectionSettings.getReadBufferSize());
  134. }
  135. else
  136. {
  137. assertEquals("unexpected value for send buffer", value, _conConnectionSettings.getWriteBufferSize());
  138. }
  139. }
  140. private void resetSystemProperty(String propertyName, String value)
  141. {
  142. setTestSystemProperty(propertyName, value);
  143. _conConnectionSettings = new ConnectionSettings();
  144. }
  145. }