use of org.ff4j.core.FlippingExecutionContext 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.core.FlippingExecutionContext in project ff4j by ff4j.
the class ServerFilterStrategyTest method testFilterOK.
@Test
public void testFilterOK() throws ParseException {
// Given
Feature f1 = ff4j.getFeature(F1);
Assert.assertNotNull(f1.getFlippingStrategy());
ServerFilterStrategy cStra = (ServerFilterStrategy) 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(ServerFilterStrategy.SERVER_HOSTNAME, "dev01");
// Then
Assert.assertTrue(ff4j.check(F1, fex));
}
use of org.ff4j.core.FlippingExecutionContext in project ff4j by ff4j.
the class FF4jResource method checkPOST.
/**
* Check if feature if flipped
*
* @param formParams
* target custom params
* @return
* boolean if feature if flipped
*/
@POST
@Path("/" + OPERATION_CHECK + "/{uid}")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@ApiOperation(value = "<b>Advanced check</b> feature toggle (parameterized)", response = Boolean.class)
@ApiResponses({ @ApiResponse(code = 200, message = "if feature is flipped"), @ApiResponse(code = 400, message = "Invalid parameter") })
public Response checkPOST(@Context HttpHeaders headers, @PathParam("uid") String uid, MultivaluedMap<String, String> formParams) {
// HoldSecurity Context
FF4JSecurityContextHolder.save(securityContext);
if (!ff4j.getFeatureStore().exist(uid)) {
String errMsg = new FeatureNotFoundException(uid).getMessage();
return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build();
}
// Flipping Strategy may expected some dedicated parameters if not present, will return 400
FlippingExecutionContext flipExecCtx = new FlippingExecutionContext();
for (String key : formParams.keySet()) {
flipExecCtx.putString(key, formParams.getFirst(key));
}
try {
boolean flipped = ff4j.check(uid, flipExecCtx);
return Response.ok(String.valueOf(flipped)).build();
} catch (IllegalArgumentException iae) {
String errMsg = "Invalid parameter " + iae.getMessage();
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
}
}
Aggregations