1
|
|
package fr.sii.ogham.spring.template.freemarker; |
2
|
|
|
3
|
|
import java.util.Iterator; |
4
|
|
import java.util.NoSuchElementException; |
5
|
|
|
6
|
|
import org.springframework.context.ApplicationContext; |
7
|
|
|
8
|
|
import freemarker.ext.beans.BeanModel; |
9
|
|
import freemarker.ext.beans.BeansWrapper; |
10
|
|
import freemarker.ext.beans.IteratorModel; |
11
|
|
import freemarker.ext.beans.StringModel; |
12
|
|
import freemarker.template.TemplateCollectionModel; |
13
|
|
import freemarker.template.TemplateHashModelEx2; |
14
|
|
import freemarker.template.TemplateModel; |
15
|
|
import freemarker.template.TemplateModelException; |
16
|
|
|
17
|
|
/** |
18
|
|
* Specific model to be able to access Spring beans from template using |
19
|
|
* {@code @beanName.method(args)} syntax. |
20
|
|
* |
21
|
|
* @author Aurélien Baudet |
22
|
|
* |
23
|
|
*/ |
24
|
|
public class SpringBeansTemplateHashModelEx implements TemplateHashModelEx2 { |
25
|
|
private final ApplicationContext applicationContext; |
26
|
|
private final BeansWrapper beansWrapper; |
27
|
|
|
28
|
|
public SpringBeansTemplateHashModelEx(ApplicationContext applicationContext, BeansWrapper beansWrapper) { |
29
|
|
super(); |
30
|
|
this.applicationContext = applicationContext; |
31
|
|
this.beansWrapper = beansWrapper; |
32
|
|
} |
33
|
|
|
34
|
|
@Override |
35
|
|
public int size() throws TemplateModelException { |
36
|
1
1. size : replaced int return with 0 for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::size → NO_COVERAGE
|
return applicationContext.getBeanDefinitionCount(); |
37
|
|
} |
38
|
|
|
39
|
|
@Override |
40
|
|
public TemplateCollectionModel keys() throws TemplateModelException { |
41
|
2
1. keys : replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::keys → KILLED
2. keys : replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::keys → KILLED
|
return new IteratorModel(new Iterator<String>() { |
42
|
|
private int currentIdx = 0; |
43
|
|
|
44
|
|
@Override |
45
|
|
public boolean hasNext() { |
46
|
6
1. hasNext : replaced boolean return with true for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$1::hasNext → KILLED
2. hasNext : replaced boolean return with true for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$1::hasNext → KILLED
3. hasNext : changed conditional boundary → KILLED
4. hasNext : changed conditional boundary → KILLED
5. hasNext : negated conditional → KILLED
6. hasNext : negated conditional → KILLED
|
return currentIdx < applicationContext.getBeanDefinitionCount(); |
47
|
|
} |
48
|
|
|
49
|
|
@Override |
50
|
|
public String next() { |
51
|
2
1. next : negated conditional → KILLED
2. next : negated conditional → KILLED
|
if (!hasNext()) { |
52
|
|
throw new NoSuchElementException(); |
53
|
|
} |
54
|
4
1. next : replaced return value with "" for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$1::next → KILLED
2. next : replaced return value with "" for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$1::next → KILLED
3. next : Replaced integer addition with subtraction → KILLED
4. next : Replaced integer addition with subtraction → KILLED
|
return "@" + applicationContext.getBeanDefinitionNames()[currentIdx++]; |
55
|
|
} |
56
|
|
|
57
|
|
}, beansWrapper); |
58
|
|
} |
59
|
|
|
60
|
|
@Override |
61
|
|
public TemplateCollectionModel values() throws TemplateModelException { |
62
|
2
1. values : replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::values → TIMED_OUT
2. values : replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::values → KILLED
|
return new IteratorModel(new Iterator<Object>() { |
63
|
|
private int currentIdx = 0; |
64
|
|
|
65
|
|
@Override |
66
|
|
public boolean hasNext() { |
67
|
4
1. hasNext : replaced boolean return with true for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$2::hasNext → SURVIVED
2. hasNext : changed conditional boundary → SURVIVED
3. hasNext : negated conditional → KILLED
4. hasNext : negated conditional → KILLED
|
return currentIdx < applicationContext.getBeanDefinitionCount(); |
68
|
|
} |
69
|
|
|
70
|
|
@Override |
71
|
|
public Object next() { |
72
|
2
1. next : negated conditional → KILLED
2. next : negated conditional → KILLED
|
if (!hasNext()) { |
73
|
|
throw new NoSuchElementException(); |
74
|
|
} |
75
|
2
1. next : Replaced integer addition with subtraction → KILLED
2. next : Replaced integer addition with subtraction → KILLED
|
String name = applicationContext.getBeanDefinitionNames()[currentIdx++]; |
76
|
2
1. next : replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$2::next → KILLED
2. next : replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$2::next → KILLED
|
return new LazySpringBeanAccessModel(applicationContext, beansWrapper, name); |
77
|
|
} |
78
|
|
|
79
|
|
}, beansWrapper); |
80
|
|
} |
81
|
|
|
82
|
|
@Override |
83
|
|
public TemplateModel get(String key) throws TemplateModelException { |
84
|
2
1. get : negated conditional → NO_COVERAGE
2. get : replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::get → NO_COVERAGE
|
return new BeanModel(applicationContext.getBean(key.startsWith("@") ? key.substring(1) : key), beansWrapper); |
85
|
|
} |
86
|
|
|
87
|
|
@Override |
88
|
|
public boolean isEmpty() throws TemplateModelException { |
89
|
3
1. isEmpty : replaced boolean return with true for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::isEmpty → NO_COVERAGE
2. isEmpty : changed conditional boundary → NO_COVERAGE
3. isEmpty : negated conditional → NO_COVERAGE
|
return applicationContext.getBeanDefinitionCount() <= 0; |
90
|
|
} |
91
|
|
|
92
|
|
@Override |
93
|
|
public KeyValuePairIterator keyValuePairIterator() throws TemplateModelException { |
94
|
1
1. keyValuePairIterator : replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::keyValuePairIterator → NO_COVERAGE
|
return new KeyValuePairIterator() { |
95
|
|
private int currentIdx = 0; |
96
|
|
|
97
|
|
@Override |
98
|
|
public KeyValuePair next() throws TemplateModelException { |
99
|
1
1. next : negated conditional → NO_COVERAGE
|
if (!hasNext()) { |
100
|
|
throw new NoSuchElementException(); |
101
|
|
} |
102
|
|
KeyValuePair pair = new KeyValuePair() { |
103
|
|
|
104
|
|
@Override |
105
|
|
public TemplateModel getValue() throws TemplateModelException { |
106
|
|
String name = applicationContext.getBeanDefinitionNames()[currentIdx]; |
107
|
1
1. getValue : replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$3$1::getValue → NO_COVERAGE
|
return new LazySpringBeanAccessModel(applicationContext, beansWrapper, name); |
108
|
|
} |
109
|
|
|
110
|
|
@Override |
111
|
|
public TemplateModel getKey() throws TemplateModelException { |
112
|
1
1. getKey : replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$3$1::getKey → NO_COVERAGE
|
return new StringModel(applicationContext.getBeanDefinitionNames()[currentIdx], beansWrapper); |
113
|
|
} |
114
|
|
}; |
115
|
1
1. next : Replaced integer addition with subtraction → NO_COVERAGE
|
currentIdx++; |
116
|
1
1. next : replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$3::next → NO_COVERAGE
|
return pair; |
117
|
|
} |
118
|
|
|
119
|
|
@Override |
120
|
|
public boolean hasNext() throws TemplateModelException { |
121
|
3
1. hasNext : replaced boolean return with true for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$3::hasNext → NO_COVERAGE
2. hasNext : changed conditional boundary → NO_COVERAGE
3. hasNext : negated conditional → NO_COVERAGE
|
return currentIdx < applicationContext.getBeanDefinitionCount(); |
122
|
|
} |
123
|
|
}; |
124
|
|
} |
125
|
|
|
126
|
|
} |
| | Mutations |
36 |
|
1.1 Location : size Killed by : none replaced int return with 0 for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::size → NO_COVERAGE
|
41 |
|
1.1 Location : keys Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests) replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::keys → KILLED 2.2 Location : keys Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::keys → KILLED
|
46 |
|
1.1 Location : hasNext Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests) replaced boolean return with true for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$1::hasNext → KILLED 2.2 Location : hasNext Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) replaced boolean return with true for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$1::hasNext → KILLED 3.3 Location : hasNext Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) changed conditional boundary → KILLED 4.4 Location : hasNext Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests) changed conditional boundary → KILLED 5.5 Location : hasNext Killed by : oghamspringbootv1autoconfigure.it.SpringBeanResolutionTest.smsUsingFreemarkerTemplateShouldResolveBeans(oghamspringbootv1autoconfigure.it.SpringBeanResolutionTest) negated conditional → KILLED 6.6 Location : hasNext Killed by : oghamspringbootv2autoconfigure.it.SpringBeanResolutionTest.smsUsingFreemarkerTemplateShouldResolveBeans(oghamspringbootv2autoconfigure.it.SpringBeanResolutionTest) negated conditional → KILLED
|
51 |
|
1.1 Location : next Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) negated conditional → KILLED 2.2 Location : next Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests) negated conditional → KILLED
|
54 |
|
1.1 Location : next Killed by : oghamspringbootv2autoconfigure.it.SpringBeanResolutionTest.smsUsingFreemarkerTemplateShouldResolveBeans(oghamspringbootv2autoconfigure.it.SpringBeanResolutionTest) replaced return value with "" for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$1::next → KILLED 2.2 Location : next Killed by : oghamspringbootv1autoconfigure.it.SpringBeanResolutionTest.smsUsingFreemarkerTemplateShouldResolveBeans(oghamspringbootv1autoconfigure.it.SpringBeanResolutionTest) replaced return value with "" for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$1::next → KILLED 3.3 Location : next Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests) Replaced integer addition with subtraction → KILLED 4.4 Location : next Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) Replaced integer addition with subtraction → KILLED
|
62 |
|
1.1 Location : values Killed by : none replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::values → TIMED_OUT 2.2 Location : values Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::values → KILLED
|
67 |
|
1.1 Location : hasNext Killed by : none replaced boolean return with true for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$2::hasNext → SURVIVED 2.2 Location : hasNext Killed by : none changed conditional boundary → SURVIVED 3.3 Location : hasNext Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests) negated conditional → KILLED 4.4 Location : hasNext Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) negated conditional → KILLED
|
72 |
|
1.1 Location : next Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) negated conditional → KILLED 2.2 Location : next Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests) negated conditional → KILLED
|
75 |
|
1.1 Location : next Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests) Replaced integer addition with subtraction → KILLED 2.2 Location : next Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests) Replaced integer addition with subtraction → KILLED
|
76 |
|
1.1 Location : next Killed by : oghamspringbootv2autoconfigure.it.SpringBeanResolutionTest.smsUsingFreemarkerTemplateShouldResolveBeans(oghamspringbootv2autoconfigure.it.SpringBeanResolutionTest) replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$2::next → KILLED 2.2 Location : next Killed by : oghamspringbootv1autoconfigure.it.SpringBeanResolutionTest.smsUsingFreemarkerTemplateShouldResolveBeans(oghamspringbootv1autoconfigure.it.SpringBeanResolutionTest) replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$2::next → KILLED
|
84 |
|
1.1 Location : get Killed by : none negated conditional → NO_COVERAGE 2.2 Location : get Killed by : none replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::get → NO_COVERAGE
|
89 |
|
1.1 Location : isEmpty Killed by : none replaced boolean return with true for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::isEmpty → NO_COVERAGE 2.2 Location : isEmpty Killed by : none changed conditional boundary → NO_COVERAGE 3.3 Location : isEmpty Killed by : none negated conditional → NO_COVERAGE
|
94 |
|
1.1 Location : keyValuePairIterator Killed by : none replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx::keyValuePairIterator → NO_COVERAGE
|
99 |
|
1.1 Location : next Killed by : none negated conditional → NO_COVERAGE
|
107 |
|
1.1 Location : getValue Killed by : none replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$3$1::getValue → NO_COVERAGE
|
112 |
|
1.1 Location : getKey Killed by : none replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$3$1::getKey → NO_COVERAGE
|
115 |
|
1.1 Location : next Killed by : none Replaced integer addition with subtraction → NO_COVERAGE
|
116 |
|
1.1 Location : next Killed by : none replaced return value with null for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$3::next → NO_COVERAGE
|
121 |
|
1.1 Location : hasNext Killed by : none replaced boolean return with true for fr/sii/ogham/spring/template/freemarker/SpringBeansTemplateHashModelEx$3::hasNext → NO_COVERAGE 2.2 Location : hasNext Killed by : none changed conditional boundary → NO_COVERAGE 3.3 Location : hasNext Killed by : none negated conditional → NO_COVERAGE
|