PrintService { public void getPDF(PrintRequest request, PDDocument doc) throws IOException, ServiceException { PDF.getPDF(request, wmtsCapsCache, featureClient, doc); } PrintService();  PrintService(OskariFeatureClient featureClient);  PrintService(WMTSCapabilitiesCache wmtsCapsCache);  PrintService(WMTSCapabilitiesCache wmtsCapsCache, OskariFeatureClient featureClient); BufferedImage getPNG(PrintRequest request); void getPDF(PrintRequest request, PDDocument doc);  }
@Test @Ignore("Depends on karttamoottori.maanmittauslaitos.fi, doesn't test anything") public void testPDF() throws ServiceException, IOException, NoSuchAuthorityCodeException, FactoryException { PrintRequest request = new PrintRequest(); request.setFormat(PrintFormat.PDF); request.setEast(500000); request.setNorth(6750000); request.setSrsName("EPSG:3067"); request.setTitle("Hello world!"); request.setWidth(PDF.mmToPx(210 - 20)); request.setHeight(PDF.mmToPx(297 - 30)); request.setResolution(2); request.setShowLogo(true); request.setShowScale(true); OskariLayer taustakartta = new OskariLayer(); taustakartta.setId(1); taustakartta.setName("taustakartta"); taustakartta.setType(OskariLayer.TYPE_WMTS); taustakartta.setVersion("1.0.0"); taustakartta.setUrl("https: taustakartta.setStyle("default"); OskariLayer kiinteistotunnukset = new OskariLayer(); kiinteistotunnukset.setId(2); kiinteistotunnukset.setType(OskariLayer.TYPE_WMTS); kiinteistotunnukset.setVersion("1.0.0"); kiinteistotunnukset.setName("kiinteistotunnukset"); kiinteistotunnukset.setUrl("https: kiinteistotunnukset.setStyle("default"); PrintLayer bg = new PrintLayer(0); bg.setOskariLayer(taustakartta); bg.setOpacity(100); PrintLayer fg = new PrintLayer(1); fg.setOskariLayer(kiinteistotunnukset); fg.setOpacity(30); request.setLayers(Arrays.asList(bg, fg)); String dataBg = CapabilitiesCacheService.getFromService(bg.getUrl(), bg.getType(), bg.getUsername(), bg.getPassword(), bg.getVersion()); OskariLayerCapabilities answerBg = new OskariLayerCapabilities(1L, bg.getUrl(), bg.getType(), bg.getVersion(), dataBg, null, null); String dataFg = CapabilitiesCacheService.getFromService(fg.getUrl(), fg.getType(), fg.getUsername(), fg.getPassword(), fg.getVersion()); OskariLayerCapabilities answerFg = new OskariLayerCapabilities(1L, fg.getUrl(), fg.getType(), fg.getVersion(), dataFg, null, null); CapabilitiesCacheService mock = Mockito.mock(CapabilitiesCacheService.class); Mockito.when(mock.getCapabilities(bg.getUrl(), bg.getType(), bg.getVersion(), bg.getUsername(), bg.getPassword())).thenReturn(answerBg); Mockito.when(mock.getCapabilities(fg.getUrl(), fg.getType(), fg.getVersion(), fg.getUsername(), fg.getPassword())).thenReturn(answerFg); WMTSCapabilitiesCache cache = new WMTSCapabilitiesCache(mock); PrintService service = new PrintService(cache); PDDocument doc = new PDDocument(); service.getPDF(request, doc); File file = File.createTempFile("print-test", ".pdf"); doc.save(file); doc.close(); Desktop.getDesktop().open(file); }
@Test @Ignore("Depends on outside resources, doesn't test anything") public void testPDFVector() throws ServiceException, IOException, NoSuchAuthorityCodeException, FactoryException, DuplicateException, JSONException { PropertyUtil.addProperty("oskari.native.srs", "EPSG:3067", true); PrintRequest request = new PrintRequest(); request.setFormat(PrintFormat.PDF); request.setUser(new User()); request.setEast(385940); request.setNorth(6672046); request.setSrsName("EPSG:3067"); request.setTitle("Hello world!"); request.setWidth(PDF.mmToPx(210 - 20)); request.setHeight(PDF.mmToPx(297 - 30)); request.setResolution(1); request.setShowLogo(true); request.setShowScale(true); OskariLayer taustakartta = new OskariLayer(); taustakartta.setId(1); taustakartta.setName("taustakartta"); taustakartta.setType(OskariLayer.TYPE_WMTS); taustakartta.setVersion("1.0.0"); taustakartta.setUrl("https: taustakartta.setStyle("default"); PrintLayer bg = new PrintLayer(0); bg.setOskariLayer(taustakartta); bg.setOpacity(100); OskariLayer tieviiva = new OskariLayer(); tieviiva.setId(2); tieviiva.setName("tieviiva"); tieviiva.setType(OskariLayer.TYPE_WFS); tieviiva.setVersion("3.0.0"); tieviiva.setUrl("http: JSONObject opt = new JSONObject("" + "{\"styles\":{\"StyleName\":{\"tieviiva\":{\"featureStyle\":" + "{\"stroke\":{\"color\":\"#ff0000\",\"width\":2,\"lineDash\": \"dot\"}}" + "}}}}" ); tieviiva.setOptions(opt); PrintLayer fg = new PrintLayer(1); fg.setOskariLayer(tieviiva); fg.setOpacity(100); fg.setStyle("StyleName"); OskariLayer rakennus = new OskariLayer(); rakennus.setId(3); rakennus.setName("rakennus"); rakennus.setType(OskariLayer.TYPE_WFS); rakennus.setVersion("3.0.0"); rakennus.setUrl("http: JSONObject opt2 = new JSONObject("" + "{\"styles\":{\"StyleName\":{\"rakennus\":{\"featureStyle\":" + "{\"fill\":{\"color\":\"#00ff00\",\"area\":{\"pattern\": 2}}}," + "\"stroke\":{\"area\":{\"color\":\"#0000ff\"}}}" + "}}}}" ); rakennus.setOptions(opt2); PrintLayer fg2 = new PrintLayer(2); fg2.setOskariLayer(rakennus); fg2.setOpacity(50); fg2.setStyle("StyleName"); request.setLayers(Arrays.asList(bg, fg, fg2)); String dataBg = CapabilitiesCacheService.getFromService(bg.getUrl(), bg.getType(), bg.getUsername(), bg.getPassword(), bg.getVersion()); OskariLayerCapabilities answerBg = new OskariLayerCapabilities(1L, bg.getUrl(), bg.getType(), bg.getVersion(), dataBg, null, null); CapabilitiesCacheService mock = Mockito.mock(CapabilitiesCacheService.class); Mockito.when(mock.getCapabilities(bg.getUrl(), bg.getType(), bg.getVersion(), bg.getUsername(), bg.getPassword())).thenReturn(answerBg); WMTSCapabilitiesCache cache = new WMTSCapabilitiesCache(mock); PrintService service = new PrintService(cache); PDDocument doc = new PDDocument(); service.getPDF(request, doc); File file = File.createTempFile("print-test", ".pdf"); doc.save(file); doc.close(); Desktop.getDesktop().open(file); }