incubator-any23-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Ansell (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (ANY23-103) Convert tests to use getResourceAsStream() instead of direct file access
Date Fri, 10 Aug 2012 01:16:18 GMT

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

Peter Ansell commented on ANY23-103:
------------------------------------

Fix pushed in svn revision 1371537
                
> 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: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message