| 1 |
|
package org.europa.together.application; |
| 2 |
|
|
| 3 |
|
import org.europa.together.JUnit5Preperator; |
| 4 |
|
import org.europa.together.business.DatabaseActions; |
| 5 |
|
import org.europa.together.business.FeatureFlags; |
| 6 |
|
import org.europa.together.business.Logger; |
| 7 |
|
import org.europa.together.domain.ConfigurationDO; |
| 8 |
|
import org.europa.together.domain.LogLevel; |
| 9 |
|
import org.ff4j.FF4j; |
| 10 |
|
import org.ff4j.core.Feature; |
| 11 |
|
import static org.junit.jupiter.api.Assertions.*; |
| 12 |
|
import org.junit.jupiter.api.AfterAll; |
| 13 |
|
import org.junit.jupiter.api.AfterEach; |
| 14 |
|
import org.junit.jupiter.api.Assumptions; |
| 15 |
|
import org.junit.jupiter.api.BeforeAll; |
| 16 |
|
import org.junit.jupiter.api.BeforeEach; |
| 17 |
|
import org.junit.jupiter.api.Disabled; |
| 18 |
|
import org.junit.jupiter.api.Test; |
| 19 |
|
import org.junit.jupiter.api.extension.ExtendWith; |
| 20 |
|
import org.springframework.beans.factory.annotation.Autowired; |
| 21 |
|
import org.springframework.test.context.ContextConfiguration; |
| 22 |
|
import org.springframework.test.context.junit.jupiter.SpringExtension; |
| 23 |
|
|
| 24 |
|
@SuppressWarnings("unchecked") |
| 25 |
|
@ExtendWith({SpringExtension.class, JUnit5Preperator.class}) |
| 26 |
|
@ContextConfiguration(locations = {"/applicationContext.xml"}) |
| |
|
| 100% |
Uncovered Elements: 0 (69) |
Complexity: 13 |
Complexity Density: 0.23 |
|
| 27 |
|
public class FeatureFlagsFF4jTest { |
| 28 |
|
|
| 29 |
|
private static final Logger LOGGER = new LogbackLogger(FeatureFlagsFF4jTest.class); |
| 30 |
|
|
| 31 |
|
private static final String FLUSH_TABLE |
| 32 |
|
= "TRUNCATE TABLE " + ConfigurationDO.TABLE_NAME + ";"; |
| 33 |
|
private static final String FILE |
| 34 |
|
= "org/europa/together/sql/ff-configuration.sql"; |
| 35 |
|
private static final String PROPERTIES |
| 36 |
|
= "org/europa/together/configuration/jdbc.properties"; |
| 37 |
|
|
| 38 |
|
@Autowired |
| 39 |
|
private FeatureFlags featureFlags; |
| 40 |
|
|
| 41 |
|
private static DatabaseActions jdbcActions |
| 42 |
|
= JUnit5Preperator.JDBC_CONNECTION; |
| 43 |
|
private Feature feature; |
| 44 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 45 |
8 |
public FeatureFlagsFF4jTest() {... |
| 46 |
8 |
feature = new Feature("TEST"); |
| 47 |
8 |
feature.setDescription("Temporary test feature."); |
| 48 |
8 |
feature.setGroup("none"); |
| 49 |
8 |
feature.setEnable(true); |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 53 |
1 |
@BeforeAll... |
| 54 |
|
static void setUp() { |
| 55 |
1 |
Assumptions.assumeTrue(JUnit5Preperator.isConnected(), "JDBC DBMS Connection failed."); |
| 56 |
1 |
jdbcActions.executeSqlFromClasspath(FILE); |
| 57 |
|
|
| 58 |
1 |
LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG); |
| 59 |
|
} |
| 60 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 61 |
1 |
@AfterAll... |
| 62 |
|
static void tearDown() throws Exception { |
| 63 |
1 |
jdbcActions.executeQuery(FLUSH_TABLE); |
| 64 |
|
} |
| 65 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 66 |
8 |
@BeforeEach... |
| 67 |
|
void testCaseInitialization() { |
| 68 |
|
} |
| 69 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 70 |
8 |
@AfterEach... |
| 71 |
|
void testCaseTermination() throws Exception { |
| 72 |
8 |
jdbcActions.executeSqlFromClasspath("schema-drop.sql"); |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 76 |
1 |
@Test... |
| 77 |
|
void failConnectDatabase() throws Exception { |
| 78 |
1 |
LOGGER.log("TEST CASE: failConnectDatabase", LogLevel.DEBUG); |
| 79 |
|
|
| 80 |
1 |
jdbcActions.executeQuery(FLUSH_TABLE); |
| 81 |
1 |
assertThrows(Exception.class, () -> { |
| 82 |
1 |
featureFlags.getFeatureStore(PROPERTIES); |
| 83 |
|
}); |
| 84 |
1 |
jdbcActions.executeSqlFromClasspath(FILE); |
| 85 |
|
} |
| 86 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 87 |
1 |
@Test... |
| 88 |
|
void deactivatedFeatureStore() throws Exception { |
| 89 |
1 |
LOGGER.log("TEST CASE: deactivatedFeatureStore", LogLevel.DEBUG); |
| 90 |
|
|
| 91 |
|
|
| 92 |
1 |
jdbcActions.executeQuery("UPDATE " + ConfigurationDO.TABLE_NAME |
| 93 |
|
+ " SET CONF_VALUE = false WHERE IDX = '776e0858-dac5-47c5-95f3-ca79234dc129';"); |
| 94 |
1 |
assertThrows(Exception.class, () -> { |
| 95 |
1 |
featureFlags.getFeatureStore(PROPERTIES); |
| 96 |
|
}); |
| 97 |
|
|
| 98 |
1 |
jdbcActions.executeQuery("UPDATE " + ConfigurationDO.TABLE_NAME |
| 99 |
|
+ " SET CONF_VALUE = true WHERE IDX = '776e0858-dac5-47c5-95f3-ca79234dc129';"); |
| 100 |
|
} |
| 101 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 102 |
1 |
@Test... |
| 103 |
|
void activateFeatureFlags() throws Exception { |
| 104 |
1 |
LOGGER.log("TEST CASE: activateFeatureFlags", LogLevel.DEBUG); |
| 105 |
|
|
| 106 |
1 |
FF4j ff4j = featureFlags.getFeatureStore(PROPERTIES); |
| 107 |
1 |
ff4j.createSchema(); |
| 108 |
|
|
| 109 |
1 |
assertTrue(ff4j.isEnableAudit()); |
| 110 |
1 |
assertFalse(ff4j.isAutocreate()); |
| 111 |
|
} |
| 112 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 113 |
1 |
@Test... |
| 114 |
|
void addFeature() throws Exception { |
| 115 |
1 |
LOGGER.log("TEST CASE: addFeature", LogLevel.DEBUG); |
| 116 |
|
|
| 117 |
1 |
featureFlags.getFeatureStore(PROPERTIES).createSchema(); |
| 118 |
1 |
featureFlags.addFeature(this.feature); |
| 119 |
|
|
| 120 |
1 |
assertNotNull(featureFlags.getFeature("TEST")); |
| 121 |
|
} |
| 122 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 123 |
1 |
@Test... |
| 124 |
|
void updateFeature() throws Exception { |
| 125 |
1 |
LOGGER.log("TEST CASE: updateFeature", LogLevel.DEBUG); |
| 126 |
|
|
| 127 |
1 |
featureFlags.getFeatureStore(PROPERTIES).createSchema(); |
| 128 |
1 |
featureFlags.addFeature(this.feature); |
| 129 |
|
|
| 130 |
1 |
Feature changedFeature = featureFlags.getFeature("TEST"); |
| 131 |
1 |
changedFeature.setGroup("changes"); |
| 132 |
|
|
| 133 |
1 |
featureFlags.updateFeature(changedFeature); |
| 134 |
1 |
assertNotEquals(feature, featureFlags.getFeature("TEST")); |
| 135 |
1 |
assertEquals(1, featureFlags.listAllFeatures().size()); |
| 136 |
|
} |
| 137 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 138 |
1 |
@Test... |
| 139 |
|
void updateFeatureNotExist() throws Exception { |
| 140 |
1 |
LOGGER.log("TEST CASE: updateFeatureNotExist", LogLevel.DEBUG); |
| 141 |
|
|
| 142 |
1 |
featureFlags.getFeatureStore(PROPERTIES).createSchema(); |
| 143 |
1 |
featureFlags.addFeature(this.feature); |
| 144 |
|
|
| 145 |
1 |
Feature changedFeature = featureFlags.getFeature("TEST"); |
| 146 |
1 |
changedFeature.setUid("UPDATE"); |
| 147 |
|
|
| 148 |
1 |
featureFlags.updateFeature(changedFeature); |
| 149 |
1 |
assertEquals(2, featureFlags.listAllFeatures().size()); |
| 150 |
|
} |
| 151 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 152 |
1 |
@Test... |
| 153 |
|
void deleteFeature() throws Exception { |
| 154 |
1 |
LOGGER.log("TEST CASE: deleteFeature", LogLevel.DEBUG); |
| 155 |
|
|
| 156 |
1 |
featureFlags.getFeatureStore(PROPERTIES).createSchema(); |
| 157 |
1 |
featureFlags.addFeature(this.feature); |
| 158 |
|
|
| 159 |
1 |
assertNotNull(featureFlags.getFeature("TEST")); |
| 160 |
|
|
| 161 |
1 |
featureFlags.removeFeature("TEST"); |
| 162 |
1 |
assertEquals(0, featureFlags.listAllFeatures().size()); |
| 163 |
|
} |
| 164 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 165 |
1 |
@Test... |
| 166 |
|
void activateDeactivateFeature() throws Exception { |
| 167 |
1 |
LOGGER.log("TEST CASE: activateDeactivateFeature", LogLevel.DEBUG); |
| 168 |
|
|
| 169 |
1 |
featureFlags.getFeatureStore(PROPERTIES).createSchema(); |
| 170 |
1 |
featureFlags.addFeature(this.feature); |
| 171 |
|
|
| 172 |
1 |
featureFlags.deactivateFeature("TEST"); |
| 173 |
1 |
assertFalse(featureFlags.check("TEST")); |
| 174 |
|
|
| 175 |
1 |
featureFlags.activateFeature("TEST"); |
| 176 |
1 |
assertTrue(featureFlags.check("TEST")); |
| 177 |
|
} |
| 178 |
|
} |