@Test
public void testDynamicQueueValidation() {

  //Setting up queue manager and emulated queue hierarchy
  CapacitySchedulerQueueManager qm =
      mock(CapacitySchedulerQueueManager.class);
  MockQueueHierarchyBuilder.create()
      .withQueueManager(qm)
      .withQueue("root.unmanaged")
      .withManagedParentQueue("root.managed")
      .withQueue("root.unmanagedwithchild.child")
      .withQueue("root.leaf")
      .build();
  when(qm.getQueue(isNull())).thenReturn(null);
  MappingRuleValidationContextImpl ctx =
      new MappingRuleValidationContextImpl(qm);
  try {
    ctx.addVariable("%dynamic");
    ctx.addVariable("%user");
  } catch (YarnException e) {
    fail("We don't expect the add variable to fail: " + e.getMessage());
  }
  assertValidPath(ctx, "%dynamic");
  assertValidPath(ctx, "root.%dynamic");
  assertValidPath(ctx, "%user.%dynamic");
  assertValidPath(ctx, "root.managed.%dynamic");
  assertValidPath(ctx, "managed.%dynamic");
  assertInvalidPath(ctx, "root.invalid.%dynamic");
  assertInvalidPath(ctx, "root.umanaged.%dynamic");
  assertValidPath(ctx, "root.unmanagedwithchild.%user");
  assertValidPath(ctx, "unmanagedwithchild.%user");
}