VelocityRenderer.java

1
package org.europa.together.application;
2
3
import java.io.StringWriter;
4
import java.util.Map;
5
import org.apache.velocity.Template;
6
import org.apache.velocity.VelocityContext;
7
import org.apache.velocity.app.Velocity;
8
import org.apache.velocity.app.VelocityEngine;
9
import org.apache.velocity.runtime.RuntimeConstants;
10
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
11
import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
12
import org.apache.velocity.runtime.resource.util.StringResourceRepository;
13
import org.europa.together.business.Logger;
14
import org.europa.together.domain.LogLevel;
15
import org.springframework.stereotype.Repository;
16
import org.europa.together.business.TemplateRenderer;
17
18
/**
19
 * Implementation of a Template Renderer.
20
 */
21
@Repository
22
public class VelocityRenderer implements TemplateRenderer {
23
24
    private static final long serialVersionUID = 3L;
25
    private static final Logger LOGGER = new LogbackLogger(VelocityRenderer.class);
26
27
    private VelocityEngine engine = new VelocityEngine();
28
29
    /**
30
     * Constructor.
31
     */
32
    public VelocityRenderer() {
33
        LOGGER.log("instance class", LogLevel.INFO);
34
    }
35
36
    @Override
37
    public String loadContentByClasspathResource(final String resourcePath,
38
            final String template,
39
            final Map<String, String> properties) {
40 1 1. loadContentByClasspathResource : removed call to org/apache/velocity/app/VelocityEngine::setProperty → KILLED
        engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
41 1 1. loadContentByClasspathResource : removed call to org/apache/velocity/app/VelocityEngine::setProperty → KILLED
        engine.setProperty("classpath.resource.loader.class",
42
                ClasspathResourceLoader.class.getName());
43 1 1. loadContentByClasspathResource : removed call to org/apache/velocity/app/VelocityEngine::init → SURVIVED
        engine.init();
44 1 1. loadContentByClasspathResource : replaced return value with "" for org/europa/together/application/VelocityRenderer::loadContentByClasspathResource → KILLED
        return processContent(resourcePath + template, properties);
45
    }
46
47
    @Override
48
    public String loadContentByFileResource(final String resourcePath,
49
            final String template,
50
            final Map<String, String> properties) {
51 1 1. loadContentByFileResource : removed call to org/apache/velocity/app/VelocityEngine::setProperty → KILLED
        engine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, resourcePath);
52 1 1. loadContentByFileResource : removed call to org/apache/velocity/app/VelocityEngine::init → SURVIVED
        engine.init();
53 1 1. loadContentByFileResource : replaced return value with "" for org/europa/together/application/VelocityRenderer::loadContentByFileResource → KILLED
        return processContent(template, properties);
54
    }
55
56
    @Override
57
    public String loadContentByStringResource(final String resource,
58
            final Map<String, String> properties) {
59 1 1. loadContentByStringResource : removed call to org/apache/velocity/app/VelocityEngine::setProperty → KILLED
        engine.setProperty(Velocity.RESOURCE_LOADER, "string");
60 1 1. loadContentByStringResource : removed call to org/apache/velocity/app/VelocityEngine::addProperty → KILLED
        engine.addProperty("string.resource.loader.class",
61
                StringResourceLoader.class.getName());
62 1 1. loadContentByStringResource : removed call to org/apache/velocity/app/VelocityEngine::addProperty → KILLED
        engine.addProperty("string.resource.loader.repository.static", "false");
63 1 1. loadContentByStringResource : removed call to org/apache/velocity/app/VelocityEngine::init → KILLED
        engine.init();
64
        StringResourceRepository templateRepository
65
                = (StringResourceRepository) engine
66
                        .getApplicationAttribute(StringResourceLoader.REPOSITORY_NAME_DEFAULT);
67 1 1. loadContentByStringResource : removed call to org/apache/velocity/runtime/resource/util/StringResourceRepository::putStringResource → KILLED
        templateRepository.putStringResource("stringResource", resource);
68 1 1. loadContentByStringResource : replaced return value with "" for org/europa/together/application/VelocityRenderer::loadContentByStringResource → KILLED
        return processContent("stringResource", properties);
69
    }
