@Test
  public void testFlagsOnRootResource() throws Exception {

    rootRegistration.registerOperationHandler(
        "one", TestHandler.INSTANCE, new TestDescriptionProvider("one"));
    rootRegistration.registerOperationHandler(
        "two",
        TestHandler.INSTANCE,
        new TestDescriptionProvider("two"),
        false,
        OperationEntry.EntryType.PUBLIC,
        EnumSet.of(OperationEntry.Flag.READ_ONLY));

    Set<OperationEntry.Flag> oneFlags =
        rootRegistration.getOperationFlags(PathAddress.EMPTY_ADDRESS, "one");
    assertNotNull(oneFlags);
    assertEquals(0, oneFlags.size());

    Set<OperationEntry.Flag> twoFlags =
        rootRegistration.getOperationFlags(PathAddress.EMPTY_ADDRESS, "two");
    assertNotNull(twoFlags);
    assertEquals(1, twoFlags.size());
  }
  @Test
  public void testFlagsOnChildResource() throws Exception {

    ManagementResourceRegistration child =
        rootRegistration.registerSubModel(childElement, new TestDescriptionProvider("child"));
    child.registerOperationHandler("one", TestHandler.INSTANCE, new TestDescriptionProvider("one"));
    child.registerOperationHandler(
        "two",
        TestHandler.INSTANCE,
        new TestDescriptionProvider("two"),
        false,
        OperationEntry.EntryType.PUBLIC,
        EnumSet.of(OperationEntry.Flag.READ_ONLY));

    Set<OperationEntry.Flag> oneFlags = child.getOperationFlags(PathAddress.EMPTY_ADDRESS, "one");
    assertNotNull(oneFlags);
    assertEquals(0, oneFlags.size());

    Set<OperationEntry.Flag> twoFlags = child.getOperationFlags(PathAddress.EMPTY_ADDRESS, "two");
    assertNotNull(twoFlags);
    assertEquals(1, twoFlags.size());

    oneFlags = rootRegistration.getOperationFlags(childAddress, "one");
    assertNotNull(oneFlags);
    assertEquals(0, oneFlags.size());

    twoFlags = rootRegistration.getOperationFlags(childAddress, "two");
    assertNotNull(twoFlags);
    assertEquals(1, twoFlags.size());

    oneFlags = rootRegistration.getOperationFlags(fullChildAddress, "one");
    assertNotNull(oneFlags);
    assertEquals(0, oneFlags.size());

    twoFlags = rootRegistration.getOperationFlags(fullChildAddress, "two");
    assertNotNull(twoFlags);
    assertEquals(1, twoFlags.size());
  }
