use of org.ff4j.strategy.ClientFilterStrategy in project ff4j by ff4j.
the class ClientFilterStrategyTest method testFilterOK.
@Test
public void testFilterOK() throws ParseException {
// Given
Feature f1 = ff4j.getFeature(F1);
Assert.assertNotNull(f1.getFlippingStrategy());
org.ff4j.strategy.ClientFilterStrategy cStra = (ClientFilterStrategy) f1.getFlippingStrategy();
Assert.assertNotNull(cStra.getInitParams());
Assert.assertEquals(1, cStra.getInitParams().size());
Assert.assertTrue(f1.isEnable());
// When (add correct client name)
FlippingExecutionContext fex = new FlippingExecutionContext();
fex.addValue(ClientFilterStrategy.CLIENT_HOSTNAME, "pierre");
// Then
Assert.assertTrue(ff4j.check(F1, fex));
Assert.assertNotNull(cStra.toJson());
}
use of org.ff4j.strategy.ClientFilterStrategy in project ff4j by ff4j.
the class ClientFilterStrategyTest method testInitialisationProgram.
@Test
public void testInitialisationProgram() {
FlippingStrategy fs = new ClientFilterStrategy("Pierre, Paul, Jacques");
fs.init("f1", null);
fs.init("f1", new HashMap<String, String>());
new WhiteListStrategy();
new WhiteListStrategy("Pierre");
// Working
new BlackListStrategy();
FlippingStrategy bl2 = new BlackListStrategy("Pierre");
FlippingExecutionContext context = new FlippingExecutionContext();
context.putString("clientHostName", "localhost");
Assert.assertTrue(bl2.evaluate("f1", new InMemoryFeatureStore(), context));
context.putString("clientHostName", "Pierre");
Assert.assertFalse(bl2.evaluate("f1", new InMemoryFeatureStore(), context));
}
use of org.ff4j.strategy.ClientFilterStrategy in project ff4j by ff4j.
the class FF4JResource2TestIT method testPostIsFlippedInvalidParameter.
/**
* TDD.
*/
@Test
public void testPostIsFlippedInvalidParameter() {
// Given
Feature featureWithParameters = new Feature("FWIP", true);
featureWithParameters.setFlippingStrategy(new ClientFilterStrategy("C1,C2"));
ff4j.createFeature(featureWithParameters);
assertFF4J.assertThatFeatureExist("FWIP");
// When
Form formData = new Form();
formData.param("InvalidParameter", "localhost");
Response resHttp = //
resourceff4j().path(OPERATION_CHECK).path(//
"FWIP").request(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept(MediaType.TEXT_PLAIN_TYPE).post(Entity.form(new Form()));
String resEntity = resHttp.readEntity(String.class);
// Then
Assert.assertEquals("Expected status is 400", Status.BAD_REQUEST.getStatusCode(), resHttp.getStatus());
Assert.assertNotNull(resEntity);
Assert.assertTrue(resEntity.contains("Invalid parameter"));
ff4j.delete("FWIP");
}
Aggregations