Search in sources :

Example 6 with ClientFilterStrategy

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());
}
Also used : ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Feature(org.ff4j.core.Feature) Test(org.junit.Test) AbstractFf4jTest(org.ff4j.test.AbstractFf4jTest)

Example 7 with ClientFilterStrategy

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));
}
Also used : ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) BlackListStrategy(org.ff4j.strategy.BlackListStrategy) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) FlippingStrategy(org.ff4j.core.FlippingStrategy) WhiteListStrategy(org.ff4j.strategy.WhiteListStrategy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext) Test(org.junit.Test) AbstractFf4jTest(org.ff4j.test.AbstractFf4jTest)

Example 8 with ClientFilterStrategy

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");
}
Also used : Response(javax.ws.rs.core.Response) ClientFilterStrategy(org.ff4j.strategy.ClientFilterStrategy) Form(javax.ws.rs.core.Form) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Aggregations

ClientFilterStrategy (org.ff4j.strategy.ClientFilterStrategy)8 Test (org.junit.Test)8 Feature (org.ff4j.core.Feature)6 AbstractFf4jTest (org.ff4j.test.AbstractFf4jTest)6 FlippingExecutionContext (org.ff4j.core.FlippingExecutionContext)4 Form (javax.ws.rs.core.Form)2 Response (javax.ws.rs.core.Response)2 FlippingStrategy (org.ff4j.core.FlippingStrategy)1 InMemoryFeatureStore (org.ff4j.store.InMemoryFeatureStore)1 BlackListStrategy (org.ff4j.strategy.BlackListStrategy)1 WhiteListStrategy (org.ff4j.strategy.WhiteListStrategy)1