CmsTemplateMapper.java

1
package com.fwmotion.threescale.cms.mappers;
2
3
import com.fwmotion.threescale.cms.model.*;
4
import com.redhat.threescale.rest.cms.model.*;
5
import org.mapstruct.Mapper;
6
import org.mapstruct.Mapping;
7
8
@Mapper
9
public interface CmsTemplateMapper {
10
11
    CmsBuiltinPage fromRestBuiltinPage(BuiltinPage builtinPage);
12
13
    @Mapping(target = "layoutName", source = "layout")
14
    @Mapping(target = "draft", ignore = true)
15
    @Mapping(target = "layoutId", ignore = true)
16
    @Mapping(target = "sectionId", ignore = true)
17
    TemplateUpdatableFields toRestBuiltinPage(CmsBuiltinPage builtinPage);
18
19
    CmsBuiltinPartial fromRestBuiltinPartial(BuiltinPartial builtinPartial);
20
21
    @Mapping(target = "draft", ignore = true)
22
    @Mapping(target = "layoutId", ignore = true)
23
    @Mapping(target = "layoutName", ignore = true)
24
    @Mapping(target = "path", ignore = true)
25
    @Mapping(target = "sectionId", ignore = true)
26
    @Mapping(target = "title", ignore = true)
27
    TemplateUpdatableFields toRestBuiltinPartial(CmsBuiltinPartial builtinPartial);
28
29
    @Mapping(target = "draftContent", source = "draft")
30
    @Mapping(target = "publishedContent", source = "published")
31
    CmsLayout fromRestLayout(Layout layout);
32
33
    @Mapping(target = "type", constant = "LAYOUT")
34
    @Mapping(target = "contentType", ignore = true)
35
    @Mapping(target = "draft", ignore = true)
36
    @Mapping(target = "layoutId", ignore = true)
37
    @Mapping(target = "layoutName", ignore = true)
38
    @Mapping(target = "path", ignore = true)
39
    @Mapping(target = "sectionId", ignore = true)
40
    TemplateCreationRequest toRestLayoutCreation(CmsLayout layout);
41
42
    @Mapping(target = "contentType", ignore = true)
43
    @Mapping(target = "draft", ignore = true)
44
    @Mapping(target = "layoutId", ignore = true)
45
    @Mapping(target = "layoutName", ignore = true)
46
    @Mapping(target = "path", ignore = true)
47
    @Mapping(target = "sectionId", ignore = true)
48
    TemplateUpdatableFields toRestLayoutUpdate(CmsLayout layout);
49
50
    @Mapping(target = "sectionId", ignore = true)
51
    CmsPage fromRestPage(Page page);
52
53
    @Mapping(target = "type", constant = "PAGE")
54
    @Mapping(target = "layoutName", source = "layout")
55
    @Mapping(target = "draft", ignore = true)
56
    @Mapping(target = "layoutId", ignore = true)
57
    @Mapping(target = "systemName", ignore = true)
58
    TemplateCreationRequest toRestPageCreation(CmsPage page);
59
60
    @Mapping(target = "layoutName", source = "layout")
61
    @Mapping(target = "draft", ignore = true)
62
    @Mapping(target = "layoutId", ignore = true)
63
    @Mapping(target = "systemName", ignore = true)
64
    TemplateUpdatableFields toRestPageUpdate(CmsPage page);
65
66
    CmsPartial fromRestPartial(Partial partial);
67
68
    @Mapping(target = "type", constant = "PARTIAL")
69
    @Mapping(target = "draft", ignore = true)
70
    @Mapping(target = "layoutId", ignore = true)
71
    @Mapping(target = "layoutName", ignore = true)
72
    @Mapping(target = "path", ignore = true)
73
    @Mapping(target = "sectionId", ignore = true)
74
    @Mapping(target = "title", ignore = true)
75
    TemplateCreationRequest toRestPartialCreation(CmsPartial partial);
76
77
    @Mapping(target = "draft", ignore = true)
78
    @Mapping(target = "layoutId", ignore = true)
79
    @Mapping(target = "layoutName", ignore = true)
80
    @Mapping(target = "path", ignore = true)
81
    @Mapping(target = "sectionId", ignore = true)
82
    @Mapping(target = "title", ignore = true)
83
    TemplateUpdatableFields toRestPartialUpdate(CmsPartial partial);
84
85
    default CmsTemplate fromRest(Template template) {
86
        /* When upgraded to JDK21:
87
        return switch (template) {
88
            case null -> null;
89
90
            case BuiltinPage builtinPage -> fromRestBuiltinPage(builtinPage);
91
            case BuiltinPartial builtinPartial -> fromRestBuiltinPartial(builtinPartial);
92
            case Layout layout -> fromRestLayout(layout);
93
            case Page page -> fromRestPage(page);
94
            case Partial partial -> fromRestPartial(partial);
95
96
            default -> throw new UnsupportedOperationException("Unknown template type: " + template.getClass().getName());
97
        };
98
        */
99 2 1. fromRest : removed conditional - replaced equality check with false → SURVIVED
2. fromRest : removed conditional - replaced equality check with true → KILLED
        if (template == null) {
100
            return null;
101 2 1. fromRest : removed conditional - replaced equality check with false → KILLED
2. fromRest : removed conditional - replaced equality check with true → KILLED
        } else if (template instanceof BuiltinPage builtinPage) {
102 1 1. fromRest : replaced return value with null for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::fromRest → KILLED
            return fromRestBuiltinPage(builtinPage);
103 2 1. fromRest : removed conditional - replaced equality check with true → KILLED
2. fromRest : removed conditional - replaced equality check with false → KILLED
        } else if (template instanceof BuiltinPartial builtinPartial) {
104 1 1. fromRest : replaced return value with null for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::fromRest → KILLED
            return fromRestBuiltinPartial(builtinPartial);
105 2 1. fromRest : removed conditional - replaced equality check with true → KILLED
2. fromRest : removed conditional - replaced equality check with false → KILLED
        } else if (template instanceof Layout layout) {
106 1 1. fromRest : replaced return value with null for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::fromRest → KILLED
            return fromRestLayout(layout);
107 2 1. fromRest : removed conditional - replaced equality check with false → KILLED
2. fromRest : removed conditional - replaced equality check with true → KILLED
        } else if (template instanceof Page page) {
108 1 1. fromRest : replaced return value with null for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::fromRest → KILLED
            return fromRestPage(page);
109 2 1. fromRest : removed conditional - replaced equality check with true → SURVIVED
2. fromRest : removed conditional - replaced equality check with false → KILLED
        } else if (template instanceof Partial partial) {
110 1 1. fromRest : replaced return value with null for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::fromRest → KILLED
            return fromRestPartial(partial);
111
        } else {
112
            throw new UnsupportedOperationException("Unknown template type: " + template.getClass().getName());
113
        }
114
    }
115
116
    default String mapHandlerFromRest(EnumHandler handler) {
117 4 1. mapHandlerFromRest : removed conditional - replaced equality check with true → KILLED
2. mapHandlerFromRest : removed conditional - replaced equality check with false → KILLED
3. mapHandlerFromRest : removed conditional - replaced equality check with true → KILLED
4. mapHandlerFromRest : removed conditional - replaced equality check with false → KILLED
        if (handler == null
118
            || handler == EnumHandler.UNKNOWN_DEFAULT_OPEN_API) {
119 1 1. mapHandlerFromRest : replaced return value with "" for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::mapHandlerFromRest → KILLED
            return null;
120
        }
121
122 1 1. mapHandlerFromRest : replaced return value with "" for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::mapHandlerFromRest → KILLED
        return handler.getValue();
123
    }
124
125
    default EnumHandler mapHandlerToRest(String handlerName) {
126
        EnumHandler enumHandler = EnumHandler.fromValue(handlerName);
127
128 2 1. mapHandlerToRest : removed conditional - replaced equality check with false → KILLED
2. mapHandlerToRest : removed conditional - replaced equality check with true → KILLED
        if (enumHandler == EnumHandler.UNKNOWN_DEFAULT_OPEN_API) {
129
            return null;
130
        }
131
132 1 1. mapHandlerToRest : replaced return value with null for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::mapHandlerToRest → KILLED
        return enumHandler;
133
    }
134
135
}

