TreeTypeProvider { public TreeType getType(@NotNull Tree tree) { if (tree.isRoot()) { return TreeType.DEFAULT; } else { TreeType type; if (tree instanceof TreeTypeAware) { type = ((TreeTypeAware) tree).getType(); if (type == null) { type = internalGetType(tree); ((TreeTypeAware) tree).setType(type); } } else { type = internalGetType(tree); } return type; } } TreeTypeProvider(@NotNull TreeContext authorizationContext); TreeType getType(@NotNull Tree tree); TreeType getType(@NotNull Tree tree, @NotNull TreeType parentType);  }
@Test public void testGetType() { for (TypeTest test : tests) { assertEquals(test.path, test.type, typeProvider.getType(mockTree(test.path, true))); } }
@Test public void testGetTypeWithParentType() { for (TypeTest test : tests) { assertEquals(test.path, test.type, typeProvider.getType(mockTree(test.path, true), test.parentType)); } }
@Test public void testGetTypeWithDefaultParentType() { for (TypeTest test : tests) { TreeType typeIfParentDefault = typeProvider.getType(mockTree(test.path, true), TreeType.DEFAULT); if (TreeType.DEFAULT == test.parentType) { assertEquals(test.path, test.type, typeIfParentDefault); } else { assertNotEquals(test.path, test.type, typeIfParentDefault); } } }
@Test public void testGetTypeForRootTree() { Tree t = mockTree(PathUtils.ROOT_PATH, true); assertEquals(TreeType.DEFAULT, typeProvider.getType(t)); assertEquals(TreeType.DEFAULT, typeProvider.getType(t, TreeType.DEFAULT)); assertEquals(TreeType.DEFAULT, typeProvider.getType(t, TreeType.HIDDEN)); assertEquals(TreeType.DEFAULT, typeProvider.getType(t, TreeType.VERSION)); }
@Test public void testInternal() { Tree internal = mockTree("/internal", rootTree, true); Tree internalChild = mockTree("/internal/child", internal, true); assertEquals(TreeType.INTERNAL, typeProvider.getType(internal)); assertEquals(TreeType.INTERNAL, typeProvider.getType(internalChild)); assertEquals(TreeType.INTERNAL, typeProvider.getType(child, TreeType.INTERNAL)); }
@Test public void testAc() { Tree ctxRoot = mockTree("/ctxRoot", rootTree, true); Tree ctxRootChild = mockTree("/ctxRoot/child", ctxRoot, true); assertEquals(TreeType.ACCESS_CONTROL, typeProvider.getType(ctxRoot)); assertEquals(TreeType.ACCESS_CONTROL, typeProvider.getType(ctxRootChild)); assertEquals(TreeType.ACCESS_CONTROL, typeProvider.getType(child, TreeType.ACCESS_CONTROL)); }
@Test public void testTypeAware() { Tree typeAware = mockTree("/typeAware", rootTree, true, TreeTypeAware.class); Tree awareChild = mockTree("/typeAware/child", typeAware, true, TreeTypeAware.class); assertTrue(typeAware instanceof TreeTypeAware); assertTrue(awareChild instanceof TreeTypeAware); assertEquals(TreeType.DEFAULT, typeProvider.getType(typeAware)); assertEquals(TreeType.DEFAULT, typeProvider.getType(awareChild)); assertEquals(TreeType.VERSION, typeProvider.getType(typeAware, TreeType.VERSION)); assertEquals(TreeType.VERSION, typeProvider.getType(awareChild, TreeType.VERSION)); }