You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@any23.apache.org by "Lewis John McGibbney (JIRA)" <ji...@apache.org> on 2013/01/14 03:12:12 UTC

[jira] [Commented] (ANY23-103) Convert tests to use getResourceAsStream() instead of direct file access

    [ https://issues.apache.org/jira/browse/ANY23-103?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13552393#comment-13552393 ] 

Lewis John McGibbney commented on ANY23-103:
--------------------------------------------

So this has been addressed right? It doesn't quite look like what you implemented in your commit @ r1371537 is what you initially proposed, but all seems well anyway.
                
> Convert tests to use getResourceAsStream() instead of direct file access
> ------------------------------------------------------------------------
>
>                 Key: ANY23-103
>                 URL: https://issues.apache.org/jira/browse/ANY23-103
>             Project: Apache Any23
>          Issue Type: Improvement
>            Reporter: Peter Ansell
>
> The eventual modularisation of the any23 codebase will be easier if all of the test resources are available in a single module that is imported by other modules for their unit tests as necessary, without either duplicating or splitting up the test resources. 
> The current tests use direct file access to get access to the test resources, using new FileInputStream(new File("src/test/resources/testResource")). If the test resources are imported in with a jar file, this direct file access method will not work and will need to be replaced by  this.getClass().getResourceAsStream("/testResource"). 
> For the CLI tests, the test resource will need to be copied to a temporary folder using something like the following pattern:
> @Rule
> public TemporaryFolder testDirectory;
> private File inputFolder;
> private File outputFolder;
> @Before
> public void setUp() throws Exception 
>  {
>     inputFolder = testDirectory.newFolder();
>     outputFolder = testDirectory.newFolder();
> }
> @Test
> public void testSomething()
> {
>         final File outFile = File.createTempFile("rover-test", "out", outputFolder);
>         final int exitCode = runTool(
>                 String.format(
>                         "-o %s -f nquads -p -n --defaultns %s %s",
>                         outFile.getAbsolutePath(),
>                         DEFAULT_GRAPH,
>                         copyResourceToTempFile("/cli/rover-test1.nq", inputFolder).getAbsolutePath()
>                 )
>         );
> }
> protected static File copyResourceToTempFile(String resourceLocation, File tempDir) throws FileNotFoundException, IOException
>     {
>         log.info("nextResource="+resourceLocation);
>         String fileEnding = resourceLocation.substring(resourceLocation.lastIndexOf("/")+1);
>         log.info("fileEnding="+fileEnding);
>         
>         File tempFile = File.createTempFile("any23test-", "-"+fileEnding, tempDir);
>         
>         FileOutputStream output = new FileOutputStream(tempFile);
>         
>         IOUtils.copy(this.getClass().getResourceAsStream(resourceLocation), output);
>         
>         return tempFile;
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira