MultiTemplateContent.java

1
package fr.sii.ogham.core.message.content;
2
3
import fr.sii.ogham.core.resource.path.ResourcePath;
4
import fr.sii.ogham.core.resource.path.UnresolvedPath;
5
import fr.sii.ogham.core.template.context.BeanContext;
6
import fr.sii.ogham.core.template.context.Context;
7
import fr.sii.ogham.core.template.context.NullContext;
8
9
/**
10
 * <p>
11
 * A shortcut for using several templates with same context.
12
 * </p>
13
 * <p>
14
 * You have to put all templates to include at once at the same place. Each file
15
 * must be named identically. Only the extension must be different.
16
 * </p>
17
 * <p>
18
 * Then you only need to indicate the path to the templates without any
19
 * extension and provide the context.
20
 * </p>
21
 * <p>
22
 * You can also specify all the extensions/variants to append to the template
23
 * path. By default, the extensions/variants will be {@link EmailVariant#HTML}
24
 * and {@link EmailVariant#TEXT}
25
 * </p>
26
 * 
27
 * @author Aurélien Baudet
28
 *
29
 */
30
public class MultiTemplateContent extends MultiContent {
31
32
	/**
33
	 * Initialize with the template path (without extension/variant) and the
34
	 * context. You may also specify the extensions to use.
35
	 * 
36
	 * @param templatePath
37
	 *            the path to the template (without extension/variant)
38
	 * @param context
39
	 *            the context to share
40
	 * @param variants
41
	 *            the variants to specify
42
	 */
43
	public MultiTemplateContent(String templatePath, Context context, Variant... variants) {
44
		this(new UnresolvedPath(templatePath), context, variants);
45
	}
46
47
	/**
48
	 * Initialize with the template path (without extension/variant) and the
49
	 * context. It uses the default variants ({@link EmailVariant#HTML} and
50
	 * {@link EmailVariant#TEXT}).
51
	 * 
52
	 * @param templatePath
53
	 *            the path to the template (without extension/variant)
54
	 * @param context
55
	 *            the context to share
56
	 */
57
	public MultiTemplateContent(String templatePath, Context context) {
58
		this(new UnresolvedPath(templatePath), context);
59
	}
60
61
	/**
62
	 * Initialize with the template path (without extension/variant) and the
63
	 * context as simple bean. You may also specify the extensions/variants to
64
	 * use.
65
	 * 
66
	 * @param templatePath
67
	 *            the path to the template (without extension/variant)
68
	 * @param bean
69
	 *            the context to share as a simple POJO object
70
	 * @param extensions
71
	 *            the extensions to specify
72
	 */
73
	public MultiTemplateContent(String templatePath, Object bean, Variant... extensions) {
74
		this(new UnresolvedPath(templatePath), bean, extensions);
75
	}
76
77
	/**
78
	 * Initialize with the template path (without extension/variant) and the
79
	 * context as simple bean. It uses the default variants (
80
	 * {@link EmailVariant#HTML} and {@link EmailVariant#TEXT}).
81
	 * 
82
	 * @param templatePath
83
	 *            the path to the template (without extension/variant)
84
	 * @param bean
85
	 *            the context to share as a simple POJO object
86
	 */
87
	public MultiTemplateContent(String templatePath, Object bean) {
88
		this(new UnresolvedPath(templatePath), bean);
89
	}
90
	
91
92
	/**
93
	 * Initialize with the template path (without extension/variant) and the
94
	 * context. You may also specify the extensions to use.
95
	 * 
96
	 * @param templatePath
97
	 *            the path to the template (without extension/variant)
98
	 * @param context
99
	 *            the context to share
100
	 * @param variants
101
	 *            the variants to specify
102
	 */
103
	public MultiTemplateContent(ResourcePath templatePath, Context context, Variant... variants) {
104
		super(createTemplates(templatePath, context, variants));
105
	}
106
107
	/**
108
	 * Initialize with the template path (without extension/variant) and the
109
	 * context. It uses the default variants ({@link EmailVariant#HTML} and
110
	 * {@link EmailVariant#TEXT}).
111
	 * 
112
	 * @param templatePath
113
	 *            the path to the template (without extension/variant)
114
	 * @param context
115
	 *            the context to share
116
	 */
117
	public MultiTemplateContent(ResourcePath templatePath, Context context) {
118
		this(templatePath, context, EmailVariant.TEXT, EmailVariant.HTML);
119
	}
120
121
	/**
122
	 * Initialize with the template path (without extension/variant) and the
123
	 * context as simple bean. You may also specify the extensions/variants to
124
	 * use.
125
	 * 
126
	 * @param templatePath
127
	 *            the path to the template (without extension/variant)
128
	 * @param bean
129
	 *            the context to share as a simple POJO object
130
	 * @param extensions
131
	 *            the extensions to specify
132
	 */
133
	public MultiTemplateContent(ResourcePath templatePath, Object bean, Variant... extensions) {
134 1 1. <init> : negated conditional → NO_COVERAGE
		this(templatePath, bean != null ? new BeanContext(bean) : new NullContext(), extensions);
135
	}
136
137
	/**
138
	 * Initialize with the template path (without extension/variant) and the
139
	 * context as simple bean. It uses the default variants (
140
	 * {@link EmailVariant#HTML} and {@link EmailVariant#TEXT}).
141
	 * 
142
	 * @param templatePath
143
	 *            the path to the template (without extension/variant)
144
	 * @param bean
145
	 *            the context to share as a simple POJO object
146
	 */
147
	public MultiTemplateContent(ResourcePath templatePath, Object bean) {
148 2 1. <init> : negated conditional → NO_COVERAGE
2. <init> : negated conditional → KILLED
		this(templatePath, bean != null ? new BeanContext(bean) : new NullContext());
149
	}
150
151
	private static TemplateContent[] createTemplates(ResourcePath templatePath, Context context, Variant[] variants) {
152
		TemplateContent[] contents = new TemplateContent[variants.length];
153 4 1. createTemplates : changed conditional boundary → NO_COVERAGE
2. createTemplates : negated conditional → NO_COVERAGE
3. createTemplates : changed conditional boundary → KILLED
4. createTemplates : negated conditional → KILLED
		for (int i = 0; i < variants.length; i++) {
154
			contents[i] = new TemplateVariantContent(templatePath, variants[i], context);
155
		}
156 2 1. createTemplates : replaced return value with null for fr/sii/ogham/core/message/content/MultiTemplateContent::createTemplates → NO_COVERAGE
2. createTemplates : replaced return value with null for fr/sii/ogham/core/message/content/MultiTemplateContent::createTemplates → KILLED
		return contents;
157
	}
158
}

Mutations

134

1.1
Location : <init>
Killed by : none
negated conditional → NO_COVERAGE

148

1.1
Location : <init>
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : <init>
Killed by : oghamall.it.email.EmailMultiTemplateTest.withFreemarkerOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
negated conditional → KILLED

153

1.1
Location : createTemplates
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : createTemplates
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
changed conditional boundary → KILLED

3.3
Location : createTemplates
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
negated conditional → KILLED

4.4
Location : createTemplates
Killed by : none
negated conditional → NO_COVERAGE

156

1.1
Location : createTemplates
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
replaced return value with null for fr/sii/ogham/core/message/content/MultiTemplateContent::createTemplates → KILLED

2.2
Location : createTemplates
Killed by : none
replaced return value with null for fr/sii/ogham/core/message/content/MultiTemplateContent::createTemplates → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM