RequiredModulesVisitor implements ElementVisitor<Set<String>> { @Override public Set<String> visit(Container container) { Set<String> modules = new HashSet<>(); Widget widget = widgetRepository.get(container.getId()); modules.addAll(widget.getRequiredModules()); modules.addAll(visitRows(container.getRows())); return modules; } RequiredModulesVisitor(WidgetRepository widgetRepository); @Override Set<String> visit(Container container); @Override Set<String> visit(FormContainer formContainer); @Override Set<String> visit(TabsContainer tabsContainer); @Override Set<String> visit(ModalContainer modalContainer); @Override Set<String> visit(TabContainer tabContainer); @Override Set<String> visit(Component component); @Override Set<String> visit(P previewable);  }
@Test public void should_return_empty_set_when_no_extra_modules_are_needed() throws Exception { Component component = mockComponentFor(aWidget()); Page page = aPage().with(component).build(); Set<String> modules = requiredModulesVisitor.visit(page); assertThat(modules).isEmpty(); }
@Test public void should_return_list_of_module_needed_by_widgets() throws Exception { Component component = mockComponentFor(aWidget().modules("aModule", "anotherModule")); Set<String> modules = requiredModulesVisitor.visit(component); assertThat(modules).containsOnly("aModule", "anotherModule"); }
@Test public void should_return_list_of_module_needed_by_widgets_in_container() throws Exception { Component component1 = mockComponentFor(aWidget().modules("component1Module", "component1OtherModule")); Component component2 = mockComponentFor(aWidget().modules("component2Module", "component2OtherModule")); when(widgetRepository.get("pbContainer")).thenReturn(aWidget().build()); Set<String> modules = requiredModulesVisitor.visit(aContainer().with(component1, component2).build()); assertThat(modules).containsOnly("component1Module", "component1OtherModule", "component2Module", "component2OtherModule"); }
@Test public void should_return_list_of_module_needed_by_widgets_in_container_who_has_a_required_module() throws Exception { Component component1 = mockComponentFor(aWidget().modules("component1Module", "component1OtherModule")); Component component2 = mockComponentFor(aWidget().modules("component2Module", "component2OtherModule")); when(widgetRepository.get("pbContainer")).thenReturn(aWidget().modules("containerModule").build()); Set<String> modules = requiredModulesVisitor.visit(aContainer().with(component1, component2).build()); assertThat(modules).containsOnly("component1Module", "component1OtherModule", "component2Module", "component2OtherModule", "containerModule"); }
@Test public void should_return_list_of_module_needed_by_widgets_in_formcontainer() throws Exception { Component component1 = mockComponentFor(aWidget().modules("component1Module", "component1OtherModule")); Component component2 = mockComponentFor(aWidget().modules("component2Module", "component2OtherModule")); when(widgetRepository.get("pbFormContainer")).thenReturn(aWidget().build()); when(widgetRepository.get("pbContainer")).thenReturn(aWidget().build()); Set<String> modules = requiredModulesVisitor.visit(aFormContainer().with( aContainer().with(component1, component2)).build()); assertThat(modules).containsOnly("component1Module", "component1OtherModule", "component2Module", "component2OtherModule"); }
@Test public void should_return_list_of_module_needed_by_widgets_in_tabscontainer() throws Exception { Component component1 = mockComponentFor(aWidget().modules("component1Module", "component1OtherModule")); Component component2 = mockComponentFor(aWidget().modules("component2Module", "component2OtherModule")); when(widgetRepository.get("pbTabsContainer")).thenReturn(aWidget().build()); when(widgetRepository.get("pbContainer")).thenReturn(aWidget().build()); Set<String> modules = requiredModulesVisitor.visit(aTabsContainer().with( aTabContainer().with(aContainer().with(component1)), aTabContainer().with(aContainer().with(component2))).build()); assertThat(modules).containsOnly("component1Module", "component1OtherModule", "component2Module", "component2OtherModule"); }
@Test public void should_return_list_of_module_needed_by_widgets_in_tabscontainer_who_has_a_required_module() throws Exception { Component component1 = mockComponentFor(aWidget().modules("component1Module", "component1OtherModule")); Component component2 = mockComponentFor(aWidget().modules("component2Module", "component2OtherModule")); when(widgetRepository.get("pbTabsContainer")).thenReturn(aWidget().modules("tabContainerModule").build()); when(widgetRepository.get("pbContainer")).thenReturn(aWidget().build()); Set<String> modules = requiredModulesVisitor.visit(aTabsContainer().with( aTabContainer().with(aContainer().with(component1)), aTabContainer().with(aContainer().with(component2))).build()); assertThat(modules).containsOnly("component1Module", "component1OtherModule", "component2Module", "component2OtherModule", "tabContainerModule"); }
@Test public void should_return_list_of_module_needed_by_widgets_in_modal_container() throws Exception { Component component1 = mockComponentFor(aWidget().modules("component1Module", "component1OtherModule")); Component component2 = mockComponentFor(aWidget().modules("component2Module", "component2OtherModule")); when(widgetRepository.get("pbModalContainer")).thenReturn(aWidget().build()); when(widgetRepository.get("pbContainer")).thenReturn(aWidget().build()); Set<String> modules = requiredModulesVisitor.visit(aModalContainer().with(aContainer().with(component1, component2)).build()); assertThat(modules).containsOnly("component1Module", "component1OtherModule", "component2Module", "component2OtherModule"); }
@Test public void should_return_list_of_module_needed_by_widgets_in_modal_container_who_has_a_required_module() throws Exception { Component component1 = mockComponentFor(aWidget().modules("component1Module", "component1OtherModule")); Component component2 = mockComponentFor(aWidget().modules("component2Module", "component2OtherModule")); when(widgetRepository.get("pbModalContainer")).thenReturn(aWidget().modules("containerModule").build()); when(widgetRepository.get("pbContainer")).thenReturn(aWidget().build()); Set<String> modules = requiredModulesVisitor.visit(aModalContainer().with(aContainer().with(component1, component2)).build()); assertThat(modules).containsOnly("component1Module", "component1OtherModule", "component2Module", "component2OtherModule", "containerModule"); }
@Test public void should_return_list_of_module_needed_by_widgets_in_previewable() throws Exception { Component component1 = mockComponentFor(aWidget().modules("component1Module", "component1OtherModule")); Component component2 = mockComponentFor(aWidget().modules("component2Module", "component2OtherModule")); Set<String> modules = requiredModulesVisitor.visit(aPage().with(component1, component2).build()); assertThat(modules).containsOnly("component1Module", "component1OtherModule", "component2Module", "component2OtherModule"); }