예제 #3
0
 @Override
 public Set<OperationEntry.Flag> getOperationFlags(PathAddress address, String operationName) {
   return deployments.getOperationFlags(address, operationName);
 }
  @Test
  public void testFlagsInheritance() throws Exception {

    rootRegistration.registerOperationHandler(
        "one",
        TestHandler.INSTANCE,
        new TestDescriptionProvider("one"),
        true,
        OperationEntry.EntryType.PUBLIC,
        EnumSet.of(OperationEntry.Flag.READ_ONLY));
    rootRegistration.registerOperationHandler(
        "two",
        TestHandler.INSTANCE,
        new TestDescriptionProvider("two"),
        true,
        OperationEntry.EntryType.PUBLIC,
        EnumSet.of(OperationEntry.Flag.READ_ONLY));
    rootRegistration.registerOperationHandler(
        "three",
        TestHandler.INSTANCE,
        new TestDescriptionProvider("three"),
        true,
        OperationEntry.EntryType.PUBLIC,
        EnumSet.of(OperationEntry.Flag.READ_ONLY));
    rootRegistration.registerOperationHandler(
        "four",
        TestHandler.INSTANCE,
        new TestDescriptionProvider("four"),
        false,
        OperationEntry.EntryType.PUBLIC,
        EnumSet.of(OperationEntry.Flag.READ_ONLY));

    ManagementResourceRegistration child =
        rootRegistration.registerSubModel(childElement, new TestDescriptionProvider("child"));
    child.registerOperationHandler(
        "one", TestHandler.INSTANCE, new TestDescriptionProvider("one"), true);
    child.registerOperationHandler(
        "two",
        TestHandler.INSTANCE,
        new TestDescriptionProvider("two"),
        true,
        OperationEntry.EntryType.PUBLIC,
        EnumSet.of(OperationEntry.Flag.MASTER_HOST_CONTROLLER_ONLY));

    ManagementResourceRegistration grandchild =
        child.registerSubModel(grandchildElement, new TestDescriptionProvider("grandchild"));

    Set<OperationEntry.Flag> oneFlags = child.getOperationFlags(PathAddress.EMPTY_ADDRESS, "one");
    assertNotNull(oneFlags);
    assertEquals(0, oneFlags.size());

    Set<OperationEntry.Flag> twoFlags = child.getOperationFlags(PathAddress.EMPTY_ADDRESS, "two");
    assertNotNull(twoFlags);
    assertEquals(1, twoFlags.size());
    assertTrue(twoFlags.contains(OperationEntry.Flag.MASTER_HOST_CONTROLLER_ONLY));

    Set<OperationEntry.Flag> threeFlags =
        child.getOperationFlags(PathAddress.EMPTY_ADDRESS, "three");
    assertNotNull(threeFlags);
    assertEquals(1, threeFlags.size());
    assertTrue(threeFlags.contains(OperationEntry.Flag.READ_ONLY));

    oneFlags = rootRegistration.getOperationFlags(childAddress, "one");
    assertNotNull(oneFlags);
    assertEquals(0, oneFlags.size());

    twoFlags = rootRegistration.getOperationFlags(childAddress, "two");
    assertNotNull(twoFlags);
    assertEquals(1, twoFlags.size());
    assertTrue(twoFlags.contains(OperationEntry.Flag.MASTER_HOST_CONTROLLER_ONLY));

    threeFlags = child.getOperationFlags(PathAddress.EMPTY_ADDRESS, "three");
    assertNotNull(threeFlags);
    assertEquals(1, threeFlags.size());
    assertTrue(threeFlags.contains(OperationEntry.Flag.READ_ONLY));

    Set<OperationEntry.Flag> fourFlags = child.getOperationFlags(PathAddress.EMPTY_ADDRESS, "four");
    assertNull(fourFlags);

    fourFlags = rootRegistration.getOperationFlags(childAddress, "four");
    assertNull(fourFlags);

    // Sanity check
    fourFlags = rootRegistration.getOperationFlags(PathAddress.EMPTY_ADDRESS, "four");
    assertNotNull(fourFlags);
    assertEquals(1, fourFlags.size());
    assertTrue(fourFlags.contains(OperationEntry.Flag.READ_ONLY));

    oneFlags = rootRegistration.getOperationFlags(grandchildAddress, "one");
    assertNotNull(oneFlags);
    assertEquals(0, oneFlags.size());

    oneFlags = rootRegistration.getOperationFlags(fullGrandchildAddress, "one");
    assertNotNull(oneFlags);
    assertEquals(0, oneFlags.size());

    oneFlags = grandchild.getOperationFlags(PathAddress.EMPTY_ADDRESS, "one");
    assertNotNull(oneFlags);
    assertEquals(0, oneFlags.size());

    twoFlags = rootRegistration.getOperationFlags(grandchildAddress, "two");
    assertNotNull(twoFlags);
    assertEquals(1, twoFlags.size());
    assertTrue(twoFlags.contains(OperationEntry.Flag.MASTER_HOST_CONTROLLER_ONLY));

    twoFlags = rootRegistration.getOperationFlags(fullGrandchildAddress, "two");
    assertNotNull(twoFlags);
    assertEquals(1, twoFlags.size());
    assertTrue(twoFlags.contains(OperationEntry.Flag.MASTER_HOST_CONTROLLER_ONLY));

    twoFlags = grandchild.getOperationFlags(PathAddress.EMPTY_ADDRESS, "two");
    assertNotNull(twoFlags);
    assertEquals(1, twoFlags.size());
    assertTrue(twoFlags.contains(OperationEntry.Flag.MASTER_HOST_CONTROLLER_ONLY));

    threeFlags = rootRegistration.getOperationFlags(grandchildAddress, "three");
    assertNotNull(threeFlags);
    assertEquals(1, threeFlags.size());
    assertTrue(threeFlags.contains(OperationEntry.Flag.READ_ONLY));

    threeFlags = rootRegistration.getOperationFlags(fullGrandchildAddress, "three");
    assertNotNull(threeFlags);
    assertEquals(1, threeFlags.size());
    assertTrue(threeFlags.contains(OperationEntry.Flag.READ_ONLY));

    threeFlags = grandchild.getOperationFlags(PathAddress.EMPTY_ADDRESS, "three");
    assertNotNull(threeFlags);
    assertEquals(1, threeFlags.size());
    assertTrue(threeFlags.contains(OperationEntry.Flag.READ_ONLY));
  }