LayoutTemplateAnalyzer { public LayoutRecursionIssue analyzeRecursion(LayoutTemplate layoutTemplate) { return analyzeRecursion(layoutTemplate, null); } LayoutTemplateAnalyzer(); @Inject  LayoutTemplateAnalyzer(PerspectivePluginServicesImpl pluginServices, NavigationServicesImpl navigationServices); LayoutRecursionIssue analyzeRecursion(LayoutTemplate layoutTemplate); LayoutRecursionIssue analyzeRecursion(LayoutTemplate layoutTemplate, LayoutTemplateContext layoutCtx); boolean analyzeRecursion(LayoutTemplate layoutTemplate, LayoutRecursionIssue issue, LayoutTemplateContext layoutCtx); boolean analyzeRecursion(LayoutRow row, LayoutRecursionIssue issue, LayoutTemplateContext layoutCtx); boolean analyzeRecursion(NavGroup navGroup, LayoutNavigationRefType navGroupRefType, LayoutRecursionIssue issue); boolean analyzeRecursion(String perspectiveId, LayoutRecursionIssue issue); boolean hasNavigationComponents(LayoutTemplate layoutTemplate); boolean hasNavigationComponents(LayoutRow row);  }
@Test public void testOneLevelNoRecursiveIssue() throws Exception { when(navigationServices.loadNavTree()).thenReturn(new NavTreeBuilder() .group("groupA", "", "", true) .item("layout", "", "", true, NavWorkbenchCtx.perspective("B")) .endGroup() .build()); LayoutRecursionIssue info = layoutTemplateAnalyzer.analyzeRecursion(layoutA); assertTrue(info.isEmpty()); }
@Test public void testPerspectiveReuseNoRecursiveIssue() throws Exception { when(navigationServices.loadNavTree()).thenReturn(new NavTreeBuilder() .group("groupC", "", "", true) .item("layout", "", "", true, NavWorkbenchCtx.perspective("B")) .endGroup() .build()); LayoutRecursionIssue info = layoutTemplateAnalyzer.analyzeRecursion(layoutC); assertTrue(info.isEmpty()); }
@Test public void testSimpleRecursion() throws Exception { when(navigationServices.loadNavTree()).thenReturn(new NavTreeBuilder() .group("groupA", "", "", true) .item("layout", "", "", true, NavWorkbenchCtx.perspective("A")) .endGroup() .build()); LayoutRecursionIssue info = layoutTemplateAnalyzer.analyzeRecursion(layoutA); assertEquals(info.getRefList().size(), 4); assertEquals(info.getRefList().get(0), new LayoutNavigationRef(PERSPECTIVE, "A")); assertEquals(info.getRefList().get(1), new LayoutNavigationRef(NAV_COMPONENT, CAROUSEL.getFQClassName())); assertEquals(info.getRefList().get(2), new LayoutNavigationRef(NAV_GROUP_DEFINED, "groupA")); assertEquals(info.getRefList().get(3), new LayoutNavigationRef(PERSPECTIVE, "A")); }
@Test public void testPerspectiveComponent() throws Exception { LayoutComponent layoutComponentB = new LayoutComponent("PerspectiveDrag"); layoutComponentB.addProperty(PERSPECTIVE_ID, "B"); layoutColumnA.add(layoutComponentB); when(navigationServices.loadNavTree()).thenReturn(new NavTreeBuilder().build()); LayoutRecursionIssue info = layoutTemplateAnalyzer.analyzeRecursion(layoutA); assertTrue(info.isEmpty()); }
@Test public void testPerspectiveRecursiveIssue() throws Exception { LayoutComponent layoutComponentB = new LayoutComponent("PerspectiveDrag"); layoutComponentB.addProperty(PERSPECTIVE_ID, "B"); layoutColumnA.add(layoutComponentB); LayoutComponent layoutComponentA = new LayoutComponent("PerspectiveDrag"); layoutComponentB.addProperty(PERSPECTIVE_ID, "A"); layoutColumnB.add(layoutComponentA); when(navigationServices.loadNavTree()).thenReturn(new NavTreeBuilder().build()); LayoutRecursionIssue info = layoutTemplateAnalyzer.analyzeRecursion(layoutA); assertEquals(info.getRefList().size(), 3); assertEquals(info.getRefList().get(0), new LayoutNavigationRef(PERSPECTIVE, "A")); assertEquals(info.getRefList().get(1), new LayoutNavigationRef(NAV_COMPONENT, "PerspectiveDrag")); assertEquals(info.getRefList().get(2), new LayoutNavigationRef(PERSPECTIVE, "A")); }
@Test public void testIndirectRecursiveIssue() throws Exception { when(navigationServices.loadNavTree()).thenReturn(new NavTreeBuilder() .group("groupA", "", "", true) .item("layout", "", "", true, NavWorkbenchCtx.perspective("B")) .endGroup() .group("groupB", "", "", true) .item("layout", "", "", true, NavWorkbenchCtx.perspective("A")) .endGroup() .build()); LayoutRecursionIssue info = layoutTemplateAnalyzer.analyzeRecursion(layoutA); assertEquals(info.getRefList().size(), 7); assertEquals(info.getRefList().get(0), new LayoutNavigationRef(PERSPECTIVE, "A")); assertEquals(info.getRefList().get(1), new LayoutNavigationRef(NAV_COMPONENT, CAROUSEL.getFQClassName())); assertEquals(info.getRefList().get(2), new LayoutNavigationRef(NAV_GROUP_DEFINED, "groupA")); assertEquals(info.getRefList().get(3), new LayoutNavigationRef(PERSPECTIVE, "B")); assertEquals(info.getRefList().get(4), new LayoutNavigationRef(NAV_COMPONENT, CAROUSEL.getFQClassName())); assertEquals(info.getRefList().get(5), new LayoutNavigationRef(NAV_GROUP_DEFINED, "groupB")); assertEquals(info.getRefList().get(6), new LayoutNavigationRef(PERSPECTIVE, "A")); }
@Test public void testDefaultItemNoRecursiveIssue() throws Exception { layoutComponentC1.addProperty(NAV_DEFAULT_ID, "item2"); layoutComponentC2.addProperty(NAV_DEFAULT_ID, "item2"); when(navigationServices.loadNavTree()).thenReturn(new NavTreeBuilder() .group("groupC", "", "", true) .item("item1", "", "", true, NavWorkbenchCtx.perspective("C")) .item("item2", "", "", true, NavWorkbenchCtx.perspective("B")) .endGroup() .build()); LayoutRecursionIssue info = layoutTemplateAnalyzer.analyzeRecursion(layoutC); assertTrue(info.isEmpty()); }
@Test public void testIndirectNavGroupRecursiveIssue() throws Exception { layoutComponentC1.addProperty(NAV_DEFAULT_ID, "item2"); layoutComponentD.addProperty(NAV_DEFAULT_ID, "item4"); when(navigationServices.loadNavTree()).thenReturn(new NavTreeBuilder() .group("groupC", "", "", true) .item("item1", "", "", true, NavWorkbenchCtx.perspective("A")) .item("item2", "", "", true, NavWorkbenchCtx.perspective("D").setNavGroupId("groupX")) .endGroup() .group("groupX", "", "", true) .item("item3", "", "", true, NavWorkbenchCtx.perspective("D").setNavGroupId("groupX")) .item("item4", "", "", true, NavWorkbenchCtx.perspective("A")) .endGroup() .build()); LayoutRecursionIssue info = layoutTemplateAnalyzer.analyzeRecursion(layoutC); assertEquals(info.getRefList().size(), 9); assertEquals(info.getRefList().get(0), new LayoutNavigationRef(PERSPECTIVE, "C")); assertEquals(info.getRefList().get(1), new LayoutNavigationRef(NAV_COMPONENT, TABLIST.getFQClassName())); assertEquals(info.getRefList().get(2), new LayoutNavigationRef(NAV_GROUP_DEFINED, "groupC")); assertEquals(info.getRefList().get(3), new LayoutNavigationRef(DEFAULT_ITEM_DEFINED, "item2")); assertEquals(info.getRefList().get(4), new LayoutNavigationRef(PERSPECTIVE, "D")); assertEquals(info.getRefList().get(5), new LayoutNavigationRef(NAV_COMPONENT, TREE.getFQClassName())); assertEquals(info.getRefList().get(6), new LayoutNavigationRef(NAV_GROUP_CONTEXT, "groupX")); assertEquals(info.getRefList().get(7), new LayoutNavigationRef(DEFAULT_ITEM_FOUND, "item3")); assertEquals(info.getRefList().get(8), new LayoutNavigationRef(PERSPECTIVE, "D")); }
@Test public void testDefaultItemRecursiveIssue() throws Exception { layoutComponentC1.addProperty(NAV_DEFAULT_ID, "item1"); layoutComponentC2.addProperty(NAV_DEFAULT_ID, "item1"); when(navigationServices.loadNavTree()).thenReturn(new NavTreeBuilder() .group("groupC", "", "", true) .item("item1", "", "", true, NavWorkbenchCtx.perspective("C")) .item("item2", "", "", true, NavWorkbenchCtx.perspective("B")) .endGroup() .build()); LayoutRecursionIssue info = layoutTemplateAnalyzer.analyzeRecursion(layoutC); assertEquals(info.getRefList().size(), 5); assertEquals(info.getRefList().get(0), new LayoutNavigationRef(PERSPECTIVE, "C")); assertEquals(info.getRefList().get(1), new LayoutNavigationRef(NAV_COMPONENT, TABLIST.getFQClassName())); assertEquals(info.getRefList().get(2), new LayoutNavigationRef(NAV_GROUP_DEFINED, "groupC")); assertEquals(info.getRefList().get(3), new LayoutNavigationRef(DEFAULT_ITEM_DEFINED, "item1")); assertEquals(info.getRefList().get(4), new LayoutNavigationRef(PERSPECTIVE, "C")); }
@Test public void testFirstItemIndirectRecursiveIssue() throws Exception { when(navigationServices.loadNavTree()).thenReturn(new NavTreeBuilder() .group("groupA", "", "", true) .item("itemA", "", "", true, NavWorkbenchCtx.perspective("C")) .endGroup() .group("groupC", "", "", true) .item("itemC", "", "", true, NavWorkbenchCtx.perspective("A")) .endGroup() .build()); LayoutRecursionIssue info = layoutTemplateAnalyzer.analyzeRecursion(layoutC); assertEquals(info.getRefList().size(), 8); assertEquals(info.getRefList().get(0), new LayoutNavigationRef(PERSPECTIVE, "C")); assertEquals(info.getRefList().get(1), new LayoutNavigationRef(NAV_COMPONENT, TABLIST.getFQClassName())); assertEquals(info.getRefList().get(2), new LayoutNavigationRef(NAV_GROUP_DEFINED, "groupC")); assertEquals(info.getRefList().get(3), new LayoutNavigationRef(DEFAULT_ITEM_FOUND, "itemC")); assertEquals(info.getRefList().get(4), new LayoutNavigationRef(PERSPECTIVE, "A")); assertEquals(info.getRefList().get(5), new LayoutNavigationRef(NAV_COMPONENT, CAROUSEL.getFQClassName())); assertEquals(info.getRefList().get(6), new LayoutNavigationRef(NAV_GROUP_DEFINED, "groupA")); assertEquals(info.getRefList().get(7), new LayoutNavigationRef(PERSPECTIVE, "C")); }
@Test public void testNavGroupFromContext() throws Exception { when(navigationServices.loadNavTree()).thenReturn(new NavTreeBuilder() .group("groupC", "", "", true) .item("item1", "", "", true, NavWorkbenchCtx.perspective("A")) .endGroup() .group("groupX", "", "", true) .item("item2", "", "", true, NavWorkbenchCtx.perspective("C")) .endGroup() .build()); LayoutRecursionIssue info = layoutTemplateAnalyzer.analyzeRecursion(layoutC, new LayoutTemplateContext("groupX")); assertEquals(info.getRefList().size(), 5); assertEquals(info.getRefList().get(0), new LayoutNavigationRef(PERSPECTIVE, "C")); assertEquals(info.getRefList().get(1), new LayoutNavigationRef(NAV_COMPONENT, TABLIST.getFQClassName())); assertEquals(info.getRefList().get(2), new LayoutNavigationRef(NAV_GROUP_CONTEXT, "groupX")); assertEquals(info.getRefList().get(3), new LayoutNavigationRef(DEFAULT_ITEM_FOUND, "item2")); assertEquals(info.getRefList().get(4), new LayoutNavigationRef(PERSPECTIVE, "C")); }