FeatureFlagsFF4j.java

1
package org.europa.together.application;
2
3
import java.io.IOException;
4
import java.net.ConnectException;
5
import java.util.HashMap;
6
import java.util.List;
7
import java.util.Map;
8
import org.apache.commons.dbcp2.BasicDataSource;
9
import org.europa.together.business.ConfigurationDAO;
10
import org.europa.together.business.CryptoTools;
11
import org.europa.together.business.FeatureFlags;
12
import org.europa.together.business.Logger;
13
import org.europa.together.business.PropertyReader;
14
import org.europa.together.domain.ConfigurationDO;
15
import org.europa.together.domain.HashAlgorithm;
16
import org.europa.together.domain.LogLevel;
17
import org.europa.together.exceptions.MisconfigurationException;
18
import org.europa.together.utils.Constraints;
19
import org.europa.together.utils.StringUtils;
20
import org.ff4j.FF4j;
21
import org.ff4j.audit.repository.JdbcEventRepository;
22
import org.ff4j.core.Feature;
23
import org.ff4j.property.store.JdbcPropertyStore;
24
import org.ff4j.store.JdbcFeatureStore;
25
import org.springframework.beans.factory.annotation.Autowired;
26
import org.springframework.stereotype.Repository;
27
28
/**
29
 * Implementation of feature toggels.
30
 */
31
@Repository
32
public class FeatureFlagsFF4j implements FeatureFlags {
33
34
    private static final long serialVersionUID = 13L;
35
    private static final Logger LOGGER = new LogbackLogger(FeatureFlagsFF4j.class);
36
37
    @Autowired
38
    private ConfigurationDAO configurationDAO;
39
    @Autowired
40
    private CryptoTools cryptoTools;
41
    @Autowired
42
    private PropertyReader reader;
43
44
    private FF4j ff4j;
45
    private Map<String, String> configuration;
46
47
    /**
48
     * Constructor.
49
     */
50
    public FeatureFlagsFF4j() {
51
        LOGGER.log("instance class", LogLevel.INFO);
52
        configuration = new HashMap<>();
53
    }
54
55
    @Override
56
    public FF4j getFeatureStore(final String propertyFile)
57
            throws IOException, ConnectException, MisconfigurationException {
58 1 1. getFeatureStore : removed call to org/europa/together/application/FeatureFlagsFF4j::loadConfigurationFromDatabase → KILLED
        loadConfigurationFromDatabase();
59 1 1. getFeatureStore : negated conditional → KILLED
        if (Boolean.parseBoolean(configuration.get("ff.activation"))) {
60
            reader.appendPropertiesFromClasspath(propertyFile);
61
            BasicDataSource cpds = new BasicDataSource();
62 1 1. getFeatureStore : removed call to org/apache/commons/dbcp2/BasicDataSource::setDriverClassName → KILLED
            cpds.setDriverClassName(reader.getPropertyAsString("jdbc.driverClassName"));
63 1 1. getFeatureStore : removed call to org/apache/commons/dbcp2/BasicDataSource::setUrl → KILLED
            cpds.setUrl(reader.getPropertyAsString("jdbc.url"));
64 1 1. getFeatureStore : removed call to org/apache/commons/dbcp2/BasicDataSource::setUsername → KILLED
            cpds.setUsername(reader.getPropertyAsString("jdbc.user"));
65 1 1. getFeatureStore : removed call to org/apache/commons/dbcp2/BasicDataSource::setPassword → KILLED
            cpds.setPassword(reader.getPropertyAsString("jdbc.password"));
66
67
            ff4j = new FF4j();
68 1 1. getFeatureStore : removed call to org/ff4j/FF4j::setFeatureStore → KILLED
            ff4j.setFeatureStore(new JdbcFeatureStore(cpds));
69 1 1. getFeatureStore : removed call to org/ff4j/FF4j::setPropertiesStore → KILLED
            ff4j.setPropertiesStore(new JdbcPropertyStore(cpds));
70 1 1. getFeatureStore : removed call to org/ff4j/FF4j::setEventRepository → KILLED
            ff4j.setEventRepository(new JdbcEventRepository(cpds));
71
            ff4j.audit(Boolean.parseBoolean(configuration.get("ff.audit")));
72
            ff4j.autoCreate(Boolean.parseBoolean(configuration.get("ff.autocreate")));
73
        } else {
74
            String message = "Feature Flags are deactivated by database configuration";
75
            throw new MisconfigurationException(message);
76
        }
77 1 1. getFeatureStore : replaced return value with null for org/europa/together/application/FeatureFlagsFF4j::getFeatureStore → KILLED
        return ff4j.audit();
78
    }
79
80
    @Override
81
    public boolean check(final String featureId) {
82 2 1. check : replaced boolean return with true for org/europa/together/application/FeatureFlagsFF4j::check → KILLED
2. check : replaced boolean return with false for org/europa/together/application/FeatureFlagsFF4j::check → KILLED
        return ff4j.check(featureId);
83
    }
84
85
    @Override
86
    public void activateFeature(final String featureId) {
87
        ff4j.enable(featureId);
88
    }
89
90
    @Override
91
    public void deactivateFeature(final String featureId) {
92
        ff4j.disable(featureId);
93
    }
94
95
    @Override
96
    public void addFeature(final Feature feature) {
97
        ff4j.createFeature(feature);
98
    }
99
100
    @Override
101
    public Feature getFeature(final String featureId) {
102 1 1. getFeature : replaced return value with null for org/europa/together/application/FeatureFlagsFF4j::getFeature → KILLED
        return ff4j.getFeature(featureId);
103
    }
104
105
    @Override
106
    public void updateFeature(final Feature feature) {
107 1 1. updateFeature : negated conditional → KILLED
        if (ff4j.exist(feature.getUid())) {
108
            ff4j.delete(feature.getUid());
109
        }
110
        ff4j.createFeature(feature);
111
    }
112
113
    @Override
114
    public void removeFeature(final String featureId) {
115
        ff4j.delete(featureId);
116
    }
117
118
    @Override
119
    public Map<String, Feature> listAllFeatures() {
120 1 1. listAllFeatures : replaced return value with Collections.emptyMap for org/europa/together/application/FeatureFlagsFF4j::listAllFeatures → KILLED
        return ff4j.getFeatures();
121
    }
122
123
    private void loadConfigurationFromDatabase() throws ConnectException {
124
        LOGGER.log("Load all configuration sets of: " + CONFIG_SET
125
                + " - Version: " + CONFIG_VERSION
126
                + " - Module: " + Constraints.MODULE_NAME, LogLevel.DEBUG);
127
        List<ConfigurationDO> configurationEntries
128
                = configurationDAO.getAllConfigurationSetEntries(Constraints.MODULE_NAME,
129
                        CONFIG_VERSION, CONFIG_SET);
130 1 1. loadConfigurationFromDatabase : negated conditional → KILLED
        if (!configurationEntries.isEmpty()) {
131
            LOGGER.log("Size of config SET: " + configurationEntries.size(), LogLevel.DEBUG);
132
            for (ConfigurationDO entry : configurationEntries) {
133
                String value;
134 1 1. loadConfigurationFromDatabase : negated conditional → KILLED
                if (StringUtils.isEmpty(entry.getValue())) {
135
                    value = entry.getDefaultValue();
136
                } else {
137
                    value = entry.getValue();
138
                }
139
                if (entry.getKey()
140 1 1. loadConfigurationFromDatabase : negated conditional → KILLED
                        .equals(cryptoTools.calculateHash("ff.activation",
141
                                HashAlgorithm.SHA256))) {
142
                    this.configuration.put("ff.activation", value);
143
                } else if (entry.getKey()
144 1 1. loadConfigurationFromDatabase : negated conditional → SURVIVED
                        .equals(cryptoTools.calculateHash("ff.audit",
145
                                HashAlgorithm.SHA256))) {
146
                    this.configuration.put("ff.audit", value);
147
                } else if (entry.getKey()
148 1 1. loadConfigurationFromDatabase : negated conditional → SURVIVED
                        .equals(cryptoTools.calculateHash("ff.autocreate",
149
                                HashAlgorithm.SHA256))) {
150
                    this.configuration.put("ff.autocreate", value);
151
                }
152
            }
153
        } else {
154
            throw new ConnectException("Feature Flags can't access the configuration.");
155
        }
156
    }
157
}

