@Test
  public void testSetOwnerProperties_ownerId() {

    Set<String> ownerIds = new HashSet<>();

    InMemoryClient client = new InMemoryClient(new InMemoryRoutingContext(), RecipientKind.DM);
    client.setOwnerProperties(RecipientKind.DM, "domain", null, null);
    ownerIds.add(client.getOwnerId());

    client.setOwnerProperties(RecipientKind.AGENTS, "domain", "app1", "root1");
    ownerIds.add(client.getOwnerId());

    client.setOwnerProperties(RecipientKind.AGENTS, "domain", "app1", "root2");
    ownerIds.add(client.getOwnerId());

    client.setOwnerProperties(RecipientKind.AGENTS, "domain", "app2", "root2");
    ownerIds.add(client.getOwnerId());

    Assert.assertEquals(4, ownerIds.size());
  }
  @Test
  public void testSetOwnerProperties_propertiesAreMoved() throws Exception {

    // Init...
    InMemoryClient client = new InMemoryClient(new InMemoryRoutingContext(), RecipientKind.DM);
    LinkedBlockingQueue<Message> queue = new LinkedBlockingQueue<>();
    client.setMessageQueue(queue);
    client.openConnection();

    MessagingContext ctx = new MessagingContext(RecipientKind.AGENTS, "domain", "app");
    client.subscribe(ctx);
    String ownerId_1 = client.getOwnerId();

    // Verify associations
    Map<String, Set<MessagingContext>> sub = client.getRoutingContext().subscriptions;
    Map<String, LinkedBlockingQueue<Message>> ctxToQueue =
        ((InMemoryRoutingContext) client.getRoutingContext()).ctxToQueue;
    Assert.assertEquals(queue, ctxToQueue.get(ownerId_1));

    Set<MessagingContext> subscribedContexts = sub.get(ownerId_1);
    Assert.assertNotNull(subscribedContexts);
    Assert.assertEquals(1, subscribedContexts.size());
    Assert.assertTrue(subscribedContexts.contains(ctx));

    // Change the owner ID
    client.setOwnerProperties(RecipientKind.AGENTS, "domain", "app1", "root1");

    // Verify properties were kept
    String ownerId_2 = client.getOwnerId();
    Assert.assertFalse(ownerId_2.equals(ownerId_1));

    Assert.assertEquals(queue, ctxToQueue.get(ownerId_2));
    Assert.assertNull(ctxToQueue.get(ownerId_1));
    Assert.assertNull(sub.get(ownerId_1));

    subscribedContexts = sub.get(ownerId_2);
    Assert.assertNotNull(subscribedContexts);
    Assert.assertEquals(1, subscribedContexts.size());
    Assert.assertTrue(subscribedContexts.contains(ctx));
  }
 private Set<MessagingContext> getSubscriptions(InMemoryClient client) {
   return client.getRoutingContext().subscriptions.get(client.getOwnerId());
 }