Package org.apache.sirona.reporting.web.handler

Examples of org.apache.sirona.reporting.web.handler.TemplateHelper


    }

    @Test
    public void renderToXML() throws Exception {
        final StringWriter out = new StringWriter();
        final TemplateHelper helper = new TemplateHelper(new PrintWriter(out), Collections.<String, Object>emptyMap());
        final Template template = Format.Defaults.XML.render(Collections.<String, Object>emptyMap());
        helper.renderPlain(template.getTemplate(), template.getUserParams());

        assertEquals("<?xml version=\"1.0\"?> <repository> " +
            "<counter name=\"RendererTest\" role=\"failures\" unit=\"u\" Hits=\"1.0\" Max=\"1.0\" Mean=\"1.0\" Min=\"1.0\" " +
            "StandardDeviation=\"0.0\" Sum=\"1.0\" Variance=\"0.0\" Value=\"1.0\" Concurrency=\"0.0\" MaxConcurrency=\"1.0\" />" +
            " </repository>", inline(out));
View Full Code Here


    }

    @Test
    public void renderToJSON() throws Exception {
        final StringWriter out = new StringWriter();
        final TemplateHelper helper = new TemplateHelper(new PrintWriter(out), Collections.<String, Object>emptyMap());
        final Template template = Format.Defaults.JSON.render(Collections.<String, Object>emptyMap());
        helper.renderPlain(template.getTemplate(), template.getUserParams());

        assertEquals("{\"counters\":[" +
            " {\"name\":\"RendererTest\", \"role\":\"failures\",\"unit\":\"u\",\"Hits\":\"1.0\",\"Max\":\"1.0\",\"Mean\":\"1.0\",\"Min\":\"1.0\"," +
            "\"StandardDeviation\":\"0.0\",\"Sum\":\"1.0\",\"Variance\":\"0.0\"," +
            "\"Value\":\"1.0\",\"Concurrency\":\"0.0\",\"MaxConcurrency\":\"1.0\"} ]}", inline(out));
View Full Code Here

    }

    @Test
    public void renderToCSV() throws Exception {
        final StringWriter out = new StringWriter();
        final TemplateHelper helper = new TemplateHelper(new PrintWriter(out), Collections.<String, Object>emptyMap());
        final Template template = Format.Defaults.CSV.render(Collections.<String, Object>emptyMap());
        helper.renderPlain(template.getTemplate(), template.getUserParams());

        assertEquals(CSVFormat.HEADER +
            "RendererTest;failures (u);1.0;1.0;1.0;1.0;0.0;1.0;0.0;1.0;0.0;1.0\n",
            out.toString());
    }
View Full Code Here

        try {
            final Object result = method.invoke(instance, params);
            if (Template.class.isInstance(result)) {
                final Template template = Template.class.cast(result);
                populateRequestParameters( template, request );
                final TemplateHelper helper = new TemplateHelperExtractor(name).extract(request, response, matcher);
                if (template.isHtml()) {
                    response.setContentType(TEXT_HTML);
                    helper.renderHtml(template.getTemplate(), template.getUserParams());
                } else {
                    helper.renderPlain(template.getTemplate(), template.getUserParams());
                }
            } else if (result != null) {
                response.getWriter().write(result.toString());
            }
        } catch (final InvocationTargetException e) {
View Full Code Here

        }

        @Override
        public TemplateHelper extract(final HttpServletRequest request, final HttpServletResponse response, final Matcher matcher) {
            try {
                return new TemplateHelper(response.getWriter(),
                                          new MapBuilder<String, Object>().set( "templateId", plugin ).build());
            } catch (final IOException e) {
                throw new SironaException(e);
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.sirona.reporting.web.handler.TemplateHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.