Mutations

99

1.1
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest]/[method:listTemplates_WithNoContent()]
removed conditional - replaced equality check with true → KILLED

2.2
Location : fromRest
Killed by : none
removed conditional - replaced equality check with false → SURVIVED

101

1.1
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest]/[method:listAllCmsObjects()]
removed conditional - replaced equality check with false → KILLED

2.2
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest]/[method:listTemplates_WithNoContent()]
removed conditional - replaced equality check with true → KILLED

102

1.1
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest]/[method:listAllCmsObjects()]
replaced return value with null for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::fromRest → KILLED

103

1.1
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest]/[method:listTemplates_WithNoContent()]
removed conditional - replaced equality check with true → KILLED

2.2
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest]/[method:listAllCmsObjects()]
removed conditional - replaced equality check with false → KILLED

104

1.1
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest]/[method:listAllCmsObjects()]
replaced return value with null for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::fromRest → KILLED

105

1.1
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest]/[method:listAllCmsObjects()]
removed conditional - replaced equality check with true → KILLED

2.2
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest]/[method:listTemplates_WithNoContent()]
removed conditional - replaced equality check with false → KILLED

106

1.1
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplUnitTest]/[method:listTemplates_WithNoContent()]
replaced return value with null for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::fromRest → KILLED

107

