use of org.ff4j.web.api.resources.domain.GroupDescApiBean in project ff4j by ff4j.
the class FeatureStoreHttp method readAllGroups.
/**
* {@inheritDoc}
*/
@Override
public Set<String> readAllGroups() {
ClientResponse cRes = getGroups().get(ClientResponse.class);
List<GroupDescApiBean> groupApiBeans = cRes.getEntity(new GenericType<List<GroupDescApiBean>>() {
});
if (Status.OK.getStatusCode() != cRes.getStatus()) {
throw new FeatureAccessException("Cannot read groups, an HTTP error " + cRes.getStatus() + OCCURED);
}
Set<String> groupNames = new HashSet<String>();
for (GroupDescApiBean groupApiBean : groupApiBeans) {
groupNames.add(groupApiBean.getGroupName());
}
return groupNames;
}
use of org.ff4j.web.api.resources.domain.GroupDescApiBean in project ff4j by ff4j.
the class GroupsResourceGetTestIT method getGroups.
/**
* TDD.
*/
@Test
public void getGroups() {
// Given
Assert.assertEquals(2, ff4j.getFeatureStore().readAllGroups().size());
// When
WebResource wResff4j = resourceGroups();
ClientResponse resHttp = wResff4j.get(ClientResponse.class);
List<GroupDescApiBean> groupApiBeans = resHttp.getEntity(new GenericType<List<GroupDescApiBean>>() {
});
// Then, HTTPResponse
Assert.assertEquals("Expected status is 200", Status.OK.getStatusCode(), resHttp.getStatus());
// Then, Entity Object
Assert.assertNotNull(groupApiBeans);
Assert.assertEquals(2, groupApiBeans.size());
}
use of org.ff4j.web.api.resources.domain.GroupDescApiBean in project ff4j by ff4j.
the class FeatureStoreResource method readGroups.
/**
* Access groups part of the API.
*
* @return groups resource
*/
@GET
@Path("/" + RESOURCE_GROUPS)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Display information regarding <b>Groups</b>", response = GroupDescApiBean.class)
@ApiResponses({ @ApiResponse(code = 200, message = "Groups resource", response = GroupDescApiBean.class) })
public List<GroupDescApiBean> readGroups() {
Map<String, Feature> features = getFeatureStore().readAll();
Map<String, GroupDescApiBean> groups = new HashMap<String, GroupDescApiBean>();
if (features != null && !features.isEmpty()) {
// Build groups from features
for (Map.Entry<String, Feature> featureName : features.entrySet()) {
String groupName = featureName.getValue().getGroup();
// Add current group to list
if (groupName != null && !groupName.isEmpty()) {
if (!groups.containsKey(groupName)) {
groups.put(groupName, new GroupDescApiBean(groupName, new ArrayList<String>()));
}
groups.get(groupName).getFeatures().add(featureName.getKey());
}
}
}
return new ArrayList<GroupDescApiBean>(groups.values());
}
use of org.ff4j.web.api.resources.domain.GroupDescApiBean in project ff4j by ff4j.
the class GroupsResourceGetTestIT method getGroups.
/**
* TDD.
*/
@Test
public void getGroups() {
// Given
Assert.assertEquals(2, ff4j.getFeatureStore().readAllGroups().size());
// When
WebTarget wResFeatures = resourceGroups();
Response resHttp = wResFeatures.request().get();
List<GroupDescApiBean> groupApiBeans = resHttp.readEntity(new GenericType<List<GroupDescApiBean>>() {
});
// Then, HTTPResponse
Assert.assertEquals("Expected status is 200", Status.OK.getStatusCode(), resHttp.getStatus());
// Then, Entity Object
Assert.assertNotNull(groupApiBeans);
Assert.assertEquals(2, groupApiBeans.size());
}
Aggregations