forked from ff4j/ff4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
256 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <a href="mailto:[email protected]">Cedrick LUNVEN</a> | ||
*/ | ||
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; | ||
} | ||
|
||
} |
Oops, something went wrong.