use of org.ff4j.web.api.resources.domain.FeatureApiBean in project ff4j by ff4j.
the class FeatureResource2PutUpdateGroup2TestIT method testPut_upsertUpdateAddGroup.
/**
* TDD, update by adding in the authorization
*/
@Test
public void testPut_upsertUpdateAddGroup() {
// Given
assertFF4J.assertThatFeatureExist(F3);
assertFF4J.assertThatFeatureIsInGroup(F3, G1);
// When
Feature f3 = ff4j.getFeature(F3);
f3.setGroup("");
WebTarget webResFeat = resourceFeatures().path(F3);
Response res = //
webResFeat.request(//
MediaType.APPLICATION_JSON).put(Entity.entity(new FeatureApiBean(f3), MediaType.APPLICATION_JSON), Response.class);
// Then HTTPResponse
Assert.assertEquals(Status.NO_CONTENT.getStatusCode(), res.getStatus());
// Then Object Entity : null
// Then
assertFF4J.assertThatFeatureNotInGroup(F3, G1);
}
use of org.ff4j.web.api.resources.domain.FeatureApiBean in project ff4j by ff4j.
the class FeatureResourcePutCreateTestIT method testPutUpsertIfNotExistCreateIt.
/**
* TDD.
*/
@Test
public void testPutUpsertIfNotExistCreateIt() {
// Given
assertFF4J.assertThatFeatureDoesNotExist(FEATURE_X);
// When
Feature f = new Feature(FEATURE_X);
WebResource webResFeat = resourceFeatures().path(FEATURE_X);
ClientResponse res = //
webResFeat.type(//
MediaType.APPLICATION_JSON).put(ClientResponse.class, new FeatureApiBean(f));
// Then HTTPResponse
Assert.assertEquals(Status.CREATED.getStatusCode(), res.getStatus());
Assert.assertNotNull(res.getHeaders().getFirst(LOCATION));
// Then, testing target store
assertFF4J.assertThatFeatureExist(FEATURE_X);
res.close();
}
use of org.ff4j.web.api.resources.domain.FeatureApiBean in project ff4j by ff4j.
the class FeatureStoreHttp method update.
/**
* {@inheritDoc}
*/
@Override
public void update(Feature fp) {
Util.assertNotNull(fp);
if (!exist(fp.getUid())) {
throw new FeatureNotFoundException(fp.getUid());
}
ClientResponse cRes = //
getStore().path(fp.getUid()).type(MediaType.APPLICATION_JSON).put(ClientResponse.class, new FeatureApiBean(fp));
if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) {
throw new FeatureAccessException("Cannot update feature, an HTTP error " + cRes.getStatus() + OCCURED);
}
}
use of org.ff4j.web.api.resources.domain.FeatureApiBean in project ff4j by ff4j.
the class FeatureStoreResource method readFeatures.
@GET
@Path("/" + RESOURCE_FEATURES)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Display information regarding <b>Features</b>", response = FeatureApiBean.class)
@ApiResponses(@ApiResponse(code = 200, message = "get all features"))
public List<FeatureApiBean> readFeatures() {
Feature[] storeContent = getFeatureStore().readAll().values().toArray(new Feature[0]);
List<FeatureApiBean> apiBean = new ArrayList<FeatureApiBean>();
for (Feature feature : storeContent) {
apiBean.add(new FeatureApiBean(feature));
}
return apiBean;
}
use of org.ff4j.web.api.resources.domain.FeatureApiBean in project ff4j by ff4j.
the class FeatureResource2PutUpdateAuth1TestIT method testPut_upsertUpdateAddAuthorization.
/**
* TDD, update by adding in the authorization
*/
@Test
public void testPut_upsertUpdateAddAuthorization() {
// Given
assertFF4J.assertThatFeatureExist(F1);
ff4j.getFeatureStore().removeRoleFromFeature(F1, ROLE_NEW);
assertFF4J.assertThatFeatureHasNotRole(F1, ROLE_NEW);
// When
Feature fNew = ff4j.getFeature(F1);
fNew.getPermissions().add(ROLE_NEW);
WebTarget webResFeat = resourceFeatures().path(F1);
Response res = //
webResFeat.request(//
MediaType.APPLICATION_JSON).put(Entity.entity(new FeatureApiBean(fNew), MediaType.APPLICATION_JSON), Response.class);
// Then HTTPResponse
Assert.assertEquals(Status.NO_CONTENT.getStatusCode(), res.getStatus());
// Then Object Entity : null
// Then
assertFF4J.assertThatFeatureHasRole(F1, ROLE_NEW);
}
Aggregations