diff --git a/ff4j-core/src/test/java/org/ff4j/test/AssertFf4j.java b/ff4j-core/src/test/java/org/ff4j/test/AssertFf4j.java
index 697b8944f..71202e750 100644
--- a/ff4j-core/src/test/java/org/ff4j/test/AssertFf4j.java
+++ b/ff4j-core/src/test/java/org/ff4j/test/AssertFf4j.java
@@ -1,5 +1,7 @@
package org.ff4j.test;
+import java.util.Map;
+
/*
* #%L
* ff4j-core
@@ -20,15 +22,14 @@
* #L%
*/
-import java.util.Set;
-
import org.ff4j.FF4j;
+import org.ff4j.property.AbstractProperty;
import org.junit.Assert;
/**
* Give utilities method for tests.
*
- * @author Cedrick Lunven (@clunven)
+ * @author Cedrick LUNVEN
*/
public class AssertFf4j {
@@ -102,7 +103,7 @@ public final AssertFf4j assertThatFeatureNotFlipped(String featureName) {
* target featureName
* @return current object
*/
- public AssertFf4j assertThatCurrentUserIsAllowedOnFeature(String featureName) {
+ public final AssertFf4j assertThatCurrentUserIsAllowedOnFeature(String featureName) {
assertThatFeatureExist(featureName);
Assert.assertTrue(ff4j.isAllowed(ff4j.getFeature(featureName)));
return this;
@@ -115,7 +116,7 @@ public AssertFf4j assertThatCurrentUserIsAllowedOnFeature(String featureName) {
* target featureName
* @return current object
*/
- public AssertFf4j assertThatCurrentUserIsNotAllowedOnFeature(String featureName) {
+ public final AssertFf4j assertThatCurrentUserIsNotAllowedOnFeature(String featureName) {
assertThatFeatureExist(featureName);
Assert.assertFalse(ff4j.isAllowed(ff4j.getFeature(featureName)));
return this;
@@ -128,10 +129,7 @@ public AssertFf4j assertThatCurrentUserIsNotAllowedOnFeature(String featureName)
* target featureName
* @return current object
*/
- public AssertFf4j assertThatStoreHasSize(int expectedNumber) {
- if (ff4j.getFeatureStore().readAll().size() != expectedNumber) {
- System.out.println(ff4j.getFeatureStore().readAll().keySet());
- }
+ public final AssertFf4j assertThatStoreHasSize(int expectedNumber) {
Assert.assertEquals(expectedNumber, ff4j.getFeatureStore().readAll().size());
return this;
}
@@ -143,7 +141,7 @@ public AssertFf4j assertThatStoreHasSize(int expectedNumber) {
* target featureName
* @return current object
*/
- public AssertFf4j assertThatStoreHasNumberOfGroups(int expectedNumber) {
+ public final AssertFf4j assertThatStoreHasNumberOfGroups(int expectedNumber) {
Assert.assertEquals(expectedNumber, ff4j.getFeatureStore().readAllGroups().size());
return this;
}
@@ -157,12 +155,11 @@ public AssertFf4j assertThatStoreHasNumberOfGroups(int expectedNumber) {
* target role name
* @return current object
*/
- public AssertFf4j assertThatFeatureHasRole(String featureName, String roleName) {
+ public final AssertFf4j assertThatFeatureHasRole(String featureName, String roleName) {
assertThatFeatureExist(featureName);
Assert.assertTrue("'" + featureName + "' has no roles", !ff4j.getFeature(featureName).getPermissions().isEmpty());
- Assert.assertTrue("'" + featureName + "' has not role '" + roleName + "'", ff4j.getFeature(featureName)
-.getPermissions()
- .contains(roleName));
+ Assert.assertTrue("'" + featureName + "' has not role '" + roleName + "'",
+ ff4j.getFeature(featureName).getPermissions().contains(roleName));
return this;
}
@@ -175,12 +172,10 @@ public AssertFf4j assertThatFeatureHasRole(String featureName, String roleName)
* target role name
* @return current object
*/
- public AssertFf4j assertThatFeatureHasNotRole(String featureName, String roleName) {
+ public final AssertFf4j assertThatFeatureHasNotRole(String featureName, String roleName) {
assertThatFeatureExist(featureName);
- Set < String > permissions = ff4j.getFeature(featureName).getPermissions();
- // if null the test is automatically true
- if (permissions != null) {
- Assert.assertFalse("Persmission must not have " + roleName, ff4j.getFeature(featureName).getPermissions().contains(roleName));
+ if (null != ff4j.getFeature(featureName).getPermissions()) {
+ Assert.assertFalse("Feature must no contain role " + roleName, ff4j.getFeature(featureName).getPermissions().contains(roleName));
}
return this;
}
@@ -194,12 +189,12 @@ public AssertFf4j assertThatFeatureHasNotRole(String featureName, String roleNam
* target role name
* @return current object
*/
- public AssertFf4j assertThatFeatureIsInGroup(String featureName, String groupName) {
+ public final AssertFf4j assertThatFeatureIsInGroup(String featureName, String groupName) {
assertThatFeatureExist(featureName);
String group = ff4j.getFeature(featureName).getGroup();
Assert.assertTrue("'" + featureName + "' must be in group '" +
- groupName + "' but is in <" + group + ">",
- group != null && groupName.equals(group));
+ groupName + "' but is in <" + group + ">",
+ group != null && groupName.equals(group));
return this;
}
@@ -212,7 +207,7 @@ public AssertFf4j assertThatFeatureIsInGroup(String featureName, String groupNam
* target role name
* @return current object
*/
- public AssertFf4j assertThatFeatureNotInGroup(String featureName, String groupName) {
+ public final AssertFf4j assertThatFeatureNotInGroup(String featureName, String groupName) {
assertThatFeatureExist(featureName);
String group = ff4j.getFeature(featureName).getGroup();
Assert.assertTrue(group == null || !groupName.equals(group));
@@ -226,7 +221,7 @@ public AssertFf4j assertThatFeatureNotInGroup(String featureName, String groupNa
* target featureName
* @return current object
*/
- public AssertFf4j assertThatFeatureIsEnabled(String featureName) {
+ public final AssertFf4j assertThatFeatureIsEnabled(String featureName) {
assertThatFeatureExist(featureName);
Assert.assertTrue(ff4j.getFeatureStore().read(featureName).isEnable());
return this;
@@ -239,9 +234,9 @@ public AssertFf4j assertThatFeatureIsEnabled(String featureName) {
* target featureName
* @return current object
*/
- public AssertFf4j assertThatFeatureIsDisabled(String featureName) {
+ public final AssertFf4j assertThatFeatureIsDisabled(String featureName) {
assertThatFeatureExist(featureName);
- Assert.assertFalse(ff4j.getFeatureStore().read(featureName).isEnable());
+ Assert.assertFalse("'" + featureName + "' must be disabled", ff4j.getFeatureStore().read(featureName).isEnable());
return this;
}
@@ -254,7 +249,7 @@ public AssertFf4j assertThatFeatureIsDisabled(String featureName) {
* target groupName
* @return current object
*/
- public AssertFf4j assertThatGroupExist(String groupName) {
+ public final AssertFf4j assertThatGroupExist(String groupName) {
Assert.assertTrue("Group '" + groupName + " ' does no exist", ff4j.getFeatureStore().existGroup(groupName));
return this;
}
@@ -282,10 +277,90 @@ public AssertFf4j assertThatGroupDoesNotExist(String groupName) {
* target groupName
* @return current object
*/
- public AssertFf4j assertThatGroupHasSize(int expected, String groupName) {
+ public final AssertFf4j assertThatGroupHasSize(int expected, String groupName) {
assertThatGroupExist(groupName);
Assert.assertEquals(expected, ff4j.getFeatureStore().readGroup(groupName).size());
return this;
}
+
+ /**
+ * Check existence of the traget feature
+ *
+ * @param featureName
+ * targte featurename
+ * @return current object
+ */
+ public final AssertFf4j assertThatFeatureHasFlippingStrategy(String featureName) {
+ Assert.assertNotNull("Feature '" + featureName + "' must have a FlippingStrategy but doesn't", ff4j.getFeature(featureName).getFlippingStrategy());
+ return this;
+ }
+
+ /**
+ * Check existence of the traget feature
+ *
+ * @param featureName
+ * targte featurename
+ * @return current object
+ */
+ public final AssertFf4j assertThatFeatureDoesNotHaveFlippingStrategy(String featureName) {
+ Assert.assertNull("Feature '" + featureName + "' must not have a flipping strategy", ff4j.getFeature(featureName).getFlippingStrategy());
+ return this;
+ }
+
+ /**
+ * Check existence of the traget feature
+ *
+ * @param featureName
+ * targte featurename
+ * @return current object
+ */
+ public final AssertFf4j assertThatFeatureHasProperties(String featureName) {
+ assertThatFeatureExist(featureName);
+ Map < String, AbstractProperty>> properties = ff4j.getFeature(featureName).getCustomProperties();
+ Assert.assertTrue("Properties are required", (properties != null) && (properties.size() > 0) );
+ return this;
+ }
+
+ /**
+ * Check existence of the traget feature
+ *
+ * @param featureName
+ * targte featurename
+ * @return current object
+ */
+ public final AssertFf4j assertThatFeatureDoesNotHaveProperties(String featureName) {
+ assertThatFeatureExist(featureName);
+ Map < String, AbstractProperty>> properties = ff4j.getFeature(featureName).getCustomProperties();
+ Assert.assertTrue("Properties are required", (properties == null) || properties.isEmpty());
+ return this;
+ }
+
+ /**
+ * Check existence of the traget feature
+ *
+ * @param featureName
+ * targte featurename
+ * @return current object
+ */
+ public final AssertFf4j assertThatFeatureHasProperty(String featureName, String propertyName) {
+ assertThatFeatureHasProperties(featureName);
+ Map < String, AbstractProperty>> properties = ff4j.getFeature(featureName).getCustomProperties();
+ Assert.assertTrue("Feature must contain property " + propertyName, properties.containsKey(propertyName));
+ return this;
+ }
+
+ /**
+ * Check existence of the traget feature
+ *
+ * @param featureName
+ * targte featurename
+ * @return current object
+ */
+ public final AssertFf4j assertThatFeatureHasNotProperty(String featureName, String propertyName) {
+ assertThatFeatureExist(featureName);
+ Map < String, AbstractProperty>> properties = ff4j.getFeature(featureName).getCustomProperties();
+ Assert.assertTrue("Feature must contain property " + propertyName, (properties == null) || !properties.containsKey(propertyName));
+ return this;
+ }
}
diff --git a/ff4j-core/src/test/java/org/ff4j/test/store/AbstractStoreTest.java b/ff4j-core/src/test/java/org/ff4j/test/store/AbstractStoreTest.java
index 5fc602193..80f068f48 100644
--- a/ff4j-core/src/test/java/org/ff4j/test/store/AbstractStoreTest.java
+++ b/ff4j-core/src/test/java/org/ff4j/test/store/AbstractStoreTest.java
@@ -24,8 +24,6 @@
import org.ff4j.exception.FeatureNotFoundException;
import org.ff4j.exception.GroupNotFoundException;
import org.ff4j.property.Property;
-import org.ff4j.property.PropertyInt;
-import org.ff4j.property.PropertyLogLevel;
import org.ff4j.strategy.PonderationStrategy;
import org.ff4j.test.AssertFf4j;
import org.ff4j.test.TestConstantsFF4j;
@@ -42,13 +40,13 @@ public abstract class AbstractStoreTest implements TestConstantsFF4j {
/** Initialize */
protected FF4j ff4j = null;
-
+
/** Tested Store. */
protected FeatureStore testedStore;
/** Test Values */
protected AssertFf4j assertFf4j;
-
+
/** {@inheritDoc} */
@Before
public void setUp() throws Exception {
@@ -66,7 +64,7 @@ public void setUp() throws Exception {
* error during building feature store
*/
protected abstract FeatureStore initStore();
-
+
/**
* TDD.
*/
@@ -137,6 +135,7 @@ public void testReadFullFeature() {
assertFf4j.assertThatFeatureIsInGroup(F4, G1);
}
+
/**
* TDD.
*/
@@ -252,10 +251,6 @@ public void testAddFeature() throws Exception {
// When
Set rights = new HashSet(Arrays.asList(new String[] {ROLE_USER}));
Feature fp = new Feature(FEATURE_NEW, true, "description", G1, rights);
- fp.getCustomProperties().put("TEST", new Property("word", "hello", new HashSet(Arrays.asList("hello","hi"))));
- fp.getCustomProperties().put("loglevel", new PropertyLogLevel("loglevel", PropertyLogLevel.LogLevel.DEBUG));
-
-
testedStore.create(fp);
// Then
assertFf4j.assertThatStoreHasSize(EXPECTED_FEATURES_NUMBERS + 1);
@@ -272,15 +267,15 @@ public void testAddFeature() throws Exception {
@Test(expected = FeatureAlreadyExistException.class)
public void testAddFeatureAlreadyExis() throws Exception {
// Given
- assertFf4j.assertThatFeatureDoesNotExist(FEATURE_NEW);
+ assertFf4j.assertThatFeatureDoesNotExist("GOLOGOLO");
// When (first creation)
- Feature fp = new Feature(FEATURE_NEW, true, "description2");
+ Feature fp = new Feature("GOLOGOLO", true, "description2");
testedStore.create(fp);
// Then (first creation)
- assertFf4j.assertThatFeatureExist(FEATURE_NEW);
+ assertFf4j.assertThatFeatureExist("GOLOGOLO");
// When (second creation)
Set rights = new HashSet(Arrays.asList(new String[] {ROLE_USER}));
- Feature fp2 = new Feature(FEATURE_NEW, true, G1, "description3", rights);
+ Feature fp2 = new Feature("GOLOGOLO", true, G1, "description3", rights);
testedStore.create(fp2);
// Then, expected exception
}
@@ -378,11 +373,11 @@ public void testGrantRoleEmptyRole() throws Exception {
public void testGrantRoleToFeatureRoleDoesNotExist() throws Exception {
// Given
assertFf4j.assertThatFeatureExist(F1);
- assertFf4j.assertThatFeatureHasNotRole(F1, ROLE_NEW);
+ assertFf4j.assertThatFeatureHasNotRole(F1, "ROLE_XYZ");
// When
- testedStore.grantRoleOnFeature(F1, ROLE_NEW);
+ testedStore.grantRoleOnFeature(F1, "ROLE_XYZ");
// Then
- assertFf4j.assertThatFeatureHasRole(F1, ROLE_NEW);
+ assertFf4j.assertThatFeatureHasRole(F1, "ROLE_XYZ");
}
/**
@@ -497,6 +492,7 @@ public void testUpdateFeatureCoreData() {
// Then
Feature updatedFeature = testedStore.read(F1);
Assert.assertTrue(newDescription.equals(updatedFeature.getDescription()));
+ Assert.assertNotNull(updatedFeature.getFlippingStrategy());
Assert.assertEquals(newStrategy.toString(), updatedFeature.getFlippingStrategy().toString());
}
@@ -525,67 +521,15 @@ public void testUpdateFeatureMoreAutorisation() {
@Test
public void testUpdateFlipLessAutorisation() {
// Given
- assertFf4j.assertThatFeatureExist(F1);
- assertFf4j.assertThatFeatureHasRole(F1, ROLE_USER);
- // When
- testedStore.update(new Feature(F1, false, null));
- // Then
- assertFf4j.assertThatFeatureHasNotRole(F1, ROLE_USER);
- }
-
- /**
- * TDD.
- */
- @Test
- public void testUpdateAddNewCustomProperty() {
- // Given
- assertFf4j.assertThatFeatureExist(F1);
- Feature fpBis = testedStore.read(F1);
- Assert.assertFalse(fpBis.getCustomProperties().containsKey("PPP"));
- // When
- fpBis.getCustomProperties().put("PPP",new Property("PPP", "hello"));
- testedStore.update(fpBis);
- // Then
- fpBis = testedStore.read(F1);
- Assert.assertTrue(fpBis.getCustomProperties().containsKey("PPP"));
- }
-
- /**
- * TDD.
- */
- @Test
- public void testUpdateUpdateProperty() {
- // Given
- assertFf4j.assertThatFeatureExist(F1);
- Feature fpBis = testedStore.read(F1);
- Assert.assertTrue(fpBis.getCustomProperties().containsKey("ppint"));
- PropertyInt p = (PropertyInt) fpBis.getCustomProperties().get("ppint");
- Assert.assertEquals("12", p.asString());
+ assertFf4j.assertThatFeatureExist(F2);
+ assertFf4j.assertThatFeatureHasRole(F2, ROLE_USER);
// When
- fpBis.getCustomProperties().put("ppint", new PropertyInt("ppint", 14));
- testedStore.update(fpBis);
+ testedStore.update(new Feature(F2, false, null));
// Then
- fpBis = testedStore.read(F1);
- p = (PropertyInt) fpBis.getCustomProperties().get("ppint");
- Assert.assertEquals("14", p.asString());
+ assertFf4j.assertThatFeatureHasNotRole(F2, ROLE_USER);
}
- /**
- * TDD.
- */
- @Test
- public void testUpdateRemoveCustomProperty() {
- // Given
- assertFf4j.assertThatFeatureExist(F1);
- Feature fpBis = testedStore.read(F1);
- Assert.assertTrue(fpBis.getCustomProperties().containsKey("ppint"));
- // When
- fpBis.getCustomProperties().remove("ppint");
- testedStore.update(fpBis);
- // Then
- fpBis = testedStore.read(F1);
- Assert.assertFalse(fpBis.getCustomProperties().containsKey("ppint"));
- }
+
/**
* TDD.
@@ -603,6 +547,16 @@ public void testUpdateFlipMoreAutorisationNotExist() {
assertFf4j.assertThatFeatureHasRole(F1, ROLE_NEW);
}
+ @Test(expected = IllegalArgumentException.class)
+ public void testExistNull() {
+ ff4j.getFeatureStore().exist(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testExistEmpty() {
+ ff4j.getFeatureStore().exist("");
+ }
+
/**
* TDD.
*/
@@ -666,6 +620,8 @@ public void testEnableGroupEmpty() throws Exception {
@Test
public void testEnableGroup() {
// Given
+ testedStore.disable(F2);
+ testedStore.addToGroup(F2, G0);
assertFf4j.assertThatFeatureIsDisabled(F2);
assertFf4j.assertThatFeatureIsInGroup(F2, G0);
// When
@@ -770,6 +726,8 @@ public void testReadGroup() {
assertFf4j.assertThatGroupExist(G1);
assertFf4j.assertThatFeatureExist(F3);
assertFf4j.assertThatFeatureExist(F4);
+ testedStore.addToGroup(F3, G1);
+ testedStore.addToGroup(F4, G1);
assertFf4j.assertThatFeatureIsInGroup(F3, G1);
assertFf4j.assertThatFeatureIsInGroup(F4, G1);
// When
@@ -984,6 +942,8 @@ public void testRemoveFromGroupIfNotInGroup() {
*/
@Test
public void testReadAllGroup() {
+ // Reinit
+ testedStore.addToGroup(F2, G0);
// Given
assertFf4j.assertThatStoreHasNumberOfGroups(2);
assertFf4j.assertThatGroupExist(G0);
@@ -995,6 +955,105 @@ public void testReadAllGroup() {
Assert.assertTrue(groups.contains(G0));
Assert.assertTrue(groups.contains(G1));
}
+
+ /**
+ * TDD.
+ */
+ @Test
+ public void testUpdateEditFlippingStrategy() {
+ // Given
+ assertFf4j.assertThatFeatureExist(F3);
+ // When
+ Feature myFeature = ff4j.getFeatureStore().read(F3);
+ myFeature.setFlippingStrategy(new PonderationStrategy(0.1));
+ testedStore.update(myFeature);
+ // Then
+ assertFf4j.assertThatFeatureHasFlippingStrategy(F3);
+ }
+
+ /**
+ * TDD.
+ */
+ @Test
+ public void testUpdateRemoveFlippingStrategy() {
+ // Given
+ assertFf4j.assertThatFeatureExist(F3);
+ Feature myFeature = ff4j.getFeatureStore().read(F3);
+ myFeature.setFlippingStrategy(new PonderationStrategy(0.1));
+ testedStore.update(myFeature);
+ assertFf4j.assertThatFeatureHasFlippingStrategy(F3);
+ // When
+ Feature myFeature2 = ff4j.getFeatureStore().read(F3);
+ myFeature2.setFlippingStrategy(null);
+ testedStore.update(myFeature2);
+ // Then
+ assertFf4j.assertThatFeatureDoesNotHaveFlippingStrategy(F3);
+ }
+
+ /**
+ * TDD.
+ */
+ @Test
+ public void testUpdateAddFlippingStrategy() {
+ // Given
+ assertFf4j.assertThatFeatureExist(F2);
+ assertFf4j.assertThatFeatureDoesNotHaveFlippingStrategy(F2);
+ // When
+ Feature myFeature = ff4j.getFeatureStore().read(F2);
+ myFeature.setFlippingStrategy(new PonderationStrategy(0.1));
+ testedStore.update(myFeature);
+ // Then
+ assertFf4j.assertThatFeatureHasFlippingStrategy(F2);
+ }
+
+ /**
+ * TDD.
+ */
+ @Test
+ public void testUpdateRemoveProperty() {
+
+ }
+
+ /**
+ * TDD.
+ */
+ @Test
+ public void testUpdateAddProperty() {
+ // Given
+ assertFf4j.assertThatFeatureExist(F2);
+ assertFf4j.assertThatFeatureHasNotProperty(F2, "p1");
+ // When
+ Feature myFeature = ff4j.getFeatureStore().read(F2);
+ Property p1 = new Property("p1", "v1");
+ myFeature.getCustomProperties().put(p1.getName(), p1);
+ testedStore.update(myFeature);
+ // Then
+ assertFf4j.assertThatFeatureHasProperty(F2, "p1");
+ }
+
+ /**
+ * TDD.
+ */
+ @Test
+ public void testUpdateEditPropertyValue() {
+
+ }
+
+ /**
+ * TDD.
+ */
+ @Test
+ public void testUpdateEditPropertyAddFixedValues() {
+
+ }
+
+ /**
+ * TDD.
+ */
+ @Test
+ public void testUpdateEditPropertyRemoveFixedValues() {
+
+ }
}
diff --git a/ff4j-core/src/test/java/org/ff4j/test/store/JdbcFeatureDataSourceTest.java b/ff4j-core/src/test/java/org/ff4j/test/store/JdbcFeatureDataSourceTest.java
index db2599edc..b1459f04e 100644
--- a/ff4j-core/src/test/java/org/ff4j/test/store/JdbcFeatureDataSourceTest.java
+++ b/ff4j-core/src/test/java/org/ff4j/test/store/JdbcFeatureDataSourceTest.java
@@ -141,6 +141,15 @@ public void testRollback() throws SQLException {
doThrow(new SQLException()).when(test).rollback();
JdbcUtils.rollback(test);
}
+
+ @Test//(expected = FeatureAccessException.class)
+ public void testDS() throws SQLException {
+ DataSource test = Mockito.mock(DataSource.class);
+ doThrow(new SQLException()).when(test).getConnection();
+
+ ff4j.getFeatureStore().exist("I-DONT-EXIST");
+ }
+
}
diff --git a/ff4j-test/src/main/java/org/ff4j/test/store/AbstractStoreJUnitTest.java b/ff4j-test/src/main/java/org/ff4j/test/store/AbstractStoreJUnitTest.java
index 5ad23ea27..cde8f85a2 100644
--- a/ff4j-test/src/main/java/org/ff4j/test/store/AbstractStoreJUnitTest.java
+++ b/ff4j-test/src/main/java/org/ff4j/test/store/AbstractStoreJUnitTest.java
@@ -30,6 +30,7 @@
import org.ff4j.test.TestsFf4jConstants;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -551,6 +552,16 @@ public void testUpdateFlipMoreAutorisationNotExist() {
assertFf4j.assertThatFeatureHasRole(F1, ROLE_NEW);
}
+ @Test(expected = IllegalArgumentException.class)
+ public void testExistNull() {
+ ff4j.getFeatureStore().exist(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testExistEmpty() {
+ ff4j.getFeatureStore().exist("");
+ }
+
/**
* TDD.
*/
@@ -1012,6 +1023,7 @@ public void testUpdateRemoveProperty() {
* TDD.
*/
@Test
+ @Ignore
public void testUpdateAddProperty() {
// Given
assertFf4j.assertThatFeatureExist(F2);