70
71
    private String processContent(final String resource,
72
            final Map<String, String> properties) {
73
        StringWriter writer = new StringWriter();
74
        Template template = engine.getTemplate(resource);
75 1 1. processContent : removed call to java/io/StringWriter::flush → SURVIVED
        writer.flush();
76
        VelocityContext context = new VelocityContext();
77 1 1. processContent : negated conditional → KILLED
        if (properties != null) {
78
            for (Map.Entry<String, String> entry : properties.entrySet()) {
79
                context.put(entry.getKey(), entry.getValue());
80
            }
81
        } else {
82
            context.put("__init__", "");
83
        }
84 1 1. processContent : removed call to org/apache/velocity/Template::merge → KILLED
        template.merge(context, writer);
85 1 1. processContent : replaced return value with "" for org/europa/together/application/VelocityRenderer::processContent → KILLED
        return writer.toString();
86
    }
87
}

Mutations

40

1.1
Location : loadContentByClasspathResource
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:loadContentByClasspathResource()]
removed call to org/apache/velocity/app/VelocityEngine::setProperty → KILLED

41

1.1
Location : loadContentByClasspathResource
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:loadContentByClasspathResource()]
removed call to org/apache/velocity/app/VelocityEngine::setProperty → KILLED

43

1.1
Location : loadContentByClasspathResource
Killed by : none
removed call to org/apache/velocity/app/VelocityEngine::init → SURVIVED
Covering tests

44

1.1
Location : loadContentByClasspathResource
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:loadContentByClasspathResource()]
replaced return value with "" for org/europa/together/application/VelocityRenderer::loadContentByClasspathResource → KILLED

51

1.1
Location : loadContentByFileResource
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:loadContentByFileResource()]
removed call to org/apache/velocity/app/VelocityEngine::setProperty → KILLED

52

1.1
Location : loadContentByFileResource
Killed by : none
removed call to org/apache/velocity/app/VelocityEngine::init → SURVIVED
Covering tests

53

1.1
Location : loadContentByFileResource
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:loadContentByFileResource()]
replaced return value with "" for org/europa/together/application/VelocityRenderer::loadContentByFileResource → KILLED

59

1.1
Location : loadContentByStringResource
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:generateContentWithProperties()]
removed call to org/apache/velocity/app/VelocityEngine::setProperty → KILLED

60

1.1
Location : loadContentByStringResource
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:generateContentWithProperties()]
removed call to org/apache/velocity/app/VelocityEngine::addProperty → KILLED

62

1.1
Location : loadContentByStringResource
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:generateContentWithProperties()]
removed call to org/apache/velocity/app/VelocityEngine::addProperty → KILLED

63

1.1
Location : loadContentByStringResource
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:generateContentWithProperties()]
removed call to org/apache/velocity/app/VelocityEngine::init → KILLED

67

1.1
Location : loadContentByStringResource
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:generateContentWithProperties()]
removed call to org/apache/velocity/runtime/resource/util/StringResourceRepository::putStringResource → KILLED

68

1.1
Location : loadContentByStringResource
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:generateContent()]
replaced return value with "" for org/europa/together/application/VelocityRenderer::loadContentByStringResource → KILLED

75

1.1
Location : processContent
Killed by : none
removed call to java/io/StringWriter::flush → SURVIVED
Covering tests

77

1.1
Location : processContent
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:generateContent()]
negated conditional → KILLED

84

1.1
Location : processContent
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:generateContent()]
removed call to org/apache/velocity/Template::merge → KILLED

85

1.1
Location : processContent
Killed by : org.europa.together.application.VelocityRendererTest.[engine:junit-jupiter]/[class:org.europa.together.application.VelocityRendererTest]/[method:generateContent()]
replaced return value with "" for org/europa/together/application/VelocityRenderer::processContent → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.0