Search in sources :

Example 11 with Feature

use of org.ff4j.core.Feature in project ff4j by ff4j.

the class FeatureResourcePutUpdateGroup1TestIT method testPutUpsertUpdateAddGroup.

/**
 * TDD, update by adding in the authorization
 */
@Test
public void testPutUpsertUpdateAddGroup() throws Exception {
    // Given
    assertFF4J.assertThatFeatureExist(AWESOME);
    assertFF4J.assertThatFeatureNotInGroup(AWESOME, "g2");
    // When
    Feature f1 = ff4j.getFeature(AWESOME);
    f1.setGroup("g2");
    WebResource webResFeat = resourceFeatures().path(AWESOME);
    ClientResponse res = // 
    webResFeat.type(// 
    MediaType.APPLICATION_JSON).put(ClientResponse.class, toJson(new FeatureApiBean(f1)));
    // Then HTTPResponse
    Assert.assertEquals(Status.NO_CONTENT.getStatusCode(), res.getStatus());
    // Then Object Entity : null
    // Then
    assertFF4J.assertThatFeatureIsInGroup(AWESOME, "g2");
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureApiBean(org.ff4j.web.api.resources.domain.FeatureApiBean) WebResource(com.sun.jersey.api.client.WebResource) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 12 with Feature

use of org.ff4j.core.Feature in project ff4j by ff4j.

the class GroupResourceTestIT method testGet_readGroup.

/**
 * TDD
 */
@Test
public void testGet_readGroup() {
    // Given
    assertFF4J.assertThatGroupExist(G1);
    assertFF4J.assertThatGroupHasSize(2, G1);
    assertFF4J.assertThatFeatureIsInGroup(F3, G1);
    assertFF4J.assertThatFeatureIsInGroup(F4, G1);
    // When
    WebResource wrsc = resourceGroups().path(G1);
    ClientResponse resHttp = wrsc.get(ClientResponse.class);
    String resEntity = resHttp.getEntity(String.class);
    // Then, HTTPResponse
    Assert.assertEquals("Expected status is 200", Status.OK.getStatusCode(), resHttp.getStatus());
    // Then, Entity Object
    Assert.assertNotNull(resEntity);
    Feature[] f = parseFeatureArray(resEntity);
    Set<String> features = new HashSet<String>();
    for (Feature feature : f) {
        features.add(feature.getUid());
    }
    Assert.assertEquals(2, features.size());
    Assert.assertTrue(features.contains(F3));
    Assert.assertTrue(features.contains(F4));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) Feature(org.ff4j.core.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with Feature

use of org.ff4j.core.Feature in project ff4j by ff4j.

the class FeatureJsonParserTest method testMarshaling.

@Test
public void testMarshaling() throws Exception {
    Map<String, Feature> features = ff4j.getFeatures();
    for (String key : features.keySet()) {
        // Check serialised
        assertMarshalling(features.get(key));
        Feature f1 = FeatureJsonParser.parseFeature(features.get(key).toJson());
        assertMarshalling(f1);
    }
}
Also used : Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 14 with Feature

use of org.ff4j.core.Feature in project ff4j by ff4j.

the class FeatureJsonParserTest method testSerialisation.

@Test
public void testSerialisation() {
    Feature[] features = { new Feature("f1"), new Feature("f2") };
    Assert.assertNotNull(FeatureJsonParser.featureArrayToJson(features));
    Assert.assertNotNull(FeatureJsonParser.featureArrayToJson(null));
}
Also used : Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 15 with Feature

use of org.ff4j.core.Feature in project ff4j by ff4j.

the class FeatureStoreCassandra method readAll.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, Feature> readAll() {
    Map<String, Feature> features = new HashMap<String, Feature>();
    ResultSet resultSet = conn.getSession().execute(getBuilder().selectAllFeatures());
    for (Row row : resultSet.all()) {
        Feature f = CassandraMapper.mapFeature(row);
        features.put(f.getUid(), f);
    }
    return features;
}
Also used : HashMap(java.util.HashMap) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) Feature(org.ff4j.core.Feature)

Aggregations

Feature (org.ff4j.core.Feature)258 Test (org.junit.Test)136 PropertyString (org.ff4j.property.PropertyString)49 HashMap (java.util.HashMap)29 HashSet (java.util.HashSet)29 PonderationStrategy (org.ff4j.strategy.PonderationStrategy)19 LinkedHashMap (java.util.LinkedHashMap)15 AbstractFf4jTest (org.ff4j.test.AbstractFf4jTest)14 Property (org.ff4j.property.Property)12 Set (java.util.Set)11 FeatureAccessException (org.ff4j.exception.FeatureAccessException)11 FeatureApiBean (org.ff4j.web.api.resources.domain.FeatureApiBean)11 XmlParser (org.ff4j.conf.XmlParser)10 InputStream (java.io.InputStream)9 Map (java.util.Map)9 FlippingStrategy (org.ff4j.core.FlippingStrategy)9 GroupNotFoundException (org.ff4j.exception.GroupNotFoundException)9 ClientResponse (com.sun.jersey.api.client.ClientResponse)8 ArrayList (java.util.ArrayList)8 Response (javax.ws.rs.core.Response)8