@Test
  public void provide_types() {
    ResourceTypeTree tree = DefaultResourceTypes.get();

    assertThat(tree.getTypes()).hasSize(7);
    assertThat(tree.getChildren(Qualifiers.PROJECT)).containsExactly(Qualifiers.MODULE);
  }
Exemplo n.º 2
0
 public List<String> getLeavesQualifiers(String qualifier) {
   ResourceTypeTree tree = getTree(qualifier);
   if (tree != null) {
     return tree.getLeaves();
   }
   return Collections.emptyList();
 }
  @Test
  public void projects_should_be_available_for_global_widgets() {
    ResourceTypeTree tree = DefaultResourceTypes.get();

    ResourceType projectResourceType = tree.getTypes().get(0);

    assertThat(projectResourceType.getQualifier()).isEqualTo(Qualifiers.PROJECT);
    assertThat(projectResourceType.getBooleanProperty("supportsGlobalDashboards")).isTrue();
  }
  @Test
  public void getChildren() {
    assertThat(tree.getChildren("TRK").size(), is(1));
    assertThat(tree.getChildren("TRK"), hasItems("DIR"));

    assertThat(tree.getChildren("DIR").size(), is(2));
    assertThat(tree.getChildren("DIR"), hasItems("FIL", "UTS"));

    assertThat(tree.getChildren("FIL").size(), is(0));
  }
 @Test(expected = IllegalArgumentException.class)
 public void forbidDuplicatedType() {
   ResourceTypeTree.builder()
       .addType(ResourceType.builder("TRK").build())
       .addType(ResourceType.builder("TRK").build())
       .build();
 }
 @Test(expected = IllegalArgumentException.class)
 public void forbidNullRelation() {
   ResourceTypeTree.builder()
       .addType(ResourceType.builder("TRK").build())
       .addType(ResourceType.builder("DIR").build())
       .addRelations("DIR" /* missing child */)
       .build();
 }
public class ResourceTypeTreeTest {
  private final ResourceTypeTree tree =
      ResourceTypeTree.builder()
          .addType(ResourceType.builder("TRK").build())
          .addType(ResourceType.builder("DIR").build())
          .addType(ResourceType.builder("FIL").build())
          .addType(ResourceType.builder("UTS").build())
          .addRelations("TRK", "DIR")
          .addRelations("DIR", "FIL")
          .addRelations("DIR", "UTS")
          .build();

  @Test
  public void getTypes() {
    assertThat(tree.getTypes().size(), is(4));
    assertThat(qualifiers(tree.getTypes()), hasItems("TRK", "DIR", "FIL", "UTS"));
  }

  @Test
  public void getChildren() {
    assertThat(tree.getChildren("TRK").size(), is(1));
    assertThat(tree.getChildren("TRK"), hasItems("DIR"));

    assertThat(tree.getChildren("DIR").size(), is(2));
    assertThat(tree.getChildren("DIR"), hasItems("FIL", "UTS"));

    assertThat(tree.getChildren("FIL").size(), is(0));
  }

  @Test
  public void getRoot() {
    assertThat(tree.getRootType(), is(ResourceType.builder("TRK").build()));
  }

  @Test
  public void getLeaves() {
    assertThat(tree.getLeaves().size(), is(2));
    assertThat(tree.getLeaves(), hasItems("FIL", "UTS"));
  }

  @Test(expected = IllegalArgumentException.class)
  public void forbidNullRelation() {
    ResourceTypeTree.builder()
        .addType(ResourceType.builder("TRK").build())
        .addType(ResourceType.builder("DIR").build())
        .addRelations("DIR" /* missing child */)
        .build();
  }

  @Test(expected = IllegalArgumentException.class)
  public void forbidDuplicatedType() {
    ResourceTypeTree.builder()
        .addType(ResourceType.builder("TRK").build())
        .addType(ResourceType.builder("TRK").build())
        .build();
  }
}
Exemplo n.º 8
0
  public ResourceTypes(ResourceTypeTree[] trees) {
    Preconditions.checkNotNull(trees);

    Map<String, ResourceTypeTree> treeMap = Maps.newHashMap();
    Map<String, ResourceType> typeMap = Maps.newLinkedHashMap();
    Collection<ResourceType> rootsSet = Sets.newHashSet();

    for (ResourceTypeTree tree : trees) {
      rootsSet.add(tree.getRootType());
      for (ResourceType type : tree.getTypes()) {
        if (treeMap.containsKey(type.getQualifier())) {
          throw new IllegalStateException(
              "Qualifier " + type.getQualifier() + " is defined in several trees");
        }
        treeMap.put(type.getQualifier(), tree);
        typeMap.put(type.getQualifier(), type);
      }
    }
    treeByQualifier = ImmutableMap.copyOf(treeMap);
    typeByQualifier = ImmutableMap.copyOf(typeMap);
    rootTypes = ImmutableList.copyOf(rootsSet);
  }
Exemplo n.º 9
0
 @Override
 public ResourceTypeTree provide() {
   return ResourceTypeTree.builder()
       .addType(
           ResourceType.builder(Qualifiers.PROJECT)
               .setProperty("deletable", TRUE)
               .setProperty("modifiable_history", TRUE)
               .setProperty("hasRolePolicy", TRUE)
               .setProperty("updatable_key", TRUE)
               .build())
       .addType(ResourceType.builder(Qualifiers.MODULE).setProperty("updatable_key", TRUE).build())
       .addType(ResourceType.builder(Qualifiers.DIRECTORY).build())
       .addType(ResourceType.builder(Qualifiers.PACKAGE).build())
       .addType(ResourceType.builder(Qualifiers.FILE).hasSourceCode().build())
       .addType(ResourceType.builder(Qualifiers.CLASS).hasSourceCode().build())
       .addType(ResourceType.builder(Qualifiers.UNIT_TEST_FILE).hasSourceCode().build())
       .addRelations(Qualifiers.PROJECT, Qualifiers.MODULE)
       .addRelations(Qualifiers.MODULE, Qualifiers.DIRECTORY, Qualifiers.PACKAGE)
       .addRelations(Qualifiers.DIRECTORY, Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE)
       .addRelations(Qualifiers.PACKAGE, Qualifiers.CLASS, Qualifiers.UNIT_TEST_FILE)
       .build();
 }
 @Test
 public void getLeaves() {
   assertThat(tree.getLeaves().size(), is(2));
   assertThat(tree.getLeaves(), hasItems("FIL", "UTS"));
 }
 @Test
 public void getRoot() {
   assertThat(tree.getRootType(), is(ResourceType.builder("TRK").build()));
 }
 @Test
 public void getTypes() {
   assertThat(tree.getTypes().size(), is(4));
   assertThat(qualifiers(tree.getTypes()), hasItems("TRK", "DIR", "FIL", "UTS"));
 }