Exemplo n.º 1
0
  @Test
  public void testSeedMetaTiled() throws Exception {
    WMSLayer layer = createWMSLayer("image/png");

    WMSSourceHelper mockSourceHelper = new MockWMSSourceHelper();
    MockLockProvider lockProvider = new MockLockProvider();
    layer.setSourceHelper(mockSourceHelper);
    layer.setLockProvider(lockProvider);

    final StorageBroker mockStorageBroker = EasyMock.createMock(StorageBroker.class);
    Capture<TileObject> captured = new Capture<TileObject>();
    expect(mockStorageBroker.put(EasyMock.capture(captured))).andReturn(true).anyTimes();
    replay(mockStorageBroker);

    String layerId = layer.getName();
    HttpServletRequest servletReq = new MockHttpServletRequest();
    HttpServletResponse servletResp = new MockHttpServletResponse();

    long[] gridLoc = {0, 0, 0}; // x, y, level
    MimeType mimeType = layer.getMimeTypes().get(0);
    GridSet gridSet = gridSetBroker.WORLD_EPSG4326;
    String gridSetId = gridSet.getName();
    ConveyorTile tile =
        new ConveyorTile(
            mockStorageBroker,
            layerId,
            gridSetId,
            gridLoc,
            mimeType,
            null,
            servletReq,
            servletResp);

    boolean tryCache = false;
    layer.seedTile(tile, tryCache);

    assertEquals(1, captured.getValues().size());
    TileObject value = captured.getValue();
    assertNotNull(value);
    assertEquals("image/png", value.getBlobFormat());
    assertNotNull(value.getBlob());
    assertTrue(value.getBlob().getSize() > 0);

    verify(mockStorageBroker);

    // check the lock provider was called in a symmetric way
    lockProvider.verify();
    lockProvider.clear();
  }
Exemplo n.º 2
0
  @Test
  public void testSeedJpegPngMetaTiled() throws Exception {
    WMSLayer layer = createWMSLayer("image/vnd.jpeg-png");

    WMSSourceHelper mockSourceHelper =
        new WMSSourceHelper() {

          @Override
          protected void makeRequest(
              TileResponseReceiver tileRespRecv,
              WMSLayer layer,
              Map<String, String> wmsParams,
              MimeType expectedMimeType,
              Resource target)
              throws GeoWebCacheException {
            int width = Integer.parseInt(wmsParams.get("WIDTH"));
            int height = Integer.parseInt(wmsParams.get("HEIGHT"));
            assertEquals(768, width);
            assertEquals(768, height);
            BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
            Graphics2D graphics = img.createGraphics();
            graphics.setColor(Color.BLACK);
            // fill an L shaped set of tiles, making a few partially filled
            graphics.fillRect(0, 0, width, 300);
            graphics.fillRect(0, 0, 300, height);
            graphics.dispose();
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            try {
              ImageIO.write(img, "PNG", output);
              ImageIO.write(img, "PNG", new java.io.File("/tmp/meta.png"));
            } catch (IOException e) {
              throw new RuntimeException(e);
            }

            try {
              target.transferFrom(
                  Channels.newChannel(new ByteArrayInputStream(output.toByteArray())));
            } catch (IOException e) {
              throw new RuntimeException(e);
            }
          }
        };
    MockLockProvider lockProvider = new MockLockProvider();
    layer.setSourceHelper(mockSourceHelper);
    layer.setLockProvider(lockProvider);

    final StorageBroker mockStorageBroker = EasyMock.createMock(StorageBroker.class);
    Capture<TileObject> captured = new Capture<TileObject>(CaptureType.ALL);
    expect(mockStorageBroker.put(EasyMock.capture(captured)))
        .andAnswer(
            new IAnswer<Boolean>() {

              @Override
              public Boolean answer() throws Throwable {
                TileObject to = (TileObject) EasyMock.getCurrentArguments()[0];
                assertEquals("image/vnd.jpeg-png", to.getBlobFormat());
                assertNotNull(to.getBlob());
                assertTrue(to.getBlob().getSize() > 0);
                String format = ImageMime.jpegPng.getMimeType(to.getBlob());
                long[] xyz = to.getXYZ();
                assertEquals(10, xyz[2]);
                // check the ones in the full black area are jpeg, the others png
                if (xyz[0] == 900 || xyz[1] == 602) {
                  assertEquals("image/jpeg", format);
                } else {
                  assertEquals("image/png", format);
                }

                return true;
              }
            })
        .anyTimes();
    replay(mockStorageBroker);

    String layerId = layer.getName();
    HttpServletRequest servletReq = new MockHttpServletRequest();
    HttpServletResponse servletResp = new MockHttpServletResponse();

    long[] gridLoc = {900, 600, 10}; // x, y, level
    MimeType mimeType = layer.getMimeTypes().get(0);
    GridSet gridSet = gridSetBroker.WORLD_EPSG4326;
    String gridSetId = gridSet.getName();
    ConveyorTile tile =
        new ConveyorTile(
            mockStorageBroker,
            layerId,
            gridSetId,
            gridLoc,
            mimeType,
            null,
            servletReq,
            servletResp);

    boolean tryCache = false;
    layer.seedTile(tile, tryCache);

    assertEquals(9, captured.getValues().size());
    verify(mockStorageBroker);

    // check the lock provider was called in a symmetric way
    lockProvider.verify();
    lockProvider.clear();
  }