/******************************************************************************************************************* * * FIXME Wrapper against ResourceFileSystem: its methods should throw NFE by themselves * ******************************************************************************************************************/ @Nonnull private static ResourceFile findMandatoryFolder (final @Nonnull ResourceFileSystem fileSystem, final @Nonnull String path) throws NotFoundException { return NotFoundException.throwWhenNull(fileSystem.findFileByPath(path), "Cannot find folder: " + path); // don't log fileSystem.getRoot() since if fileSystem is broken it can trigger secondary errors // FileUtil.toFile(fileSystem.getRoot()).getAbsolutePath() + "/" + path); } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Nonnull protected ResourceFile createRootMockFolder (final @Nonnull ResourceFileSystem fileSystem, final @Nonnull String name) { final ResourceFile folder = createMockFolder(name); when(fileSystem.findFileByPath(eq(name))).thenReturn(folder); return folder; }
final ResourceFile fileObject = fileSystem.findFileByPath(name);
final ResourceFile delegateDirectory = fileSystem.findFileByPath(path.asString());
final ResourceFile zipFolder = localFileSystemProvider.getFileSystem().findFileByPath(fileSystemsFolder);
/******************************************************************************************************************* * ******************************************************************************************************************/ @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); }
/* 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); } } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @BeforeMethod public void setup() { ContextManager.Locator.set(null); context = new ClassPathXmlApplicationContext("DefaultContentExplorerPresentationControlTestBeans.xml"); underTest = context.getBean(DefaultContentExplorerPresentationControl.class); presentation = context.getBean(ContentExplorerPresentation.class); messageBus = context.getBean(MessageBus.class); modelFactory = context.getBean(ModelFactory.class); openSiteEvent = mock(OpenSiteEvent.class); fileSystem = mock(ResourceFileSystem.class); root = mock(ResourceFile.class); content = mockWithAsSupport(Content.class, (RoleFactory<Content>)(c -> new SimpleCompositePresentable(c))); when(fileSystem.findFileByPath(eq(ROOT_DOCUMENT_PATH))).thenReturn(root); when(openSiteEvent.getFileSystem()).thenReturn(fileSystem); // FIXME: this is cumbersome // when(modelFactory.createContent(eq(root))).thenReturn(content); FIXME!!! final Content.Builder.CallBack callBack = mock(Content.Builder.CallBack.class); when(callBack.build(any(Content.Builder.class))).thenReturn(content); when(modelFactory.createContent()).thenReturn(new Content.Builder(modelFactory, callBack)); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Nonnull protected ResourceFile createMockFile (final @Nonnull ResourceFileSystem fileSystem, final @Nonnull ResourceFile parentFolder, final @Nonnull String name) { final ResourcePath path = parentFolder.getPath().appendedWith(name); final ResourceFile file = createMockFile(name); when(file.getParent()).thenReturn(parentFolder); when(file.getPath()).thenReturn(path); when(file.toString()).thenReturn(path.asString()); when(fileSystem.findFileByPath(eq(path.asString()))).thenReturn(file); final Collection<ResourceFile> children = new ArrayList<>(parentFolder.findChildren().results()); children.add(file); when(parentFolder.findChildren()).thenReturn(new ListFinder(children)); return file; }
/* visible for testing */ void onOpenSite (final @ListensTo @Nonnull OpenSiteEvent event) { log.debug("onOpenSite({})", event); final ResourceFile root = event.getFileSystem().findFileByPath(ROOT_DOCUMENT_PATH); final Content rootContent = modelFactory.createContent().withFolder(root).build(); presentation.populate(rootContent.as(Presentable).createPresentationModel()); presentation.expandFirstLevel(); messageBus.publish(emptySelectionEvent()); } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Nonnull protected ResourceFile createMockFolder (final @Nonnull ResourceFileSystem fileSystem, final @Nonnull ResourceFile parentFolder, final @Nonnull String name) { final ResourcePath path = parentFolder.getPath().appendedWith(name); final ResourceFile folder = createMockFolder(name); when(folder.getParent()).thenReturn(parentFolder); when(folder.getPath()).thenReturn(path); when(folder.toString()).thenReturn(path.asString()); when(fileSystem.findFileByPath(eq(path.asString()))).thenReturn(folder); final Collection<ResourceFile> children = new ArrayList<>(parentFolder.findChildren().results()); children.add(folder); when(parentFolder.findChildren()).thenReturn(new ListFinder(children)); return folder; }
@BeforeMethod public void setup() throws Exception { final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/CommonsAutoBeans.xml", "META-INF/XsltTemplateTestBeans.xml", "META-INF/CachedUriResolverBeans.xml"); filter = context.getBean(XsltMacroFilter.class); context.getBean(CachedURIResolver.class).setCacheFolderPath("target/CachedUriResolver"); final SiteProvider siteProvider = context.getBean(SiteProvider.class); final Site site = mock(Site.class); when(siteProvider.getSite()).thenReturn(site); final ResourceFileSystemProvider fileSystemProvider = mock(ResourceFileSystemProvider.class); when(site.getFileSystemProvider()).thenReturn(fileSystemProvider); final File root = new File("src/main/resources/content/library/XsltTemplates").getAbsoluteFile(); final ResourceFileSystemProvider localFileSystemProvider = new LocalFileSystemProvider(); final ResourceFile file = localFileSystemProvider.getFileSystem().findFileByPath(root.getAbsolutePath()); final List<Resource> resources = new ArrayList<>(); for (final ResourceFile xsltFile : file.findChildren().results()) { final Resource resource = mock(Resource.class); when(resource.getFile()).thenReturn(xsltFile); resources.add(resource); } when(site.find(eq(Resource.class))).thenReturn(new MockResourceFinder(resources)); }