Mutations

58

1.1
Location : getFeatureStore
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]/[method:deactivatedFeatureStore()]
removed call to org/europa/together/application/FeatureFlagsFF4j::loadConfigurationFromDatabase → KILLED

59

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

62

1.1
Location : getFeatureStore
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]/[method:activateFeatureFlags()]
removed call to org/apache/commons/dbcp2/BasicDataSource::setDriverClassName → KILLED

63

1.1
Location : getFeatureStore
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]/[method:deleteFeature()]
removed call to org/apache/commons/dbcp2/BasicDataSource::setUrl → KILLED

64

1.1
Location : getFeatureStore
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]/[method:deleteFeature()]
removed call to org/apache/commons/dbcp2/BasicDataSource::setUsername → KILLED

65

1.1
Location : getFeatureStore
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]/[method:deleteFeature()]
removed call to org/apache/commons/dbcp2/BasicDataSource::setPassword → KILLED

68

1.1
Location : getFeatureStore
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]/[method:updateFeature()]
removed call to org/ff4j/FF4j::setFeatureStore → KILLED

69

1.1
Location : getFeatureStore
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]/[method:updateFeatureNotExist()]
removed call to org/ff4j/FF4j::setPropertiesStore → KILLED

70

1.1
Location : getFeatureStore
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]/[method:updateFeatureNotExist()]
removed call to org/ff4j/FF4j::setEventRepository → KILLED

77

1.1
Location : getFeatureStore
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]/[method:deleteFeature()]
replaced return value with null for org/europa/together/application/FeatureFlagsFF4j::getFeatureStore → KILLED

82

1.1
Location : check
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]/[method:activateDeactivateFeature()]
replaced boolean return with true for org/europa/together/application/FeatureFlagsFF4j::check → KILLED

2.2
Location : check
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]
replaced boolean return with false for org/europa/together/application/FeatureFlagsFF4j::check → KILLED

102

1.1
Location : getFeature
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]/[method:deleteFeature()]
replaced return value with null for org/europa/together/application/FeatureFlagsFF4j::getFeature → KILLED

107

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

120

1.1
Location : listAllFeatures
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]/[method:updateFeatureNotExist()]
replaced return value with Collections.emptyMap for org/europa/together/application/FeatureFlagsFF4j::listAllFeatures → KILLED

130

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

134

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

140

1.1
Location : loadConfigurationFromDatabase
Killed by : org.europa.together.application.FeatureFlagsFF4jTest.[engine:junit-jupiter]/[class:org.europa.together.application.FeatureFlagsFF4jTest]
negated conditional → KILLED

144

1.1
Location : loadConfigurationFromDatabase
Killed by : none
negated conditional → SURVIVED
Covering tests

148

1.1
Location : loadConfigurationFromDatabase
Killed by : none
negated conditional → SURVIVED
Covering tests

Active mutators

Tests examined


Report generated by PIT 1.22.0