25
25
import java .io .DataOutputStream ;
26
26
import java .io .IOException ;
27
27
import java .net .URI ;
28
- import java .util .concurrent .atomic .AtomicReference ;
29
28
30
29
import org .apache .activemq .ActiveMQConnection ;
31
30
import org .apache .activemq .ActiveMQConnectionFactory ;
32
31
import org .apache .activemq .ActiveMQConnectionMetaData ;
33
32
import org .apache .activemq .broker .BrokerService ;
34
33
import org .apache .activemq .broker .TransportConnector ;
35
34
import org .apache .activemq .command .WireFormatInfo ;
36
- import org .apache .activemq .transport .DefaultTransportListener ;
35
+ import org .junit .After ;
36
+ import org .junit .Before ;
37
37
import org .junit .Test ;
38
38
import org .slf4j .Logger ;
39
39
import org .slf4j .LoggerFactory ;
@@ -42,36 +42,60 @@ public class WireFormatInfoPropertiesTest {
42
42
43
43
static final Logger LOG = LoggerFactory .getLogger (WireFormatInfoPropertiesTest .class );
44
44
45
- protected BrokerService master ;
46
- protected String brokerUri ;
45
+ private BrokerService service ;
46
+ private String brokerUri ;
47
+ private TransportConnector connector ;
48
+
49
+ @ Before
50
+ public void before () throws Exception {
51
+ service = new BrokerService ();
52
+ connector = service .addConnector ("tcp://localhost:0" );
53
+ brokerUri = connector .getPublishableConnectString ();
54
+ service .setPersistent (false );
55
+ service .setUseJmx (false );
56
+ service .setBrokerName ("Master" );
57
+ service .start ();
58
+ service .waitUntilStarted ();
59
+ }
60
+
61
+ @ After
62
+ public void after () throws Exception {
63
+ if (service != null ) {
64
+ service .stop ();
65
+ service .waitUntilStopped ();
66
+ }
67
+ }
47
68
48
69
@ Test
49
- public void testClientProperties () throws Exception {
50
- BrokerService service = createBrokerService ();
51
- try {
52
- ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory (new URI (brokerUri ));
53
- ActiveMQConnection conn = (ActiveMQConnection )factory .createConnection ();
54
- final AtomicReference <WireFormatInfo > clientWf = new AtomicReference <WireFormatInfo >();
55
- conn .addTransportListener (new DefaultTransportListener () {
56
- @ Override
57
- public void onCommand (Object command ) {
58
- if (command instanceof WireFormatInfo ) {
59
- clientWf .set ((WireFormatInfo )command );
60
- }
61
- }
62
- });
63
- conn .start ();
64
- if (clientWf .get () == null ) {
65
- fail ("Wire format info is null" );
66
- }
67
- assertTrue (clientWf .get ().getProperties ().containsKey ("ProviderName" ));
68
- assertTrue (clientWf .get ().getProperties ().containsKey ("ProviderVersion" ));
69
- assertTrue (clientWf .get ().getProperties ().containsKey ("PlatformDetails" ));
70
- assertTrue (clientWf .get ().getProviderName ().equals (ActiveMQConnectionMetaData .PROVIDER_NAME ));
71
- assertTrue (clientWf .get ().getPlatformDetails ().equals (ActiveMQConnectionMetaData .PLATFORM_DETAILS ));
72
- } finally {
73
- stopBroker (service );
70
+ public void testClientPropertiesWithDefaultPlatformDetails () throws Exception {
71
+ WireFormatInfo clientWf = testClientProperties (brokerUri );
72
+ assertTrue (clientWf .getPlatformDetails ().equals (ActiveMQConnectionMetaData .DEFAULT_PLATFORM_DETAILS ));
73
+ }
74
+
75
+ @ Test
76
+ public void testClientPropertiesWithPlatformDetails () throws Exception {
77
+ WireFormatInfo clientWf = testClientProperties (brokerUri + "?wireFormat.includePlatformDetails=true" );
78
+ assertTrue (clientWf .getPlatformDetails ().equals (ActiveMQConnectionMetaData .PLATFORM_DETAILS ));
79
+ }
80
+
81
+ private WireFormatInfo testClientProperties (String brokerUri ) throws Exception {
82
+ ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory (new URI (brokerUri ));
83
+ ActiveMQConnection conn = (ActiveMQConnection )factory .createConnection ();
84
+ conn .start ();
85
+
86
+ assertTrue (connector .getConnections ().size () == 1 );
87
+ final WireFormatInfo clientWf = connector .getConnections ().get (0 ).getRemoteWireFormatInfo ();
88
+ if (clientWf == null ) {
89
+ fail ("Wire format info is null" );
74
90
}
91
+
92
+ //verify properties that the client sends to the broker
93
+ assertTrue (clientWf .getProperties ().containsKey ("ProviderName" ));
94
+ assertTrue (clientWf .getProperties ().containsKey ("ProviderVersion" ));
95
+ assertTrue (clientWf .getProperties ().containsKey ("PlatformDetails" ));
96
+ assertTrue (clientWf .getProviderName ().equals (ActiveMQConnectionMetaData .PROVIDER_NAME ));
97
+
98
+ return clientWf ;
75
99
}
76
100
77
101
@ Test
@@ -100,23 +124,4 @@ public void testMarshalClientProperties() throws IOException {
100
124
assertTrue (result .getPlatformDetails ().equals (orig .getPlatformDetails ()));
101
125
}
102
126
103
- private BrokerService createBrokerService () throws Exception {
104
- BrokerService service = new BrokerService ();
105
- TransportConnector connector = service .addConnector ("tcp://localhost:0" );
106
- brokerUri = connector .getPublishableConnectString ();
107
- service .setPersistent (false );
108
- service .setUseJmx (false );
109
- service .setBrokerName ("Master" );
110
- service .start ();
111
- service .waitUntilStarted ();
112
- return service ;
113
- }
114
-
115
- private void stopBroker (BrokerService service ) throws Exception {
116
- if (service != null ) {
117
- service .stop ();
118
- service .waitUntilStopped ();
119
- }
120
- }
121
-
122
127
}
0 commit comments