@@ -32,35 +32,63 @@ public class AmqpUriTest extends BrokerTestCase
32
32
{
33
33
/* From the spec (subset of the tests) */
34
34
parseSuccess ("amqp://user:pass@host:10000/vhost" ,
35
- "user" , "pass" , "host" , 10000 , "vhost" );
35
+ "user" , "pass" , "host" , 10000 , "vhost" , false );
36
36
parseSuccess ("aMQps://user%61:%61pass@host:10000/v%2fhost" ,
37
- "usera" , "apass" , "host" , 10000 , "v/host" );
38
- parseSuccess ("amqp://host" , "guest" , "guest" , "host" , 5672 , "/" );
37
+ "usera" , "apass" , "host" , 10000 , "v/host" , true );
38
+ parseSuccess ("amqp://host" , "guest" , "guest" , "host" , 5672 , "/" , false );
39
39
parseSuccess ("amqp:///vhost" ,
40
- "guest" , "guest" , "localhost" , 5672 , "vhost" );
41
- parseSuccess ("amqp://host/" , "guest" , "guest" , "host" , 5672 , "" );
42
- parseSuccess ("amqp://host/%2f" , "guest" , "guest" , "host" , 5672 , "/" );
43
- parseSuccess ("amqp://[::1]" , "guest" , "guest" , "[::1]" , 5672 , "/" );
40
+ "guest" , "guest" , "localhost" , 5672 , "vhost" , false );
41
+ parseSuccess ("amqp://host/" , "guest" , "guest" , "host" , 5672 , "" , false );
42
+ parseSuccess ("amqp://host/%2f" , "guest" , "guest" , "host" , 5672 , "/" , false );
43
+ parseSuccess ("amqp://[::1]" , "guest" , "guest" , "[::1]" , 5672 , "/" , false );
44
44
45
45
/* Various other success cases */
46
- parseSuccess ("amqp://host:100" , "guest" , "guest" , "host" , 100 , "/" );
47
- parseSuccess ("amqp://[::1]:100" , "guest" , "guest" , "[::1]" , 100 , "/" );
46
+ parseSuccess ("amqp://host:100" , "guest" , "guest" , "host" , 100 , "/" , false );
47
+ parseSuccess ("amqp://[::1]:100" , "guest" , "guest" , "[::1]" , 100 , "/" , false );
48
48
49
49
parseSuccess ("amqp://host/blah" ,
50
- "guest" , "guest" , "host" , 5672 , "blah" );
50
+ "guest" , "guest" , "host" , 5672 , "blah" , false );
51
51
parseSuccess ("amqp://host:100/blah" ,
52
- "guest" , "guest" , "host" , 100 , "blah" );
52
+ "guest" , "guest" , "host" , 100 , "blah" , false );
53
53
parseSuccess ("amqp://[::1]/blah" ,
54
- "guest" , "guest" , "[::1]" , 5672 , "blah" );
54
+ "guest" , "guest" , "[::1]" , 5672 , "blah" , false );
55
55
parseSuccess ("amqp://[::1]:100/blah" ,
56
- "guest" , "guest" , "[::1]" , 100 , "blah" );
56
+ "guest" , "guest" , "[::1]" , 100 , "blah" , false );
57
57
58
58
parseSuccess ("amqp://user:pass@host" ,
59
- "user" , "pass" , "host" , 5672 , "/" );
59
+ "user" , "pass" , "host" , 5672 , "/" , false );
60
60
parseSuccess ("amqp://user:pass@[::1]" ,
61
- "user" , "pass" , "[::1]" , 5672 , "/" );
61
+ "user" , "pass" , "[::1]" , 5672 , "/" , false );
62
62
parseSuccess ("amqp://user:pass@[::1]:100" ,
63
- "user" , "pass" , "[::1]" , 100 , "/" );
63
+ "user" , "pass" , "[::1]" , 100 , "/" , false );
64
+
65
+ /* using query parameters */
66
+ parseSuccess ("amqp://user:pass@host:10000/vhost?" ,
67
+ "user" , "pass" , "host" , 10000 , "vhost" , false );
68
+ parseSuccess ("amqp://user:pass@host:10000/vhost?&" ,
69
+ "user" , "pass" , "host" , 10000 , "vhost" , false );
70
+ parseSuccess ("amqp://user:pass@host:10000/vhost?unknown_parameter" ,
71
+ "user" , "pass" , "host" , 10000 , "vhost" , false );
72
+ parseSuccess ("amqp://user:pass@host:10000/vhost?unknown_parameter=value" ,
73
+ "user" , "pass" , "host" , 10000 , "vhost" , false );
74
+ parseSuccess ("amqp://user:pass@host:10000/vhost?unknown%2fparameter=value" ,
75
+ "user" , "pass" , "host" , 10000 , "vhost" , false );
76
+
77
+ parseSuccess ("amqp://user:pass@host:10000/vhost?heartbeat=342" ,
78
+ "user" , "pass" , "host" , 10000 , "vhost" , false ,
79
+ 342 , null , null );
80
+ parseSuccess ("amqp://user:pass@host:10000/vhost?connection_timeout=442" ,
81
+ "user" , "pass" , "host" , 10000 , "vhost" , false ,
82
+ null , 442 , null );
83
+ parseSuccess ("amqp://user:pass@host:10000/vhost?channel_max=542" ,
84
+ "user" , "pass" , "host" , 10000 , "vhost" , false ,
85
+ null , null , 542 );
86
+ parseSuccess ("amqp://user:pass@host:10000/vhost?heartbeat=342&connection_timeout=442&channel_max=542" ,
87
+ "user" , "pass" , "host" , 10000 , "vhost" , false ,
88
+ 342 , 442 , 542 );
89
+ parseSuccess ("amqp://user:pass@host:10000/vhost?heartbeat=342&connection_timeout=442&channel_max=542&a=b" ,
90
+ "user" , "pass" , "host" , 10000 , "vhost" , false ,
91
+ 342 , 442 , 542 );
64
92
65
93
/* Various failure cases */
66
94
parseFail ("https://www.rabbitmq.com" );
@@ -71,10 +99,26 @@ public class AmqpUriTest extends BrokerTestCase
71
99
parseFail ("amqp://foo%1" );
72
100
parseFail ("amqp://foo%1x" );
73
101
parseFail ("amqp://foo%xy" );
102
+
103
+ parseFail ("amqp://user:pass@host:10000/vhost?heartbeat=not_an_integer" );
104
+ parseFail ("amqp://user:pass@host:10000/vhost?heartbeat=-1" );
105
+ parseFail ("amqp://user:pass@host:10000/vhost?connection_timeout=not_an_integer" );
106
+ parseFail ("amqp://user:pass@host:10000/vhost?connection_timeout=-1" );
107
+ parseFail ("amqp://user:pass@host:10000/vhost?channel_max=not_an_integer" );
108
+ parseFail ("amqp://user:pass@host:10000/vhost?channel_max=-1" );
109
+ parseFail ("amqp://user:pass@host:10000/vhost?heartbeat=342?connection_timeout=442" );
74
110
}
75
111
76
112
private void parseSuccess (String uri , String user , String password ,
77
- String host , int port , String vhost )
113
+ String host , int port , String vhost , boolean secured )
114
+ throws URISyntaxException , NoSuchAlgorithmException , KeyManagementException
115
+ {
116
+ parseSuccess (uri , user , password , host , port , vhost , secured , null , null , null );
117
+ }
118
+
119
+ private void parseSuccess (String uri , String user , String password ,
120
+ String host , int port , String vhost , boolean secured ,
121
+ Integer heartbeat , Integer connectionTimeout , Integer channelMax )
78
122
throws URISyntaxException , NoSuchAlgorithmException , KeyManagementException
79
123
{
80
124
ConnectionFactory cf = TestUtils .connectionFactory ();
@@ -85,6 +129,17 @@ private void parseSuccess(String uri, String user, String password,
85
129
assertEquals (host , cf .getHost ());
86
130
assertEquals (port , cf .getPort ());
87
131
assertEquals (vhost , cf .getVirtualHost ());
132
+ assertEquals (secured , cf .isSSL ());
133
+
134
+ if (heartbeat != null ) {
135
+ assertEquals (heartbeat .intValue (), cf .getRequestedHeartbeat ());
136
+ }
137
+ if (connectionTimeout != null ) {
138
+ assertEquals (connectionTimeout .intValue (), cf .getConnectionTimeout ());
139
+ }
140
+ if (channelMax != null ) {
141
+ assertEquals (channelMax .intValue (), cf .getRequestedChannelMax ());
142
+ }
88
143
}
89
144
90
145
private void parseFail (String uri ) {
0 commit comments