|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertTrue; |
4 | 4 |
|
5 | 5 | import com.codahale.metrics.MetricRegistry; |
| 6 | +import java.awt.Dimension; |
6 | 7 | import java.awt.image.BufferedImage; |
7 | 8 | import java.io.IOException; |
| 9 | +import org.junit.Assert; |
8 | 10 | import org.junit.jupiter.api.Assertions; |
9 | 11 | import org.junit.jupiter.api.Test; |
10 | 12 | import org.mapfish.print.Constants; |
@@ -36,6 +38,34 @@ public void testFetchImage() throws IOException { |
36 | 38 | } |
37 | 39 | } |
38 | 40 |
|
| 41 | + @Test |
| 42 | + public void testFetch204NonContent() throws IOException { |
| 43 | + MapfishMapContext mapContext = |
| 44 | + new MapfishMapContext(null, new Dimension(10, 10), 100, 100, false, true); |
| 45 | + MockClientHttpRequest mockClientHttpRequest = new MockClientHttpRequest(); |
| 46 | + final int noContentCode = 204; |
| 47 | + mockClientHttpRequest.setResponse(new MockClientHttpResponse(new byte[0], noContentCode)); |
| 48 | + AbstractLayerParams layerParams = new AbstractLayerParams(); |
| 49 | + layerParams.failOnError = true; |
| 50 | + AbstractSingleImageLayer layer = new AbstractSingleImageLayerTestImpl(layerParams); |
| 51 | + try { |
| 52 | + BufferedImage bufferedImage = layer.fetchImage(mockClientHttpRequest, mapContext); |
| 53 | + |
| 54 | + Assert.assertEquals("Image width is not correct", 10, bufferedImage.getWidth()); |
| 55 | + Assert.assertEquals("Image height is not correct", 10, bufferedImage.getHeight()); |
| 56 | + |
| 57 | + // check alpha chanel is equal to 0 for every pixels |
| 58 | + for (int x = 0; x < bufferedImage.getWidth(); x++) { |
| 59 | + for (int y = 0; y < bufferedImage.getHeight(); y++) { |
| 60 | + int argb = bufferedImage.getRGB(x, y); |
| 61 | + Assert.assertEquals("Pixel (" + x + "," + y + ") is not transparent", 0, (argb >>> 24)); |
| 62 | + } |
| 63 | + } |
| 64 | + } catch (Exception e) { |
| 65 | + Assert.fail("Did throw exception " + e.getMessage()); |
| 66 | + } |
| 67 | + } |
| 68 | + |
39 | 69 | private static class AbstractSingleImageLayerTestImpl extends AbstractSingleImageLayer { |
40 | 70 |
|
41 | 71 | public AbstractSingleImageLayerTestImpl(AbstractLayerParams layerParams) { |
|
0 commit comments