Search in sources :

Example 1 with FeatureApiBean

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

the class FeatureResourceGetTestIT method testGetRead.

/**
 * TDD.
 */
@Test
public void testGetRead() {
    // Given
    assertFF4J.assertThatFeatureExist(F4);
    // When
    WebResource wResf4 = resourceFeatures().path(F4);
    ClientResponse resHttp = wResf4.get(ClientResponse.class);
    FeatureApiBean resEntity = resHttp.getEntity(FeatureApiBean.class);
    // Then
    Assert.assertEquals("Expected status is 200", Status.OK.getStatusCode(), resHttp.getStatus());
    Assert.assertNotNull(resEntity);
    Assert.assertNotNull(F4, resEntity.getUid());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureApiBean(org.ff4j.web.api.resources.domain.FeatureApiBean) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 2 with FeatureApiBean

use of org.ff4j.web.api.resources.domain.FeatureApiBean 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 3 with FeatureApiBean

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

the class FeatureResource2GetTestIT method testGet_read.

/**
 * TDD.
 */
@Test
public void testGet_read() {
    // Given
    assertFF4J.assertThatFeatureExist(F4);
    // When
    WebTarget wResf4 = resourceFeatures().path(F4);
    Response resHttp = wResf4.request().get();
    FeatureApiBean resEntity = resHttp.readEntity(FeatureApiBean.class);
    // Then
    Assert.assertEquals("Expected status is 200", Status.OK.getStatusCode(), resHttp.getStatus());
    Assert.assertNotNull(resEntity);
    Assert.assertNotNull(F4, resEntity.getUid());
}
Also used : Response(javax.ws.rs.core.Response) FeatureApiBean(org.ff4j.web.api.resources.domain.FeatureApiBean) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 4 with FeatureApiBean

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

the class FeatureResource2PutCreateTestIT method testPut_upsertIfNotExistCreateIt.

/**
 * TDD.
 */
@Test
public void testPut_upsertIfNotExistCreateIt() {
    // Given
    assertFF4J.assertThatFeatureDoesNotExist(FEATURE_X);
    // When
    Feature f = new Feature(FEATURE_X);
    WebTarget webResFeat = resourceFeatures().path(FEATURE_X);
    Response res = // 
    webResFeat.request(// 
    MediaType.APPLICATION_JSON).put(Entity.entity(new FeatureApiBean(f), MediaType.APPLICATION_JSON), Response.class);
    // 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 : 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 5 with FeatureApiBean

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

the class FeatureResource2PutUpdateGroup1TestIT method testPut_upsertUpdateAddGroup.

/**
 * TDD, update by adding in the authorization
 */
@Test
public void testPut_upsertUpdateAddGroup() throws Exception {
    // Given
    assertFF4J.assertThatFeatureExist(F1);
    assertFF4J.assertThatFeatureNotInGroup(F1, "g2");
    // When
    Feature f1 = ff4j.getFeature(F1);
    f1.setGroup("g2");
    WebTarget webResFeat = resourceFeatures().path(F1);
    Response res = // 
    webResFeat.request(// 
    MediaType.APPLICATION_JSON).put(Entity.entity(new FeatureApiBean(f1), MediaType.APPLICATION_JSON), Response.class);
    // Then HTTPResponse
    Assert.assertEquals(Status.NO_CONTENT.getStatusCode(), res.getStatus());
    // Then Object Entity : null
    // Then
    assertFF4J.assertThatFeatureIsInGroup(F1, "g2");
}
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