Skip to content

Commit

Permalink
fix travis
Browse files Browse the repository at this point in the history
  • Loading branch information
clun committed Jan 2, 2016
1 parent 49741a8 commit a4d6189
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 101 deletions.
131 changes: 103 additions & 28 deletions ff4j-core/src/test/java/org/ff4j/test/AssertFf4j.java
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
Expand All @@ -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 {

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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));
Expand All @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

}
Loading

0 comments on commit a4d6189

Please sign in to comment.