@Test public void getStorageLocation() throws Exception { WikiReference currentWikiReference = new WikiReference("wiki"); ModelContext modelContext = this.componentManager.getInstance(ModelContext.class); when(modelContext.getCurrentEntityReference()).thenReturn(currentWikiReference); Environment environment = this.componentManager.getInstance(Environment.class); when(environment.getTemporaryDirectory()).thenReturn(new File("/tmpdir")); File location = this.componentManager.getComponentUnderTest().getStorageLocation( new ImageId(new ChartMacroParameters())); Assert.assertTrue("Got: " + location.toString(), location.toString().matches("/tmpdir/temp/chart/wiki/space/page/.*\\.png")); }
protected File getStorageLocation(ImageId imageId) throws MacroExecutionException { File directory; try { String currentWiki = URLEncoder.encode(getCurrentWiki(), DEFAULT_ENCODING); directory = new File(this.environment.getTemporaryDirectory(), String.format("temp/%s/%s/%s/%s", MODULE_NAME, currentWiki, SPACE, PAGE)); directory.mkdirs(); } catch (Exception e) { throw new MacroExecutionException("Failed to compute chart image location", e); } File locationFile = new File(directory, String.format("%s.png", imageId.getId())); return locationFile; }
TemporaryChartImageWriter implements ChartImageWriter { protected File getStorageLocation(ImageId imageId) throws MacroExecutionException { File directory; try { String currentWiki = URLEncoder.encode(getCurrentWiki(), DEFAULT_ENCODING); directory = new File(this.environment.getTemporaryDirectory(), String.format("temp/%s/%s/%s/%s", MODULE_NAME, currentWiki, SPACE, PAGE)); directory.mkdirs(); } catch (Exception e) { throw new MacroExecutionException("Failed to compute chart image location", e); } File locationFile = new File(directory, String.format("%s.png", imageId.getId())); return locationFile; } }
TemporaryChartImageWriter implements ChartImageWriter { protected File getStorageLocation(ImageId imageId) throws MacroExecutionException { File directory; try { String currentWiki = URLEncoder.encode(getCurrentWiki(), DEFAULT_ENCODING); directory = new File(this.environment.getTemporaryDirectory(), String.format("temp/%s/%s/%s/%s", MODULE_NAME, currentWiki, SPACE, PAGE)); directory.mkdirs(); } catch (Exception e) { throw new MacroExecutionException("Failed to compute chart image location", e); } File locationFile = new File(directory, String.format("%s.png", imageId.getId())); return locationFile; }  }
TemporaryChartImageWriter implements ChartImageWriter { protected File getStorageLocation(ImageId imageId) throws MacroExecutionException { File directory; try { String currentWiki = URLEncoder.encode(getCurrentWiki(), DEFAULT_ENCODING); directory = new File(this.environment.getTemporaryDirectory(), String.format("temp/%s/%s/%s/%s", MODULE_NAME, currentWiki, SPACE, PAGE)); directory.mkdirs(); } catch (Exception e) { throw new MacroExecutionException("Failed to compute chart image location", e); } File locationFile = new File(directory, String.format("%s.png", imageId.getId())); return locationFile; }  @Override void writeImage(ImageId imageId, byte[] imageData); @Override String getURL(ImageId imageId); }
TemporaryChartImageWriter implements ChartImageWriter { protected File getStorageLocation(ImageId imageId) throws MacroExecutionException { File directory; try { String currentWiki = URLEncoder.encode(getCurrentWiki(), DEFAULT_ENCODING); directory = new File(this.environment.getTemporaryDirectory(), String.format("temp/%s/%s/%s/%s", MODULE_NAME, currentWiki, SPACE, PAGE)); directory.mkdirs(); } catch (Exception e) { throw new MacroExecutionException("Failed to compute chart image location", e); } File locationFile = new File(directory, String.format("%s.png", imageId.getId())); return locationFile; }  @Override void writeImage(ImageId imageId, byte[] imageData); @Override String getURL(ImageId imageId);  }