Search in sources :

Example 6 with FeatureApiBean

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);
}
Also used : Response(javax.ws.rs.core.Response) FeatureApiBean(org.ff4j.web.api.resources.domain.FeatureApiBean) WebTarget(javax.ws.rs.client.WebTarget) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Example 7 with FeatureApiBean

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();
}
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 8 with FeatureApiBean

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);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureAccessException(org.ff4j.exception.FeatureAccessException) FeatureApiBean(org.ff4j.web.api.resources.domain.FeatureApiBean) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException)

Example 9 with FeatureApiBean

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;
}
Also used : FeatureApiBean(org.ff4j.web.api.resources.domain.FeatureApiBean) ArrayList(java.util.ArrayList) Feature(org.ff4j.core.Feature) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 10 with FeatureApiBean

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);
}
Also used : Response(javax.ws.rs.core.Response) FeatureApiBean(org.ff4j.web.api.resources.domain.FeatureApiBean) WebTarget(javax.ws.rs.client.WebTarget) Feature(org.ff4j.core.Feature) Test(org.junit.Test)

Aggregations

FeatureApiBean (org.ff4j.web.api.resources.domain.FeatureApiBean)15 Test (org.junit.Test)13 Feature (org.ff4j.core.Feature)11 ClientResponse (com.sun.jersey.api.client.ClientResponse)8 WebResource (com.sun.jersey.api.client.WebResource)7 WebTarget (javax.ws.rs.client.WebTarget)6 Response (javax.ws.rs.core.Response)6 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 FeatureAccessException (org.ff4j.exception.FeatureAccessException)1 FeatureNotFoundException (org.ff4j.exception.FeatureNotFoundException)1