[ http://jira.codehaus.org/browse/JBEHAVE-389?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=249109#action_249109 ]
Ayrat commented on JBEHAVE-389: ------------------------------- I had a similar issue, my project was in [mage_hg] folder and I got "story not found" exception. Couldn't understand what was going wrong until downloaded sources and debugged where I found out that "[mage_hg]" is converted to "%5bmage%5d". If anyone don't want to fix sources, here is the workaround I came to: extend LoadFromRelativeFile and use it in configuration: {code:title=MageEmbedder.java|borderStyle=solid} // private class MageStoryFilePath extends LoadFromRelativeFile { private final StoryFilePath[] traversals; private final URL location; public MageStoryFilePath(URL location, StoryFilePath... traversals) { super(location, traversals); this.location = location; this.traversals = traversals; } @Override public String loadResourceAsText(String resourcePath) { List<String> traversalPaths = new ArrayList<String>(); String locationPath = new File(location.getFile()).getAbsolutePath(); // Add here your code for conversion File file = new File(filePath); if (file.exists()) { return loadContent(filePath); } throw new StoryResourceNotFound(resourcePath, traversalPaths); } } @Override public Configuration configuration() { Class<?> embedderClass = this.getClass(); URL codeLocation = CodeLocations.codeLocationFromClass(embedderClass); Configuration configuration = new MostUsefulConfiguration() .useStoryLoader(new MageStoryFilePath(codeLocation, LoadFromRelativeFile.mavenModuleTestStoryFilePath("src/test/java") )) .useStoryReporterBuilder(new StoryReporterBuilder() .withCodeLocation(codeLocation) .withDefaultFormats()); return configuration; } {code} > Spaces in Path breaks LoadFromRelativeFile > ------------------------------------------ > > Key: JBEHAVE-389 > URL: http://jira.codehaus.org/browse/JBEHAVE-389 > Project: JBehave > Issue Type: Bug > Components: Core > Affects Versions: 3.0.3 > Environment: Redhat Linux 5.5 > Reporter: Leif Carlsen > Priority: Minor > Fix For: 3.2 > > > LoadFromRelativeFile function loadStoryAsTextfails to unescape URLs passed > into the constructor that have escaped characters like %20 for a space. As a > result, the story files cannot be found. > Test case snippet follows... add it to StoryLoaderBehaviour.java. Also need > to add folder "foldername has spaces" to > jbehave-core/src/test/java/org/jbehave/core/io/stories/ and copy > MyPendingStory.txt into it. Also including revised code snippet for > loadStoryAsText function. I didn't immediately see a way to do it without > either checked exceptions or deprecated functions (ex > UrlDecoder.decode(string)). Not sure if InvalidStoryResource was the right > exception to convert to. > {code:title=StoryLoaderBehaviour.java} > @Test > public void shouldLoadStoryFromRelativeFilePathsWithSpace() throws > MalformedURLException, URISyntaxException { > // Given > String storyPath = "MyPendingStory.txt"; > String storyAsText = "Given my step"; > java.net.URL url = > CodeLocations.codeLocationFromClass(MyPendingStory.class); > java.io.File folderWithSpacesInName = new > java.io.File(url.toURI().getPath() + "/org/jbehave/core/io/stories/foldername > has spaces"); > java.net.URL urlThatHasEscapedSpaces = > folderWithSpacesInName.toURI().toURL(); > assertThat(folderWithSpacesInName.exists(), is(true)); > // When > StoryLoader loader = new > LoadFromRelativeFile(urlThatHasEscapedSpaces); > // Then > assertThat(loader.loadStoryAsText(storyPath), equalTo(storyAsText)); > } > {code} > {code:title=LoadFromRelativeFile.java} > public String loadStoryAsText(String storyPath) { > List<String> traversalPaths = new ArrayList<String>(); > String locationPath; > try { > locationPath = new > File(URLDecoder.decode(location.getFile(),"UTF-8")).getAbsolutePath(); > } catch (UnsupportedEncodingException e) { > throw new InvalidStoryResource(storyPath, e); > } > for (StoryFilePath traversal : traversals) { > String filePath = locationPath.replace(traversal.toRemove, > traversal.relativePath) + "/" + storyPath; > File file = new File(filePath); > if (file.exists()) { > return loadContent(filePath); > } else { > traversalPaths.add(filePath); > } > } > throw new StoryResourceNotFound(storyPath, traversalPaths); > } > {code} -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email