00001
00004 package org.ros.internal.node.server.master;
00005
00006 import static org.junit.Assert.assertEquals;
00007 import static org.junit.Assert.assertFalse;
00008 import static org.junit.Assert.assertNull;
00009 import static org.junit.Assert.assertTrue;
00010 import static org.mockito.Mockito.mock;
00011 import static org.mockito.Mockito.verify;
00012
00013 import com.google.common.collect.Sets;
00014
00015 import org.junit.Before;
00016 import org.junit.Test;
00017 import org.mockito.Mockito;
00018 import org.ros.namespace.GraphName;
00019 import org.ros.node.topic.Subscriber;
00020
00021 import java.net.URI;
00022
00028 public class MasterRegistrationManagerImplTest {
00029
00030 private MasterRegistrationManagerImpl masterRegistrationManager;
00031 private MasterRegistrationListener registrationListener;
00032
00033 @Before
00034 public void setup() {
00035 registrationListener = mock(MasterRegistrationListener.class);
00036 masterRegistrationManager = new MasterRegistrationManagerImpl(registrationListener);
00037 }
00038
00044 @Test
00045 public void testRegisterOnlyPublisher() throws Exception {
00046 GraphName nodeName = GraphName.of("/node");
00047 URI nodeSlaveUri = new URI("http://localhost:12345");
00048 GraphName topicName = GraphName.of("/topic");
00049 String topicMessageType = "topic/Message";
00050
00051 TopicRegistrationInfo topic =
00052 masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri, topicName,
00053 topicMessageType);
00054
00055 assertTrue(topic.getSubscribers().isEmpty());
00056
00057 assertEquals(topicMessageType, topic.getMessageType());
00058
00059 NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00060 assertTrue(node.hasRegistrations());
00061 assertTrue(node.getSubscribers().isEmpty());
00062 assertEquals(Sets.newHashSet(topic), node.getPublishers());
00063
00064
00065
00066 assertEquals(Sets.newHashSet(node), topic.getPublishers());
00067
00068
00069 verify(registrationListener, Mockito.never()).onNodeReplacement(node);
00070 }
00071
00077 @Test
00078 public void testRegisterOnlySubscriber() throws Exception {
00079 GraphName nodeName = GraphName.of("/node");
00080 URI nodeSlaveUri = new URI("http://localhost:12345");
00081 GraphName topicName = GraphName.of("/topic");
00082 String topicMessageType = "topic/Message";
00083
00084 TopicRegistrationInfo topic =
00085 masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName,
00086 topicMessageType);
00087
00088 assertTrue(topic.getPublishers().isEmpty());
00089
00090 assertEquals(topicMessageType, topic.getMessageType());
00091
00092 NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00093 assertTrue(node.hasRegistrations());
00094 assertTrue(node.getPublishers().isEmpty());
00095 assertEquals(Sets.newHashSet(topic), node.getSubscribers());
00096
00097
00098
00099 assertEquals(Sets.newHashSet(node), topic.getSubscribers());
00100
00101
00102 verify(registrationListener, Mockito.never()).onNodeReplacement(node);
00103 }
00104
00111 @Test
00112 public void testOnlySubscriberWildcard() throws Exception {
00113 GraphName nodeName = GraphName.of("/node");
00114 URI nodeSlaveUri = new URI("http://localhost:12345");
00115 GraphName topicName = GraphName.of("/topic");
00116
00117 TopicRegistrationInfo topic =
00118 masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName,
00119 Subscriber.TOPIC_MESSAGE_TYPE_WILDCARD);
00120
00121
00122
00123
00124 assertNull(topic.getMessageType());
00125
00126 assertTrue(topic.getPublishers().isEmpty());
00127
00128
00129 NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00130 assertTrue(node.hasRegistrations());
00131 assertTrue(node.getPublishers().isEmpty());
00132 assertEquals(Sets.newHashSet(topic), node.getSubscribers());
00133
00134
00135 verify(registrationListener, Mockito.never()).onNodeReplacement(node);
00136 }
00137
00145 @Test
00146 public void testSubscriberSubscriber() throws Exception {
00147 GraphName topicName = GraphName.of("/topic");
00148
00149 GraphName nodeName1 = GraphName.of("/node1");
00150 URI nodeSlaveUri1 = new URI("http://localhost:12345");
00151 String topicMessageType1 = "topic/Message1";
00152
00153 TopicRegistrationInfo topic1 =
00154 masterRegistrationManager.registerSubscriber(nodeName1, nodeSlaveUri1, topicName,
00155 topicMessageType1);
00156
00157 GraphName nodeName2 = GraphName.of("/node2");
00158 URI nodeSlaveUri2 = new URI("http://localhost:54321");
00159 String topicMessageType2 = "topic/Message2";
00160
00161 TopicRegistrationInfo topic2 =
00162 masterRegistrationManager.registerSubscriber(nodeName2, nodeSlaveUri2, topicName,
00163 topicMessageType2);
00164
00165
00166
00167 assertEquals(topicMessageType2, topic2.getMessageType());
00168
00169
00170 assertTrue(topic1 == topic2);
00171
00172
00173 assertTrue(topic1.getPublishers().isEmpty());
00174 NodeRegistrationInfo node1 = masterRegistrationManager.getNodeRegistrationInfo(nodeName1);
00175 assertTrue(node1.hasRegistrations());
00176 assertTrue(node1.getPublishers().isEmpty());
00177 assertEquals(Sets.newHashSet(topic1), node1.getSubscribers());
00178
00179 assertTrue(topic2.getPublishers().isEmpty());
00180 NodeRegistrationInfo node2 = masterRegistrationManager.getNodeRegistrationInfo(nodeName2);
00181 assertTrue(node2.hasRegistrations());
00182 assertTrue(node2.getPublishers().isEmpty());
00183 assertEquals(Sets.newHashSet(topic1), node2.getSubscribers());
00184
00185
00186 verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00187 verify(registrationListener, Mockito.never()).onNodeReplacement(node2);
00188 }
00189
00197 @Test
00198 public void testSubscriberSubscriberWildcard() throws Exception {
00199 GraphName topicName = GraphName.of("/topic");
00200
00201 GraphName nodeName1 = GraphName.of("/node1");
00202 URI nodeSlaveUri1 = new URI("http://localhost:12345");
00203 String topicMessageType1 = "msgs/Message";
00204
00205 TopicRegistrationInfo topic1 =
00206 masterRegistrationManager.registerSubscriber(nodeName1, nodeSlaveUri1, topicName,
00207 topicMessageType1);
00208
00209 GraphName nodeName2 = GraphName.of("/node2");
00210 URI nodeSlaveUri2 = new URI("http://localhost:54321");
00211
00212 TopicRegistrationInfo topic2 =
00213 masterRegistrationManager.registerSubscriber(nodeName2, nodeSlaveUri2, topicName,
00214 Subscriber.TOPIC_MESSAGE_TYPE_WILDCARD);
00215
00216 assertTrue(topic1.getPublishers().isEmpty());
00217
00218
00219 assertTrue(topic1 == topic2);
00220
00221 assertEquals(topicMessageType1, topic1.getMessageType());
00222
00223
00224 NodeRegistrationInfo node1 = masterRegistrationManager.getNodeRegistrationInfo(nodeName1);
00225 assertTrue(node1.hasRegistrations());
00226 assertTrue(node1.getPublishers().isEmpty());
00227 assertEquals(Sets.newHashSet(topic1), node1.getSubscribers());
00228
00229 NodeRegistrationInfo node2 = masterRegistrationManager.getNodeRegistrationInfo(nodeName2);
00230 assertTrue(node2.hasRegistrations());
00231 assertTrue(node2.getPublishers().isEmpty());
00232 assertEquals(Sets.newHashSet(topic1), node2.getSubscribers());
00233
00234
00235 verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00236 verify(registrationListener, Mockito.never()).onNodeReplacement(node2);
00237 }
00238
00245 @Test
00246 public void testSubscriberPublisher() throws Exception {
00247 GraphName topicName = GraphName.of("/topic");
00248
00249 GraphName nodeNameSubscriber = GraphName.of("/node1");
00250 URI nodeSlaveUriSubscriber = new URI("http://localhost:12345");
00251 String topicMessageTypeSubscriber = "msgs/Message1";
00252
00253 TopicRegistrationInfo topicSubscriber =
00254 masterRegistrationManager.registerSubscriber(nodeNameSubscriber, nodeSlaveUriSubscriber,
00255 topicName, topicMessageTypeSubscriber);
00256
00257 GraphName nodeNamePublisher = GraphName.of("/node2");
00258 URI nodeSlaveUriPublisher = new URI("http://localhost:54321");
00259 String topicMessageTypePublisher = "msgs/Message2";
00260
00261 TopicRegistrationInfo topicPublisher =
00262 masterRegistrationManager.registerPublisher(nodeNamePublisher, nodeSlaveUriPublisher,
00263 topicName, topicMessageTypePublisher);
00264
00265
00266 assertTrue(topicSubscriber == topicPublisher);
00267
00268
00269 assertEquals(topicMessageTypePublisher, topicSubscriber.getMessageType());
00270
00271
00272 NodeRegistrationInfo node1 =
00273 masterRegistrationManager.getNodeRegistrationInfo(nodeNameSubscriber);
00274 assertTrue(node1.hasRegistrations());
00275 assertTrue(node1.getPublishers().isEmpty());
00276 assertEquals(Sets.newHashSet(topicSubscriber), node1.getSubscribers());
00277
00278 NodeRegistrationInfo node2 =
00279 masterRegistrationManager.getNodeRegistrationInfo(nodeNamePublisher);
00280 assertTrue(node2.hasRegistrations());
00281 assertTrue(node2.getSubscribers().isEmpty());
00282 assertEquals(Sets.newHashSet(topicSubscriber), node2.getPublishers());
00283
00284
00285 verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00286 verify(registrationListener, Mockito.never()).onNodeReplacement(node2);
00287 }
00288
00295 @Test
00296 public void testPublisherSubscriber() throws Exception {
00297 GraphName topicName = GraphName.of("/topic");
00298
00299 GraphName nodeNamePublisher = GraphName.of("/node2");
00300 URI nodeSlaveUriPublisher = new URI("http://localhost:54321");
00301 String topicMessageTypePublisher = "msgs/Message2";
00302
00303 TopicRegistrationInfo topicPublisher =
00304 masterRegistrationManager.registerPublisher(nodeNamePublisher, nodeSlaveUriPublisher,
00305 topicName, topicMessageTypePublisher);
00306
00307 GraphName nodeNameSubscriber = GraphName.of("/node1");
00308 URI nodeSlaveUriSubscriber = new URI("http://localhost:12345");
00309 String topicMessageTypeSubscriber = "msgs/Message1";
00310
00311 TopicRegistrationInfo topicSubscriber =
00312 masterRegistrationManager.registerSubscriber(nodeNameSubscriber, nodeSlaveUriSubscriber,
00313 topicName, topicMessageTypeSubscriber);
00314
00315
00316 assertTrue(topicSubscriber == topicPublisher);
00317
00318
00319 assertEquals(topicMessageTypePublisher, topicSubscriber.getMessageType());
00320
00321
00322 NodeRegistrationInfo node1 =
00323 masterRegistrationManager.getNodeRegistrationInfo(nodeNameSubscriber);
00324 assertTrue(node1.hasRegistrations());
00325 assertTrue(node1.getPublishers().isEmpty());
00326 assertEquals(Sets.newHashSet(topicSubscriber), node1.getSubscribers());
00327
00328 NodeRegistrationInfo node2 =
00329 masterRegistrationManager.getNodeRegistrationInfo(nodeNamePublisher);
00330 assertTrue(node2.hasRegistrations());
00331 assertTrue(node2.getSubscribers().isEmpty());
00332 assertEquals(Sets.newHashSet(topicSubscriber), node2.getPublishers());
00333
00334
00335 verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00336 verify(registrationListener, Mockito.never()).onNodeReplacement(node2);
00337 }
00338
00345 @Test
00346 public void testPublisherPublisher() throws Exception {
00347 GraphName topicName = GraphName.of("/topic");
00348
00349 GraphName nodeNamePublisher1 = GraphName.of("/node1");
00350 URI nodeSlaveUriPublisher1 = new URI("http://localhost:54321");
00351 String topicMessageTypePublisher1 = "msgs/Message1";
00352
00353 TopicRegistrationInfo topicPublisher1 =
00354 masterRegistrationManager.registerPublisher(nodeNamePublisher1, nodeSlaveUriPublisher1,
00355 topicName, topicMessageTypePublisher1);
00356
00357 GraphName nodeNamePublisher2 = GraphName.of("/node2");
00358 URI nodeSlaveUriPublisher2 = new URI("http://localhost:12345");
00359 String topicMessageTypePublisher2 = "msgs/Message2";
00360
00361 TopicRegistrationInfo topicPublisher2 =
00362 masterRegistrationManager.registerPublisher(nodeNamePublisher2, nodeSlaveUriPublisher2,
00363 topicName, topicMessageTypePublisher2);
00364
00365
00366 assertTrue(topicPublisher2 == topicPublisher1);
00367
00368
00369 assertEquals(topicMessageTypePublisher2, topicPublisher2.getMessageType());
00370
00371
00372 NodeRegistrationInfo node1 =
00373 masterRegistrationManager.getNodeRegistrationInfo(nodeNamePublisher2);
00374 assertTrue(node1.hasRegistrations());
00375 assertTrue(node1.getSubscribers().isEmpty());
00376 assertEquals(Sets.newHashSet(topicPublisher2), node1.getPublishers());
00377
00378 NodeRegistrationInfo node2 =
00379 masterRegistrationManager.getNodeRegistrationInfo(nodeNamePublisher1);
00380 assertTrue(node2.hasRegistrations());
00381 assertTrue(node2.getSubscribers().isEmpty());
00382 assertEquals(Sets.newHashSet(topicPublisher2), node2.getPublishers());
00383
00384
00385 assertEquals(Sets.newHashSet(node1, node2), topicPublisher1.getPublishers());
00386
00387
00388 verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00389 verify(registrationListener, Mockito.never()).onNodeReplacement(node2);
00390 }
00391
00398 @Test
00399 public void testNodeNameRepeated() throws Exception {
00400 GraphName nodeName = GraphName.of("/node1");
00401
00402 GraphName topicName1 = GraphName.of("/topic1");
00403 URI nodeSlaveUri1 = new URI("http://localhost:54321");
00404 String topicMessageType1 = "msgs/Message1";
00405
00406 TopicRegistrationInfo topic1 =
00407 masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri1, topicName1,
00408 topicMessageType1);
00409
00410 NodeRegistrationInfo node1 = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00411
00412 URI nodeSlaveUri2 = new URI("http://localhost:12345");
00413 GraphName topicName2 = GraphName.of("/topic2");
00414 String topicMessageType2 = "msgs/Message2";
00415
00416 TopicRegistrationInfo topic2 =
00417 masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri2, topicName2,
00418 topicMessageType2);
00419
00420 NodeRegistrationInfo node2 = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00421
00422
00423 verify(registrationListener, Mockito.times(1)).onNodeReplacement(node1);
00424
00425
00426 assertFalse(topic2 == topic1);
00427
00428
00429
00430 assertEquals(topicMessageType2, topic2.getMessageType());
00431
00432
00433 assertTrue(topic1.getPublishers().isEmpty());
00434
00435
00436 assertTrue(node2.hasRegistrations());
00437 assertTrue(node2.getSubscribers().isEmpty());
00438 assertEquals(Sets.newHashSet(topic2), node2.getPublishers());
00439 }
00440
00446 @Test
00447 public void testSinglePublisherRemoved() throws Exception {
00448 GraphName nodeName = GraphName.of("/node1");
00449 GraphName topicName = GraphName.of("/topic1");
00450 URI nodeSlaveUri = new URI("http://localhost:54321");
00451 String topicMessageType = "msgs/Message1";
00452
00453 TopicRegistrationInfo topic =
00454 masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri, topicName,
00455 topicMessageType);
00456
00457 masterRegistrationManager.unregisterPublisher(nodeName, topicName);
00458
00459
00460 assertTrue(topic.getPublishers().isEmpty());
00461
00462
00463 assertNull(masterRegistrationManager.getNodeRegistrationInfo(nodeName));
00464 }
00465
00471 @Test
00472 public void testTwoPublishersOneRemoved() throws Exception {
00473 GraphName nodeName = GraphName.of("/node1");
00474 URI nodeSlaveUri = new URI("http://localhost:54321");
00475
00476 GraphName topicName1 = GraphName.of("/topic1");
00477 String topicMessageType1 = "msgs/Message1";
00478
00479 TopicRegistrationInfo topic1 =
00480 masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri, topicName1,
00481 topicMessageType1);
00482
00483 GraphName topicName2 = GraphName.of("/topic2");
00484 String topicMessageType2 = "msgs/Message2";
00485
00486 TopicRegistrationInfo topic2 =
00487 masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri, topicName2,
00488 topicMessageType2);
00489
00490 NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00491
00492
00493 masterRegistrationManager.unregisterPublisher(nodeName, topicName1);
00494
00495
00496
00497 assertTrue(topic1.getPublishers().isEmpty());
00498 assertEquals(Sets.newHashSet(topic2), node.getPublishers());
00499 assertEquals(Sets.newHashSet(node), topic2.getPublishers());
00500 }
00501
00507 @Test
00508 public void testSingleSubscriberRemoved() throws Exception {
00509 GraphName nodeName = GraphName.of("/node1");
00510 GraphName topicName = GraphName.of("/topic1");
00511 URI nodeSlaveUri = new URI("http://localhost:54321");
00512 String topicMessageType = "msgs/Message1";
00513
00514 TopicRegistrationInfo topic =
00515 masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName,
00516 topicMessageType);
00517
00518 masterRegistrationManager.unregisterSubscriber(nodeName, topicName);
00519
00520
00521 assertTrue(topic.getSubscribers().isEmpty());
00522
00523
00524 assertNull(masterRegistrationManager.getNodeRegistrationInfo(nodeName));
00525 }
00526
00532 @Test
00533 public void testTwoSubscribersOneRemoved() throws Exception {
00534 GraphName nodeName = GraphName.of("/node1");
00535 URI nodeSlaveUri = new URI("http://localhost:54321");
00536
00537 GraphName topicName1 = GraphName.of("/topic1");
00538 String topicMessageType1 = "msgs/Message1";
00539
00540 TopicRegistrationInfo topic1 =
00541 masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName1,
00542 topicMessageType1);
00543
00544 GraphName topicName2 = GraphName.of("/topic2");
00545 String topicMessageType2 = "msgs/Message2";
00546
00547 TopicRegistrationInfo topic2 =
00548 masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName2,
00549 topicMessageType2);
00550
00551 NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00552
00553
00554 masterRegistrationManager.unregisterSubscriber(nodeName, topicName1);
00555
00556
00557
00558
00559 assertTrue(topic1.getSubscribers().isEmpty());
00560 assertEquals(Sets.newHashSet(topic2), node.getSubscribers());
00561 assertEquals(Sets.newHashSet(node), topic2.getSubscribers());
00562 }
00563
00569 @Test
00570 public void testSubscriberTwice() throws Exception {
00571 GraphName topicName = GraphName.of("/topic");
00572
00573 GraphName nodeName = GraphName.of("/node");
00574 URI nodeSlaveUri = new URI("http://localhost:12345");
00575 String topicMessageType = "topic/Message";
00576
00577 TopicRegistrationInfo topic1 =
00578 masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName,
00579 topicMessageType);
00580 NodeRegistrationInfo node1 = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00581
00582 TopicRegistrationInfo topic2 =
00583 masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName,
00584 topicMessageType);
00585 NodeRegistrationInfo node2 = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00586
00587
00588 assertTrue(topic1 == topic2);
00589 assertTrue(node1 == node2);
00590
00591
00592 assertTrue(topic1.getPublishers().isEmpty());
00593 assertTrue(node1.hasRegistrations());
00594 assertTrue(node1.getPublishers().isEmpty());
00595 assertEquals(Sets.newHashSet(topic1), node1.getSubscribers());
00596
00597
00598 verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00599 }
00600
00606 @Test
00607 public void testPublisherTwice() throws Exception {
00608 GraphName topicName = GraphName.of("/topic");
00609
00610 GraphName nodeName = GraphName.of("/node");
00611 URI nodeSlaveUri = new URI("http://localhost:12345");
00612 String topicMessageType = "topic/Message";
00613
00614 TopicRegistrationInfo topic1 =
00615 masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri, topicName,
00616 topicMessageType);
00617 NodeRegistrationInfo node1 = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00618
00619 TopicRegistrationInfo topic2 =
00620 masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri, topicName,
00621 topicMessageType);
00622 NodeRegistrationInfo node2 = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00623
00624
00625
00626 assertTrue(topic1 == topic2);
00627 assertTrue(node1 == node2);
00628
00629
00630 assertTrue(topic1.getSubscribers().isEmpty());
00631 assertTrue(node1.hasRegistrations());
00632 assertTrue(node1.getSubscribers().isEmpty());
00633 assertEquals(Sets.newHashSet(topic1), node1.getPublishers());
00634
00635
00636 verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00637 }
00638
00644 @Test
00645 public void testRegisterOnlyService() throws Exception {
00646 GraphName nodeName = GraphName.of("/node");
00647 URI nodeSlaveUri = new URI("http://localhost:12345");
00648 GraphName serviceName = GraphName.of("/service");
00649 URI serviceUri = new URI("http://foo");
00650
00651 ServiceRegistrationInfo service =
00652 masterRegistrationManager.registerService(nodeName, nodeSlaveUri, serviceName, serviceUri);
00653
00654 assertEquals(serviceName, service.getServiceName());
00655
00656 assertEquals(serviceUri, service.getServiceUri());
00657
00658 NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00659 assertTrue(node.hasRegistrations());
00660 assertEquals(Sets.newHashSet(service), node.getServices());
00661
00662
00663
00664 assertEquals(node, service.getNode());
00665
00666
00667 verify(registrationListener, Mockito.never()).onNodeReplacement(node);
00668 }
00669
00675 @Test
00676 public void testRegisterUnregisterService() throws Exception {
00677 GraphName nodeName = GraphName.of("/node");
00678 URI nodeSlaveUri = new URI("http://localhost:12345");
00679 GraphName serviceName = GraphName.of("/service");
00680 URI serviceUri = new URI("http://foo");
00681
00682 masterRegistrationManager.registerService(nodeName, nodeSlaveUri, serviceName, serviceUri);
00683
00684 NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00685
00686 masterRegistrationManager.unregisterService(nodeName, serviceName, serviceUri);
00687
00688 assertNull(masterRegistrationManager.getServiceRegistrationInfo(serviceName));
00689 assertNull(masterRegistrationManager.getNodeRegistrationInfo(nodeName));
00690
00691
00692 verify(registrationListener, Mockito.never()).onNodeReplacement(node);
00693 }
00694
00701 @Test
00702 public void testRegisterUnregisterServiceWithPublisher() throws Exception {
00703 GraphName nodeName = GraphName.of("/node");
00704 URI nodeSlaveUri = new URI("http://localhost:12345");
00705 GraphName serviceName = GraphName.of("/service");
00706 URI serviceUri = new URI("http://foo");
00707 GraphName topicName = GraphName.of("/topic");
00708 String topicMessageType = "foo/Bar";
00709
00710 masterRegistrationManager.registerService(nodeName, nodeSlaveUri, serviceName, serviceUri);
00711 masterRegistrationManager
00712 .registerPublisher(nodeName, nodeSlaveUri, topicName, topicMessageType);
00713
00714 NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00715
00716 masterRegistrationManager.unregisterService(nodeName, serviceName, serviceUri);
00717
00718 assertNull(masterRegistrationManager.getServiceRegistrationInfo(serviceName));
00719 assertEquals(node, masterRegistrationManager.getNodeRegistrationInfo(nodeName));
00720 assertTrue(node.getServices().isEmpty());
00721
00722
00723 verify(registrationListener, Mockito.never()).onNodeReplacement(node);
00724 }
00725
00732 @Test
00733 public void testRegisterServiceReplaceNode() throws Exception {
00734 GraphName nodeName = GraphName.of("/node");
00735 URI nodeSlaveUri1 = new URI("http://localhost:12345");
00736 GraphName serviceName = GraphName.of("/service");
00737 URI serviceUri = new URI("http://foo");
00738 GraphName topicName = GraphName.of("/topic");
00739 String topicMessageType = "foo/Bar";
00740
00741 URI nodeSlaveUri2 = new URI("http://localhost:54321");
00742
00743 masterRegistrationManager.registerService(nodeName, nodeSlaveUri1, serviceName, serviceUri);
00744 masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri1, topicName,
00745 topicMessageType);
00746
00747 NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00748
00749 masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri2, topicName,
00750 topicMessageType);
00751
00752 assertNull(masterRegistrationManager.getServiceRegistrationInfo(serviceName));
00753 assertTrue(masterRegistrationManager.getNodeRegistrationInfo(nodeName).getServices().isEmpty());
00754
00755
00756 verify(registrationListener).onNodeReplacement(node);
00757 }
00758 }