コード例 #1
0
  @Test
  public void testCascadeGetLegendGraphics() throws Exception {
    // setup the layer
    WMSLayer layer = createWMSLayer("image/png");
    final byte[] responseBody = new String("Fake body").getBytes();
    layer.setSourceHelper(
        new WMSHttpHelper() {
          @Override
          public GetMethod executeRequest(
              URL url, Map<String, String> queryParams, Integer backendTimeout)
              throws HttpException, IOException {
            GetMethod response = EasyMock.createMock(GetMethod.class);
            expect(response.getStatusCode()).andReturn(200);
            expect(response.getResponseBodyAsStream())
                .andReturn(new ByteArrayInputStream(responseBody));
            expect(response.getResponseCharSet()).andReturn("UTF-8");
            expect(response.getResponseHeader("Content-Type"))
                .andReturn(new Header("Content-Type", "image/png"));
            response.releaseConnection();
            expectLastCall();
            replay(response);
            return response;
          }
        });
    MockLockProvider lockProvider = new MockLockProvider();
    layer.setLockProvider(lockProvider);

    // setup the conveyor tile
    final StorageBroker mockStorageBroker = EasyMock.createMock(StorageBroker.class);

    String layerId = layer.getName();
    MockHttpServletRequest servletReq = new MockHttpServletRequest();
    servletReq.setQueryString(
        "REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=topp:states");
    MockHttpServletResponse 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);

    // proxy the request, and check the response
    layer.proxyRequest(tile);

    assertEquals(200, servletResp.getStatus());
    assertEquals("Fake body", servletResp.getContentAsString());
    assertEquals("image/png", servletResp.getContentType());
  }
コード例 #2
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();
  }
コード例 #3
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();
  }