AuthRulesCollector implements ElementVisitor<Set<String>> { @Override public Set<String> visit(Container container) { return visitRows(container.getRows()); } AuthRulesCollector(WidgetRepository widgetRepository); @Override Set<String> visit(Container container); @Override Set<String> visit(FormContainer formContainer); @Override Set<String> visit(TabsContainer tabsContainer); @Override Set<String> visit(TabContainer tabContainer); @Override Set<String> visit(Component component); @Override Set<String> visit(ModalContainer modalContainer); @Override Set<String> visit(P previewable);  }
@Test public void should_return_collect_nothing_when_page_does_not_contain_any_widget_with_auth_rules() throws Exception { Component component = mockComponentFor(aWidget()); Page page = aPage().with(component).build(); Set<String> modules = authRulesCollector.visit(page); assertThat(modules).isEmpty(); }
@Test public void should_collect_auth_rules_needed_by_widgets() throws Exception { Component component = mockComponentFor(aWidget().authRules("GET|living/application-menu", "POST|bpm/process")); Set<String> modules = authRulesCollector.visit(component); assertThat(modules).containsOnly("GET|living/application-menu", "POST|bpm/process"); }
@Test public void should_collect_auth_rules_needed_by_widgets_in_container() throws Exception { Component component1 = mockComponentFor(aWidget().authRules("GET|living/application-menu", "POST|bpm/process")); Component component2 = mockComponentFor(aWidget().authRules("GET|bpm/userTask")); Set<String> modules = authRulesCollector.visit(aContainer().with(component1, component2).build()); assertThat(modules).containsOnly("GET|living/application-menu", "POST|bpm/process", "GET|bpm/userTask"); }
@Test public void should_collect_auth_rules_needed_by_widgets_in_formcontainer() throws Exception { Component component1 = mockComponentFor(aWidget().authRules("GET|living/application-menu", "POST|bpm/process")); Component component2 = mockComponentFor(aWidget().authRules("GET|bpm/userTask")); Set<String> modules = authRulesCollector.visit(aFormContainer().with(aContainer().with(component1, component2)).build()); assertThat(modules).containsOnly("GET|living/application-menu", "POST|bpm/process", "GET|bpm/userTask"); }
@Test public void should_collect_auth_rules_needed_by_widgets_in_tabscontainer() throws Exception { Component component1 = mockComponentFor(aWidget().authRules("GET|living/application-menu", "POST|bpm/process")); Component component2 = mockComponentFor(aWidget().authRules("GET|bpm/userTask")); Set<String> modules = authRulesCollector.visit(aTabsContainer().with( aTabContainer().with(aContainer().with(component1)), aTabContainer().with(aContainer().with(component2))).build()); assertThat(modules).containsOnly("GET|living/application-menu", "POST|bpm/process", "GET|bpm/userTask"); }
@Test public void should_collect_auth_rules_needed_by_widgets_in_previewable() throws Exception { Component component1 = mockComponentFor(aWidget().authRules("GET|living/application-menu", "POST|bpm/process")); Component component2 = mockComponentFor(aWidget().authRules("GET|bpm/userTask")); Set<String> modules = authRulesCollector.visit(aPage().with(component1, component2).build()); assertThat(modules).containsOnly("GET|living/application-menu", "POST|bpm/process", "GET|bpm/userTask"); }
@Test public void should_collect_auth_rules_needed_by_widgets_in_modal_container() throws Exception { Component component1 = mockComponentFor(aWidget().authRules("GET|living/application-menu", "POST|bpm/process")); Component component2 = mockComponentFor(aWidget().authRules("GET|bpm/userTask")); when(widgetRepository.get("pbContainer")).thenReturn(aWidget().build()); Set<String> modules = authRulesCollector.visit(aModalContainer().with(aContainer().with(component1, component2)).build()); assertThat(modules).containsOnly("GET|living/application-menu", "POST|bpm/process", "GET|bpm/userTask"); }