Skip to content

Commit

Permalink
ScreenshotCard image href have timestamp query appended to prevent
Browse files Browse the repository at this point in the history
browser serving up cached image
  • Loading branch information
Andrew Sumner committed Apr 11, 2016
1 parent 8010538 commit 64f455a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 27 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/concordion/ext/storyboard/ScreenshotCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.awt.Dimension;
import java.io.File;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;

import org.concordion.api.Element;
import org.concordion.api.Resource;
import org.concordion.ext.ScreenshotTaker;
Expand Down Expand Up @@ -83,9 +87,11 @@ private File combine(String path1, String path2)

@Override
protected void addHTMLToContainer(final Element container) {
String href = this.imageName + "?version=" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());

// Add link to image
Element anchorImg = new Element("a");
anchorImg.addAttribute("href", this.imageName);
anchorImg.addAttribute("href", href);
container.appendChild(anchorImg);

// Add image to card
Expand All @@ -98,7 +104,7 @@ protected void addHTMLToContainer(final Element container) {
img.addStyleClass("sizeportrait");
}

img.addAttribute("src", this.imageName);
img.addAttribute("src", href);
img.addAttribute("width", Integer.toString(this.imageSize.width));
anchorImg.appendChild(img);

Expand Down
12 changes: 0 additions & 12 deletions src/test/java/demo/StoryboardDemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,5 @@ <h4>Example: Hello World</h4>
<p>This is <span c:assertTrue="addCard(#TEXT)">example 1b</span></p>
</div>

<div c:example="example2">
<h4>Example 2</h4>
<p>This is <span c:assertTrue="addCard(#TEXT)">example 2a</span></p>
<p>This is <span c:assertTrue="addCard(#TEXT)">example 2b</span></p>
</div>

<div class="example">
<h4>Example 3</h4>
<p>This is <span c:assertTrue="addCard(#TEXT)">example 3a</span></p>
<p>This is <span c:assertTrue="addCard(#TEXT)">example 3b</span></p>
</div>

</body>
</html>
8 changes: 3 additions & 5 deletions src/test/java/demo/StoryboardDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class StoryboardDemo {

@Extension
public final StoryboardExtension storyboard = new StoryboardExtension()
.setScreenshotTaker(new DummyScreenshotTaker())
.setScreenshotTaker(new DummyScreenshotTaker(1))
.setAppendMode(AppendTo.EXAMPLE);

public boolean addCard(final String description) {
Expand All @@ -26,10 +26,8 @@ public boolean addCard(final String description) {
//storyboard.addScreenshot("Try this", "hey");

storyboard.addSectionBreak(title);
storyboard.addNotification("Example", description, null, StockCardImage.TEXT, CardResult.SUCCESS);
// storyboard.addSectionBreak("Inner");
storyboard.addNotification("Example", description, null, StockCardImage.TEXT, CardResult.FAILURE);
// storyboard.addSectionBreak("");
storyboard.addNotification("n1", "description", StockCardImage.EMAIL, CardResult.SUCCESS);
storyboard.addScreenshot("s2", "description");
storyboard.addSectionBreak("");

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,39 @@
* Returns the contents of a static file, so that screenshots of my system don't inadvertently make it onto the net :-)
*/
public final class DummyScreenshotTaker implements ScreenshotTaker {
private static final String IMAGE_PATH = "image/details.jpg";
static final BufferedImage IMAGE;

static {
private static final String IMAGE_PATH = "image/details#.jpg";
private int index = 1;

public DummyScreenshotTaker() {
}
public DummyScreenshotTaker(int startIndex) {
index = startIndex;
}

private BufferedImage getImage() {

try {
InputStream imageStream = DummyStoryboardFactory.class.getClassLoader().getResourceAsStream(IMAGE_PATH);
InputStream imageStream = DummyStoryboardFactory.class.getClassLoader().getResourceAsStream(IMAGE_PATH.replace("#", String.valueOf(index)));
if (imageStream == null) {
throw new RuntimeException(String.format("Unable to find IMAGE '%s' on classpath", IMAGE_PATH));
}
IMAGE = ImageIO.read(imageStream);

index ++;
if (index > 2) {
index = 1;
}
return ImageIO.read(imageStream);
} catch (IOException e) {
throw new RuntimeException("Unable to create DummyScreenshotFactory", e);
}
}

@Override
public Dimension writeScreenshotTo(OutputStream outputStream) throws IOException {
ImageIO.write(IMAGE, getFileExtension(), outputStream);
return new Dimension(IMAGE.getWidth(), IMAGE.getHeight());
BufferedImage image = getImage();

ImageIO.write(image, getFileExtension(), outputStream);
return new Dimension(image.getWidth(), image.getHeight());
}

@Override
Expand Down
Binary file removed src/test/resources/image/details.jpg
Binary file not shown.
Binary file added src/test/resources/image/details1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/test/resources/image/details2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 64f455a

Please sign in to comment.