Search in sources :

Example 11 with FeatureApiBean

use of org.ff4j.web.api.resources.domain.FeatureApiBean in project ff4j by ff4j.

the class FeatureResource2PutUpdateAuth2TestIT method testPut_upsertUpdateRemoveAuthorization.

/**
 * TDD, update by adding in the authorization
 */
@Test
public void testPut_upsertUpdateRemoveAuthorization() {
    // Given
    assertFF4J.assertThatFeatureExist(F1);
    ff4j.getFeatureStore().grantRoleOnFeature(F1, ROLE_USER);
    assertFF4J.assertThatFeatureHasRole(F1, ROLE_USER);
    // When
    Feature fNew = ff4j.getFeature(F1);
    fNew.getPermissions().remove(ROLE_USER);
    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.assertThatFeatureHasNotRole(F1, ROLE_USER);
}
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 12 with FeatureApiBean

use of org.ff4j.web.api.resources.domain.FeatureApiBean in project ff4j by ff4j.

the class FeatureResourcePutUpdateAuth1TestIT method testPutUpsertUpdateAddAuthorization.

/**
 * TDD, update by adding in the authorization
 */
@Test
public void testPutUpsertUpdateAddAuthorization() {
    // 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);
    WebResource webResFeat = resourceFeatures().path(F1);
    ClientResponse res = // 
    webResFeat.type(// 
    MediaType.APPLICATION_JSON).put(ClientResponse.class, new FeatureApiBean(fNew));
    // Then HTTPResponse
    Assert.assertEquals(Status.NO_CONTENT.getStatusCode(), res.getStatus());
    // Then Object Entity : null
    // Then
    assertFF4J.assertThatFeatureHasRole(F1, ROLE_NEW);
}
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 13 with FeatureApiBean

use of org.ff4j.web.api.resources.domain.FeatureApiBean in project ff4j by ff4j.

the class FeatureResourcePutUpdateAuth2TestIT method testPutUpsertUpdateRemoveAuthorization.

/**
 * TDD, update by adding in the authorization
 */
@Test
public void testPutUpsertUpdateRemoveAuthorization() {
    // Given
    assertFF4J.assertThatFeatureExist(F1);
    ff4j.getFeatureStore().grantRoleOnFeature(F1, ROLE_USER);
    assertFF4J.assertThatFeatureHasRole(F1, ROLE_USER);
    // When
    Feature fNew = ff4j.getFeature(F1);
    fNew.getPermissions().remove(ROLE_USER);
    WebResource webResFeat = resourceFeatures().path(F1);
    ClientResponse res = // 
    webResFeat.type(// 
    MediaType.APPLICATION_JSON).put(ClientResponse.class, new FeatureApiBean(fNew));
    // Then HTTPResponse
    Assert.assertEquals(Status.NO_CONTENT.getStatusCode(), res.getStatus());
    // Then Object Entity : null
    // Then
    assertFF4J.assertThatFeatureHasNotRole(F1, ROLE_USER);
}
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 14 with FeatureApiBean

use of org.ff4j.web.api.resources.domain.FeatureApiBean in project ff4j by ff4j.

the class FeatureResourcePutUpdateGroup2TestIT method testPutUpsertUpdateAddGroup.

/**
 * TDD, update by adding in the authorization
 */
@Test
public void testPutUpsertUpdateAddGroup() {
    // Given
    assertFF4J.assertThatFeatureExist(F3);
    assertFF4J.assertThatFeatureIsInGroup(F3, G1);
    // When
    Feature f3 = ff4j.getFeature(F3);
    f3.setGroup("");
    WebResource webResFeat = resourceFeatures().path(F3);
    ClientResponse res = // 
    webResFeat.type(// 
    MediaType.APPLICATION_JSON).put(ClientResponse.class, toJson(new FeatureApiBean(f3)));
    // Then HTTPResponse
    Assert.assertEquals(Status.NO_CONTENT.getStatusCode(), res.getStatus());
    // Then Object Entity : null
    // Then
    assertFF4J.assertThatFeatureNotInGroup(F3, G1);
}
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 15 with FeatureApiBean

use of org.ff4j.web.api.resources.domain.FeatureApiBean in project ff4j by ff4j.

the class FeaturesResourceTestIT method testGet.

/**
 * TDD.
 */
@Test
public void testGet() {
    // Given
    // When
    WebResource wResFeatures = resourceFeatures();
    ClientResponse httpResponse = wResFeatures.get(ClientResponse.class);
    List<FeatureApiBean> fList = httpResponse.getEntity(new GenericType<List<FeatureApiBean>>() {
    });
    // Then, HTTPResponse
    Assert.assertEquals("Expected status is 200", Status.OK.getStatusCode(), httpResponse.getStatus());
    Assert.assertNotNull(fList);
    // Then, Entity Object
    Assert.assertFalse(fList.isEmpty());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureApiBean(org.ff4j.web.api.resources.domain.FeatureApiBean) WebResource(com.sun.jersey.api.client.WebResource) List(java.util.List) 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