1.1
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest]/[method:listAllCmsObjects()]
removed conditional - replaced equality check with false → KILLED

2.2
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest]/[method:listAllCmsObjects()]
removed conditional - replaced equality check with true → KILLED

108

1.1
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest]/[method:listAllCmsObjects()]
replaced return value with null for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::fromRest → KILLED

109

1.1
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest]/[method:listAllCmsObjects()]
removed conditional - replaced equality check with false → KILLED

2.2
Location : fromRest
Killed by : none
removed conditional - replaced equality check with true → SURVIVED

110

1.1
Location : fromRest
Killed by : com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.ThreescaleCmsClientImplIntegrationTest]/[method:listAllCmsObjects()]
replaced return value with null for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::fromRest → KILLED

117

1.1
Location : mapHandlerFromRest
Killed by : com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest]/[method:mapHandlerFromRest_Null()]
removed conditional - replaced equality check with true → KILLED

2.2
Location : mapHandlerFromRest
Killed by : com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest]/[method:mapHandlerFromRest_Value()]
removed conditional - replaced equality check with false → KILLED

3.3
Location : mapHandlerFromRest
Killed by : com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest]/[method:mapHandlerFromRest_Value()]
removed conditional - replaced equality check with true → KILLED

4.4
Location : mapHandlerFromRest
Killed by : com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest]/[method:mapHandlerFromRest_Unknown()]
removed conditional - replaced equality check with false → KILLED

119

1.1
Location : mapHandlerFromRest
Killed by : com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest]/[method:mapHandlerFromRest_Unknown()]
replaced return value with "" for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::mapHandlerFromRest → KILLED

122

1.1
Location : mapHandlerFromRest
Killed by : com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest]/[method:mapHandlerFromRest_Value()]
replaced return value with "" for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::mapHandlerFromRest → KILLED

128

1.1
Location : mapHandlerToRest
Killed by : com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest]/[method:mapHandlerToRest_Unknown()]
removed conditional - replaced equality check with false → KILLED

2.2
Location : mapHandlerToRest
Killed by : com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest]/[method:mapHandlerToRest_Value()]
removed conditional - replaced equality check with true → KILLED

132

1.1
Location : mapHandlerToRest
Killed by : com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest.[engine:junit-jupiter]/[class:com.fwmotion.threescale.cms.mappers.CmsTemplateMapperUnitTest]/[method:mapHandlerToRest_Value()]
replaced return value with null for com/fwmotion/threescale/cms/mappers/CmsTemplateMapper::mapHandlerToRest → KILLED

Active mutators

Tests examined


Report generated by PIT 1.15.3