Skip to content

Commit 1961244

Browse files
committed
Fix server version parsing in test
1 parent 60a28bc commit 1961244

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/test/java/com/rabbitmq/client/test/ClientTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
RecoveryDelayHandlerTest.class,
5656
FrameBuilderTest.class,
5757
PropertyFileInitialisationTest.class,
58-
ClientVersionTest.class
58+
ClientVersionTest.class,
59+
TestUtilsTest.class
5960
})
6061
public class ClientTests {
6162

src/test/java/com/rabbitmq/client/test/TestUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public static boolean isVersion37orLater(Connection connection) {
5454
if (currentVersion.contains("~")) {
5555
currentVersion = currentVersion.substring(0, currentVersion.indexOf("~"));
5656
}
57+
// alpha (snapshot) versions: 3.7.1-alpha.40
58+
if (currentVersion.contains("-")) {
59+
currentVersion = currentVersion.substring(0, currentVersion.indexOf("-"));
60+
}
5761
return "0.0.0".equals(currentVersion) || versionCompare(currentVersion, "3.7.0") >= 0;
5862
}
5963

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2017-Present Pivotal Software, Inc. All rights reserved.
2+
//
3+
// This software, the RabbitMQ Java client library, is triple-licensed under the
4+
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
5+
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6+
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7+
// please see LICENSE-APACHE2.
8+
//
9+
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10+
// either express or implied. See the LICENSE file for specific language governing
11+
// rights and limitations of this software.
12+
//
13+
// If you have any questions regarding licensing, please contact us at
14+
// info@rabbitmq.com.
15+
16+
package com.rabbitmq.client.test;
17+
18+
import com.rabbitmq.client.Connection;
19+
import org.junit.Test;
20+
21+
import java.util.HashMap;
22+
import java.util.Map;
23+
24+
import static org.hamcrest.Matchers.is;
25+
import static org.junit.Assert.assertThat;
26+
import static org.mockito.Mockito.mock;
27+
import static org.mockito.Mockito.when;
28+
29+
public class TestUtilsTest {
30+
31+
@Test
32+
public void isVersion37orLater() {
33+
Map<String, Object> serverProperties = new HashMap<>();
34+
Connection connection = mock(Connection.class);
35+
when(connection.getServerProperties()).thenReturn(serverProperties);
36+
37+
serverProperties.put("version", "3.7.0+rc.1.4.gedc5d96");
38+
assertThat(TestUtils.isVersion37orLater(connection), is(true));
39+
40+
serverProperties.put("version", "3.7.0~alpha.449-1");
41+
assertThat(TestUtils.isVersion37orLater(connection), is(true));
42+
43+
serverProperties.put("version", "3.7.1-alpha.40");
44+
assertThat(TestUtils.isVersion37orLater(connection), is(true));
45+
}
46+
}

0 commit comments

Comments
 (0)