@Test
  public void testGetQueueNames() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString anotherQueue = RandomUtil.randomSimpleString();

    session.createQueue(address, queue, true);

    CoreMessagingProxy proxy = createProxy(address);
    Object[] queueNames = (Object[]) proxy.retrieveAttributeValue("queueNames");
    Assert.assertEquals(1, queueNames.length);
    Assert.assertEquals(queue.toString(), queueNames[0]);

    session.createQueue(address, anotherQueue, false);
    queueNames = (Object[]) proxy.retrieveAttributeValue("queueNames");
    Assert.assertEquals(2, queueNames.length);

    session.deleteQueue(queue);

    queueNames = (Object[]) proxy.retrieveAttributeValue("queueNames");
    Assert.assertEquals(1, queueNames.length);
    Assert.assertEquals(anotherQueue.toString(), queueNames[0]);

    session.deleteQueue(anotherQueue);
  }
  @Test
  public void testGetBindingNames() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    String divertName = RandomUtil.randomString();

    session.createQueue(address, queue, false);

    CoreMessagingProxy proxy = createProxy(address);
    Object[] bindingNames = (Object[]) proxy.retrieveAttributeValue("bindingNames");
    assertEquals(1, bindingNames.length);
    assertEquals(queue.toString(), bindingNames[0]);

    server
        .getActiveMQServerControl()
        .createDivert(
            divertName,
            randomString(),
            address.toString(),
            RandomUtil.randomString(),
            false,
            null,
            null);

    bindingNames = (Object[]) proxy.retrieveAttributeValue("bindingNames");
    assertEquals(2, bindingNames.length);

    session.deleteQueue(queue);

    bindingNames = (Object[]) proxy.retrieveAttributeValue("bindingNames");
    assertEquals(1, bindingNames.length);
    assertEquals(divertName.toString(), bindingNames[0]);
  }
  @Test
  public void testGetAddress() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();

    session.createQueue(address, queue, false);

    CoreMessagingProxy proxy = createProxy(address);

    Assert.assertEquals(address.toString(), proxy.retrieveAttributeValue("address"));

    session.deleteQueue(queue);
  }
  private void deleteSubscriberQueue(QueueConsumer consumer) {
    String subscriptionName = consumer.getId();
    ClientSession session = null;
    try {
      session = sessionFactory.createSession();

      session.deleteQueue(subscriptionName);
    } catch (ActiveMQException e) {
    } finally {
      if (session != null) {
        try {
          session.close();
        } catch (ActiveMQException e) {
        }
      }
    }
  }
  @Test
  public void testGetRoles() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    Role role =
        new Role(
            RandomUtil.randomString(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean());

    session.createQueue(address, queue, true);

    CoreMessagingProxy proxy = createProxy(address);
    Object[] roles = (Object[]) proxy.retrieveAttributeValue("roles");
    for (Object role2 : roles) {
      System.out.println(((Object[]) role2)[0]);
    }
    Assert.assertEquals(0, roles.length);

    Set<Role> newRoles = new HashSet<>();
    newRoles.add(role);
    server.getSecurityRepository().addMatch(address.toString(), newRoles);

    roles = (Object[]) proxy.retrieveAttributeValue("roles");
    Assert.assertEquals(1, roles.length);
    Object[] r = (Object[]) roles[0];
    Assert.assertEquals(role.getName(), r[0]);
    Assert.assertEquals(CheckType.SEND.hasRole(role), r[1]);
    Assert.assertEquals(CheckType.CONSUME.hasRole(role), r[2]);
    Assert.assertEquals(CheckType.CREATE_DURABLE_QUEUE.hasRole(role), r[3]);
    Assert.assertEquals(CheckType.DELETE_DURABLE_QUEUE.hasRole(role), r[4]);
    Assert.assertEquals(CheckType.CREATE_NON_DURABLE_QUEUE.hasRole(role), r[5]);
    Assert.assertEquals(CheckType.DELETE_NON_DURABLE_QUEUE.hasRole(role), r[6]);
    Assert.assertEquals(CheckType.MANAGE.hasRole(role), r[7]);

    session.deleteQueue(queue);
  }
  @Test
  public void testPagedMessageWithMissingBinding() throws Exception {
    final String MY_ADDRESS = "myAddress";
    final String MY_QUEUE = "myQueue";
    final String MY_QUEUE2 = "myQueue2";

    ActiveMQServer server = createServer(true);

    AddressSettings defaultSetting =
        new AddressSettings().setPageSizeBytes(10 * 1024).setMaxSizeBytes(20 * 1024);
    server.getAddressSettingsRepository().addMatch("#", defaultSetting);
    server.start();

    ServerLocator locator =
        createInVMNonHALocator()
            // Making it synchronous, just because we want to stop sending messages as soon as the
            // page-store becomes in
            // page mode and we could only guarantee that by setting it to synchronous
            .setBlockOnNonDurableSend(true)
            .setBlockOnDurableSend(true)
            .setBlockOnAcknowledge(true);

    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, true, true);

    session.createQueue(MY_ADDRESS, MY_QUEUE, true);
    session.createQueue(MY_ADDRESS, MY_QUEUE2, true);

    ClientProducer producer = session.createProducer(MY_ADDRESS);

    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeBytes(new byte[1024]);

    for (int i = 0; i < 200; i++) {
      producer.send(message);
    }

    session.deleteQueue(MY_QUEUE2);

    session.close();
    locator.close();
    server.stop();

    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(
        xmlOutputStream,
        server.getConfiguration().getBindingsDirectory(),
        server.getConfiguration().getJournalDirectory(),
        server.getConfiguration().getPagingDirectory(),
        server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));

    clearDataRecreateServerDirs();
    server.start();
    locator = createInVMNonHALocator();
    factory = locator.createSessionFactory();
    session = factory.createSession(false, true, true);

    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session);

    ClientConsumer consumer = session.createConsumer(MY_QUEUE);

    session.start();

    for (int i = 0; i < 200; i++) {
      message = consumer.receive(CONSUMER_TIMEOUT);

      assertNotNull(message);
    }

    session.close();
    locator.close();
    server.stop();
  }