@Test
public void testRenderLegend() throws Exception {

	LegendComponentInfo legend = new LegendComponentInfo();
	FontStyleInfo style = new FontStyleInfo();
	style.setFamily("Dialog");
	style.setStyle("Italic");
	style.setSize(12);
	legend.setFont(style);
	legend.setMapId("mainMap");
	legend.setTag("legend");
	legend.setTitle("legend");
	for (ClientLayerInfo layer : configurationService.getMapInfo("mainMap", "application").getLayers()) {
		if (layer instanceof ClientVectorLayerInfo) {
			ClientVectorLayerInfo layerInfo = (ClientVectorLayerInfo) layer;
			String label = layerInfo.getLabel();
			List<FeatureStyleInfo> defs = layerInfo.getNamedStyleInfo().getFeatureStyles();
			for (FeatureStyleInfo styleDefinition : defs) {
				String text = "";
				if (defs.size() > 1) {
					text = label + "(" + styleDefinition.getName() + ")";
				} else {
					text = label;
				}
				LegendItemComponentInfo item = new LegendItemComponentInfo();
				LegendIconComponentInfo icon = new LegendIconComponentInfo();
				icon.setLabel(text);
				icon.setStyleInfo(styleDefinition);
				icon.setLayerType(layerInfo.getLayerType());
				LabelComponentInfo legendLabel = new LabelComponentInfo();
				legendLabel.setBackgroundColor("0xFFFFFF");
				legendLabel.setBorderColor("0x000000");
				legendLabel.setFontColor("0x000000");
				legendLabel.setFont(legend.getFont());
				legendLabel.setText(text);
				legendLabel.setTextOnly(true);
				item.addChild(icon);
				item.addChild(legendLabel);
				legend.addChild(item);
			}
		} else if (layer instanceof ClientRasterLayerInfo) {
			ClientRasterLayerInfo layerInfo = (ClientRasterLayerInfo) layer;
			LegendItemComponentInfo item = new LegendItemComponentInfo();
			LegendIconComponentInfo icon = new LegendIconComponentInfo();
			icon.setLabel(layerInfo.getLabel());
			icon.setLayerType(layerInfo.getLayerType());
			LabelComponentInfo legendLabel = new LabelComponentInfo();
			legendLabel.setFont(legend.getFont());
			legendLabel.setBackgroundColor("0xFFFFFF");
			legendLabel.setBorderColor("black");
			legendLabel.setFontColor("0x000000");
			legendLabel.setText(layerInfo.getLabel());
			legendLabel.setTextOnly(true);
			item.addChild(icon);
			item.addChild(legendLabel);
			legend.addChild(item);
		}
	}
	LegendComponent comp = (LegendComponent) printDtoService.toInternal(legend);
	PageComponentImpl page = new PageComponentImpl();
	page.setSize("0 0", false);
	page.addComponent(comp);
	PrintTemplate template = new PrintTemplate();
	template.setPage(page);
	SinglePageDocument pdfDoc = new SinglePageDocument(page, null);
	FileOutputStream fo = new FileOutputStream("target/legend.png");
	pdfDoc.render(fo, Format.PNG, 200);
	fo.flush();
	fo.close();
}