@Override @Nonnull public Finder<SiteNode> findChildren() { return new ResourceFinder<>(getResource().getFile(), folder -> modelFactory.createSiteNode(site, folder)); } }
/* visible for testing */ void onOpenSite (final @ListensTo @Nonnull OpenSiteEvent event) { try { log.debug("onOpenSite({})", event); final ResourceFile root = event.getFileSystem().findFileByPath(ROOT_SITE_NODE_PATH); final SiteNode rootSiteNode = modelFactory.createSiteNode(site, root); presentation.populate(rootSiteNode.as(Presentable).createPresentationModel()); presentation.expandFirstLevel(); messageBus.publish(emptySelectionEvent()); } catch (IOException | NotFoundException e) { log.warn("", e); } } }
@Override public void apply (final @Nonnull ResourceFile folder, final @Nonnull ResourcePath relativePath) { try { final SiteNode siteNode = modelFactory.createSiteNode(DefaultSite.this, folder); nodeMapByRelativePath.put(relativePath.asString(), siteNode); if (!siteNode.isPlaceHolder()) { final ResourcePath relativeUri = siteNode.getRelativeUri(); // Nodes which manage path params are registered with a relativeUri having a wildcard suffix if ("true".equals(siteNode.getProperties().getProperty(SiteNode.PROPERTY_MANAGES_PATH_PARAMS, "false"))) { final String suffix = relativeUri.asString().endsWith("/") ? "(|.*$)" : "(|/.*$)"; nodeMapByRelativeUri.putRegex("^" + RegexTreeMap.escape(relativeUri.asString()) + suffix, siteNode); } else { nodeMapByRelativeUri.put(relativeUri.asString(), siteNode); } } } catch (IOException | NotFoundException e) { throw new RuntimeException(e); } } });
/******************************************************************************************************************* * ******************************************************************************************************************/ @BeforeMethod public void setup() throws Exception { ContextManager.Locator.set(null); context = new ClassPathXmlApplicationContext("DefaultStructureExplorerPresentationControlTestBeans.xml"); underTest = context.getBean(DefaultStructureExplorerPresentationControl.class); presentation = context.getBean(StructureExplorerPresentation.class); messageBus = context.getBean(MessageBus.class); modelFactory = context.getBean(ModelFactory.class); openSiteEvent = mock(OpenSiteEvent.class); fileSystem = mock(ResourceFileSystem.class); root = mock(ResourceFile.class); node = mockWithAsSupport(SiteNode.class, (RoleFactory<SiteNode>)(n -> new SimpleCompositePresentable(n))); when(fileSystem.findFileByPath(eq(ROOT_SITE_NODE_PATH))).thenReturn(root); when(openSiteEvent.getFileSystem()).thenReturn(fileSystem); when(modelFactory.createSiteNode(any(Site.class), eq(root))).thenReturn(node); }